:root {
    color-scheme: light;
    --bg: #f2f5f6;
    --panel: #ffffff;
    --line: #d9e1e5;
    --text: #172026;
    --muted: #667782;
    --call: #e9f7ee;
    --put: #fff0ed;
    --strike: #9fc5e8;
    --accent: #0f766e;
    --danger: #a33a2f;
    --banner: #16485a;
    --banner-dark: #0e3544;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

.stream-header {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    min-height: 42px;
    padding: 4px 14px;
    background: linear-gradient(180deg, var(--banner), var(--banner-dark));
    color: #fff;
    border-bottom: 3px solid #0a2731;
    text-transform: uppercase;
}

.live-chip {
    padding: 3px 8px;
    background: #d60000;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 900;
}

.clock {
    min-width: 96px;
    color: #e8eef1;
    font-weight: 900;
}

.headline {
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 18px;
    font-weight: 900;
    letter-spacing: 0;
    text-shadow: 0 2px 0 rgba(0, 0, 0, .35);
}

.app-shell {
    width: min(100%, 1600px);
    margin: 0 auto;
    padding: 8px;
}

.toolbar {
    display: grid;
    grid-template-columns: minmax(360px, .95fr) minmax(560px, 1.05fr);
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    border-radius: 0;
}

h1 {
    margin: 0 0 6px;
    font-size: 22px;
    line-height: 1.1;
}

p {
    margin: 0;
    color: var(--muted);
}

.controls {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(140px, .9fr) minmax(140px, .9fr) minmax(145px, .9fr) minmax(168px, auto) auto;
    align-items: end;
    justify-content: stretch;
    gap: 8px;
    width: 100%;
}

label {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

select,
input,
button {
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

select {
    min-width: 0;
    width: 100%;
    padding: 0 34px 0 10px;
}

input {
    min-width: 0;
    padding: 0 10px;
}

button {
    padding: 0 16px;
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.summary {
}

.toolbar-stats {
    display: grid;
    grid-template-columns: minmax(84px, .6fr) minmax(176px, 1.25fr) minmax(84px, .6fr) minmax(154px, .9fr);
    gap: 8px;
    min-width: 0;
}

.metric-card,
.toggle {
    min-height: 34px;
    padding: 7px 10px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
}

.meta-label {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.toolbar-stats strong {
    font-size: 15px;
}

.metric-card {
    display: grid;
    align-content: center;
}

.metric-card.wide strong {
    white-space: nowrap;
}

.hidden-meta,
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
}

.workspace {
    display: block;
}

.chain-panel {
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 14px;
}

.compact-toggle {
    min-height: 34px;
    padding: 0 10px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
}

.auto-toggle {
    justify-content: center;
    line-height: 1.1;
}

.auto-toggle input {
    width: 22px;
    height: 22px;
    min-width: 22px;
}

.table-wrap {
    max-height: calc(100vh - 154px);
    overflow: auto;
    background: var(--panel);
}

.history-bar {
    display: grid;
    grid-template-columns: minmax(420px, auto) minmax(260px, 1fr);
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    background: #f8fbfc;
}

.history-bar button {
    min-height: 32px;
}

.history-controls {
    display: grid;
    grid-template-columns: 150px 160px auto auto auto;
    align-items: end;
    gap: 8px;
}

#history-state {
    justify-self: end;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

table {
    width: 100%;
    min-width: 1120px;
    border-collapse: collapse;
    font-size: 13px;
}

th,
td {
    height: 34px;
    padding: 5px 8px;
    border-bottom: 1px solid var(--line);
    text-align: center;
    white-space: nowrap;
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #351d72;
    color: #fff;
    font-size: 11px;
}

th span {
    display: block;
    margin-top: 2px;
    font-size: 10px;
    font-weight: 800;
}

.group-row th:first-child {
    background: #351d72;
    text-align: center;
}

.group-row th:last-child {
    background: #351d72;
    text-align: center;
}

td:nth-child(-n+6),
td:nth-child(n+8) {
    background: #fff;
}

.strike,
.strike-head {
    position: sticky;
    left: 0;
    z-index: 2;
    min-width: 86px;
    background: var(--strike) !important;
    color: #001a33;
    text-align: center;
    font-weight: 800;
    border-left: 1px solid #6fa8dc;
    border-right: 1px solid #6fa8dc;
}

.strike-price,
.strike-pcr,
.level-main,
.level-sub {
    display: block;
    line-height: 1.05;
    text-align: center;
}

.strike-price,
.level-main {
    font-weight: 900;
}

.strike-pcr {
    margin-top: 4px;
    font-size: 11px;
    font-weight: 800;
}

.pcr-low {
    color: #d83333;
}

.pcr-mid {
    color: #b26b00;
}

.pcr-high {
    color: #00875a;
}

.level-cell {
    min-width: 74px;
}

.level-sub {
    margin-top: 3px;
    color: #172026;
    font-size: 12px;
    font-weight: 700;
}

.call-level .level-main {
    color: #ff3333;
}

.put-level .level-main {
    color: #00a870;
}

.atm td {
    border-top: 0;
    box-shadow: inset 0 -3px 0 #6aa84f;
}

.atm .strike {
    background: #ffff00 !important;
    color: #000;
    outline: 2px solid #1c64f2;
    outline-offset: -2px;
    box-shadow: inset 0 -3px 0 #6aa84f;
}

.rank-highest {
    background: #cc0000 !important;
    color: #fff;
    font-weight: 800;
}

.rank-second {
    background: #F1C232 !important;
    color: #172026;
    font-weight: 800;
}

td.itm-call:not(.rank-highest):not(.rank-second) {
    background: #FFFBEB !important;
}

td.itm-put:not(.rank-highest):not(.rank-second) {
    background: #FFFBEB !important;
}

.cell-main,
.cell-percent {
    display: block;
    line-height: 1.05;
}

.cell-main {
    font-weight: 800;
}

.cell-percent {
    margin-top: 3px;
    color: #667782;
    font-size: 10px;
    font-weight: 700;
}

.rank-highest .cell-percent {
    color: rgba(255, 255, 255, .88);
}

.rank-second .cell-percent {
    color: #594300;
}

.reversal {
    display: inline-block;
    min-width: 48px;
    text-align: center;
    font-size: 10px;
    font-weight: 900;
    line-height: 1.05;
    text-transform: uppercase;
}

.break-out {
    color: #d83333;
}

.break-down {
    color: #d83333;
}

.reversal.neutral {
    color: #9aa8ae;
}

.muted {
    color: #9aa8ae;
}

.empty {
    height: 140px;
    background: #fff !important;
    color: var(--muted);
    text-align: center;
    font-size: 15px;
    line-height: 1.45;
    padding: 24px;
    white-space: normal;
}

.error {
    color: var(--danger);
}

@media (max-width: 860px) {
    .app-shell {
        padding: 10px;
    }

    .stream-header {
        grid-template-columns: auto 1fr;
    }

    .headline {
        grid-column: 1 / -1;
        font-size: 14px;
        white-space: normal;
    }

    .toolbar {
        grid-template-columns: 1fr;
    }

    .controls {
        grid-template-columns: 1fr;
    }

    .controls label,
    .controls button {
        flex: 1 1 160px;
    }

    select {
        width: 100%;
        min-width: 0;
    }

    input {
        width: 100%;
        min-width: 0;
    }

    .toolbar-stats,
    .history-bar,
    .history-controls {
        grid-template-columns: 1fr;
    }

    #history-state {
        justify-self: start;
        white-space: normal;
    }

    table {
        min-width: 1040px;
    }
}
