:root {
    --bg-base: #090d16;
    --bg-surface: #111827;
    --bg-elevated: #172033;
    --bg-hover: #1e293b;
    --border-subtle: rgba(148, 163, 184, 0.14);
    --border-strong: rgba(148, 163, 184, 0.28);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --gold: #f59e0b;
    --gold-soft: rgba(245, 158, 11, 0.14);
    --cyan: #38bdf8;
    --cyan-soft: rgba(56, 189, 248, 0.14);
    /* Taiwan Stock Convention: Red = Up, Green = Down */
    --tw-up: #f43f5e;
    --tw-up-soft: rgba(244, 63, 94, 0.15);
    --tw-down: #10b981;
    --tw-down-soft: rgba(16, 185, 129, 0.15);
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: radial-gradient(circle at 12% 0%, rgba(245, 158, 11, 0.08), transparent 36%),
                radial-gradient(circle at 88% 8%, rgba(56, 189, 248, 0.08), transparent 36%),
                var(--bg-base);
    color: var(--text-primary);
    font-family: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

.mono {
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
    font-variant-numeric: tabular-nums;
}

/* Navbar */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: rgba(9, 13, 22, 0.88);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border-subtle);
}

.nav-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.7rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    text-decoration: none;
    color: var(--text-primary);
    flex-shrink: 0;
}

.brand-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(245, 158, 11, 0.65);
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.25);
}

.brand-title {
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    background: linear-gradient(90deg, #fde68a, #f59e0b, #38bdf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-sub {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1;
}

/* Global Search */
.search-wrap {
    position: relative;
    flex: 1 1 280px;
    max-width: 460px;
}

.search-input {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    border-radius: 999px;
    padding: 0.52rem 1rem 0.52rem 2.4rem;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.16);
}

.search-icon {
    position: absolute;
    left: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #131c2e;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
    max-height: 360px;
    overflow-y: auto;
    display: none;
    z-index: 1050;
}

.search-dropdown.show { display: block; }

.search-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.65rem 0.95rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-subtle);
    text-decoration: none;
    color: var(--text-primary);
}

.search-item:last-child { border-bottom: none; }
.search-item:hover, .search-item.active { background: var(--bg-hover); }

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: auto;
}

.nav-pill {
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 600;
    transition: all 0.18s ease;
    border: 1px solid transparent;
}

.nav-pill:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

.nav-pill.active {
    color: #fde68a;
    background: var(--gold-soft);
    border-color: rgba(245, 158, 11, 0.35);
}

/* Main Container */
.main-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.25rem;
    flex: 1;
}

/* Panels & Cards */
.panel {
    background: rgba(17, 24, 39, 0.86);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.15rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}

.panel-title {
    font-size: 0.98rem;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.text-up { color: var(--tw-up) !important; }
.text-down { color: var(--tw-down) !important; }
.text-gold { color: var(--gold) !important; }
.text-cyan { color: var(--cyan) !important; }
.text-soft { color: var(--text-secondary) !important; }

/* Signal Borders */
.accent-top-red { border-top: 3px solid var(--tw-up); }
.accent-top-green { border-top: 3px solid var(--tw-down); }
.accent-top-gold { border-top: 3px solid var(--gold); }
.accent-top-cyan { border-top: 3px solid var(--cyan); }

/* Badges & Chips */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.22rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    white-space: nowrap;
}

.chip-up { background: var(--tw-up-soft); border-color: rgba(244, 63, 94, 0.35); color: #fda4af; }
.chip-down { background: var(--tw-down-soft); border-color: rgba(16, 185, 129, 0.35); color: #6ee7b7; }
.chip-gold { background: var(--gold-soft); border-color: rgba(245, 158, 11, 0.4); color: #fde68a; }
.chip-cyan { background: var(--cyan-soft); border-color: rgba(56, 189, 248, 0.35); color: #7dd3fc; }

.concept-tile {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.75rem;
    cursor: pointer;
    transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
    color: var(--text-primary);
    text-align: left;
    width: 100%;
}

.concept-tile:hover {
    transform: translateY(-1px);
    border-color: rgba(245, 158, 11, 0.55);
    background: var(--bg-hover);
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.88rem;
}

.data-table thead th {
    background: rgba(23, 32, 51, 0.9);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
}

.data-table tbody td {
    padding: 0.72rem 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background 0.15s ease;
}

.data-table tbody tr:hover {
    background: rgba(30, 41, 59, 0.65);
}

/* Custom Tabs */
.ds-tabs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}

.ds-tab-btn {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.18s ease;
}

.ds-tab-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.ds-tab-btn.active {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.22), rgba(56, 189, 248, 0.18));
    border-color: rgba(245, 158, 11, 0.55);
    color: #fff;
}

/* KPI Grid */
.kpi-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
}

.kpi-label {
    font-size: 0.76rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.kpi-value {
    font-size: 1.4rem;
    font-weight: 800;
}

/* Rank Progress Bar */
.rank-bar {
    height: 8px;
    background: #1e293b;
    border-radius: 999px;
    overflow: hidden;
    min-width: 72px;
}

.rank-fill {
    height: 100%;
    border-radius: 999px;
}

/* ECharts Container */
.chart-stage {
    width: 100%;
    height: 680px;
}

.chart-stage.fullscreen {
    position: fixed;
    inset: 0;
    height: 100vh;
    z-index: 2000;
    background: var(--bg-base);
    padding: 1rem;
}

/* Gem Report Markdown Styling */
.gem-markdown {
    line-height: 1.75;
    font-size: 0.95rem;
    color: #e2e8f0;
}

.gem-markdown h1, .gem-markdown h2, .gem-markdown h3 {
    color: #fde68a;
    margin-top: 1.25rem;
    margin-bottom: 0.6rem;
    font-weight: 700;
}

.gem-markdown h2 { font-size: 1.2rem; border-bottom: 1px solid var(--border-subtle); padding-bottom: 0.4rem; }
.gem-markdown h3 { font-size: 1.05rem; color: #7dd3fc; }
.gem-markdown ul, .gem-markdown ol { padding-left: 1.35rem; }
.gem-markdown li { margin-bottom: 0.35rem; }
.gem-markdown blockquote {
    border-left: 3px solid var(--gold);
    background: var(--gold-soft);
    padding: 0.75rem 1rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin: 1rem 0;
}
.gem-markdown table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.86rem;
    display: block;
    overflow-x: auto;
}
.gem-markdown th, .gem-markdown td {
    border: 1px solid var(--border-strong);
    padding: 0.5rem 0.7rem;
    text-align: left;
}
.gem-markdown th { background: var(--bg-elevated); color: #fde68a; }
.gem-markdown code {
    background: rgba(56, 189, 248, 0.14);
    color: #7dd3fc;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
}

/* Gem Mode Selector Buttons */
.gem-mode-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.9rem;
    cursor: pointer;
    transition: all 0.18s ease;
    text-align: left;
    color: var(--text-primary);
    width: 100%;
    height: 100%;
}

.gem-mode-card:hover {
    border-color: rgba(245, 158, 11, 0.6);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.gem-mode-card.active {
    border-color: var(--gold);
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.14), rgba(23, 32, 51, 0.95));
}

/* Footer */
.site-footer {
    margin-top: 2.5rem;
    border-top: 1px solid var(--border-subtle);
    background: rgba(11, 16, 27, 0.95);
    padding: 1.5rem 1.25rem;
}

.footer-inner {
    max-width: 1400px;
    margin: 0 auto;
}

.social-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    transition: border-color 0.15s, background 0.15s;
}

.social-pill:hover {
    border-color: var(--gold);
    color: #fde68a;
}

.disclaimer-box {
    margin-top: 1rem;
    font-size: 0.76rem;
    color: var(--text-muted);
    line-height: 1.6;
}

/* Toast Notification */
.toast-banner {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 2100;
    background: #1e293b;
    border: 1px solid var(--gold);
    color: #fff;
    padding: 0.75rem 1.1rem;
    border-radius: var(--radius-md);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    display: none;
    font-size: 0.88rem;
}

@media (max-width: 768px) {
    .nav-inner { padding: 0.6rem 0.85rem; }
    .main-container { padding: 0.85rem; }
    .chart-stage { height: 540px; }
    .search-wrap { order: 3; flex: 1 1 100%; max-width: none; }
}
