/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Layout */
.container { max-width: 1280px; margin: 0 auto; padding: 0 1.5rem; }

main.container { flex: 1; padding-top: 2rem; padding-bottom: 3rem; }

/* Navbar */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-content { display: flex; align-items: center; justify-content: space-between; }
.navbar-brand { font-weight: 700; font-size: 1.25rem; color: var(--primary); text-decoration: none; }
.navbar-links { display: flex; align-items: center; gap: 1.25rem; }
.navbar-links a { color: var(--text-secondary); text-decoration: none; font-size: 0.9rem; }
.navbar-links a:hover { color: var(--primary); }
.admin-link { font-weight: 600; }

/* Footer */
.footer { border-top: 1px solid var(--border); padding: 1.5rem 0; text-align: center; color: var(--text-secondary); font-size: 0.85rem; }

/* Typography */
h1 { font-size: 1.75rem; margin-bottom: 0.5rem; }
h2 { font-size: 1.35rem; margin: 1.5rem 0 0.75rem; }
h3 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.subtitle { color: var(--text-secondary); margin-bottom: 1.5rem; }
.breadcrumb { margin-bottom: 1rem; }
.breadcrumb a { color: var(--primary); text-decoration: none; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-outline { background: transparent; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-link { background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 0.9rem; padding: 0; }
.btn-link:hover { color: var(--primary); }

/* Forms */
.form { max-width: 700px; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.25rem; font-size: 0.9rem; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--surface);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.inline-form { display: inline; }
.inline-form-row { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.5rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* Tables */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-weight: 600; font-size: 0.8rem; text-transform: uppercase; color: var(--text-secondary); background: var(--bg); }
.table td { font-size: 0.9rem; }
.table a { color: var(--primary); text-decoration: none; }
.table a:hover { text-decoration: underline; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--bg);
    border: 1px solid var(--border);
}
.badge-active, .badge-completed { background: #dcfce7; color: var(--success); border-color: #bbf7d0; }
.badge-exited, .badge-used { background: #f1f5f9; color: var(--text-secondary); }
.badge-rumored, .badge-pending { background: #fef3c7; color: var(--warning); border-color: #fde68a; }
.badge-running { background: #dbeafe; color: var(--primary); border-color: #bfdbfe; }
.badge-failed, .badge-expired { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.badge-telecom { background: #dbeafe; color: #1e40af; }
.badge-tech { background: #ede9fe; color: #5b21b6; }
.badge-media { background: #fce7f3; color: #9d174d; }
.badge-real_estate { background: #fef3c7; color: #92400e; }
.badge-education { background: #dcfce7; color: #166534; }
.badge-finance { background: #f0fdfa; color: #115e59; }
.badge-other { background: #f1f5f9; color: #475569; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }

/* Cards */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.detail-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.detail-card.full-width { grid-column: 1 / -1; }
.detail-card dl { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 1rem; }
.detail-card dt { font-weight: 500; color: var(--text-secondary); font-size: 0.85rem; }
.detail-card dd { font-size: 0.9rem; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; text-align: center; box-shadow: var(--shadow); }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--text-secondary); font-size: 0.85rem; }

.admin-nav { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* Auth */
.auth-container { max-width: 420px; margin: 3rem auto; }

/* Simulator */
.simulator-form { max-width: 100%; }
.results-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 2rem; margin-top: 1rem; }
.chart-container { max-width: 400px; }

/* Research */
.research-section { margin-top: 2rem; }
.research-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.research-meta { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.5rem; }
.research-content { white-space: pre-wrap; font-size: 0.9rem; line-height: 1.7; }

.form-section { margin-bottom: 1.5rem; }
.form-section summary { cursor: pointer; margin-bottom: 1rem; }
.form-section[open] form { margin-top: 1rem; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); max-width: 100%; }

.token-code { font-size: 0.8rem; background: var(--bg); padding: 0.15rem 0.4rem; border-radius: 4px; }
.token-full { word-break: break-all; user-select: all; }
.token-row { display: flex; align-items: center; gap: 0.5rem; }
.btn-copy { white-space: nowrap; flex-shrink: 0; }
.text-error { color: var(--danger); }
.empty-state { text-align: center; color: var(--text-secondary); padding: 3rem 1rem; }

/* Code input */
.code-input { font-size: 1.5rem; letter-spacing: 0.5em; text-align: center; font-family: monospace; }
.auth-footer { margin-top: 1.5rem; text-align: center; font-size: 0.9rem; }
.auth-footer a { color: var(--primary); text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }

/* Research Assistant */
.research-layout { display: flex; gap: 2rem; align-items: flex-start; }
.research-panel { flex: 1; }
.research-history { width: 280px; flex-shrink: 0; }

.research-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.research-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    box-shadow: var(--shadow);
}
.research-option:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(37,99,235,0.12); }
.research-option:disabled { opacity: 0.5; cursor: wait; }
.research-option-active { border-color: var(--primary); background: #eff6ff; }
.research-option-icon { font-size: 1.5rem; margin-bottom: 0.4rem; }
.research-option-label { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.2rem; }
.research-option-desc { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.4; }

.research-history-list { display: flex; flex-direction: column; gap: 0.25rem; }
.research-history-item {
    display: block;
    padding: 0.6rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s;
}
.research-history-item:hover { border-color: var(--primary); }
.research-history-title { display: block; font-size: 0.85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.research-history-date { font-size: 0.75rem; color: var(--text-secondary); }


/* Guide */
.guide-section { margin-top: 2rem; }
.guide-section .detail-card { margin-bottom: 1rem; }
.eligibility-badges { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.guide-note { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.5rem; }
.guide-content { font-size: 0.9rem; line-height: 1.7; }
.guide-content h2 { font-size: 1.1rem; margin-top: 1rem; }
.guide-content ol, .guide-content ul { padding-left: 1.5rem; margin: 0.5rem 0; }
.guide-content li { margin-bottom: 0.25rem; }

/* Plans */
.plan-card { margin-bottom: 1rem; }

/* News */
.news-list { display: flex; flex-direction: column; gap: 1rem; }
.news-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.news-card-header { margin-bottom: 0.5rem; }
.news-card-header h3 { font-size: 1rem; margin-bottom: 0.25rem; }
.news-meta { display: flex; align-items: center; gap: 0.75rem; font-size: 0.8rem; color: var(--text-secondary); flex-wrap: wrap; }
.news-source { font-weight: 500; }
.news-summary { font-size: 0.9rem; line-height: 1.6; margin-bottom: 0.5rem; }
.news-tags { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.news-tag { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 0.1rem 0.5rem; font-size: 0.7rem; color: var(--text-secondary); }
.news-link { font-size: 0.85rem; color: var(--primary); text-decoration: none; }
.news-link:hover { text-decoration: underline; }

/* Portraits gallery */
.portraits-gallery { display: flex; flex-direction: column; gap: 1rem; }
.portrait-card {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.portrait-card:hover { border-color: var(--primary); box-shadow: 0 2px 12px rgba(37,99,235,0.1); }
.portrait-avatar { flex-shrink: 0; }
.portrait-avatar img {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}
.portrait-initials {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 700;
}
.portrait-info { flex: 1; min-width: 0; }
.portrait-info h2 { font-size: 1.15rem; margin-bottom: 0.25rem; }
.portrait-bio { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; margin-bottom: 0.4rem; }
.portrait-stats { display: flex; gap: 2rem; flex-shrink: 0; text-align: center; }
.portrait-stat-value { display: block; font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.portrait-stat-label { display: block; font-size: 0.75rem; color: var(--text-secondary); }

@media (max-width: 768px) {
    .portrait-card { flex-direction: column; text-align: center; }
    .portrait-stats { justify-content: center; }
}

/* Price indicators */
.price-up { color: var(--success); font-weight: 600; }
.price-down { color: var(--danger); font-weight: 600; }

/* Angel badges in table */
.table .badge + .badge { margin-left: 0.25rem; }

/* Performance */
.perf-chart-wrap { position: relative; height: 400px; }

/* Description body */
.desc-body { font-size: 0.9rem; line-height: 1.7; }
.desc-body p { margin-bottom: 0.6rem; }

/* Markdown body (GitLab-style) */
.md-body {
    font-size: 0.92rem;
    line-height: 1.75;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow);
}
.md-body h1 { font-size: 1.5rem; margin: 1.5rem 0 0.75rem; padding-bottom: 0.4rem; border-bottom: 2px solid var(--border); }
.md-body h2 { font-size: 1.25rem; margin: 1.3rem 0 0.5rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--border); color: #334155; }
.md-body h3 { font-size: 1.05rem; margin: 1rem 0 0.4rem; color: #475569; }
.md-body h4 { font-size: 0.95rem; margin: 0.8rem 0 0.3rem; color: #475569; }
.md-body p { margin-bottom: 0.6rem; }
.md-body ul, .md-body ol { padding-left: 1.75rem; margin: 0.5rem 0 0.75rem; }
.md-body li { margin-bottom: 0.3rem; }
.md-body li > ul, .md-body li > ol { margin-top: 0.2rem; margin-bottom: 0; }
.md-body strong { color: #0f172a; }
.md-body em { color: #475569; }
.md-body a { color: var(--primary); text-decoration: none; }
.md-body a:hover { text-decoration: underline; }
.md-body blockquote { border-left: 4px solid var(--primary); margin: 0.75rem 0; padding: 0.5rem 1rem; background: #f8fafc; color: #475569; }
.md-body code { background: #f1f5f9; padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.85em; font-family: "SF Mono", Monaco, Consolas, monospace; }
.md-body pre { background: #1e293b; color: #e2e8f0; padding: 1rem; border-radius: var(--radius); overflow-x: auto; margin: 0.75rem 0; }
.md-body pre code { background: none; padding: 0; color: inherit; }
.md-body table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; }
.md-body th, .md-body td { padding: 0.5rem 0.75rem; border: 1px solid var(--border); font-size: 0.85rem; text-align: left; }
.md-body th { background: #f8fafc; font-weight: 600; color: #334155; }
.md-body tr:nth-child(even) { background: #fafbfc; }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.md-body img { max-width: 100%; border-radius: var(--radius); }

/* Responsive */
@media (max-width: 768px) {
    .form-row { grid-template-columns: 1fr; }
    .results-grid { grid-template-columns: 1fr; }
    .navbar-links { gap: 0.75rem; font-size: 0.85rem; }
    .research-layout { flex-direction: column; }
    .research-history { width: 100%; }
}
