.desk-toggle {
    display: flex;
    gap: 0.5rem;
    margin: 0 0 1rem;
    padding: 0.25rem;
    background: rgba(49, 38, 24, 0.08);
    border-radius: 0.75rem;
    width: fit-content;
}
.desk-tab {
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.5rem 1.1rem;
    border: none;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--text-soft);
    cursor: pointer;
    transition: background 120ms ease-out, color 120ms ease-out, transform 120ms ease-out;
}
.desk-tab:hover { color: var(--text); }
.desk-tab:active { transform: scale(0.96); transition-duration: 60ms; }
.desk-tab.active {
    background: var(--text);
    color: var(--surface-strong);
}

:root {
    --bg: #ebe5dc;
    --surface: rgba(255, 251, 245, 0.94);
    --surface-strong: #fffdfa;
    --surface-alt: #f3eadc;
    --border: rgba(49, 38, 24, 0.16);
    --border-strong: rgba(49, 38, 24, 0.3);
    --text: #17120d;
    --text-soft: #4f4130;
    --text-muted: #70614f;
    --accent: #91511d;
    --accent-soft: rgba(145, 81, 29, 0.14);
    --accent-strong: #4b2408;
    --success: #0b7a4c;
    --success-soft: #e6f5ed;
    --danger: #b23d22;
    --danger-soft: #fdebe5;
    --warning: #9d5b06;
    --warning-soft: #f9ecd7;
    --info: #234f7d;
    --info-soft: #e8f0f8;
    --shadow: 0 22px 54px rgba(57, 39, 14, 0.12);
    --radius-xl: 30px;
    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --font-body: "Space Grotesk", sans-serif;
    --font-mono: "IBM Plex Mono", monospace;
    --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --t-fast: 80ms var(--ease-out);
    --t-base: 140ms var(--ease-out);
    --t-slow: 250ms var(--ease-out);
    color-scheme: light;
}

body[data-mode="crypto"] {
    --bg: #e2ece5;
    --surface: rgba(247, 252, 248, 0.94);
    --surface-strong: #ffffff;
    --surface-alt: #edf5ef;
    --border: rgba(20, 48, 32, 0.16);
    --border-strong: rgba(20, 48, 32, 0.28);
    --text: #0d1912;
    --text-soft: #355240;
    --text-muted: #587262;
    --accent: #186a4b;
    --accent-soft: rgba(24, 106, 75, 0.14);
    --accent-strong: #103826;
    --shadow: 0 24px 60px rgba(18, 43, 29, 0.1);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 15px;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-body);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-kerning: normal;
    background:
        radial-gradient(circle at top left, rgba(255, 180, 92, 0.2), transparent 28%),
        radial-gradient(circle at top right, rgba(55, 101, 181, 0.1), transparent 24%),
        linear-gradient(180deg, #f7f2ea 0%, var(--bg) 56%, #ddd3c5 100%);
}

body[data-mode="crypto"] {
    background:
        radial-gradient(circle at top left, rgba(84, 179, 129, 0.2), transparent 28%),
        radial-gradient(circle at top right, rgba(28, 77, 58, 0.12), transparent 24%),
        linear-gradient(180deg, #f6fbf6 0%, var(--bg) 56%, #d4e1d7 100%);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.13) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.13) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.3), transparent 70%);
}

h1,
h2,
p {
    margin: 0;
}

h1,
h2 {
    text-wrap: balance;
}

::selection {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.page-shell {
    width: min(1360px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 24px 0 36px;
}

.hero,
.mode-card,
.kpi-card,
.panel {
    backdrop-filter: blur(18px);
}

.hero {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 20px;
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.hero-copy {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.eyebrow,
.kpi-label,
.filter-label,
.meta-label,
.metric-label,
.detail-label {
    text-transform: uppercase;
    letter-spacing: 0.13em;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
}

.hero h1 {
    font-size: clamp(2.2rem, 5vw, 4rem);
    line-height: 0.95;
}

.hero-subtitle {
    max-width: 46rem;
    color: var(--text-soft);
    font-size: 1rem;
}

.hero-meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.meta-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface-strong);
}

.meta-value,
.kpi-value,
.metric-value,
.detail-value,
.row-subtitle {
    font-family: var(--font-mono);
}

.meta-value {
    font-size: 1rem;
    font-weight: 600;
}

.mode-switcher {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.mode-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 20px;
    text-decoration: none;
    color: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
    transition: transform 140ms ease-out, border-color 140ms ease-out, background 140ms ease-out;
    cursor: pointer;
}

.mode-card:hover,
.mode-card.active {
    transform: translateY(-2px);
    border-color: var(--border-strong);
    background: linear-gradient(180deg, var(--surface-strong), var(--surface-alt));
}

.mode-card:active {
    transform: scale(0.98);
    transition-duration: 80ms;
}

.mode-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.mode-chip,
.pill,
.filter-chip,
.type-pill,
.status-badge,
.side-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-weight: 700;
}

.mode-chip {
    width: fit-content;
    padding: 6px 10px;
    font-size: 0.76rem;
    color: var(--accent-strong);
    background: var(--accent-soft);
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.kpi-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
    transition: transform var(--t-base), box-shadow var(--t-base);
}

.kpi-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 28px 64px rgba(57, 39, 14, 0.16);
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.panel {
    margin-top: 20px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.strategy-panel {
    padding-bottom: 24px;
}

.strategy-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.strategy-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(237, 245, 239, 0.92));
}

.strategy-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.strategy-card-pnl {
    font-size: 1.1rem;
    font-weight: 700;
}

.strategy-card-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.strategy-metric {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.panel-head,
.activity-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel-head {
    margin-bottom: 20px;
}

.connection-status {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 999px;
    background: var(--accent-strong);
    color: #fff9f2;
    font-size: 0.82rem;
    font-weight: 700;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.45);
}

.connection-status.live .status-dot {
    background: #8ff0b6;
    box-shadow: 0 0 0 6px rgba(143, 240, 182, 0.16);
}

.connection-status.error .status-dot {
    background: #ffb3a0;
    box-shadow: 0 0 0 6px rgba(255, 179, 160, 0.15);
}

.filter-bar {
    display: grid;
    grid-template-columns: 1.4fr repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chip-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

select,
.filter-chip,
.pill {
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.92rem;
}

select:focus,
.filter-chip:focus {
    outline: 2px solid rgba(145, 81, 29, 0.35);
    outline-offset: 2px;
}

body[data-mode="crypto"] select:focus,
body[data-mode="crypto"] .filter-chip:focus {
    outline-color: rgba(24, 106, 75, 0.35);
}

select {
    border-radius: 14px;
    outline: none;
}

.filter-chip {
    cursor: pointer;
    transition: background 120ms ease-out, color 120ms ease-out, border-color 120ms ease-out, transform 120ms ease-out;
}

.filter-chip.active {
    border-color: transparent;
    background: var(--accent-strong);
    color: #fff8f0;
}

.filter-chip:active {
    transform: scale(0.96);
    transition-duration: 60ms;
}

.activity-head {
    margin-bottom: 16px;
}

.pill {
    width: fit-content;
    border-radius: 999px;
}

.activity-caption {
    color: var(--text-soft);
    font-size: 0.92rem;
}

.activity-table-shell {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(247, 241, 232, 0.92));
    overflow: hidden;
}

body[data-mode="crypto"] .activity-table-shell {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(239, 247, 241, 0.92));
}

.activity-table-scroll {
    overflow-x: auto;
}

.activity-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 980px;
}

.activity-table th,
.activity-table td {
    padding: 14px 16px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
}

.activity-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: rgba(251, 247, 241, 0.96);
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.73rem;
}

body[data-mode="crypto"] .activity-table thead th {
    background: rgba(245, 251, 246, 0.96);
}

.activity-table tbody tr {
    background: rgba(255, 255, 255, 0.72);
    transition: background var(--t-fast);
}

.activity-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.96);
}

.activity-table tbody tr:last-child td {
    border-bottom: 0;
}

.activity-table-row.row-type-position {
    box-shadow: inset 4px 0 0 var(--accent);
}

.activity-table-row.row-status-won {
    background: linear-gradient(90deg, rgba(11, 122, 76, 0.08), rgba(255, 255, 255, 0.72) 28%);
}

.activity-table-row.row-status-lost {
    background: linear-gradient(90deg, rgba(178, 61, 34, 0.08), rgba(255, 255, 255, 0.72) 28%);
}

.activity-table-row[data-expandable="1"] {
    cursor: pointer;
}

.activity-table-row[data-expandable="1"]:hover {
    background: rgba(0, 0, 0, 0.03);
}

.activity-table-row.is-expanded {
    background: rgba(59, 130, 246, 0.08);
}

.activity-detail-row td {
    background: rgba(248, 250, 252, 0.92);
    border-top: 0 !important;
    padding: 14px 18px 18px;
}

.trade-detail {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.trade-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.trade-detail-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.trade-detail-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.trade-detail-value {
    font-size: 0.95rem;
    font-weight: 600;
}

.trade-detail-reasoning p {
    margin: 4px 0 0;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
}

.sibling-markets {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sibling-loading {
    margin: 4px 0 0;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.sibling-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.sibling-table th,
.sibling-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.sibling-table th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--surface-alt);
}

.sibling-table tbody tr:last-child td {
    border-bottom: 0;
}

.sibling-table tr.sibling-current {
    background: rgba(59, 130, 246, 0.1);
    font-weight: 600;
}

.sibling-table td.pos { color: var(--success); }
.sibling-table td.neg { color: var(--danger); }

.market-cell {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 280px;
}

.market-title {
    font-size: 0.98rem;
    font-weight: 700;
    line-height: 1.35;
}

.market-subtitle {
    color: var(--text-soft);
    font-size: 0.81rem;
}

.market-meta {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
}

.type-pill,
.status-badge,
.side-badge {
    padding: 6px 10px;
    font-size: 0.78rem;
}

.type-position {
    color: var(--accent-strong);
    background: var(--accent-soft);
}

.type-trade {
    color: var(--info);
    background: var(--info-soft);
}

.status-open {
    color: var(--warning);
    background: var(--warning-soft);
}

.status-won {
    color: var(--success);
    background: var(--success-soft);
}

.status-lost {
    color: var(--danger);
    background: var(--danger-soft);
}

.status-resolved {
    color: var(--text-soft);
    background: rgba(73, 73, 73, 0.1);
}

.side-yes {
    color: var(--success);
    background: var(--success-soft);
}

.side-no {
    color: var(--danger);
    background: var(--danger-soft);
}

.side-flat {
    color: var(--text-soft);
    background: rgba(64, 64, 64, 0.1);
}

.table-inline-text {
    display: none;
}

.empty-state {
    display: none;
    padding: 24px;
    border-radius: var(--radius-lg);
    border: 1px dashed var(--border-strong);
    color: var(--text-soft);
    text-align: center;
    background: rgba(255, 255, 255, 0.45);
}

.mono {
    font-family: var(--font-mono);
    font-feature-settings: 'tnum' 1;
}

.positive {
    color: var(--success);
}

.negative {
    color: var(--danger);
}

@media (max-width: 1100px) {
    .hero,
    .filter-bar,
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .page-shell {
        width: min(100vw - 18px, 100%);
        padding-top: 10px;
    }

    .hero,
    .mode-switcher,
    .kpi-grid,
    .filter-bar,
    .hero-meta {
        grid-template-columns: 1fr;
    }

    .panel,
    .hero,
    .mode-card,
    .kpi-card {
        padding: 16px;
    }

    .panel-head,
    .activity-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .strategy-card-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .activity-table {
        min-width: 0;
    }

    .activity-table thead {
        display: none;
    }

    .activity-table,
    .activity-table tbody,
    .activity-table tr,
    .activity-table td {
        display: block;
        width: 100%;
    }

    .activity-table tbody tr {
        padding: 10px 12px;
        border-bottom: 1px solid var(--border);
    }

    .activity-table tbody tr:last-child {
        border-bottom: 0;
    }

    .activity-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 8px 0;
        border-bottom: 0;
    }

    .activity-table td::before {
        content: attr(data-label);
        flex: 0 0 96px;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.08em;
        font-size: 0.68rem;
        font-weight: 700;
    }

    .activity-table td:first-child {
        display: block;
        padding-top: 2px;
    }

    .activity-table td:first-child::before {
        display: block;
        margin-bottom: 8px;
    }

    .market-cell {
        min-width: 0;
    }

    .table-inline-text {
        display: inline;
        margin-left: 8px;
        color: var(--text-soft);
        font-size: 0.84rem;
    }
}

.live-pnl-totals {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin: 16px 0 20px;
}
.live-pnl-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}
.live-pnl-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}
.live-pnl-value {
    font-size: 1.1rem;
    font-weight: 600;
}
.live-pnl-value.positive,
.activity-table td.positive { color: var(--success); }
.live-pnl-value.negative,
.activity-table td.negative { color: var(--danger); }

/* Top nav (bot selector) */
.top-nav {
    display: flex;
    gap: 0.75rem;
    margin: 0 0 1.5rem;
    flex-wrap: wrap;
}
.nav-link {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.75rem 1.1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-soft);
    text-decoration: none;
    min-width: 180px;
    transition: border-color 120ms ease-out, color 120ms ease-out, background 120ms ease-out, transform 120ms ease-out;
    position: relative;
}
.nav-link:hover {
    border-color: var(--border-strong);
    color: var(--text);
    transform: translateY(-1px);
}
.nav-link:active {
    transform: scale(0.97);
    transition-duration: 60ms;
}
.nav-link.active {
    border-color: var(--accent);
    background: var(--surface-strong);
    color: var(--text);
    box-shadow: 0 6px 22px rgba(57, 39, 14, 0.08);
}
.nav-link .nav-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border-strong);
    position: absolute;
    top: 0.85rem;
    right: 0.9rem;
}
.nav-link.active .nav-dot {
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}
.nav-title {
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: 0.01em;
}
.nav-sub {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Pill variants */
.pill-live {
    background: var(--success-soft);
    color: var(--success);
    border-color: rgba(11, 122, 76, 0.3);
}
.pill-ok {
    background: var(--accent-soft);
    color: var(--accent-strong);
    border-color: rgba(145, 81, 29, 0.3);
}
.pill-warn {
    background: var(--warning-soft);
    color: var(--warning);
    border-color: rgba(157, 91, 6, 0.3);
}
.pill-neutral {
    background: rgba(49, 38, 24, 0.08);
    color: var(--text-muted);
}

/* Verdict pills */
.verdict-hawk {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: rgba(178, 61, 34, 0.3);
}
.verdict-dove {
    background: var(--info-soft);
    color: var(--info);
    border-color: rgba(35, 79, 125, 0.3);
}
.verdict-neutral {
    background: rgba(49, 38, 24, 0.08);
    color: var(--text-muted);
}

/* Table sub-line (secondary text under a cell value) */
.table-sub {
    font-family: var(--font-body);
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
    line-height: 1.3;
    max-width: 42ch;
}

/* P&L colors */
.pnl-pos { color: var(--success); }
.pnl-neg { color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
