/* ============================================================
   TraderCDC — Linear-inspired design system
   Dark-first, muted violet accent, refined density
   ============================================================ */

:root {
    --bg-base: #0a0a0b;
    --bg-surface: #131316;
    --bg-elevated: #1b1b1e;
    --bg-hover: #1f1f23;
    --bg-active: #25253a;
    --border: rgba(255,255,255,0.06);
    --border-strong: rgba(255,255,255,0.1);
    --text-primary: #ebebef;
    --text-secondary: #9b9ba7;
    --text-tertiary: #6b6b76;
    --text-quaternary: #5e5e68;
    --accent: #5e6ad2;
    --accent-hover: #6e7ae2;
    --accent-muted: rgba(94,106,210,0.15);
    --green: #4ade80;
    --green-muted: rgba(74,222,128,0.12);
    --red: #f87171;
    --red-muted: rgba(248,113,113,0.12);
    --yellow: #fbbf24;
    --yellow-muted: rgba(251,191,36,0.12);
    --purple: #a78bfa;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --font-mono: 'SF Mono', 'Cascadia Mono', 'Fira Code', ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0 }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 12px;
    background: var(--bg-base);
    color: var(--text-primary);
    padding: 0;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Header
   ============================================================ */
.header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: nowrap;
    position: sticky;
    top: 0;
    z-index: 20;
}
.header h1 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0 }
.dot.ok { background: var(--green) }
.dot.err { background: var(--red) }
.dot.warn { background: var(--yellow) }
.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: 0;
    padding-left: 10px;
    border-left: 1px solid var(--border-strong);
}
.meta {
    color: var(--text-tertiary);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    min-width: 180px;
    text-align: right;
}

/* ============================================================
   Tabs
   ============================================================ */
.tabs-row { display: flex; flex: 1; min-width: 0; align-items: center; position: relative }
.tabs { display: flex; gap: 2px; overflow: hidden; flex-wrap: nowrap; flex: 1; min-width: 0 }
.tabs-more {
    display: none;
    align-items: center;
    padding: 3px 8px 12px; /* extra bottom padding bridges gap to popup */
    margin-bottom: -12px; /* compensate so layout isn't affected */
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
    position: relative;
}
.tabs-more:hover { color: var(--text-primary) }
.tabs-more.visible { display: flex }
.tabs-overflow {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 30px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.2);
    z-index: 30;
    padding: 6px;
    flex-wrap: wrap;
    gap: 2px;
    max-width: 400px;
    min-width: 200px;
}
.tabs-more:hover .tabs-overflow { display: flex }
:root[data-theme="light"] .tabs-overflow {
    box-shadow: 0 8px 30px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
}
.tab-select {
    display: none;
    font-size: 12px;
    padding: 4px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    outline: none;
}
.tab {
    padding: 3px 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: 11px;
    font-weight: 500;
    transition: all 0.15s ease;
    letter-spacing: -0.01em;
}
.tab:hover { background: var(--bg-hover); color: var(--text-secondary) }
.tab.active {
    background: var(--accent-muted);
    border-color: rgba(94,106,210,0.25);
    color: #c4c8f5;
}
.tab-flash { animation: tabflash 1.5s ease-out }
@keyframes tabflash {
    0% { box-shadow: inset 0 0 0 1px rgba(74,222,128,0.4) }
    100% { box-shadow: none }
}

/* ============================================================
   Swap info panel
   ============================================================ */
.swap-info-wrap { margin: 0; border-bottom: 1px solid var(--border) }
.swap-info-toggle { display: none }
.swap-info {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    background: var(--bg-surface);
    font-size: 11px;
}
.swap-info-cell { padding: 6px 12px; border-right: 1px solid var(--border) }
.swap-info-cell:last-child { border-right: none }
.swap-info-cell .si-title {
    font-weight: 500;
    color: var(--text-tertiary);
    margin-bottom: 3px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.swap-info-cell .si-row { color: var(--text-secondary); white-space: nowrap; line-height: 1.6 }
.swap-info-cell .si-label { color: var(--text-quaternary); margin-right: 3px }
.swap-info-cell .si-val { font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: 11px }
.swap-info-cell .si-val.neg { color: var(--red) }
.swap-info-cell .si-subacc {
    display: inline; max-width: none; overflow: hidden; text-overflow: ellipsis;
    color: var(--text-tertiary); font-size: 10px;
}

/* ============================================================
   Traders table
   ============================================================ */
.traders-wrap { overflow-x: auto; padding: 0 }
table.traders { border-collapse: collapse; width: 100%; font-size: 11px; table-layout: fixed }
table.traders th {
    padding: 4px 6px;
    text-align: left;
    font-weight: 500;
    color: var(--text-quaternary);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
    cursor: default;
    position: sticky;
    top: 0;
    z-index: 1;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
table.traders th.sortable { cursor: pointer }
table.traders th.sortable:hover { color: var(--text-tertiary) }
table.traders th .sort-arrow { color: var(--text-quaternary); font-size: 8px; margin-left: 2px }
table.traders th.sorted .sort-arrow { color: var(--accent) }
table.traders td {
    padding: 3px 6px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono);
    font-size: 11px;
    border-bottom: 1px solid var(--border);
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-secondary);
}
table.traders td.neg { color: var(--red) }
table.traders td.na { color: var(--text-quaternary) }
table.traders td.name-cell {
    font-weight: 500;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    color: var(--text-primary);
}
table.traders tr:hover td { background: var(--bg-hover) }
table.traders tr.group-sep td {
    background: var(--accent-muted);
    font-weight: 600;
    color: #8b92d6;
    padding: 4px 12px;
    font-size: 11px;
    border-bottom: 1px solid rgba(94,106,210,0.15);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    letter-spacing: -0.01em;
    text-transform: none;
}
table.traders + table.traders { margin-top: 0 }
table.traders[data-group="swapfull"] td { padding: 4px 6px }
table.traders td .sub { font-size: 9px; color: var(--text-quaternary); line-height: 1 }
table.traders td.mpp-cell { position: relative; padding-bottom: 12px }
table.traders td .sub-br {
    position: absolute; bottom: 1px; right: 8px;
    font-size: 9px; color: var(--text-quaternary); line-height: 1;
}

/* Traffic column */
.traffic-cell { white-space: nowrap; font-size: 10px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif }
.traffic-circle { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--text-quaternary); vertical-align: middle }
.traffic-green { background: var(--green) }
.traffic-yellow { background: var(--yellow) }
.traffic-red { background: var(--red) }
.traffic-mint { color: var(--red); font-weight: 600; font-size: 9px }
.traffic-arrow { color: var(--red); font-weight: bold; font-size: 11px }
.traffic-timer { font-size: 10px; color: var(--text-tertiary) }
.timer-green { color: var(--green); font-size: 10px }
.timer-red { color: var(--red); font-size: 10px }
.timer-neutral { color: var(--text-tertiary); font-size: 10px }
.timer-purple { color: var(--purple); font-size: 11px }

/* Loading */
.traders-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-quaternary);
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.pulse {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--accent);
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8) }
    50% { opacity: 1; transform: scale(1.1) }
}
.empty {
    padding: 20px;
    text-align: center;
    color: var(--text-quaternary);
    font-size: 12px;
    width: 100%;
}

/* Flash animation */
.flash .val { animation: flash 1.5s ease-out }
@keyframes flash {
    0% { background: rgba(94,106,210,0.12) }
    30% { background: rgba(94,106,210,0.06) }
    100% { background: transparent }
}

/* ============================================================
   Footer
   ============================================================ */
.footer-wrap { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10 }
.footer-toggle { display: none }
.fields {
    display: flex;
    flex-wrap: wrap;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-strong);
}
.field {
    display: flex;
    flex-direction: column;
    align-items: center;
    border-right: 1px solid var(--border);
}
.field .lbl {
    padding: 1px 3px;
    font-size: 8px;
    color: var(--text-quaternary);
    background: var(--bg-surface);
    white-space: nowrap;
    width: 100%;
    text-align: center;
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 500;
}
.field .lbl .chart { color: var(--text-quaternary); margin-right: 2px; vertical-align: middle; cursor: pointer }
.field .lbl .chart:hover { color: var(--accent) }
.field .val {
    padding: 1px 3px;
    font-size: 10px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono);
    white-space: nowrap;
    width: 100%;
    text-align: center;
    background: var(--bg-base);
    min-height: 15px;
}
.field .val.neg { color: var(--red) }
.field .val.na { color: var(--text-quaternary) }
.field .val.ovh-red { color: var(--red); font-weight: 600 }
.field .val.ovh-orange { color: #fb923c; font-weight: 600 }
.field .val.ovh-yellow { color: var(--yellow); font-weight: 600 }
.field .val.ovh-cell { font-weight: 600 }
.sep { width: 1px; background: var(--border-strong); align-self: stretch; flex-shrink: 0 }
.rates-inline { display: inline-flex; gap: 0 }
.rates-inline span { padding: 0 2px; border-right: 1px solid var(--border); font-size: 9px }
.rates-inline span:last-child { border-right: none }

/* ============================================================
   Settings panel
   ============================================================ */
.settings-wrap { position: relative; flex-shrink: 0 }
.settings-btn {
    cursor: pointer;
    color: var(--text-quaternary);
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}
.settings-btn:hover { background: var(--bg-hover); color: var(--text-tertiary) }
.settings-panel {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 30px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.2);
    z-index: 20;
    min-width: 160px;
    padding: 0;
    user-select: none;
    overflow: hidden;
}
.settings-title {
    padding: 8px 12px 6px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-quaternary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}
.settings-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    transition: background 0.1s;
}
.settings-row:hover { background: var(--bg-hover) }
.settings-icon { display: flex; align-items: center; color: var(--text-quaternary) }
.settings-label { flex: 1 }

/* ============================================================
   Light theme overrides
   ============================================================ */
:root[data-theme="light"] {
    --bg-base: #f9f9fb;
    --bg-surface: #ffffff;
    --bg-elevated: #ffffff;
    --bg-hover: #f3f3f6;
    --bg-active: #eeeef5;
    --border: rgba(0,0,0,0.06);
    --border-strong: rgba(0,0,0,0.1);
    --text-primary: #1a1a1e;
    --text-secondary: #5a5a65;
    --text-tertiary: #5a5a65;
    --text-quaternary: #4a4a55;
    --accent: #5e6ad2;
    --accent-hover: #4e5ac2;
    --accent-muted: rgba(94,106,210,0.08);
    --green: #16a34a;
    --green-muted: rgba(22,163,74,0.08);
    --red: #dc2626;
    --red-muted: rgba(220,38,38,0.08);
    --yellow: #ca8a04;
    --yellow-muted: rgba(202,138,4,0.08);
    --purple: #7c3aed;
}
:root[data-theme="light"] .tab.active { color: var(--accent) }
:root[data-theme="light"] table.traders tr.group-sep td { color: var(--accent) }
:root[data-theme="light"] .settings-panel {
    box-shadow: 0 8px 30px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
}
:root[data-theme="light"] .footer-toggle {
    background: var(--bg-surface);
    border-top-color: var(--border-strong);
    color: var(--text-tertiary);
}
:root[data-theme="light"] .swap-info-toggle {
    background: var(--bg-surface);
    border-color: var(--border-strong);
    color: var(--text-tertiary);
}

/* ============================================================
   Mobile responsive
   ============================================================ */
@media (max-width: 768px) {
    .tabs { display: none !important }
    .tab-select { display: block; flex: 1; min-width: 0 }

    table.traders { table-layout: auto }
    table.traders col { width: auto !important }
    .traders-wrap { -webkit-overflow-scrolling: touch }

    .footer-toggle {
        display: flex; align-items: center; gap: 4px;
        padding: 6px 12px; font-size: 11px; font-weight: 500;
        color: var(--text-tertiary); background: var(--bg-surface);
        border-top: 1px solid var(--border-strong);
        cursor: pointer; user-select: none;
    }
    .footer-wrap.collapsed .fields { display: none }
    .footer-wrap:not(.collapsed) .fields { display: flex }

    body { padding: 0 0 28px }
    .header { gap: 6px; padding: 6px 8px }
    .header h1 { font-size: 12px }
    .meta { font-size: 10px }
    table.traders tr.group-sep td { font-size: 10px; padding: 3px 8px }

    .swap-info-toggle {
        display: flex; align-items: center; gap: 4px;
        padding: 6px 12px; font-size: 11px; font-weight: 500;
        color: var(--text-tertiary); background: var(--bg-surface);
        border: 1px solid var(--border-strong);
        border-radius: var(--radius-sm) var(--radius-sm) 0 0;
        cursor: pointer; user-select: none;
    }
    .swap-info-wrap.collapsed .swap-info { display: none }
    .swap-info-wrap.collapsed .swap-info-toggle { border-radius: var(--radius-sm) }
    .swap-info-wrap:not(.collapsed) .swap-info { border-top: none }
    .swap-info { grid-template-columns: repeat(2, 1fr); font-size: 10px }
    .swap-info-cell { padding: 4px 8px }
    .swap-info-cell .si-subacc {
        display: inline-block; max-width: 80px; overflow: hidden;
        text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
    }
}
