/* ==========================================================================
   StackTox - design system
   One stylesheet, no framework, no CDN dependency. Dark first with a light
   theme, every colour defined as a token so the two stay in step.
   ========================================================================== */

/* ---------- tokens ------------------------------------------------------- */
:root {
    color-scheme: dark;

    --bg:            #060a12;
    --bg-grad-1:     #0b1b2b;
    --bg-grad-2:     #0a1020;
    --panel:         rgba(16, 24, 39, 0.78);
    --panel-solid:   #111a28;
    --panel-2:       rgba(27, 38, 59, 0.55);
    --line:          rgba(148, 163, 184, 0.16);
    --line-strong:   rgba(148, 163, 184, 0.3);

    --text:          #e9eef7;
    --text-dim:      #aab7c8;
    --muted:         #7e8ea4;

    --primary:       #2dd4bf;
    --primary-ink:   #052b27;
    --primary-soft:  rgba(45, 212, 191, 0.14);
    --accent:        #8b8cf9;
    --accent-soft:   rgba(139, 140, 249, 0.14);

    --toxic:         #fb7185;
    --toxic-soft:    rgba(251, 113, 133, 0.14);
    --safe:          #34d399;
    --safe-soft:     rgba(52, 211, 153, 0.14);
    --warn:          #fbbf24;
    --warn-soft:     rgba(251, 191, 36, 0.14);

    --radius:        16px;
    --radius-sm:     10px;
    --radius-lg:     22px;
    --shadow:        0 24px 60px -24px rgba(0, 0, 0, 0.7);
    --shadow-sm:     0 8px 24px -14px rgba(0, 0, 0, 0.65);
    --ring:          0 0 0 3px rgba(45, 212, 191, 0.26);

    --font-display:  "Space Grotesk", "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
    --font-body:     "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    --font-mono:     "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

    --head-h:        64px;

    /* BOILED-Egg plot */
    --egg-bg:        rgba(255, 255, 255, 0.035);
    --egg-white:     rgba(226, 238, 252, 0.16);
    --egg-white-ink: rgba(226, 238, 252, 0.45);
    --egg-yolk:      rgba(251, 191, 36, 0.34);
    --egg-yolk-ink:  rgba(251, 191, 36, 0.75);
}

:root[data-theme="light"] {
    color-scheme: light;

    --bg:            #f4f7fb;
    --bg-grad-1:     #e4f1f3;
    --bg-grad-2:     #eef1f8;
    --panel:         rgba(255, 255, 255, 0.86);
    --panel-solid:   #ffffff;
    --panel-2:       rgba(241, 245, 249, 0.8);
    --line:          #e2e8f0;
    --line-strong:   #cbd5e1;

    --text:          #0d1829;
    --text-dim:      #3d4b5f;
    --muted:         #64748b;

    --primary:       #0d9488;
    --primary-ink:   #ffffff;
    --primary-soft:  rgba(13, 148, 136, 0.1);
    --accent:        #5b5bd6;
    --accent-soft:   rgba(91, 91, 214, 0.1);

    --toxic:         #e11d48;
    --toxic-soft:    rgba(225, 29, 72, 0.09);
    --safe:          #059669;
    --safe-soft:     rgba(5, 150, 105, 0.1);
    --warn:          #b45309;
    --warn-soft:     rgba(180, 83, 9, 0.1);

    --shadow:        0 20px 44px -28px rgba(15, 32, 56, 0.35);
    --shadow-sm:     0 6px 18px -12px rgba(15, 32, 56, 0.3);
    --ring:          0 0 0 3px rgba(13, 148, 136, 0.22);

    --egg-bg:        #eef2f7;
    --egg-white:     #ffffff;
    --egg-white-ink: #c3cedd;
    --egg-yolk:      #ffd666;
    --egg-yolk-ink:  #e0a92a;
}

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

/* the hidden attribute must win over component display rules (flex, grid…) */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background-color: var(--bg);
    background-image:
        radial-gradient(900px 600px at 12% -10%, var(--bg-grad-1) 0%, transparent 60%),
        radial-gradient(800px 500px at 100% 0%, var(--bg-grad-2) 0%, transparent 55%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.9rem, 1.2rem + 2.4vw, 3.1rem); font-weight: 700; }
h2 { font-size: clamp(1.35rem, 1rem + 1.2vw, 1.9rem); font-weight: 650; }
h3 { font-size: 1.1rem; font-weight: 650; }
p  { margin: 0 0 1rem; color: var(--text-dim); }
a  { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, canvas { max-width: 100%; }

/* every sprite icon gets a sane default size; component rules override it */
.ic-svg { width: 16px; height: 16px; flex: none; vertical-align: -.16em; }
code, kbd, pre, .mono { font-family: var(--font-mono); }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 8px; }
::selection { background: color-mix(in srgb, var(--primary) 32%, transparent); color: var(--text); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- layout ------------------------------------------------------ */
.wrap {
    width: 100%; max-width: 1480px; margin: 0 auto;
    padding-left: max(clamp(16px, 3vw, 32px), env(safe-area-inset-left, 0px));
    padding-right: max(clamp(16px, 3vw, 32px), env(safe-area-inset-right, 0px));
}
.wrap-narrow { max-width: 1040px; }
.stack > * + * { margin-top: var(--gap, 1rem); }
.row { display: flex; align-items: center; gap: .6rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }

/* Nothing in the app may be sized by its longest unbreakable string: every
   layout child opts out of the automatic minimum size, and long chemistry
   (a 60-character SMILES) ellipsizes or wraps inside its own box instead. */
.ws-col, .ws-col > *, .panel, .panel-head, .panel-body, .panel-foot,
.row > *, .row-between > *, .stack > *, .tile, .feature,
.queue-list > *, .queue-item > *, .history > *, .legend > * { min-width: 0; }
.panel-head > h2, .panel-head > h3 { min-width: 0; overflow-wrap: break-word; }
.hide-sm { display: initial; }
.only-sm { display: none; }

/* ---------- header ------------------------------------------------------ */
.site-head {
    position: sticky; top: 0; z-index: 60;
    height: var(--head-h);
    display: flex; align-items: center;
    backdrop-filter: blur(14px);
    background: color-mix(in srgb, var(--panel-solid) 78%, transparent);
    border-bottom: 1px solid var(--line);
}
.site-head .wrap { display: flex; align-items: center; gap: 1rem; }

.brand { display: flex; align-items: center; gap: .65rem; font-family: var(--font-display); font-weight: 700; font-size: 1.12rem; color: var(--text); letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 11px; flex: none;
    display: grid; place-items: center;
    background: linear-gradient(145deg, var(--primary), var(--accent));
    box-shadow: 0 8px 20px -10px var(--primary);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand em { font-style: normal; color: var(--primary); }

.nav { display: flex; align-items: center; gap: .25rem; margin-left: auto; }
.nav a {
    padding: .45rem .7rem; border-radius: 9px; font-size: .88rem; font-weight: 550;
    color: var(--text-dim); transition: background .15s, color .15s;
}
.nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }

.icon-btn {
    width: 36px; height: 36px; flex: none; display: grid; place-items: center;
    border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2);
    color: var(--text-dim); cursor: pointer; transition: .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); transform: translateY(-1px); }
.icon-btn svg { width: 17px; height: 17px; }

.nav-toggle { display: none; }

/* status pill */
.status-pill {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .34rem .7rem; border-radius: 99px; font-size: .72rem; font-weight: 650;
    letter-spacing: .06em; text-transform: uppercase;
    border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
    cursor: pointer;
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 99px; background: var(--muted); }
.status-pill[data-state="online"] { color: var(--safe); border-color: color-mix(in srgb, var(--safe) 35%, transparent); background: var(--safe-soft); }
.status-pill[data-state="online"] .dot { background: var(--safe); box-shadow: 0 0 0 4px color-mix(in srgb, var(--safe) 22%, transparent); animation: pulse 2.4s ease-in-out infinite; }
.status-pill[data-state="offline"] { color: var(--toxic); border-color: color-mix(in srgb, var(--toxic) 35%, transparent); background: var(--toxic-soft); }
.status-pill[data-state="offline"] .dot { background: var(--toxic); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* ---------- surfaces ---------------------------------------------------- */
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(10px);
    transition: border-color .2s, box-shadow .2s;
}
.panel:focus-within { border-color: color-mix(in srgb, var(--primary) 32%, var(--line)); }
.panel-head {
    display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
    padding: .85rem 1.1rem;
    border-bottom: 1px solid var(--line);
}
/* a long meta line drops to its own row rather than squeezing the title */
.panel-head .meta { font-size: .74rem; color: var(--muted); }
@media (max-width: 720px) {
    .panel-head .meta { flex-basis: 100%; }
    .panel-head > .grow { display: none; }
}
.panel-head h2, .panel-head h3 { margin: 0; font-size: .82rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--text-dim); }
.panel-body { padding: 1.1rem; }
.panel-foot { padding: .9rem 1.1rem; border-top: 1px solid var(--line); }

.eyebrow {
    display: inline-flex; align-items: center; gap: .45rem;
    font-size: .72rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
    color: var(--primary);
}

/* ---------- buttons ----------------------------------------------------- */
.btn {
    --btn-bg: var(--panel-2);
    --btn-fg: var(--text);
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .62rem 1.05rem; border-radius: 11px;
    border: 1px solid var(--line); background: var(--btn-bg); color: var(--btn-fg);
    font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
    transition: transform .12s, box-shadow .2s, background .2s, border-color .2s;
    text-decoration: none; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); border-color: var(--line-strong); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary {
    --btn-fg: var(--primary-ink);
    border-color: transparent;
    background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--accent) 60%, var(--primary)));
    box-shadow: 0 14px 30px -16px var(--primary);
    font-weight: 700;
}
.btn-primary:hover { box-shadow: 0 18px 36px -14px var(--primary); }
.btn-ghost { background: transparent; }
.btn-lg { padding: .85rem 1.4rem; font-size: .98rem; border-radius: 13px; }
.btn-sm { padding: .4rem .7rem; font-size: .8rem; border-radius: 9px; }
.btn-block { width: 100%; }

.segmented {
    display: grid; gap: 4px;
    grid-template-columns: repeat(var(--seg-cols, 4), minmax(0, 1fr));
    padding: 4px; border-radius: 13px; background: var(--panel-2); border: 1px solid var(--line);
}
.segmented button {
    min-width: 0; padding: .5rem .4rem; border: 0; border-radius: 9px; background: transparent;
    color: var(--muted); font: inherit; font-size: .84rem; font-weight: 650; cursor: pointer;
    transition: color .15s, background .15s, box-shadow .15s;
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-selected="true"] {
    background: var(--panel-solid); color: var(--text);
    box-shadow: var(--shadow-sm); border: 1px solid var(--line);
}
.segmented button svg { width: 15px; height: 15px; }

/* ---------- form controls ---------------------------------------------- */
.field { display: block; }
.field > span.label, .label {
    display: block; margin-bottom: .35rem;
    font-size: .74rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
input[type="text"], input[type="email"], input[type="search"], select, textarea {
    width: 100%; padding: .62rem .8rem;
    font: inherit; font-size: .92rem; color: var(--text);
    background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 120px; font-family: var(--font-mono); font-size: .84rem; line-height: 1.7; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 2rem; }

.switch { display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; font-size: .86rem; color: var(--text-dim); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 38px; height: 21px; border-radius: 99px; background: var(--line-strong); position: relative; transition: background .2s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 99px; background: #fff; transition: transform .2s; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(17px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }

/* ---------- dropzone ---------------------------------------------------- */
.dropzone {
    display: grid; place-items: center; gap: .3rem; text-align: center;
    min-height: 210px; padding: 1.5rem;
    border: 1.5px dashed var(--line-strong); border-radius: var(--radius);
    background: var(--panel-2); cursor: pointer; transition: .2s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--primary); background: var(--primary-soft); transform: translateY(-1px); }
.dropzone .big { width: 42px; height: 42px; color: var(--primary); }
.dropzone strong { font-size: .95rem; }
.dropzone small { color: var(--muted); }

/* ---------- chips, badges, pills --------------------------------------- */
.chip {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .28rem .6rem; border-radius: 99px;
    font-size: .74rem; font-weight: 650;
    border: 1px solid var(--line); background: var(--panel-2); color: var(--text-dim);
    cursor: default;
}
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--line-strong); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 40%, transparent); color: var(--primary); }
.chip-toxic { background: var(--toxic-soft); border-color: color-mix(in srgb, var(--toxic) 35%, transparent); color: var(--toxic); }
.chip-safe  { background: var(--safe-soft);  border-color: color-mix(in srgb, var(--safe) 35%, transparent);  color: var(--safe); }
.chip-warn  { background: var(--warn-soft);  border-color: color-mix(in srgb, var(--warn) 40%, transparent);  color: var(--warn); }
.chip-mono { font-family: var(--font-mono); font-size: .72rem; }

.badge {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .22rem .55rem; border-radius: 7px;
    font-size: .7rem; font-weight: 750; letter-spacing: .05em; text-transform: uppercase;
}
.badge-toxic { background: var(--toxic-soft); color: var(--toxic); }
.badge-safe  { background: var(--safe-soft);  color: var(--safe); }
.badge-muted { background: var(--panel-2);    color: var(--muted); }

/* ---------- metric tiles ----------------------------------------------- */
.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.tile {
    position: relative; overflow: hidden;
    padding: .9rem 1rem; border-radius: var(--radius-sm);
    border: 1px solid var(--line); background: var(--panel-2);
    transition: border-color .18s, transform .18s;
}
.tile::before {
    content: ""; position: absolute; inset: 0 auto auto 0; height: 2px; width: 100%;
    background: linear-gradient(90deg, var(--line-strong), transparent 70%);
}
.tile:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.tile.accent-toxic::before   { background: linear-gradient(90deg, var(--toxic), transparent 70%); }
.tile.accent-safe::before    { background: linear-gradient(90deg, var(--safe), transparent 70%); }
.tile.accent-primary::before { background: linear-gradient(90deg, var(--primary), transparent 70%); }
.tile .k { font-size: .68rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.tile .v { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; line-height: 1.1;
    margin-top: .25rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile .s { font-size: .75rem; color: var(--muted); }
.tile.accent-toxic .v { color: var(--toxic); }
.tile.accent-safe  .v { color: var(--safe); }
.tile.accent-primary .v { color: var(--primary); }

/* ---------- table ------------------------------------------------------- */
.table-scroll { overflow: auto; max-height: min(58vh, 620px); }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .86rem; }
table.data thead th {
    position: sticky; top: 0; z-index: 2;
    padding: .6rem .7rem; text-align: left; white-space: nowrap;
    font-size: .68rem; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
    background: color-mix(in srgb, var(--panel-solid) 94%, transparent);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(6px);
}
table.data thead th.sortable { cursor: pointer; user-select: none; }
table.data thead th.sortable:hover { color: var(--text); }
table.data thead th .arrow { opacity: .35; font-size: .8em; }
table.data thead th[aria-sort] .arrow { opacity: 1; color: var(--primary); }
table.data tbody td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr { cursor: pointer; transition: background .12s, box-shadow .12s; }
table.data tbody tr:hover { background: var(--panel-2); }
table.data tbody tr:hover td:first-child { box-shadow: inset 2px 0 0 var(--line-strong); }
table.data tbody tr:focus-visible { outline: none; background: var(--panel-2); box-shadow: var(--ring); }
@media (prefers-reduced-motion: no-preference) {
    table.data tbody tr.enter { animation: row-in .32s cubic-bezier(.22,.8,.2,1) both; }
    @keyframes row-in { from { opacity: 0; transform: translateY(5px); } }
}
table.data tbody tr[aria-selected="true"] { background: var(--primary-soft); }
table.data tbody tr[aria-selected="true"] td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.cell-num { font-family: var(--font-mono); font-size: .78rem; color: var(--muted); }
.cell-smiles { font-family: var(--font-mono); font-size: .78rem; max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.data td, table.data th { font-variant-numeric: tabular-nums; }
/* the table may scroll inside its own box; the page never scrolls sideways */
.table-scroll > table.data { min-width: 640px; }
@media (max-width: 860px) { .table-scroll > table.data { min-width: 0; } .cell-smiles { max-width: 22ch; } }
.cell-right { text-align: right; }
.cell-center { text-align: center; }

/* probability bar inside a cell */
.pbar { display: flex; align-items: center; gap: .5rem; }
.pbar .track {
    position: relative; flex: 1 1 54px; min-width: 42px; height: 7px;
    border-radius: 99px; background: var(--line); overflow: hidden;
}
.pbar .fill {
    display: block; height: 100%; border-radius: 99px;
    background: linear-gradient(90deg, color-mix(in srgb, var(--safe) 70%, transparent), var(--safe));
    transition: width .5s cubic-bezier(.22,.8,.2,1);
}
.pbar[data-tox="1"] .fill {
    background: linear-gradient(90deg, color-mix(in srgb, var(--toxic) 65%, transparent), var(--toxic));
}
/* the decision threshold, drawn where the verdict actually flips */
.pbar .track::after {
    content: ""; position: absolute; top: -2px; bottom: -2px;
    left: calc(var(--thr, 40.4%) - 1px); width: 2px;
    background: var(--text-dim); opacity: .55; border-radius: 2px;
}
.pbar .val { font-family: var(--font-mono); font-size: .76rem; width: 3.6em; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- gauge ------------------------------------------------------- */
.gauge { position: relative; width: 148px; height: 86px; flex: none; }
.gauge svg { width: 100%; height: 100%; overflow: visible; }
.gauge .read {
    position: absolute; inset: auto 0 0; text-align: center;
    font-family: var(--font-display); font-size: 1.45rem; font-weight: 700; line-height: 1;
}
.gauge .read small { display: block; font-family: var(--font-body); font-size: .62rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-top: .25rem; }

/* ---------- progress ---------------------------------------------------- */
/* pipeline indicator in the run card */
.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .4rem; }
.step { display: grid; gap: .35rem; min-width: 0; }
.step .bar { height: 4px; border-radius: 99px; background: var(--line); overflow: hidden; }
.step .bar span { display: block; height: 100%; width: 0; border-radius: 99px;
    background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .45s ease; }
.step .lbl { font-size: .66rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
    color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step[data-state="active"] .lbl { color: var(--primary); }
.step[data-state="active"] .bar span { width: 100%; animation: step-pulse 1.6s ease-in-out infinite; }
.step[data-state="done"] .bar span { width: 100%; }
.step[data-state="done"] .lbl { color: var(--text-dim); }
@keyframes step-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
@media (max-width: 560px) { .step .lbl { font-size: .6rem; letter-spacing: .04em; } }

.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress > span {
    display: block; height: 100%; border-radius: 99px; width: 0;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    transition: width .4s ease;
}
.progress.indeterminate > span {
    width: 35% !important;
    animation: slide 1.4s ease-in-out infinite;
}
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(320%); } }

.skeleton {
    border-radius: 8px;
    background: linear-gradient(90deg, var(--panel-2) 25%, var(--line) 37%, var(--panel-2) 63%);
    background-size: 400% 100%; animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------- empty state ------------------------------------------------ */
.empty { display: grid; place-items: center; gap: .5rem; padding: 3rem 1.5rem; text-align: center; color: var(--muted); }
.empty svg { width: 44px; height: 44px; opacity: .5; }
.empty .empty-art { width: min(220px, 70%); height: auto; color: var(--primary); opacity: .55; }
.empty .empty-hint { font-size: .74rem; color: var(--muted); opacity: .85; }
.empty .empty-hint kbd { margin: 0 .1rem; }
.empty strong { color: var(--text-dim); font-size: .95rem; }
.empty p { margin: 0; font-size: .85rem; max-width: 34ch; }

/* ---------- drawer ------------------------------------------------------ */
.drawer-backdrop {
    position: fixed; inset: 0; z-index: 80;
    background: rgba(2, 6, 14, .6); backdrop-filter: blur(3px);
    opacity: 0; pointer-events: none; transition: opacity .25s;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 81;
    width: min(460px, 100%); display: flex; flex-direction: column;
    background: var(--panel-solid); border-left: 1px solid var(--line);
    box-shadow: var(--shadow);
    transform: translateX(102%); transition: transform .3s cubic-bezier(.22,.8,.2,1);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: flex-start; gap: .75rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 1.1rem; }
.drawer-foot { padding: .85rem 1.1rem; border-top: 1px solid var(--line); display: flex; gap: .5rem; }

.depiction {
    border-radius: var(--radius-sm); border: 1px solid var(--line);
    background: #ffffff; min-height: 180px; display: grid; place-items: center; overflow: hidden;
}
/* structure drawings need a white canvas; a fallback message does not */
.depiction.is-fallback { background: var(--panel-2); }
.depiction canvas, .depiction svg { display: block; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: .5rem; }
.kv > div { padding: .55rem .6rem; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line); }
.kv dt { font-size: .66rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.kv dd { margin: .15rem 0 0; font-family: var(--font-mono); font-size: .92rem; }

.rule-row {
    display: flex; align-items: center; gap: .6rem;
    padding: .55rem .7rem; border-radius: 10px; border: 1px solid var(--line);
    background: var(--panel-2); margin-bottom: .4rem;
}
.rule-row .name { font-weight: 650; font-size: .86rem; }
.rule-row .why { font-family: var(--font-mono); font-size: .72rem; color: var(--muted); margin-top: .2rem; }
.rule-row.pass { border-color: color-mix(in srgb, var(--safe) 28%, transparent); background: var(--safe-soft); }
.rule-row.fail { border-color: color-mix(in srgb, var(--toxic) 28%, transparent); background: var(--toxic-soft); }

/* ---------- toasts ------------------------------------------------------ */
.toasts { position: fixed; z-index: 100; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: .5rem; max-width: min(360px, calc(100vw - 32px)); }
.toast {
    display: flex; gap: .6rem; align-items: flex-start;
    padding: .7rem .85rem; border-radius: 12px;
    background: var(--panel-solid); border: 1px solid var(--line);
    box-shadow: var(--shadow); font-size: .87rem;
    animation: toast-in .25s ease;
}
.toast svg { width: 17px; height: 17px; flex: none; margin-top: .1rem; }
.toast.ok svg    { color: var(--safe); }
.toast.warn svg  { color: var(--warn); }
.toast.error svg { color: var(--toxic); }
.toast .close { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- egg plot ---------------------------------------------------- */
.egg-wrap { position: relative; }
.egg-wrap svg { width: 100%; height: auto; display: block; }
.egg-point { cursor: pointer; transition: r .15s; }
.egg-point:hover { r: 7; }
.egg-tip {
    position: absolute; z-index: 5; pointer-events: none;
    padding: .45rem .6rem; border-radius: 9px; font-size: .75rem;
    background: var(--panel-solid); border: 1px solid var(--line-strong);
    box-shadow: var(--shadow-sm); white-space: nowrap; opacity: 0; transition: opacity .12s;
}
.egg-tip.show { opacity: 1; }
.egg-tip .mono { font-size: .72rem; color: var(--muted); display: block; }

.legend { display: flex; flex-wrap: wrap; gap: .75rem; font-size: .76rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- charts ------------------------------------------------------ */
.hist { display: flex; align-items: flex-end; gap: 3px; height: 92px; }
.hist .b { flex: 1 1 0; min-width: 3px; border-radius: 3px 3px 0 0; background: var(--primary); opacity: .85; position: relative; }
.hist .b[data-side="tox"] { background: var(--toxic); }
.hist .b:hover { opacity: 1; }
.axis { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: .66rem; color: var(--muted); margin-top: .3rem; }

.donut { display: flex; align-items: center; gap: 1rem; }
.donut svg { width: 118px; height: 118px; flex: none; }
.donut-legend { font-size: .82rem; display: grid; gap: .35rem; }
.donut-legend span { display: flex; align-items: center; gap: .45rem; }
.donut-legend i { width: 9px; height: 9px; border-radius: 3px; }
.donut-legend b { font-family: var(--font-mono); margin-left: auto; padding-left: .75rem; }

/* ---------- hero (landing panels) -------------------------------------- */
.hero { position: relative; padding: clamp(1.75rem, 4vw, 3.25rem) 0 clamp(1.25rem, 3vw, 2.25rem); overflow: hidden; }
.hero::after {
    content: ""; position: absolute; inset: auto 0 0; height: 1px; z-index: 1;
    background: linear-gradient(90deg, transparent, var(--line-strong) 20%, var(--line-strong) 80%, transparent);
}

/* instrument strip: the four numbers that frame every prediction */
.hero-stats {
    display: grid; gap: .6rem; margin-top: 1.25rem;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.hero-stats .hs {
    min-width: 0; display: grid; gap: .1rem; padding: .7rem .85rem;
    border-radius: var(--radius-sm); border: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel-solid) 55%, transparent);
    backdrop-filter: blur(6px);
    transition: border-color .18s, transform .18s;
}
.hero-stats .hs:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); transform: translateY(-1px); }
.hero-stats .k { font-size: .65rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.hero-stats .v { font-family: var(--font-display); font-size: 1.45rem; font-weight: 700; line-height: 1.15;
    color: var(--text); font-variant-numeric: tabular-nums; }
.hero-stats .s { font-size: .72rem; color: var(--muted); overflow-wrap: anywhere; }
.hero h1 { font-size: clamp(1.75rem, 1.1rem + 2vw, 2.7rem); }
.hero-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; opacity: .55; }
.hero .wrap { position: relative; z-index: 1; }
.hero p.lede { font-size: clamp(1rem, .95rem + .4vw, 1.18rem); max-width: 62ch; }
.gradient-text {
    background: linear-gradient(120deg, var(--primary), var(--accent) 75%);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}

.feature-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.feature { padding: 1.2rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); }
.feature .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); margin-bottom: .7rem; }
.feature .ic svg { width: 19px; height: 19px; }
.feature h3 { font-size: 1rem; margin-bottom: .3rem; }
.feature p { font-size: .88rem; margin: 0; }

/* ---------- docs ------------------------------------------------------- */
.doc-layout { display: grid; gap: 2rem; grid-template-columns: 240px minmax(0, 1fr); align-items: start; }
.doc-nav { position: sticky; top: calc(var(--head-h) + 20px); font-size: .88rem; }
.doc-nav a { display: block; padding: .35rem .7rem; border-left: 2px solid var(--line); color: var(--muted); }
.doc-nav a:hover { color: var(--text); text-decoration: none; }
.doc-nav a.active { color: var(--primary); border-left-color: var(--primary); background: var(--primary-soft); }
.doc-nav .group { margin: 1rem 0 .3rem; font-size: .7rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; color: var(--text-dim); }
.prose h2 { margin-top: 2.5rem; padding-top: .5rem; }
.prose h3 { margin-top: 1.75rem; }
.prose ul, .prose ol { color: var(--text-dim); padding-left: 1.3rem; }
.prose li { margin-bottom: .35rem; }
.prose code { background: var(--panel-2); border: 1px solid var(--line); padding: .1rem .35rem; border-radius: 5px; font-size: .84em; color: var(--primary); }
pre {
    margin: 0 0 1.25rem; padding: 1rem 1.1rem; overflow-x: auto;
    background: #0a111d; color: #d8e2f0; border: 1px solid var(--line); border-radius: var(--radius-sm);
    font-size: .82rem; line-height: 1.65;
}
:root[data-theme="light"] pre { background: #0f1b2d; color: #e6edf7; }
pre code, .prose pre code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; }
.callout {
    display: flex; gap: .75rem; padding: .9rem 1rem; margin: 0 0 1.5rem;
    border-radius: var(--radius-sm); border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
    background: var(--primary-soft);
}
.callout svg { width: 18px; height: 18px; color: var(--primary); flex: none; margin-top: .15rem; }
.callout p { margin: 0; font-size: .88rem; color: var(--text-dim); }
.callout.warn { border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: var(--warn-soft); }
.callout.warn svg { color: var(--warn); }

.endpoint { display: flex; align-items: center; gap: .6rem; font-family: var(--font-mono); font-size: .86rem; margin-bottom: .6rem; flex-wrap: wrap; }
.method { padding: .15rem .45rem; border-radius: 6px; font-size: .7rem; font-weight: 750; background: var(--accent-soft); color: var(--accent); }
.method.get { background: var(--safe-soft); color: var(--safe); }

/* ---------- team -------------------------------------------------------- */
.people { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.person { padding: 1.1rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); text-align: center; }
.person img { width: 84px; height: 84px; border-radius: 99px; object-fit: cover; border: 2px solid var(--line); margin-bottom: .6rem; }
.person .nm { font-weight: 650; }
.person .rl { font-size: .78rem; color: var(--primary); }
.person p { font-size: .82rem; margin: .5rem 0 0; }

/* ---------- footer ------------------------------------------------------ */
.site-foot {
    margin-top: 3rem; padding: 1.5rem 0; border-top: 1px solid var(--line);
    font-size: .8rem; color: var(--muted);
}
.site-foot .wrap { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: space-between; align-items: center; }
.site-foot a { color: var(--text-dim); }

/* ---------- workspace grid --------------------------------------------- */
.workspace { display: grid; gap: 1.1rem; grid-template-columns: minmax(360px, 420px) minmax(0, 1fr); align-items: start; padding-bottom: 2rem; }
.ws-col { display: grid; gap: 1.1rem; }
/* The input panel is taller than most viewports, so it is never sticky:
   a sticky box taller than the screen hides its own footer (and its submit
   button) below the fold with no way to scroll to it. */
.ws-sticky { position: static; }

.queue-list {
    max-height: 210px; overflow-y: auto; overflow-x: hidden;
    display: grid; gap: .3rem; padding-right: 2px;
}
/* a cut-off row should read as "there is more", not as a broken edge */
.queue-list.is-scrollable { -webkit-mask-image: var(--queue-mask); mask-image: var(--queue-mask); }
.queue-list.is-scrollable { --queue-mask: linear-gradient(to bottom, #000 calc(100% - 26px), transparent); }
.queue-list.is-scrollable.at-end { --queue-mask: none; }
.queue-item {
    display: flex; align-items: center; gap: .5rem;
    padding: .4rem .55rem; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line);
    font-family: var(--font-mono); font-size: .76rem;
    transition: border-color .15s, background .15s;
}
.queue-item:hover { border-color: var(--line-strong); }
.queue-item .n { color: var(--muted); flex: none; width: 1.6em; text-align: right; font-variant-numeric: tabular-nums; }
.queue-item .smi { min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-item .chip { flex: none; max-width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-item .x { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 .2rem; }
.queue-item .x:hover { color: var(--toxic); }
.queue-item.bad { border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: var(--warn-soft); }

.jsme-host { min-height: 320px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: #fff; overflow: hidden; }

.history { display: flex; gap: .4rem; flex-wrap: wrap; }

kbd {
    padding: .1rem .35rem; border-radius: 5px; border: 1px solid var(--line-strong);
    background: var(--panel-2); font-size: .72rem; color: var(--text-dim);
}

/* ---------- responsive -------------------------------------------------- */
@media (max-width: 1080px) {
    .workspace { grid-template-columns: minmax(0, 1fr); }
    .doc-layout { grid-template-columns: minmax(0, 1fr); }
    .doc-nav { position: static; display: flex; gap: .3rem; overflow-x: auto; padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
    .doc-nav a { border-left: 0; border-bottom: 2px solid transparent; white-space: nowrap; }
    .doc-nav a.active { border-bottom-color: var(--primary); }
    .doc-nav .group { display: none; }
}

@media (max-width: 620px) {
    /* four input tabs do not fit on one row at phone width: two by two */
    .segmented { --seg-cols: 2; }
}

@media (max-width: 560px) {
    /* header gets tight: the status pill becomes a single dot */
    .status-pill .txt { display: none; }
    .status-pill { padding: .5rem; }
    .brand span:last-child { font-size: 1rem; }
    .segmented button { font-size: .78rem; padding: .5rem .3rem; }
    .tiles { grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); }
    .tile .v { font-size: 1.35rem; }
    .panel-body, .panel-head, .panel-foot { padding-left: .85rem; padding-right: .85rem; }
    .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 400px) {
    /* the narrowest phones: labels only, no icons, inside the tabs */
    .segmented button svg { display: none; }
}

@media (max-width: 860px) {
    .hide-sm { display: none !important; }
    .only-sm { display: initial; }
    .nav-toggle { display: grid; }
    .nav {
        position: fixed; top: var(--head-h); left: 0; right: 0; z-index: 70;
        flex-direction: column; align-items: stretch; gap: .15rem;
        padding: .6rem clamp(16px, 3vw, 32px) 1rem;
        background: var(--panel-solid); border-bottom: 1px solid var(--line);
        box-shadow: var(--shadow); display: none;
    }
    .nav.open { display: flex; }
    .nav a { padding: .6rem .7rem; font-size: .95rem; }
    .drawer { width: 100%; border-left: 0; border-top-left-radius: 18px; border-top-right-radius: 18px; top: 10vh; }
    .table-scroll { max-height: none; }
    .toasts { left: 16px; right: 16px; bottom: 16px; max-width: none; }
    .gauge { width: 128px; height: 74px; }
}

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

@media print {
    .site-head, .site-foot, .drawer, .drawer-backdrop, .toasts, .no-print { display: none !important; }
    body { background: #fff; color: #000; }
    .panel { box-shadow: none; border-color: #ccc; }
}


/* System-preference fallback. The theme script in includes/layout.php sets
   data-theme before first paint, so this only applies if that script has not
   run yet or JavaScript is off - the palette is still correct either way. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;

    --bg:            #f4f7fb;
    --bg-grad-1:     #e4f1f3;
    --bg-grad-2:     #eef1f8;
    --panel:         rgba(255, 255, 255, 0.86);
    --panel-solid:   #ffffff;
    --panel-2:       rgba(241, 245, 249, 0.8);
    --line:          #e2e8f0;
    --line-strong:   #cbd5e1;

    --text:          #0d1829;
    --text-dim:      #3d4b5f;
    --muted:         #64748b;

    --primary:       #0d9488;
    --primary-ink:   #ffffff;
    --primary-soft:  rgba(13, 148, 136, 0.1);
    --accent:        #5b5bd6;
    --accent-soft:   rgba(91, 91, 214, 0.1);

    --toxic:         #e11d48;
    --toxic-soft:    rgba(225, 29, 72, 0.09);
    --safe:          #059669;
    --safe-soft:     rgba(5, 150, 105, 0.1);
    --warn:          #b45309;
    --warn-soft:     rgba(180, 83, 9, 0.1);

    --shadow:        0 20px 44px -28px rgba(15, 32, 56, 0.35);
    --shadow-sm:     0 6px 18px -12px rgba(15, 32, 56, 0.3);
    --ring:          0 0 0 3px rgba(13, 148, 136, 0.22);

    --egg-bg:        #eef2f7;
    --egg-white:     #ffffff;
    --egg-white-ink: #c3cedd;
    --egg-yolk:      #ffd666;
    --egg-yolk-ink:  #e0a92a;
  }
}
