:root {
    --bg-color: #0a0f12;
    --bg-accent: #172026;
    --sidebar-bg: #0d1418;
    --card-bg: #111a20;
    --card-bg-strong: #0e171c;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #2dd4bf;
    --accent-hover: #14b8a6;
    --accent-soft: rgba(45, 212, 191, 0.14);
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --glass-border: rgba(148, 163, 184, 0.18);
    --panel-shadow: 0 14px 30px rgba(0, 0, 0, 0.24);
    --radius-lg: 8px;
    --radius-md: 8px;
    --radius-sm: 6px;
}

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

html {
    height: 100%;
}

body {
    min-height: 100%;
    font-family: 'Inter', system-ui, sans-serif;
    color: var(--text-primary);
    background: var(--bg-color);
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
}

.glass {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--panel-shadow);
}

.sidebar {
    width: 290px;
    padding: 28px 22px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--sidebar-bg);
    border-right: 1px solid rgba(148, 163, 184, 0.14);
    overflow-y: auto;
    min-height: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-mark {
    width: 12px;
    height: 44px;
    border-radius: 999px;
    background: var(--accent);
    box-shadow: 0 0 18px rgba(45, 212, 191, 0.35);
}

.logo h2 {
    font-size: 1.5rem;
    line-height: 1.1;
}

.page-kicker {
    color: var(--accent);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-weight: 700;
    margin-bottom: 6px;
}

.sidebar-intro {
    padding: 18px;
    border-radius: var(--radius-md);
}

.sidebar-copy {
    color: #cbd5e1;
    font-size: 0.92rem;
    line-height: 1.55;
}

.sidebar-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.sidebar-chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.7);
    color: var(--text-secondary);
    font-size: 0.75rem;
    border: 1px solid rgba(148, 163, 184, 0.15);
}

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

.menu-heading {
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-weight: 700;
    margin: 10px 0 4px;
    padding-left: 12px;
}

.menu a {
    display: block;
    padding: 12px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s ease;
    cursor: pointer;
    font-weight: 600;
}

.menu a:hover {
    background: rgba(30, 41, 59, 0.65);
    color: #e2e8f0;
}

.menu a.active {
    background: var(--accent-soft);
    color: white;
    border: 1px solid rgba(45, 212, 191, 0.3);
}

.main-content {
    flex: 1;
    padding: 28px 32px 36px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    min-height: 0;
    overscroll-behavior: contain;
}

.top-bar {
    display: flex;
    flex-shrink: 0;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

.hero-copy {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.hero-copy h1 {
    font-size: clamp(2rem, 2.8vw, 3rem);
    line-height: 1;
    letter-spacing: 0;
}

.page-subtitle {
    margin-top: 10px;
    max-width: 640px;
    color: var(--text-secondary);
    font-size: 0.98rem;
    line-height: 1.6;
}

.hero-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 8px;
}

.selector-label {
    color: var(--text-muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-weight: 700;
}

.glass-select {
    background: var(--card-bg-strong);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    padding: 11px 16px;
    border-radius: 6px;
    outline: none;
    font-size: 0.96rem;
    min-width: 150px;
}

.glass-select--compact {
    min-width: 120px;
}

.command-bar {
    display: grid;
    flex-shrink: 0;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    gap: 1px;
    overflow: hidden;
    background: rgba(148, 163, 184, 0.16);
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: var(--radius-lg);
}

.command-lane {
    min-width: 0;
    padding: 13px 15px;
    background: #0e171c;
}

.command-lane--warning,
.radar-watchbar--warning {
    background: rgba(62, 20, 28, 0.54);
}

.command-lane__identity {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.command-lane__identity .page-kicker {
    margin-bottom: 3px;
}

.command-lane__identity strong {
    display: block;
    color: var(--text-primary);
    font-size: 0.9rem;
    line-height: 1.35;
}

.command-lane__metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 11px;
}

.command-lane__metrics--research {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.command-lane__metrics div {
    min-width: 0;
}

.command-lane__metrics span {
    display: block;
    margin-bottom: 4px;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.command-lane__metrics strong {
    display: block;
    overflow: hidden;
    color: #e2e8f0;
    font-size: 0.84rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.command-bar__alerts {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 8px 15px;
    background: #0b1216;
    color: var(--text-secondary);
    font-size: 0.76rem;
    line-height: 1.4;
}

.radar-watchbar--warning ~ .command-bar__alerts #global-radar-alert,
.command-lane--warning ~ .command-bar__alerts #global-engine-alert {
    color: #fca5a5;
    font-weight: 700;
}

.status-overview {
    display: grid;
    flex-shrink: 0;
    grid-template-columns: minmax(280px, 0.9fr) minmax(340px, 1.2fr) minmax(320px, 1.1fr);
    gap: 18px;
    align-items: stretch;
}

.status-stack {
    display: grid;
    gap: 18px;
}

.status-card {
    padding: 20px;
}

.status-card--hero,
.status-card--positions,
.status-card--cycle {
    min-height: 220px;
}

.status-stack .status-card {
    min-height: 0;
}

.status-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.status-card h3 {
    font-size: 0.95rem;
    line-height: 1.2;
}

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

.status-grid--triple {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.status-grid--five {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.status-grid--radar {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.metric-block {
    padding: 10px 12px;
    border-left: 1px solid rgba(148, 163, 184, 0.16);
}

.metric-block:first-child {
    border-left: 0;
}

.metric-block__label {
    display: block;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.metric-block__value {
    display: block;
    font-size: clamp(1rem, 1.2vw, 1.35rem);
    font-weight: 800;
    letter-spacing: -0.03em;
}

.metric-block__value--muted {
    color: var(--text-secondary);
}

.metric-block__detail {
    display: block;
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 0.76rem;
    line-height: 1.35;
}

#active-pos-card .inactive {
    color: var(--text-secondary);
    font-style: italic;
}

#position-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 82px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(148, 163, 184, 0.12);
    color: #cbd5e1;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.status-pill--idle,
.status-pill--waiting {
    border-color: rgba(245, 158, 11, 0.26);
    background: rgba(245, 158, 11, 0.12);
    color: #fbbf24;
}

.status-pill--scanning,
.status-pill--running {
    border-color: rgba(56, 189, 248, 0.28);
    background: rgba(56, 189, 248, 0.14);
    color: #7dd3fc;
}

.status-pill--warning,
.status-pill--unknown {
    border-color: rgba(248, 113, 113, 0.28);
    background: rgba(127, 29, 29, 0.22);
    color: #fca5a5;
}

.cycle-summary {
    min-height: 48px;
    color: #e2e8f0;
    font-size: 0.95rem;
    line-height: 1.45;
}

.cycle-meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.cycle-meta div {
    padding: 10px;
    border-radius: var(--radius-sm);
    background: rgba(15, 23, 42, 0.56);
    border: 1px solid rgba(148, 163, 184, 0.12);
}

.cycle-meta span {
    display: block;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.cycle-meta strong {
    display: block;
    color: var(--text-primary);
    font-size: 0.98rem;
}

.cycle-footnote {
    margin-top: 14px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    line-height: 1.4;
}

.metric {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.metric .label {
    color: var(--text-secondary);
}

.metric .value {
    font-weight: 700;
    color: var(--text-primary);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.chart-section {
    flex-shrink: 0;
    min-height: 560px;
    padding: 20px;
}

.workspace-page {
    flex-shrink: 0;
    min-width: 0;
    padding: 6px 0 28px;
    border-top: 1px solid rgba(148, 163, 184, 0.16);
    overflow-x: auto;
}

.workspace-page > .section-header:first-child {
    margin: 0 0 20px;
    padding-top: 18px;
}

.workspace-section {
    min-width: 0;
    padding: 18px;
    background: rgba(17, 26, 32, 0.72);
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: var(--radius-lg);
}

.active-position-record {
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}

.active-position-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 20px;
}

.audit-metric {
    background: rgba(10, 15, 18, 0.72);
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: var(--radius-sm);
}

.panels-grid {
    display: grid;
    flex-shrink: 0;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    gap: 20px;
}

.panels-grid--single {
    grid-template-columns: minmax(0, 1fr);
}

.panel {
    padding: 20px;
}

.panel h3,
.panel h4 {
    margin-bottom: 15px;
}

.feed-container {
    max-height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.feed-item {
    background: rgba(2, 6, 23, 0.28);
    padding: 12px 14px;
    border-radius: 12px;
    border-left: 3px solid var(--accent);
    font-size: 0.92rem;
}

.feed-timestamp {
    color: var(--text-secondary);
    font-size: 0.8em;
}

.feed-item--stale {
    border-left-color: var(--warning);
    color: var(--warning);
    font-weight: 700;
}

.feed-item--stale-log {
    opacity: 0.72;
}

.orders-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.orders-table th {
    text-align: left;
    color: var(--text-secondary);
    padding: 0 0 12px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-weight: 700;
}

.orders-table td {
    padding: 12px 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

.type-buy {
    color: var(--success);
}

.type-sell {
    color: var(--danger);
}

.glass-input {
    width: 100%;
    background: rgba(2, 6, 23, 0.42);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 12px 14px;
    border-radius: 6px;
    margin: 10px 0;
}

.btn-primary {
    background: var(--accent);
    color: #04100e;
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
    box-shadow: none;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.hint {
    color: var(--text-secondary);
    font-size: 0.82rem;
    margin-top: 6px;
}

.hidden {
    display: none !important;
}

#menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
}

.policy-page {
    min-height: 100%;
    overflow-y: auto;
    background: #0a0f12;
}

.policy-shell {
    width: min(820px, calc(100% - 40px));
    margin: 0 auto;
    padding: 64px 0 80px;
}

.policy-header {
    padding-bottom: 28px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.policy-header h1 {
    font-size: clamp(2rem, 5vw, 3.5rem);
    line-height: 1.05;
    letter-spacing: 0;
}

.policy-header p,
.policy-shell section p,
.policy-shell li,
.policy-footer p {
    color: #b6c2cb;
    font-size: 1rem;
    line-height: 1.7;
}

.policy-header p {
    margin-top: 12px;
    color: var(--text-muted);
}

.policy-shell section {
    padding: 28px 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.policy-shell section h2 {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 1.15rem;
    letter-spacing: 0;
}

.policy-shell section p + p {
    margin-top: 12px;
}

.policy-shell ul {
    display: grid;
    gap: 8px;
    margin: 0 0 14px 20px;
}

.policy-footer {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding-top: 28px;
}

.policy-footer p {
    max-width: 600px;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.policy-footer a {
    flex-shrink: 0;
    color: var(--accent);
    font-weight: 700;
    text-decoration: none;
}

.policy-footer a:hover {
    text-decoration: underline;
}

@media (max-width: 1050px) {
    .command-bar {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 1180px) {
    .status-overview {
        grid-template-columns: 1fr 1fr;
    }

    .status-stack {
        grid-column: 1 / -1;
        grid-template-columns: 1fr 1fr;
    }

    .status-card--positions,
    .status-card--cycle {
        grid-column: auto;
    }

    .panels-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: 260px;
        z-index: 1000;
        transition: left 0.3s ease;
    }

    .sidebar.show {
        left: 0;
        box-shadow: 10px 0 20px rgba(0, 0, 0, 0.5);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 900;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .main-content {
        padding: 18px 16px 28px;
        width: 100%;
    }

    .top-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .hero-actions {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .command-lane__identity {
        align-items: flex-start;
    }

    .command-lane__metrics,
    .command-lane__metrics--research {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .command-bar__alerts {
        flex-direction: column;
        gap: 4px;
    }

    .status-overview {
        grid-template-columns: 1fr;
    }

    .status-stack {
        grid-column: auto;
        grid-template-columns: 1fr;
    }

    .status-grid,
    .status-grid--triple,
    .status-grid--five,
    .status-grid--radar {
        grid-template-columns: 1fr;
    }

    .metric-block,
    .metric-block:first-child {
        border-left: 0;
        border-top: 1px solid rgba(148, 163, 184, 0.16);
    }

    .metric-block:first-child {
        border-top: 0;
    }

    .active-position-grid {
        grid-template-columns: 1fr;
    }

    .chart-section {
        min-height: 420px;
        padding: 16px;
    }

    #chart-container {
        height: 350px !important;
    }

    #menu-toggle {
        display: block !important;
    }

    .policy-shell {
        width: min(100% - 32px, 820px);
        padding: 40px 0 56px;
    }

    .policy-footer {
        flex-direction: column;
    }
}
@media (max-width: 768px) {
    .counterfactual-table .cf-secondary {
        display: none;
    }

    .counterfactual-table th,
    .counterfactual-table td {
        padding-left: 6px;
        padding-right: 6px;
    }
}
