/* Galax "Clinical clean" theme + smart workspace components (home dashboard, command palette, routing hints).
   Loaded last: refines the base tokens and overrides the dark navy sidebar with a light, calm one. */

:root {
  --font-head: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --navy: #0B2545;
  --blue: #1A56A8;
  --teal: #0E8A7D;

  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --surface-2: #F0F3F7;
  --surface-3: #E6EBF2;
  --border: #E1E6EE;
  --border-strong: #C3CDDA;
  --text: #0B1F35;
  --text-2: #3E4F66;
  --text-3: #66768C;
  --primary: #1A56A8;
  --primary-hover: #154A92;
  --primary-text: #1A56A8;
  --primary-weak: #E8F0FB;
  --signal: #0E8A7D;
  --signal-text: #0B6F65;
  --signal-weak: #E3F4F1;
  --shadow-1: 0 1px 2px rgba(11, 37, 69, .06), 0 0 0 1px rgba(11, 37, 69, .02);
  --shadow-2: 0 12px 32px rgba(11, 37, 69, .14), 0 2px 6px rgba(11, 37, 69, .06);
  --r-md: 12px; --r-lg: 16px;

  --side-bg: #FFFFFF;
  --side-text: #24364D;
  --side-text-2: #66768C;
  --side-strong: #0B1F35;
  --side-hover: #F0F3F7;
  --side-active: #E8F0FB;
  --side-active-text: #1A56A8;
  --side-border: #E1E6EE;
  --side-input: #F5F7FA;
  --side-focus: #1A56A8;

  --spec-cdisc: #1A56A8; --spec-cdisc-bg: #E8F0FB;
  --spec-biostat: #0E8A7D; --spec-biostat-bg: #E3F4F1;
  --spec-statprog: #6D3FC0; --spec-statprog-bg: #F0EAFB;
  --spec-extract: #A15C00; --spec-extract-bg: #FBF1E2;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0A1422; --surface: #0F1C2E; --surface-2: #152438; --surface-3: #1C2E46; --border: #20344E; --border-strong: #31496A;
    --text: #E7EDF5; --text-2: #AFBDCF; --text-3: #8B9BB0;
    --primary: #3B7BDB; --primary-hover: #5A92E6; --primary-text: #8DB6F5; --primary-weak: #142C4D;
    --signal: #1FB5A3; --signal-text: #5FE0CF; --signal-weak: #0D3230;
    --side-bg: #0C1828; --side-text: #D2DCE8; --side-text-2: #8B9BB0; --side-strong: #FFFFFF; --side-hover: rgba(255,255,255,.06);
    --side-active: rgba(59,123,219,.22); --side-active-text: #BCD3F7; --side-border: rgba(255,255,255,.08); --side-input: rgba(255,255,255,.05); --side-focus: #8DB6F5;
    --spec-cdisc: #8DB6F5; --spec-cdisc-bg: #142C4D; --spec-biostat: #5FE0CF; --spec-biostat-bg: #0D3230;
    --spec-statprog: #C3A8F5; --spec-statprog-bg: #2A1E45; --spec-extract: #F5C27A; --spec-extract-bg: #3A2A10;
  }
}
:root[data-theme="dark"] {
  --bg: #0A1422; --surface: #0F1C2E; --surface-2: #152438; --surface-3: #1C2E46; --border: #20344E; --border-strong: #31496A;
  --text: #E7EDF5; --text-2: #AFBDCF; --text-3: #8B9BB0;
  --primary: #3B7BDB; --primary-hover: #5A92E6; --primary-text: #8DB6F5; --primary-weak: #142C4D;
  --signal: #1FB5A3; --signal-text: #5FE0CF; --signal-weak: #0D3230;
  --side-bg: #0C1828; --side-text: #D2DCE8; --side-text-2: #8B9BB0; --side-strong: #FFFFFF; --side-hover: rgba(255,255,255,.06);
  --side-active: rgba(59,123,219,.22); --side-active-text: #BCD3F7; --side-border: rgba(255,255,255,.08); --side-input: rgba(255,255,255,.05); --side-focus: #8DB6F5;
  --spec-cdisc: #8DB6F5; --spec-cdisc-bg: #142C4D; --spec-biostat: #5FE0CF; --spec-biostat-bg: #0D3230;
  --spec-statprog: #C3A8F5; --spec-statprog-bg: #2A1E45; --spec-extract: #F5C27A; --spec-extract-bg: #3A2A10;
}

h1, h2, h3, h4 { font-weight: 650; letter-spacing: -.015em; }

/* ---------------- sidebar (light) ---------------- */
.side :focus-visible, .side-search input:focus-visible, .side-item > a:focus-visible, .side-item > button.link:focus-visible { outline-color: var(--side-focus); }
.side-brand .name { color: var(--side-strong); font-weight: 650; letter-spacing: -.01em; }
.side .icon-btn:hover { color: var(--side-strong); }
.new-chat { background: var(--primary); border-radius: 10px; box-shadow: 0 1px 2px rgba(11,37,69,.15); }
.new-chat:hover { background: var(--primary-hover); }
.side-cmd {
  all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 8px; width: 100%; height: 36px; padding: 0 10px;
  border-radius: 10px; border: 1px solid var(--side-border); background: var(--side-input); color: var(--side-text-2); cursor: pointer; font-size: var(--fs-md);
}
.side-cmd:hover { border-color: var(--border-strong); color: var(--side-text); }
.side-cmd:focus-visible { outline: 2px solid var(--side-focus); }
.side-cmd .icon { width: 16px; height: 16px; }
.side-cmd span { flex: 1; }
.side-cmd kbd { background: transparent; border-color: var(--side-border); color: var(--side-text-2); }
.side-search { margin: 8px 0 0; }
.side-search input { background: var(--side-input); color: var(--side-strong); height: 32px; padding-right: 10px; font-size: var(--fs-sm); border-radius: 8px; }
.side-nav { list-style: none; margin: 4px 0 6px; padding: 0 0 8px; border-bottom: 1px solid var(--side-border); }
.side-nav-link {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--side-text); text-decoration: none; font-size: var(--fs-md); font-weight: 500;
  position: relative;
}
.side-nav-link .icon { color: var(--side-text-2); }
.side-nav-link:hover { background: var(--side-hover); }
.side-nav-link.active { background: var(--side-active); color: var(--side-active-text); font-weight: 600; }
.side-nav-link.active .icon { color: var(--side-active-text); }
.side-nav-link.active::before { content: ""; position: absolute; left: -8px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); }
.side-nav-link:focus-visible { outline: 2px solid var(--side-focus); outline-offset: -2px; }
.side-section-head { text-transform: uppercase; letter-spacing: .06em; font-size: 11px; }
.side-item { border-radius: 8px; }
.side-item.active > a { color: var(--side-active-text); font-weight: 500; }
.side-user .who div { color: var(--side-strong); }
.side-pill { background: var(--signal-weak); color: var(--signal-text); }
.archived-toggle:hover { color: var(--side-strong); }
.project-filter { background: var(--side-active); color: var(--side-active-text); }
.avatar { background: var(--blue); }

/* ---------------- topbar & chat polish ---------------- */
.topbar { background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--border); }
.readiness-banner { font-size: var(--fs-sm); }
.composer { border-radius: 16px; box-shadow: var(--shadow-1); }
.composer:focus-within { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent), var(--shadow-1); }
.example { border-radius: 12px; }
.example:hover { border-color: var(--primary); }
.route-hint { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; margin-left: 6px; }
.rh-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.route-chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.route-chip.rc-cdisc { background: var(--spec-cdisc-bg); color: var(--spec-cdisc); }
.route-chip.rc-biostat { background: var(--spec-biostat-bg); color: var(--spec-biostat); }
.route-chip.rc-statprog { background: var(--spec-statprog-bg); color: var(--spec-statprog); }
.route-chip.rc-extract { background: var(--spec-extract-bg); color: var(--spec-extract); }
.card, .table-wrap { border-radius: var(--r-md); }
table.data th { text-transform: uppercase; font-size: 11px; letter-spacing: .05em; color: var(--text-3); }

/* ---------------- home dashboard ---------------- */
.home { flex: 1; overflow-y: auto; padding: 28px clamp(16px, 4vw, 48px) 56px; display: flex; flex-direction: column; gap: 20px; max-width: 1280px; width: 100%; margin: 0 auto; }
.home > * { flex: none; }
.home-hero {
  position: relative; border-radius: 20px; padding: 28px clamp(18px, 3vw, 36px) 22px; overflow: hidden;
  background:
    radial-gradient(1200px 300px at 100% 0%, color-mix(in srgb, var(--signal) 10%, transparent), transparent 60%),
    radial-gradient(900px 260px at 0% 100%, color-mix(in srgb, var(--primary) 9%, transparent), transparent 60%),
    var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-1);
}
.home-hero .eyebrow { margin: 0 0 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--signal-text); }
.home-hero h1 { font-size: clamp(24px, 2.6vw, 32px); margin: 0 0 2px; }
.home-hero .lede { color: var(--text-2); margin: 0 0 16px; font-size: var(--fs-lg); }
.ask-box { border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface); transition: box-shadow .15s, border-color .15s; }
.ask-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 15%, transparent); }
.ask-input { display: block; width: 100%; border: 0; background: transparent; resize: none; padding: 14px 16px 6px; font-size: var(--fs-base); line-height: 1.5; color: var(--text); min-height: 64px; }
.ask-input:focus-visible { outline: none; }
.ask-bar { display: flex; align-items: center; gap: 10px; padding: 6px 8px 8px 16px; }
.ask-route { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: var(--fs-sm); }
.ask-route .route-mode { margin-left: 2px; }
.ask-go { border-radius: 10px; gap: 8px; }
.hero-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.kbd-hint { all: unset; display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text-2); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.kbd-hint:hover { background: var(--surface-2); color: var(--text); }
.kbd-hint:focus-visible { outline: 2px solid var(--focus); }
.hero-model { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-3); margin-left: auto; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "ic label" "value value" "sub sub" "bar bar"; align-items: center; column-gap: 8px;
  padding: 16px 18px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-1); color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; }
a.kpi:hover { border-color: var(--primary); transform: translateY(-1px); }
.kpi-icon { grid-area: ic; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--primary-weak); color: var(--primary-text); }
.kpi:nth-child(2) .kpi-icon { background: var(--signal-weak); color: var(--signal-text); }
.kpi:nth-child(3) .kpi-icon { background: var(--spec-statprog-bg); color: var(--spec-statprog); }
.kpi:nth-child(4) .kpi-icon { background: var(--spec-extract-bg); color: var(--spec-extract); }
.kpi-label { grid-area: label; font-size: var(--fs-sm); color: var(--text-2); font-weight: 500; }
.kpi-value { grid-area: value; font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.kpi-sub { grid-area: sub; font-size: var(--fs-xs); color: var(--text-3); }
.kpi-bar { grid-area: bar; height: 4px; border-radius: 4px; background: var(--surface-3); margin-top: 10px; overflow: hidden; }
.kpi-bar span { display: block; height: 100%; background: var(--signal); border-radius: 4px; }
.kpi-bar span.hot { background: var(--danger); }

.card-block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 18px 20px; box-shadow: var(--shadow-1); min-width: 0; }
.block-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.block-head h2 { font-size: var(--fs-lg); margin: 0; display: inline-flex; align-items: center; gap: 8px; }
.block-head h2 .icon { color: var(--signal); }
.block-head > a, .block-head > .muted, .block-head > .live-dot { margin-left: auto; }
.home-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.home-empty { color: var(--text-3); font-size: var(--fs-sm); margin: 4px 0; padding: 14px; border: 1px dashed var(--border); border-radius: var(--r-md); background: var(--surface-2); }

.next-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.next-steps li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface-2); }
.ns-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--primary-weak); color: var(--primary-text); }
.ns-icon.ns-warn { background: var(--warn-bg); color: var(--warn-text); }
.ns-icon.ns-danger { background: var(--danger-weak); color: var(--danger-text); }
.ns-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ns-text b { font-size: var(--fs-md); }
.ns-text span { font-size: var(--fs-sm); color: var(--text-2); }

.workflows { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.wf { all: unset; box-sizing: border-box; display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface); cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; }
.wf:hover { border-color: var(--primary); box-shadow: var(--shadow-1); transform: translateY(-1px); }
.wf:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.wf-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--spec-cdisc-bg); color: var(--spec-cdisc); }
.wf-icon.wf-biostat { background: var(--spec-biostat-bg); color: var(--spec-biostat); }
.wf-icon.wf-statprog { background: var(--spec-statprog-bg); color: var(--spec-statprog); }
.wf-icon.wf-extract { background: var(--spec-extract-bg); color: var(--spec-extract); }
.wf-body { display: flex; flex-direction: column; gap: 2px; }
.wf-body b { font-size: var(--fs-md); }
.wf-body span { font-size: var(--fs-sm); color: var(--text-2); line-height: 1.45; }
.wf-tag { margin-top: auto; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li + li { border-top: 1px solid var(--border); }
.row-link { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-radius: 8px; cursor: pointer; color: inherit; }
.row-link:hover { background: var(--surface-2); }
.row-link:focus-visible { outline: 2px solid var(--focus); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main b { font-weight: 500; font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-glyph { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); font-family: var(--font-mono); font-size: 12px; flex: none; }
.row-chev { color: var(--text-3); }
.file-ext { width: 38px; height: 28px; border-radius: 6px; display: grid; place-items: center; background: var(--signal-weak); color: var(--signal-text); font-size: 10px; font-weight: 700; letter-spacing: .03em; flex: none; }
.mini-progress { width: 60px; height: 4px; border-radius: 4px; background: var(--surface-3); overflow: hidden; flex: none; }
.mini-progress span { display: block; height: 100%; background: var(--primary); }
.live-dot { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--signal-text); }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--signal); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--signal) 50%, transparent); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.study-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.study-card { border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.study-card.selected { border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-weak); }
.sc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sc-id { font-weight: 600; text-decoration: none; }
.sc-title { font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-std { display: flex; flex-wrap: wrap; gap: 4px; }
.sc-std span { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--text-3); font-family: var(--font-mono); }
.sc-actions { display: flex; gap: 6px; margin-top: 4px; }

@media (max-width: 1100px) { .workflows { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .home { padding: 16px 16px 40px; gap: 14px; }
  .home-cols, .next-steps, .study-cards { grid-template-columns: minmax(0, 1fr); }
  .workflows { grid-template-columns: minmax(0, 1fr); }
  .hero-model { margin-left: 0; }
  .ask-bar { flex-wrap: wrap; }
  .ask-route > .muted:only-child { display: none; }
  .ask-go { margin-left: auto; }
}

/* ---------------- command palette ---------------- */
.pal-back { position: fixed; inset: 0; z-index: 900; background: var(--overlay); display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; animation: palIn .12s var(--ease); }
@keyframes palIn { from { opacity: 0; } to { opacity: 1; } }
.pal { width: min(640px, 100%); max-height: 70vh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-2); overflow: hidden; }
.pal-search { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.pal-search .icon { color: var(--text-3); }
.pal-input { flex: 1; height: 54px; border: 0; background: transparent; font-size: var(--fs-lg); color: var(--text); }
.pal-input:focus-visible { outline: none; }
.pal-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.pal-group { padding: 10px 10px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.pal-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: var(--fs-md); }
.pal-item.active { background: var(--primary-weak); color: var(--primary-text); }
.pal-ic { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); flex: none; }
.pal-item.active .pal-ic { background: var(--primary); color: #fff; }
.pal-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-hint { font-size: var(--fs-xs); color: var(--text-3); flex: none; max-width: 40%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-empty { padding: 24px; text-align: center; color: var(--text-3); }
.pal-foot { display: flex; gap: 16px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-3); background: var(--surface-2); }
.pal-foot kbd { margin-right: 2px; }
@media (max-width: 600px) { .pal-back { padding-top: 8vh; } .pal-foot { display: none; } }

/* ---------------- training cockpit (Admin → Training & fine-tuning) ---------------- */
.tr-cockpit { display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.lifecycle { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); overflow: hidden; }
.lc-stage { all: unset; box-sizing: border-box; position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-areas: "ic label" "value value" "sub sub"; column-gap: 8px; align-items: center; padding: 14px 18px 14px 22px; cursor: pointer; transition: background .15s; min-width: 0; }
.lc-stage + .lc-stage { border-left: 1px solid var(--border); }
.lc-stage + .lc-stage::before { content: ""; position: absolute; left: -7px; top: 50%; width: 12px; height: 12px; background: var(--surface); border-top: 1px solid var(--border); border-right: 1px solid var(--border); transform: translateY(-50%) rotate(45deg); z-index: 1; }
.lc-stage:hover { background: var(--surface-2); }
.lc-stage:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.lc-ic { grid-area: ic; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-3); }
.lc-label { grid-area: label; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.lc-value { grid-area: value; font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lc-sub { grid-area: sub; font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lc-ok .lc-ic { background: var(--signal-weak); color: var(--signal-text); }
.lc-live .lc-ic { background: var(--primary-weak); color: var(--primary-text); }
.lc-live .lc-value { color: var(--primary-text); }
.lc-warn .lc-ic { background: var(--warn-bg); color: var(--warn-text); }

.tr-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: stretch; }
.tr-row > :only-child { grid-column: 1 / -1; }
.next-action { display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-radius: var(--r-lg); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-1); border-left: 4px solid var(--primary); }
.na-ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--primary-weak); color: var(--primary-text); }
.na-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.na-eyebrow { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); }
.na-text b { font-size: var(--fs-lg); }
.na-text > span:last-child { font-size: var(--fs-sm); color: var(--text-2); }
.na-warn { border-left-color: #D99A0B; }
.na-warn .na-ic { background: var(--warn-bg); color: var(--warn-text); }
.na-ok { border-left-color: var(--signal); }
.na-ok .na-ic { background: var(--signal-weak); color: var(--signal-text); }
.na-todo { border-left-color: var(--border-strong); }

.live-job { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); cursor: pointer; min-width: 340px; max-width: 440px; }
.live-job:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.lj-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.lj-text b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ring { --p: 0; width: 52px; height: 52px; border-radius: 50%; flex: none; display: grid; place-items: center; background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--surface-3) 0); }
.ring span { width: 40px; height: 40px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.spark { width: 120px; height: 34px; flex: none; overflow: visible; }
.spark polyline { fill: none; stroke: var(--chart-1); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
td .spark { width: 96px; height: 26px; display: block; }

.wizard.wiz2 { display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.vstepper { padding: 18px 14px; border-right: 1px solid var(--border); background: var(--surface-2); display: flex; flex-direction: column; gap: 14px; }
.vphase-title { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
.vphase.current .vphase-title { color: var(--primary-text); }
.vphase.done .vphase-title { color: var(--signal-text); }
.vphase ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.vphase li button { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; font-size: var(--fs-sm); color: var(--text-3); cursor: pointer; }
.vphase li button:disabled { cursor: default; }
.vphase li button:not(:disabled):hover { background: var(--surface); color: var(--text); }
.vphase li button:focus-visible { outline: 2px solid var(--focus); }
.vphase li .n { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 600; border: 1.5px solid var(--border-strong); background: var(--surface); flex: none; }
.vphase li.done button { color: var(--text-2); }
.vphase li.done .n { background: var(--signal); border-color: var(--signal); color: #fff; }
.vphase li.current button { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-1); }
.vphase li.current .n { background: var(--primary); border-color: var(--primary); color: #fff; }
.wiz-main { min-width: 0; display: flex; flex-direction: column; }
.wiz-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px var(--s5) 0; }
.wiz-pos { font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
.wiz-progress { flex: 1; min-width: 120px; height: 4px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.wiz-progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--signal)); border-radius: 4px; transition: width .3s var(--ease); }
.run-summary { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.rs-item { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-xs); max-width: 100%; }
.rs-k { color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; font-size: 10px; font-weight: 600; }
.rs-v { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.presets { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; margin: 6px 0 18px; }
.preset { all: unset; box-sizing: border-box; display: flex; gap: 12px; padding: 14px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface); cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.preset:hover { border-color: var(--border-strong); }
.preset[aria-checked="true"] { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); background: var(--primary-weak); }
.preset:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.preset-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--signal-weak); color: var(--signal-text); }
.preset-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.preset-body b { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: var(--fs-md); }
.preset-sub { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--primary-text); }

.plan-review { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.plan-checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.plan-checks li { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; font-size: var(--fs-sm); line-height: 1.45; background: var(--surface-2); color: var(--text-2); }
.plan-checks li .icon { margin-top: 2px; }
.plan-checks .pc-ok { background: var(--signal-weak); color: var(--signal-text); }
.plan-checks .pc-warn { background: var(--warn-bg); color: var(--warn-text); }
.plan-checks .pc-danger { background: var(--danger-weak); color: var(--danger-text); }
.plan-checks .pc-info .icon { color: var(--primary-text); }

.jobs-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chip-filter { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.fchip { all: unset; display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); font-size: var(--fs-sm); cursor: pointer; color: var(--text-2); background: var(--surface); }
.fchip:hover { border-color: var(--border-strong); }
.fchip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.fchip:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.fcount { font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.fchip[aria-pressed="true"] .fcount { background: rgba(255,255,255,.22); color: #fff; }
.job-name { display: flex; flex-direction: column; min-width: 0; }
.job-prog { display: flex; flex-direction: column; gap: 4px; min-width: 120px; }
.job-prog .bar { height: 6px; }

@media (max-width: 1100px) {
  .lifecycle { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lc-stage:nth-child(4) { border-left: 0; }
  .lc-stage:nth-child(4)::before { display: none; }
  .lc-stage:nth-child(n+4) { border-top: 1px solid var(--border); }
  .presets, .plan-review, .tr-row { grid-template-columns: minmax(0, 1fr); }
  .live-job { min-width: 0; }
}
@media (max-width: 760px) {
  .lifecycle { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lc-stage::before { display: none; }
  .lc-stage, .lc-stage + .lc-stage { border-left: 0; border-top: 1px solid var(--border); padding-left: 16px; }
  .lc-stage:nth-child(-n+2) { border-top: 0; }
  .lc-stage:nth-child(even) { border-left: 1px solid var(--border); }
  .lc-stage:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .wizard.wiz2 { grid-template-columns: minmax(0, 1fr); }
  .vstepper { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 12px; gap: 10px; }
  .vphase ol { flex-direction: row; }
  .vphase li .l { display: none; }
  .vphase li.current .l { display: inline; }
  .next-action { flex-wrap: wrap; }
  .next-action .btn { width: 100%; }
  .live-job .spark { display: none; }
}

/* ---------------- app version (admin panel) ---------------- */
.admin-version { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; font-size: var(--fs-xs); color: var(--text-3); }
.admin-version b { color: var(--text-2); font-variant-numeric: tabular-nums; }
.app-ver { font-variant-numeric: tabular-nums; }

/* ---------------- upload / validation progress and the Activity panel ---------------- */
.up-progress { margin-top: 14px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.up-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.up-head b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-head .btn { margin-left: auto; }
.up-bar { height: 10px; }
.up-line { font-size: var(--fs-sm); color: var(--text-2); font-variant-numeric: tabular-nums; }
.up-note { font-size: var(--fs-xs); color: var(--warn-text); background: var(--warn-bg); border-radius: 6px; padding: 4px 8px; align-self: flex-start; }
.bar.indeterminate > span { width: 35% !important; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
@media (prefers-reduced-motion: reduce) { .bar.indeterminate > span { animation: none; width: 100% !important; opacity: .45; } }

.activity { margin-bottom: 14px; padding: 12px 16px; border-radius: var(--r-lg); border: 1px solid var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-weak); }
.act-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.act-list { list-style: none; margin: 0; padding: 0; }
.act-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.act-row + .act-row { border-top: 1px solid var(--border); }
.act-ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--primary-weak); color: var(--primary-text); }
.act-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.act-top { display: flex; align-items: baseline; gap: 8px; }
.act-top b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-md); }
.act-pct { margin-left: auto; font-size: var(--fs-sm); font-weight: 700; color: var(--primary-text); font-variant-numeric: tabular-nums; }
.act-bar { height: 6px; }
.act-main .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

/* ================================================================ mobile & touch
   Phones (≤760px): no iOS zoom on input focus, compact banner, scrollable chat toolbar, tables as labelled cards,
   safe areas for notched phones. Touch screens (pointer: coarse): ~40px tap targets, no keyboard-shortcut hints. */
@media (max-width: 760px) {
  /* iOS Safari zooms into any field with text smaller than 16px */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
  select, textarea, .input, .ask-input, #composer-input, .pal-input, .side-search input { font-size: 16px !important; }

  /* readiness / external-model banner: one line, tap to expand */
  .readiness-banner { cursor: pointer; }
  .readiness-banner:not(.expanded) .grow { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
  .readiness-banner:not(.expanded)::after { content: "More"; flex: none; font-size: 11px; font-weight: 600; color: var(--warn-text); text-decoration: underline; }

  /* chat toolbar: mode / study / model buttons scroll sideways instead of being squeezed */
  .topbar .title-zone { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .topbar .title-zone::-webkit-scrollbar { display: none; }
  .topbar .title-zone > * { flex: none; }

  /* data tables → stacked cards with the column name beside each value */
  .table-wrap { overflow: visible; border: 0; background: transparent; box-shadow: none; }
  .table-wrap table.data, .table-wrap table.data tbody, .table-wrap table.data tr, .table-wrap table.data td { display: block; width: 100%; }
  .table-wrap table.data thead { display: none; }
  .table-wrap table.data tr { border: 1px solid var(--border); border-radius: var(--r-md); margin: 0 0 10px; padding: 6px 12px; background: var(--surface); box-shadow: var(--shadow-1); }
  .table-wrap table.data td { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 0; padding: 7px 0; text-align: right; min-height: 36px; word-break: break-word; }
  .table-wrap table.data td + td { border-top: 1px solid var(--surface-3); }
  .table-wrap table.data td::before { content: attr(data-label); flex: none; max-width: 45%; text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); }
  .table-wrap table.data td[data-label=""]::before { content: none; }
  .table-wrap table.data td[data-label=""] { justify-content: flex-end; }
  .table-wrap table.data td.num { text-align: right; }
  td .spark { width: 80px; }
  .job-prog { min-width: 0; flex: 1; max-width: 60%; }

  /* notched phones: keep the composer and drawers clear of the home indicator */
  .composer-wrap { padding-bottom: calc(var(--s3) + env(safe-area-inset-bottom, 0px)); }
  .side-foot, .admin-nav-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .dlg-backdrop { padding: 8px; align-items: end; }
  .dlg { max-height: calc(100dvh - 16px); border-radius: var(--r-lg) var(--r-lg) var(--r-md) var(--r-md); }
  .dlg-foot { padding-bottom: calc(var(--s4) + env(safe-area-inset-bottom, 0px)); }
  .dlg-foot .btn { flex: 1; }
}

@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.sm, .fchip { min-height: 40px; }
  .icon-btn { width: 40px; height: 40px; }
  .icon-btn.sm { width: 36px; height: 36px; }
  .kbd-hint { min-height: 40px; }
  .side-item > a, .side-item > button.link, .side-nav-link, .admin-nav a, .pal-item, .vphase li button { min-height: 40px; }
  .side-item .more { opacity: 1; }              /* no hover on touch: always show the ⋯ menu */
  .kb-hints, .new-chat kbd, .side-cmd kbd, .kbd-hint kbd, .pal-foot { display: none; }
}
