/* Linux Triage.
 *
 * Two notes that are load-bearing rather than decorative:
 *
 * 1. There is deliberately NO `overflow-x: hidden` on html or body. Page-level
 *    clipping hides a real horizontal spill instead of fixing it, and it makes
 *    the spill invisible to a browser check as well as to the eye. Every piece
 *    of content that can legitimately exceed the viewport - a table, a <pre>, a
 *    long command - lives inside its own `overflow-x: auto` scroller.
 * 2. Every grid and flex child that contains such a scroller carries
 *    `min-width: 0`. Without it a grid item's automatic minimum size is the
 *    width of its widest content, so the scroller never scrolls and the PAGE
 *    grows instead. That is the single most common cause of a mobile spill in
 *    a layout that looks correct on a desktop.
 */

:root {
  --bg: #0b1220;
  --panel: #111a2b;
  --panel2: #16203445;
  --line: #24304a;
  --text: #e7edf7;
  --muted: #9aa8c0;
  --accent: #7dd3fc;
  --accent2: #38bdf8;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

:root[data-theme="light"] {
  --bg: #f6f8fc;
  --panel: #ffffff;
  --panel2: #eef2f9;
  --line: #d8e0ee;
  --text: #14203a;
  --muted: #566179;
  --accent: #0369a1;
  --accent2: #0284c7;
  --good: #047857;
  --warn: #b45309;
  --bad: #b91c1c;
  --shadow: 0 1px 2px rgba(16, 30, 60, .10);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); }
a:hover { color: var(--accent2); }

code, .mono { font-family: var(--mono); font-size: .92em; overflow-wrap: anywhere; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .86em; }
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

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

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.backlink { text-decoration: none; white-space: nowrap; }
.sep { color: var(--muted); }

.topactions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.credits {
  font-family: var(--mono);
  font-size: .82rem;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

.topup {
  font-size: .82rem;
  text-decoration: none;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  padding: 7px 12px;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; border-color: var(--line); }

.ghost { background: transparent; font-size: .84rem; padding: 4px 10px; }
.mini { font-size: .8rem; padding: 4px 9px; }
.big { font-size: .95rem; padding: 9px 14px; }

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04121f;
  font-weight: 620;
}
:root[data-theme="light"] .primary { color: #ffffff; }
.primary:hover { background: var(--accent2); border-color: var(--accent2); }
.primary:disabled { background: var(--panel2); color: var(--muted); border-color: var(--line); }

/* --- lane switcher ------------------------------------------------------ */

.lanebar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
}

.lanegroup { display: flex; align-items: center; gap: 7px; min-width: 0; }

.lanestage {
  font-size: .68rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.lane { font-size: .86rem; padding: 5px 11px; white-space: nowrap; }
.lane[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #04121f;
  font-weight: 620;
}
:root[data-theme="light"] .lane[aria-pressed="true"] { color: #ffffff; }

/* --- layout ------------------------------------------------------------- */

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 16px 40px;
}

.hero { padding: 12px 2px 20px; }
.hero h1 { margin: 0 0 8px; font-size: 1.6rem; line-height: 1.25; }
.lede { margin: 0 0 14px; color: var(--muted); max-width: 74ch; }
.herobtns { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 0 0 18px;
  min-width: 0;
}

.field { margin: 0 0 14px; min-width: 0; }
.field label { display: block; font-weight: 620; margin-bottom: 4px; }
.labelrow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  justify-content: space-between;
}
.hint { margin: 0 0 6px; color: var(--muted); font-size: .87em; }

textarea, input[type="search"], input[type="text"], select {
  width: 100%;
  max-width: 100%;
  font-family: var(--mono);
  font-size: .87rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}
textarea { resize: vertical; line-height: 1.45; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea.dropping { border-color: var(--accent); background: var(--panel2); }

select { font-family: inherit; width: auto; max-width: 100%; padding: 5px 8px; }

.filerow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid2 > * { min-width: 0; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }

.box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 14px;
  background: var(--panel2);
  min-width: 0;
}
.box summary { cursor: pointer; font-weight: 620; }
.box .field { margin-top: 10px; margin-bottom: 0; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin: 0 0 12px;
}
.check, .sel { display: inline-flex; align-items: center; gap: 6px; font-size: .88rem;
  min-width: 0; max-width: 100%; flex-wrap: wrap; }
/* A <select> is a flex item of its .sel label (inline-flex still establishes a
 * flex context), and a flex item's AUTOMATIC minimum width is its content's
 * width - here, the longest <option> text. That default wins over
 * `max-width: 100%` on the select itself, which is the same class of bug the
 * table/pre scrollers above exist to avoid, just on a form control instead of
 * a table. min-width: 0 on the select is what actually lets it shrink. */
.sel select { min-width: 0; }
.check input { accent-color: var(--accent); }

/* --- the free scan panel ------------------------------------------------ */

.prescan {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 12px;
  background: var(--panel2);
  min-width: 0;
}
.prescanhead { margin: 0 0 8px; font-weight: 620; }

.notice {
  margin: 0 0 10px;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--muted);
  font-size: .87em;
}

.leak {
  margin: 0 0 10px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--bad);
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  color: var(--text);
  font-size: .9em;
}

.runrow { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.gate { margin: 8px 0 0; color: var(--warn); font-size: .88em; }
.gateaction { margin-left: 4px; font-weight: 620; }

/* --- progress ----------------------------------------------------------- */

.steps { list-style: none; margin: 0 0 8px; padding: 0; }
.step { display: flex; gap: 9px; align-items: baseline; padding: 2px 0; color: var(--muted); }
.step.live { color: var(--text); font-weight: 620; }
.step.done { color: var(--good); }
.stepmark { width: 1em; display: inline-block; text-align: center; }

/* --- results ------------------------------------------------------------ */

.resulthead {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
}
.resulthead h2 { margin: 0 0 4px; font-size: 1.2rem; }
.headline { margin: 0; color: var(--muted); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  display: inline-block;
  font-size: .74rem;
  font-family: var(--mono);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel2);
  white-space: nowrap;
}
.badge.good { border-color: var(--good); color: var(--good); }
.badge.warn { border-color: var(--warn); color: var(--warn); }
.badge.bad { border-color: var(--bad); color: var(--bad); }
.badge.muted { color: var(--muted); }

.summary { margin: 12px 0; max-width: 78ch; }

.exports { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0 18px; }

.result h3 { margin: 20px 0 8px; font-size: 1rem; }

/* Wide content scrolls INSIDE this box, never by growing the page. */
.tablewrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 100%;
}

table.data { border-collapse: collapse; width: 100%; font-size: .87rem; }
table.data th, table.data td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th {
  background: var(--panel2);
  font-size: .74rem;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
table.data tr:last-child td { border-bottom: 0; }
table.data td.numcell { text-align: right; font-family: var(--mono); white-space: nowrap; }
table.data.compact { font-size: .82rem; }
table.data td.mono { font-family: var(--mono); word-break: break-word; }

.findings { display: flex; flex-direction: column; gap: 10px; }
.finding {
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: var(--panel2);
  min-width: 0;
}
.finding.sev-crit { border-left-color: var(--bad); }
.finding.sev-warn { border-left-color: var(--warn); }
.finding.sev-info { border-left-color: var(--accent); }
.findhead { margin: 0 0 5px; }
.finding p { margin: 0 0 6px; }

pre.evidence, pre.artifact, pre.code {
  font-family: var(--mono);
  font-size: .82rem;
  line-height: 1.5;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  white-space: pre;
}
pre.artifact { white-space: pre-wrap; word-break: break-word; }

.questions { margin: 0; padding-left: 20px; }
.questions li { margin: 0 0 5px; }

.handoff {
  margin-top: 20px;
  padding: 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--panel2);
}
.handoff p { margin: 0 0 8px; }
.handoffbtns { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

/* --- history ------------------------------------------------------------ */

.history h2 { margin: 0; font-size: 1.1rem; }
.histctl { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.histctl input[type="search"] { width: 230px; max-width: 100%; font-family: inherit; }
.histlist { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.histrow {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: var(--panel2);
  min-width: 0;
}
.histhead { margin: 0 0 3px; }
.histrow p { margin: 0 0 5px; }
.histbtns { display: flex; flex-wrap: wrap; gap: 7px; }

/* --- footer, toast ------------------------------------------------------ */

.foot {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 16px 40px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .87rem;
}
.foot p { margin: 0 0 7px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  z-index: 60;
  font-size: .9rem;
}
.toast.ok { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }

/* --- docs pages (api.html, tokens.html) --------------------------------- */

.doc { max-width: 900px; margin: 0 auto; padding: 20px 16px 60px; }
.doc h1 { font-size: 1.5rem; margin: 0 0 10px; }
.doc h2 { font-size: 1.12rem; margin: 28px 0 8px; }
.doc h3 { font-size: 1rem; margin: 20px 0 6px; }
.doc p, .doc li { max-width: 80ch; }
.doc table { border-collapse: collapse; width: 100%; font-size: .87rem; }
.doc table th, .doc table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.doc table th { background: var(--panel2); }

.codegroup { margin: 10px 0 18px; min-width: 0; }
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
  padding: 0;
  list-style: none;
}
.tab {
  font-size: .78rem;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--muted);
}
.tab.active { border-color: var(--accent); color: var(--text); font-weight: 620; }

.statebox {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 12px 0 20px;
  background: var(--panel2);
}
.statebox p { margin: 5px 0 0; }

.tokenrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.tokenbox {
  font-family: var(--mono);
  font-size: .82rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: var(--bg);
  overflow-x: auto;
  white-space: nowrap;
  max-width: 100%;
  flex: 1 1 260px;
  min-width: 0;
}

/* The api.html endpoint list is a grid, and a grid item's automatic minimum
 * size is its content width - so a long path pushes the PAGE wide instead of
 * scrolling. min-width: 0 is what makes the scroller inside it actually work. */
.endpoints { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 8px; }
.endpoints li {
  min-width: 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  background: var(--panel2);
  font-family: var(--mono);
  font-size: .82rem;
  white-space: nowrap;
}

@media (max-width: 560px) {
  main, .foot { padding-left: 12px; padding-right: 12px; }
  .card { padding: 12px; }
  .hero h1 { font-size: 1.32rem; }
  .lanebar { gap: 10px; padding: 8px 12px; }
}

/* --- per-command copy and the step-contract warning ---------------------- */
.cmdcell { position: relative; }
.cmdcell .cmdcopy {
  margin-left: 0.6em; font-size: 0.78em; white-space: nowrap; vertical-align: baseline;
}
.stepwarn {
  margin: 0 0 0.7em; padding: 0.55em 0.75em; border-radius: 6px;
  background: var(--warn-bg, #fff4e0); border-left: 3px solid var(--warn, #c77700);
  font-size: 0.92rem;
}
