/* ===========================================================================
 * Terminal V4.2 — dark trading-desk shell (architecture §2.6)
 *
 * Scoped entirely under `body.term` so the legacy dashboard stylesheet
 * (style.css) is never affected: /classic keeps its original look.
 *
 * Layout contract (§2.6): header strip / left-center-right columns /
 * bottom row / footer, fitting 1280px width without horizontal overflow.
 * Every numeric readout uses a monospace face with tabular alignment.
 * ========================================================================= */

body.term {
    --t-bg: #07090c;            /* near-black desk */
    --t-panel: #0d1117;
    --t-panel-2: #10161f;
    --t-border: #1d2633;
    --t-text: #c9d4e3;
    --t-dim: #66788f;
    --t-faint: #45536a;
    --t-green: #35d07f;
    --t-red: #ff5c5c;
    --t-amber: #ffb347;
    --t-cyan: #53c6e0;
    --t-violet: #9b7bff;

    background: var(--t-bg);
    color: var(--t-text);
    font-family: "IBM Plex Mono", "JetBrains Mono", ui-monospace, SFMono-Regular,
        Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    line-height: 1.45;
    margin: 0;
    padding: 8px 10px 10px;
    min-height: 100vh;
    overflow-x: hidden;
}

body.term ::selection { background: #24405e; color: #eaf2fb; }

/* thin dark scrollbars so panels don't glow white */
body.term * { scrollbar-width: thin; scrollbar-color: #26303f transparent; }
body.term *::-webkit-scrollbar { width: 6px; height: 6px; }
body.term *::-webkit-scrollbar-thumb { background: #26303f; border-radius: 3px; }
body.term *::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------------- grid --- */

.t-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);          /* single column of rows */
    grid-template-rows: auto auto auto minmax(150px, auto) auto;
    grid-template-areas:
        "header"
        "main"
        "bottom"
        "neural"
        "footer";
    gap: 8px;
    max-width: 1260px;
    margin: 0 auto;
}

.t-main {
    grid-area: main;
    display: grid;
    /* left wallet | center (chart+ladder) | right lifecycle */
    grid-template-columns: 236px minmax(0, 1fr) 300px;
    gap: 8px;
    align-items: stretch;
    min-height: 380px;
}

.t-bottom {
    grid-area: bottom;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
}

/* -------------------------------------------------------------- panels --- */

.t-panel {
    background: var(--t-panel);
    border: 1px solid var(--t-border);
    border-radius: 6px;
    padding: 8px 10px;
    min-width: 0;               /* let inner scroll areas shrink, not the grid */
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.t-panel-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--t-dim);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}
.t-panel-title .t-note {
    font-weight: 400;
    letter-spacing: .04em;
    text-transform: none;
    color: var(--t-faint);
    text-align: right;
}

.mono-num {
    font-family: inherit;
    font-variant-numeric: tabular-nums;
    letter-spacing: .02em;
}

.up   { color: var(--t-green); }
.down { color: var(--t-red); }
.dim  { color: var(--t-dim); }
.faint{ color: var(--t-faint); }

/* ------------------------------------------------------------ header ----- */

.t-header {
    grid-area: header;
    display: grid;
    grid-template-rows: auto auto auto;
    gap: 8px;
}

.t-banner-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 18px;
}

#term-id-banner {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: .06em;
    white-space: nowrap;
    color: #e8eef7;
}
#term-id-banner .hg-accent { color: var(--t-amber); }
#term-strategy-desc {
    font-size: 10px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--t-dim);
    white-space: nowrap;
}

.t-header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* connection badge — visible at all times (VAL-UI-002 / VAL-API-012) */
#conn-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 3px;
    border: 1px solid var(--t-border);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .12em;
    color: var(--t-dim);
    background: var(--t-panel-2);
    cursor: default;
    user-select: none;
}
#conn-badge::before {
    content: "";
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--t-dim);
    box-shadow: 0 0 4px rgba(102,120,143,.5);
}
#conn-badge[data-state="live"] {
    color: var(--t-green);
    border-color: #1e4634;
    background: #0c1a13;
}
#conn-badge[data-state="live"]::before {
    background: var(--t-green);
    box-shadow: 0 0 6px rgba(53,208,127,.9);
    animation: t-pulse 2s infinite;
}
#conn-badge[data-state="polling"] {
    color: var(--t-amber);
    border-color: #4d3a17;
    background: #1a1408;
}
#conn-badge[data-state="polling"]::before {
    background: var(--t-amber);
    box-shadow: 0 0 6px rgba(255,179,71,.8);
}
#conn-badge[data-state="stale"] {
    color: var(--t-red);
    border-color: #55232a;
    background: #1c0d10;
}
#conn-badge[data-state="stale"]::before {
    background: var(--t-red);
    box-shadow: 0 0 6px rgba(255,92,92,.9);
}
@keyframes t-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: .35; }
}

/* latency chip */
#latency-chip {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 3px 10px;
    border: 1px solid var(--t-border);
    border-radius: 3px;
    background: var(--t-panel-2);
    font-size: 11px;
    user-select: none;
}
#latency-chip .lbl { font-size: 9px; letter-spacing: .12em; color: var(--t-faint); }
#latency-ms { font-weight: 700; }

/* ticker cards */
.t-tickers {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 260px));
    gap: 8px;
}
.ticker-card {
    background: var(--t-panel);
    border: 1px solid var(--t-border);
    border-radius: 6px;
    padding: 6px 10px 7px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
        "sym spot mult"
        "sym edge mult";
    column-gap: 14px;
    row-gap: 1px;
    align-items: baseline;
    min-width: 0;
}
.ticker-sym {
    grid-area: sym;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: .08em;
    align-self: center;
}
.ticker-spot {
    grid-area: spot;
    font-size: 16px;
    font-weight: 700;
}
.ticker-mult {
    grid-area: mult;
    text-align: right;
    font-size: 10px;
    color: var(--t-dim);
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ticker-edge {
    grid-area: edge;
    font-size: 10px;
    color: var(--t-dim);
}
.ticker-spot .flash-up { animation: flashUp .5s; }
.ticker-spot .flash-down { animation: flashDown .5s; }
@keyframes flashUp   { 0% { color: var(--t-green); } 100% { color: inherit; } }
@keyframes flashDown { 0% { color: var(--t-red); } 100% { color: inherit; } }

/* execution tape strip */
.tape-strip-wrap { position: relative; }
#tape-strip {
    height: 118px;
    overflow-y: auto;
    border: 1px solid var(--t-border);
    border-radius: 4px;
    background: var(--t-bg);
    padding: 2px 0;
}
.tape-row {
    display: grid;
    grid-template-columns: 58px 86px 74px minmax(0, 1fr);
    gap: 8px;
    padding: 0 8px;
    font-size: 11px;
    white-space: nowrap;
    border-left: 2px solid transparent;
}
.tape-row:nth-child(even) { background: rgba(255,255,255,.015); }
.tape-row .t-ts { color: var(--t-faint); font-size: 10px; }
.tape-row .t-kind { font-weight: 700; font-size: 9.5px; letter-spacing: .06em; }
.tape-row .t-sym { color: var(--t-cyan); font-size: 10px; overflow: hidden; text-overflow: ellipsis; }
.tape-row .t-text { overflow: hidden; text-overflow: ellipsis; }
.kind-FILL        { color: var(--t-green); }
.kind-MINT_SET    { color: var(--t-green); }
.kind-QUOTE       { color: var(--t-cyan); }
.kind-CUT_UP_RISK,
.kind-CUT_DOWN_RISK { color: var(--t-amber); }
.kind-HEDGE_ADD   { color: var(--t-violet); }
.kind-SETTLE      { color: #7fe3b2; }
.kind-CANCEL      { color: var(--t-faint); }
.kind-WARN        { color: var(--t-amber); }
.kind-REJECT      { color: var(--t-red); }
.kind-INFO        { color: var(--t-dim); }

/* ------------------------------------------------------------- wallet ---- */

#wallet-panel { grid-column: 1; }

.wallet-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
}
.w-cell { min-width: 0; }
.w-label {
    font-size: 9px;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--t-faint);
}
.w-value { font-size: 15px; font-weight: 700; }
.w-sub { font-size: 9.5px; color: var(--t-faint); }
.w-wide { grid-column: 1 / -1; }
.w-pnl { font-size: 20px; }
.neg-pnl { color: var(--t-red); }

/* drawdown gauge */
.gauge-track {
    height: 8px;
    background: #131a24;
    border: 1px solid var(--t-border);
    border-radius: 4px;
    overflow: hidden;
}
.gauge-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--t-green), var(--t-amber) 60%, var(--t-red));
    transition: width .4s ease;
}

/* directional split bar */
.split-bar {
    display: flex;
    height: 14px;
    border: 1px solid var(--t-border);
    border-radius: 3px;
    overflow: hidden;
    background: #131a24;
}
.split-bar .seg-up   { background: #1f6f47; transition: width .4s ease; }
.split-bar .seg-down { background: #7c3038; transition: width .4s ease; }
.split-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    margin-top: 2px;
}

/* matched/residual split */
.matched-split {
    display: grid;
    place-items: center;
    position: relative;
    padding: 4px 0 0;
}
.donut-center {
    position: absolute;
    text-align: center;
    font-size: 11px;
    line-height: 1.25;
}
.donut-center b { font-size: 13px; }
.legend-line {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--t-dim);
    width: 100%;
}
.legend-dot {
    display: inline-block;
    width: 7px; height: 7px;
    border-radius: 2px;
    margin-right: 4px;
    vertical-align: middle;
}

/* ----------------------------------------------------------- lifecycle --- */

#lifecycle-panel { grid-column: 3; }

.win-row {
    border: 1px solid var(--t-border);
    border-radius: 4px;
    background: var(--t-panel-2);
    padding: 5px 7px 6px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 2px 8px;
    margin-bottom: 6px;
}
.win-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}
.win-name { font-weight: 700; font-size: 12px; letter-spacing: .04em; }
.win-countdown { font-size: 13px; font-weight: 700; }
.status-chip {
    font-size: 8.5px;
    font-weight: 700;
    letter-spacing: .12em;
    padding: 1px 6px;
    border-radius: 2px;
    border: 1px solid var(--t-border);
    color: var(--t-dim);
    text-transform: uppercase;
}
.st-CREATED  { color: var(--t-dim); border-color: var(--t-border); }
.st-ACTIVE   { color: var(--t-green); border-color: #1e4634; background: #0c1a13; }
.st-EXPIRING { color: var(--t-amber); border-color: #4d3a17; background: #1a1408; }
.st-SETTLED  { color: var(--t-faint); }
.countdown-track {
    grid-column: 1 / -1;
    height: 5px;
    border-radius: 2px;
    background: #131a24;
    overflow: hidden;
    margin-top: 3px;
}
.countdown-fill {
    height: 100%;
    width: 100%;
    background: var(--t-cyan);
    transition: width 1s linear;
}
.win-row.expiring .countdown-fill { background: var(--t-amber); }
.win-row.settled  { opacity: .55; }

#resolution-matrix {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    gap: 4px;
    max-height: 168px;
    overflow-y: auto;
    margin-top: 2px;
}
.res-cell {
    border: 1px solid var(--t-border);
    border-left-width: 3px;
    border-radius: 3px;
    padding: 3px 6px;
    font-size: 10px;
    background: var(--t-panel-2);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.res-cell .res-outcome { float: right; font-weight: 700; }
.res-won    { border-left-color: var(--t-green); color: var(--t-green); }
.res-lost   { border-left-color: var(--t-red); color: var(--t-red); }
.res-won .res-outcome   { color: var(--t-green); }
.res-lost .res-outcome  { color: var(--t-red); }

/* empty-state placeholder rows shared by all panels */
.empty-note {
    color: var(--t-faint);
    font-size: 10px;
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: 6px 2px;
}

/* center placeholders for milestone-2 panels */
.placeholder-center {
    min-height: 120px;
    border: 1px dashed var(--t-border);
    border-radius: 4px;
    display: grid;
    place-items: center;
    color: var(--t-faint);
    font-size: 10px;
    letter-spacing: .1em;
    text-transform: uppercase;
}

/* -------------------------------------------------------------- footer --- */

.t-footer {
    grid-area: footer;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 26px;
    align-items: baseline;
    padding: 6px 12px;
    font-size: 11px;
}
.t-footer .f-item { display: inline-flex; gap: 7px; align-items: baseline; white-space: nowrap; }
.t-footer .f-label { font-size: 9px; letter-spacing: .1em; text-transform: uppercase; color: var(--t-faint); }
.t-footer .f-val { font-weight: 700; }

/* narrow screens: stack columns instead of overflowing horizontally */
@media (max-width: 1100px) {
    body.term { padding: 6px; }
    .t-main { grid-template-columns: minmax(0, 1fr); }
    #wallet-panel, #lifecycle-panel { grid-column: 1; }
    .t-bottom { grid-template-columns: minmax(0, 1fr); }
}

/* =========================================================================
 * milestone: chart + ladder + neural shell + edge + sankey (§2.6 center)
 * ========================================================================= */

/* ------------------------------------------------------------- chart ---- */

.chart-canvas {
    width: 100%;
    height: 210px;
    display: block;
    border-radius: 4px;
}
.chart-canvas.short { height: 150px; }

/* ------------------------------------------------------------- ladder --- */

.ladder-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 20px;
    align-items: center;
}
.ladder-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    font: inherit;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .05em;
    color: var(--t-dim);
    background: var(--t-panel-2);
    border: 1px solid var(--t-border);
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    transition: border-color .15s, color .15s, background .15s;
}
.ladder-chip:hover  { color: var(--t-text); border-color: #2c3b50; }
.ladder-chip.selected {
    color: #eaf2fb;
    background: #12283a;
    border-color: var(--t-cyan);
    box-shadow: 0 0 6px rgba(83,198,224,.35);
}
.chip-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    display: inline-block;
}
.chip-dot.btc { background: var(--t-amber); }
.chip-dot.eth { background: var(--t-cyan); }

.ladder-legend {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--t-faint);
}

.ladder-body {
    overflow-y: auto;
    max-height: 218px;
    border: 1px solid var(--t-border);
    border-radius: 4px;
    background: var(--t-bg);
    scrollbar-width: thin;
}
.lad-row {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) minmax(0, 1.2fr);
    gap: 8px;
    padding: 1px 8px;
    font-size: 11.5px;
    line-height: 1.55;
    white-space: nowrap;
    border-left: 2px solid transparent;
}
.lad-row.mkt-bid-row { border-left-color: var(--t-green); background: rgba(53,208,127,.06); }
.lad-row.mkt-ask-row { border-left-color: var(--t-red);   background: rgba(255,92,92,.06); }
.lad-row.bot-bid-row,
.lad-row.bot-ask-row { background: rgba(83,198,224,.08); }
.lad-px { color: var(--t-dim); }
.lad-px.bid-side { color: var(--t-green); }
.lad-mkt b { font-size: 9px; letter-spacing: .08em; margin-right: 3px; }
.lad-bot .bot-tag {
    font-size: 8.5px;
    font-weight: 700;
    letter-spacing: .07em;
    color: #04222b;
    background: var(--t-cyan);
    border-radius: 2px;
    padding: 0 4px;
    margin-right: 5px;
}
.lad-row.bot-ask-row .bot-tag { background: var(--t-violet); color: #150b29; }
.lad-bot .bot-size { color: var(--t-cyan); font-weight: 700; }

/* ------------------------------------------------------- neural shell --- */

.neural-grid {
    display: grid;
    grid-template-columns: minmax(230px, 300px) minmax(0, 1fr) 200px;
    gap: 12px;
    align-items: stretch;
    min-width: 0;
}
.nf-ingest {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.nf-row {
    --mag: .1;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 7px;
    align-items: baseline;
    padding: 2px 6px;
    border-left: 2px solid rgba(155,123,255, calc(.25 + var(--mag) * .75));
    background: linear-gradient(90deg,
        rgba(155,123,255, calc(var(--mag) * .16)), transparent 70%);
    transition: border-color .4s, background .4s;
}
.nf-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: rgba(155,123,255, calc(.3 + var(--mag) * .7));
    box-shadow: 0 0 calc(var(--mag) * 6px) rgba(155,123,255,.8);
}
.nf-name {
    font-size: 9px;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--t-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nf-val { font-size: 11px; font-weight: 700; color: #dfe9f5; }

.neural-canvas {
    width: 100%;
    height: 100%;
    min-height: 170px;
    display: block;
}

.nf-output {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}
.pup {
    font-size: 30px;
    font-weight: 800;
    line-height: 1.1;
}
.pup.flash { animation: flashUp .5s; }

.lanes {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 3px;
}
.lane {
    display: grid;
    grid-template-columns: 62px minmax(0, 1fr) auto;
    gap: 6px;
    align-items: center;
    padding: 2px 4px;
    border: 1px solid var(--t-border);
    border-radius: 3px;
    background: var(--t-panel-2);
}
.lane.hot { border-color: #23486a; }
.lane-name {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .07em;
    color: var(--t-dim);
}
.lane.hot .lane-name { color: var(--t-cyan); }
.lane-chips {
    display: flex;
    gap: 3px;
    overflow: hidden;
}
.lane-chip {
    width: 7px; height: 7px;
    border-radius: 1px;
    background: var(--t-cyan);
    opacity: .95;
    animation: chipFlow 1.4s infinite alternate;
}
.lane-chip.alt { opacity: .35; }
@keyframes chipFlow {
    from { transform: translateX(-2px); }
    to   { transform: translateX(2px); }
}
.lane-count {
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
}
.lane-count i {
    font-style: normal;
    font-size: 7.5px;
    letter-spacing: .08em;
    color: var(--t-faint);
}

/* -------------------------------------------------------------- sankey -- */

.sankey-svg {
    width: 100%;
    height: 190px;
    display: block;
}

/* --------------------------------------------------- degradation strip -- */

#degrade-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 0;
}
#degrade-strip:empty { display: none; }
.dg-part {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border: 1px solid #55232a;
    border-radius: 3px;
    background: #1c0d10;
    color: var(--t-red);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .06em;
}
.dg-part.warn {
    border-color: #4d3a17;
    background: #1a1408;
    color: var(--t-amber);
}
.dg-part[style*="display: none"], .dg-part[hidden] { display: none !important; }
.dg-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: currentColor;
    animation: t-pulse 1.1s infinite;
}

/* degrade strip hidden entirely while healthy (both parts display:none) */
#dg-transport[style*="display: none"] ~ #dg-spot[style*="display: none"] {
    display: none;
}
