/* Terminal Precision — functional UI tokens (from DESIGN.md) */
:root {
  color-scheme: dark;
  --header-h: 66px;
  --bg: #0f131c;
  --bg-deep: #0a0e16;
  --surface: #181c24;
  --surface-2: #1c2028;
  --surface-3: #262a33;
  --text: #dfe2ee;
  --muted: #bacac2;
  --outline: #84948c;
  --line: #3b4a43;
  --primary: #6fffd1;
  --primary-container: #00e5b3;
  --on-primary: #00382a;
  --secondary: #7bd0ff;
  --tertiary: #ffbe6d;
  --error: #ffb4ab;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --radius: 4px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.55 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--secondary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }
.skip {
  position: absolute; left: -9999px; top: 0; z-index: 20;
  background: var(--primary-container); color: var(--on-primary); padding: 8px 12px;
}
.skip:focus { left: 8px; top: 8px; }
button, .chip { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
h1, h2, h3 { text-wrap: balance; scroll-margin-top: calc(var(--header-h) + 10px); }
.meta, .badge, .status-pill, .log, .pager { font-variant-numeric: tabular-nums; }
.result p, .card p, .news-item p { overflow-wrap: anywhere; }

.shell { display: grid; grid-template-columns: 232px minmax(0,1fr); min-height: 100vh; }
.rail {
  border-right: 1px solid var(--line); background: var(--bg-deep);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid var(--line); }
.mark {
  width: 30px; height: 30px; border: 1px solid var(--primary-container); color: var(--primary);
  border-radius: 6px; display: grid; place-items: center; font: 13px var(--mono);
}
.brand b { display: block; font-size: 14px; letter-spacing: -.01em; }
.brand span { display: block; color: var(--muted); font: 10px var(--mono); letter-spacing: .09em; }
.nav { padding: 14px 10px; display: grid; gap: 4px; }
.nav button {
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  padding: 9px 11px; text-align: left; color: var(--muted); font-size: 13px;
}
.nav button:hover { background: var(--surface); color: var(--text); }
.nav button[aria-current="page"] { background: var(--surface); border-color: var(--line); color: var(--text); }
.nav button .k { color: var(--primary); font: 10px var(--mono); margin-right: 9px; }
.rail-foot { margin-top: auto; padding: 14px 16px; border-top: 1px solid var(--line); color: var(--outline); font: 10px var(--mono); line-height: 1.7; }
.rail-foot a { color: var(--muted); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--outline); margin-right: 6px; }
.dot.ok { background: var(--primary-container); }
.dot.bad { background: var(--error); }

.main { min-width: 0; }
.topbar {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding: 14px 22px; border-bottom: 1px solid var(--line); background: var(--bg-deep);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.status-pill {
  font: 10px var(--mono); color: var(--muted); border: 1px solid var(--line);
  padding: 5px 8px; border-radius: 4px; white-space: nowrap;
}
.view { padding: 22px; }
.grid-2 { display: grid; grid-template-columns: minmax(0,1fr) 320px; gap: 18px; align-items: start; }
@media (max-width: 1050px) { .grid-2 { grid-template-columns: 1fr; } }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-deep); overflow: hidden; }
.panel + .panel { margin-top: 16px; }
.panel-head {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .02em; }
.panel-head .meta { color: var(--outline); font: 10px var(--mono); }
.panel-body { padding: 14px; }

.searchbar { display: flex; gap: 8px; flex-wrap: wrap; }
.searchbar input[type="search"] {
  flex: 1 1 360px; min-width: 0; background: var(--bg-deep); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 11px 12px; font-size: 14px;
}
.searchbar input[type="search"]:focus { border-color: var(--primary-container); }
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 4px; padding: 8px 12px; font-size: 12px;
}
.btn:hover:not(:disabled) { border-color: var(--primary-container); color: var(--primary); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary-container); border-color: var(--primary-container); color: var(--on-primary); font-weight: 600; }
.btn.primary:hover { color: var(--on-primary); filter: brightness(1.08); }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented button { border: 0; background: transparent; color: var(--muted); padding: 8px 10px; font-size: 11px; }
.segmented button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 4px; padding: 4px 9px; font: 10px var(--mono);
}
.chip:hover { border-color: var(--primary-container); color: var(--primary); }

.result { padding: 13px 14px; border-bottom: 1px solid var(--line); }
.result:last-child { border-bottom: 0; }
.result h3 { margin: 0 0 4px; font-size: 13px; font-weight: 600; }
.result h3 a { color: var(--text); }
.result h3 a:hover { color: var(--primary); }
.result .url { color: var(--primary); font: 10px var(--mono); overflow-wrap: anywhere; }
.result p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badge { border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; color: var(--outline); font: 10px var(--mono); }
.badge.local { border-color: var(--primary-container); color: var(--primary); }
.badge.warn { border-color: var(--tertiary); color: var(--tertiary); }
.pager { display: flex; gap: 8px; align-items: center; padding: 12px 14px; border-top: 1px solid var(--line); }
.pager .meta { color: var(--outline); font: 10px var(--mono); margin-left: auto; }

.cards { display: grid; grid-template-columns: repeat(auto-fill,minmax(min(100%, 190px),1fr)); gap: 10px; }
.card { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--surface); }
.card img { width: 100%; height: 112px; object-fit: cover; background: var(--surface-2); display: block; }
.img-fallback { height: 112px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font: 10px var(--mono); text-transform: uppercase; letter-spacing: .06em; }
.card .body { padding: 10px; }
.card h3 { font-size: 12px; margin: 0 0 5px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card p { font-size: 11px; color: var(--muted); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.news-item { padding: 11px 14px; border-bottom: 1px solid var(--line); }
.news-item:last-child { border-bottom: 0; }
.news-item h3 { margin: 0; font-size: 13px; }
.news-item .meta { color: var(--outline); font: 10px var(--mono); margin-top: 4px; }

details.inspect { border-bottom: 1px solid var(--line); }
details.inspect:last-child { border-bottom: 0; }
details.inspect summary { padding: 9px 12px; cursor: pointer; font: 11px var(--mono); color: var(--muted); }
details.inspect summary:hover { color: var(--primary); }
details.inspect pre { margin: 0; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--bg); overflow: auto; max-height: 280px; font: 10px/1.5 var(--mono); color: var(--muted); }

.field { display: grid; gap: 5px; margin-bottom: 12px; min-width: 0; }
.field label, .field .field-label { font: 10px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--outline); }
.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; }
.panel-head .meta.ok { color: var(--primary); }
.panel-head .meta.error { color: var(--error); }
.field input, .field textarea, .field select {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px;
}
.field textarea { min-height: 90px; resize: vertical; font-family: var(--mono); font-size: 11px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row .field { flex: 1 1 220px; margin-bottom: 0; }
.notice { padding: 10px 14px; color: var(--muted); font-size: 12px; }
.notice.error { color: var(--error); }
.notice.ok { color: var(--primary); }

.phase { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 10px; overflow: hidden; }
.phase h3 { margin: 0; padding: 11px 13px; background: var(--surface); font-size: 13px; }
.phase .body { padding: 12px 13px; }
.phase ul { margin: 6px 0 10px; padding-left: 18px; color: var(--muted); font-size: 12px; }
.phase .tag { color: var(--tertiary); font: 10px var(--mono); }
.qcard { border: 1px solid var(--line); border-radius: 6px; padding: 12px; margin-bottom: 10px; }
.qcard strong { font-size: 13px; }
.qcard p { color: var(--muted); font-size: 11px; margin: 4px 0 8px; }

table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--outline); font: 10px var(--mono); text-transform: uppercase; letter-spacing: .06em; }
code { font-family: var(--mono); font-size: 11px; }
pre.response { margin: 0; padding: 12px; background: var(--bg); overflow: auto; max-height: 420px; font: 11px/1.55 var(--mono); color: var(--muted); }
.log { font: 10px/1.7 var(--mono); color: var(--muted); }
.log .ok { color: var(--primary); }
.log .bad { color: var(--error); }

@media (max-width: 760px) {
  :root { --header-h: 56px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; min-width: 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 10px 14px; }
  .nav { display: flex; width: 100%; min-width: 0; overflow-x: auto; padding: 6px 10px; }
  .nav button { white-space: nowrap; }
  .rail-foot { display: none; }
  .view { padding: 12px; min-width: 0; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar .status-pill { display: none; }
  .global-search { min-width: 0; flex: 1 1 auto; max-width: none; }
  .global-search input { min-width: 0; }
}
/* Touch targets and responsive refinements */
.btn, .chip, .nav button, .segmented button, .examples button, .saved button,
.field input, .field select, .global-search input, .searchbar input { min-height: 44px; }
.chip { display: inline-flex; align-items: center; }
.panel-head .meta { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (min-width: 761px) and (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { display: flex; width: 100%; min-width: 0; overflow-x: auto; padding: 6px 10px; }
  .rail-foot { display: none; }
  .topbar { flex-wrap: nowrap; padding: 8px 14px; }
  .topbar .status-pill:not(#modeMeta) { display: none; }
  .global-search { flex: 1 1 auto; min-width: 0; max-width: none; }
}
@media (max-width: 520px) {
  .cards { grid-template-columns: minmax(0, 1fr); }
  .card img { height: 180px; }
  .img-fallback { height: 180px; }
  .card h3 { font-size: 13px; -webkit-line-clamp: 3; }
  .card p { font-size: 11px; }
  .pager .meta { display: none; }
  .pager .btn { white-space: nowrap; }
}
/* Mono microcopy follows the exported token rule */
.status-pill, .badge, .panel-head .meta, .chip, .examples button, .saved button,
.summary .line span:first-child, .log, .phase .tag, .eyebrow,
.field-label, .field label { text-transform: uppercase; letter-spacing: .06em; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Easier entry points */
.global-search { display: flex; gap: 6px; align-items: center; flex: 1 1 260px; max-width: 420px; }
.global-search input {
  width: 100%; min-width: 0; background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 10px; font-size: 12px;
}
.global-search input:focus { border-color: var(--primary-container); }
.examples, .saved { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.examples { margin-top: 10px; }
.saved { margin-top: 8px; }
.examples .eyebrow, .saved .eyebrow { color: var(--outline); font: 10px var(--mono); letter-spacing: .06em; text-transform: uppercase; margin-right: 2px; }
.examples button, .saved button {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 4px; padding: 3px 9px; font: 10px var(--mono);
}
.examples button:hover, .saved button:hover { border-color: var(--primary-container); color: var(--primary); }
.saved button.active { border-color: var(--primary-container); color: var(--primary); }
.saved .clear { color: var(--outline); border-style: dashed; }

/* Guided goal flow */
.stepper { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.stepper .step {
  display: flex; gap: 7px; align-items: center; border: 1px solid var(--line);
  border-radius: 4px; padding: 5px 10px; color: var(--outline); font: 10px var(--mono);
}
.stepper .step b { color: var(--text); font-weight: 500; }
.stepper .step.on { border-color: var(--primary-container); color: var(--primary); }
.stepper .step.done { border-color: var(--line); color: var(--muted); }

/* Reasoning summaries */
.summary { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.summary .line { display: flex; gap: 10px; justify-content: space-between; font-size: 11px; margin: 3px 0; }
.summary .line span:first-child { color: var(--outline); font-family: var(--mono); font-size: 10px; }
.summary .line span:last-child { color: var(--text); text-align: right; overflow-wrap: anywhere; }
.summary .items { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.summary .items i { font-style: normal; border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; color: var(--muted); font: 10px var(--mono); }
.summary .items i.accent { border-color: var(--primary-container); color: var(--primary); }

.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%) translateY(20px);
  background: var(--surface-3); border: 1px solid var(--primary-container); color: var(--text);
  border-radius: 6px; padding: 8px 14px; font-size: 12px; opacity: 0; pointer-events: none; z-index: 30;
  transition: opacity .16s, transform .16s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 760px) {
  .global-search { flex: 1 1 auto; max-width: none; min-width: 0; }
  .stepper .step { padding: 4px 8px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card img { height: 82px; }
  .card .body { padding: 8px; }
  .card h3 { font-size: 11px; line-height: 1.35; }
  .card p { font-size: 10px; }
}
