/* MarketTracker Dashboard — Financial Terminal Dark Theme */
:root {
    --bg-primary: #0c0f14;
    --bg-secondary: #12161c;
    --bg-card: #181c24;
    --bg-hover: #1e2330;
    --border: #2a3040;
    --text-primary: #e0e4ec;
    --text-secondary: #8892a4;
    --text-muted: #5a6478;
    --accent-green: #00c853;
    --accent-red: #ff3d4f;
    --accent-blue: #4d8af0;
    --accent-yellow: #ffb300;
    --accent-cyan: #00bcd4;
    --sidebar-width: 220px;
    --detail-width: 420px;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}
.sidebar-brand {
    padding: 20px 18px 24px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.brand-icon { color: var(--accent-green); font-size: 20px; }
.brand-text { font-size: 15px; font-weight: 700; letter-spacing: .5px; }
.nav-menu { list-style: none; padding: 12px 0; flex: 1; }
.nav-item {
    padding: 10px 18px; cursor: pointer; font-size: 13px; color: var(--text-secondary);
    display: flex; align-items: center; gap: 10px; transition: all .15s;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--bg-hover); color: var(--text-primary); border-left-color: var(--accent-green); }
.nav-icon { font-size: 16px; }
.sidebar-footer { padding: 14px 18px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted); }

/* Main */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1; padding: 28px 32px; overflow-y: auto; min-height: 100vh;
    transition: margin-right .25s;
}
.main-content.shifted { margin-right: var(--detail-width); }

.page { display: none; }
.page.active { display: block; }
.page-title {
    font-size: 22px; font-weight: 700; margin-bottom: 24px;
    padding-bottom: 12px; border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 28px; }
.kpi-card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 20px;
}
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 28px; font-weight: 700; font-family: var(--font-mono); color: var(--text-primary); }
.kpi-sub { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* Charts */
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.chart-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.chart-card h3 { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 14px; }
.chart-card canvas { max-height: 280px; }

/* Snapshot Selector */
.snapshot-selector {
    display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px;
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px;
}
.snapshot-selector select {
    background: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border);
    padding: 8px 12px; border-radius: var(--radius); font-family: var(--font-mono); font-size: 12px;
    min-width: 280px; cursor: pointer;
}
.snapshot-info { font-size: 12px; color: var(--text-secondary); margin-left: 16px; display: flex; align-items: center; }

/* Toolbar */
.toolbar {
    display: flex; gap: 8px; margin-bottom: 12px; align-items: center;
}
.toolbar input {
    background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border);
    padding: 8px 12px; border-radius: var(--radius); font-size: 13px; width: 260px;
}
.toolbar input::placeholder { color: var(--text-muted); }
.toolbar button {
    background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border);
    padding: 8px 14px; border-radius: var(--radius); cursor: pointer; font-size: 12px;
    transition: background .15s;
}
.toolbar button:hover { background: var(--bg-hover); }
.toolbar .btn-export { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }
.toolbar .btn-export:hover { opacity: .85; }
.toolbar select { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); padding: 8px 12px; border-radius: var(--radius); font-size: 12px; }

/* Table */
.table-container { overflow-x: auto; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead { position: sticky; top: 0; z-index: 2; }
th {
    background: var(--bg-secondary); padding: 10px 12px; text-align: left; font-weight: 600;
    color: var(--text-muted); border-bottom: 2px solid var(--border); white-space: nowrap;
    cursor: pointer; user-select: none; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
}
th:hover { color: var(--text-primary); }
th .sort-arrow { margin-left: 4px; opacity: .4; }
th.sorted .sort-arrow { opacity: 1; color: var(--accent-blue); }
tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tr:hover { background: var(--bg-hover); }
tr.clickable { cursor: pointer; }
td { padding: 8px 12px; white-space: nowrap; }
td.num { font-family: var(--font-mono); text-align: right; }
td.positive { color: var(--accent-green); }
td.negative { color: var(--accent-red); }
td.symbol { font-weight: 700; color: var(--accent-cyan); }
.pagination {
    display: flex; justify-content: center; align-items: center; gap: 6px;
    padding: 12px; border-top: 1px solid var(--border); font-size: 12px;
}
.pagination button {
    background: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border);
    padding: 6px 12px; border-radius: var(--radius); cursor: pointer; font-size: 12px;
}
.pagination button:hover { background: var(--bg-hover); }
.pagination button:disabled { opacity: .3; cursor: default; }
.pagination span { color: var(--text-secondary); padding: 0 8px; }

/* Detail Panel */
.detail-panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: var(--detail-width); background: var(--bg-secondary);
    border-left: 1px solid var(--border); z-index: 200;
    transform: translateX(100%); transition: transform .25s ease;
    overflow-y: auto; display: flex; flex-direction: column;
}
.detail-panel.open { transform: translateX(0); }
.detail-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.detail-header h3 { font-size: 16px; font-weight: 700; }
.detail-close {
    background: none; border: none; color: var(--text-muted); font-size: 18px;
    cursor: pointer; padding: 4px 8px; border-radius: 4px;
}
.detail-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.detail-body { padding: 16px 20px; flex: 1; }
.detail-section { margin-bottom: 20px; }
.detail-section h4 {
    font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
    color: var(--text-muted); margin-bottom: 10px; padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.detail-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13px; }
.detail-row .key { color: var(--text-secondary); }
.detail-row .value { font-family: var(--font-mono); color: var(--text-primary); }
.detail-row .value.positive { color: var(--accent-green); }
.detail-row .value.negative { color: var(--accent-red); }
.overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 150;
    display: none; transition: opacity .25s;
}
.overlay.show { display: block; }

/* Summary */
.summary-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.summary-card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px;
}
.summary-card h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 8px; }
.summary-card .card-val { font-size: 20px; font-weight: 700; font-family: var(--font-mono); }
.summary-card.full-width { grid-column: span 2; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; }
.stat-card h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .stat-row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 12px; font-family: var(--font-mono); }
.stat-card .stat-row .lbl { color: var(--text-secondary); }
.stat-card .stat-row .val { color: var(--text-primary); }

.top-lists { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-top: 20px; }
.top-list { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.top-list h4 { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 10px; }
.top-list ol { padding-left: 20px; font-size: 12px; line-height: 1.8; }
.top-list ol li { color: var(--text-primary); font-family: var(--font-mono); }

/* BingX Coin-M */
.bingx-status {
    padding: 12px 16px; margin-bottom: 18px; font-size: 12px;
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text-secondary); font-family: var(--font-mono);
}
.bingx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.bingx-symbol-card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 20px;
}
.bingx-symbol-header {
    display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px;
}
.bingx-symbol-name { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.bingx-symbol-price { font-size: 20px; font-weight: 700; font-family: var(--font-mono); color: var(--text-primary); }
.bingx-symbol-change { font-size: 12px; font-family: var(--font-mono); }
.bingx-symbol-change.positive { color: var(--accent-green); }
.bingx-symbol-change.negative { color: var(--accent-red); }
.bingx-symbol-stats {
    display: flex; gap: 16px; font-size: 11px; color: var(--text-muted); margin-bottom: 12px;
    font-family: var(--font-mono);
}
.bingx-chart-wrap { height: 80px; width: 100%; }

/* Responsive */
@media (max-width: 1200px) {
    .chart-row { grid-template-columns: 1fr; }
    .summary-grid { grid-template-columns: 1fr; }
    .top-lists { grid-template-columns: 1fr; }
    .bingx-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .sidebar { width: 180px; }
    :root { --sidebar-width: 180px; }
    .main-content { padding: 16px; }
    .detail-panel { width: 320px; }
    :root { --detail-width: 320px; }
}

.type-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 700;
    font-family: var(--font-mono);
}
.type-badge.type-c { background: rgba(0, 200, 83, 0.15); color: var(--accent-green); }
.type-badge.type-p { background: rgba(255, 61, 79, 0.15); color: var(--accent-red); }

/* Market Leaders KPI */
.leaders-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 28px;
}
.leader-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.leader-card .leader-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.leader-card .leader-header .period-icon { font-size: 14px; }
.leader-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.leader-item:last-child { border-bottom: none; }
.leader-item:hover { background: var(--bg-hover); margin: 0 -18px; padding: 10px 18px; border-radius: 4px; }
.leader-item .leader-rank {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent-yellow);
    margin-bottom: 2px;
}
.leader-item .leader-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.leader-item .leader-total {
    font-size: 13px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.leader-bar-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-family: var(--font-mono);
    margin: 2px 0;
}
.leader-bar-row .bar-label { width: 28px; text-align: right; color: var(--text-muted); }
.leader-bar-row .bar-value { width: 60px; text-align: right; color: var(--text-secondary); }

/* Progress bars */
.progress-bar-wrap {
    flex: 1;
    height: 6px;
    background: rgba(255,255,255,0.05);
    border-radius: 3px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
}
.progress-bar-call { background: var(--accent-green); }
.progress-bar-put { background: var(--accent-red); }

/* Large progress bar for expanded panel */
.progress-large {
    height: 10px;
    border-radius: 5px;
    margin: 4px 0;
}
.progress-large .progress-bar-fill { border-radius: 5px; }

/* Remaining Days column */
.remaining-days { font-family: var(--font-mono); font-weight: 600; text-align: center; }
.days-urgent { color: var(--accent-yellow); }
.days-critical { color: var(--accent-red); }

/* Expandable rows */
tr.expandable { cursor: pointer; }
tr.expandable.expanded { background: var(--bg-hover); }
tr.expanded-row-detail { background: var(--bg-secondary); }
tr.expanded-row-detail td {
    padding: 0;
    border-bottom: 2px solid var(--accent-blue);
}
.expanded-panel {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.35s ease;
}
.expanded-panel.open { max-height: 2000px; }
.expanded-panel-inner {
    padding: 16px 20px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.expanded-section h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}
.expanded-section .warrant-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
    font-size: 12px;
}
.expanded-section .warrant-info-grid .wkey { color: var(--text-muted); }
.expanded-section .warrant-info-grid .wval { font-family: var(--font-mono); color: var(--text-primary); text-align: right; }
.expanded-section .mf-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 12px;
    font-family: var(--font-mono);
}
.expanded-section .mf-label { width: 20px; color: var(--text-muted); }
.expanded-section .mf-pct { width: 40px; text-align: right; font-weight: 600; }
.expanded-section .mf-val { width: 80px; text-align: right; color: var(--text-secondary); }
.expanded-section .mf-period-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 8px 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.mf-call { color: var(--accent-green); }
.mf-put { color: var(--accent-red); }

/* Analytics period grid in expanded panel */
.analytics-periods {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

@media (max-width: 1200px) {
    .leaders-section { grid-template-columns: 1fr; }
    .expanded-panel-inner { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .leaders-section { grid-template-columns: 1fr; }
}

/* Dashboard Embedded Table Section */
.ds-table-section {
    margin-top: 20px;
}
.ds-table-section .ds-table-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    align-items: center;
}
.ds-table-section .ds-table-toolbar input {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    width: 260px;
}
.ds-table-section .ds-table-toolbar input::placeholder {
    color: var(--text-muted);
}
.ds-table-section .ds-table-toolbar button {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    transition: background 0.15s;
}
.ds-table-section .ds-table-toolbar button:hover {
    background: var(--bg-hover);
}
.ds-table-section .ds-table-toolbar #dsBtnCSV,
.ds-table-section .ds-table-toolbar #dsBtnJSON {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #fff;
}
.ds-table-section .ds-table-toolbar #dsBtnCSV:hover,
.ds-table-section .ds-table-toolbar #dsBtnJSON:hover {
    opacity: 0.85;
}
.ds-table-section .ds-table-toolbar select {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 12px;
}
.ds-table-section .ds-table-toolbar .snapshot-info {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 8px;
}
