/* Spec Import's own styling. The header, logo and brand line come from
   tabm-brand.css, which is linked first and owns .topbar/.brand/.brand-*.
   Everything below is this tool's own.

   Light and dark follow the convention the other TAB M tools use: an
   explicit data-theme wins, and its absence means follow the system. There
   is no toggle here yet -- this is a workbench, not a product -- but the
   tokens are set up so adding one is a script tag. */

:root {
  --brand: #cc3627;
  --brand-dark: #a82c1f;
  --ink: #14171d;
  --muted: #5b626e;
  --bg: #f6f7f9;
  --card: #ffffff;
  --card-raised: #f0f2f5;
  --border: #ccd1da;
  --link: #b32d1b;
  --ok: #2f7d55;
  --ok-bg: #dcf3e6;
  --warn: #b06305;
  --warn-bg: #fdf0d5;
  --danger: #c0261c;
  --danger-bg: #fbe0dd;
  --shadow: 0 1px 2px rgba(16, 20, 28, 0.08), 0 1px 3px rgba(16, 20, 28, 0.06);
  --tabm-header-bg: #ffffff;
  --tabm-header-text: #14171d;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --ink: #e5e7eb;
    --muted: #9aa3af;
    --bg: #12151c;
    --card: #1b1f29;
    --card-raised: #242a36;
    --border: #2b3140;
    --link: #ff9086;
    --ok: #6cc48f;
    --ok-bg: #12362a;
    --warn: #f5a623;
    --warn-bg: #4a3a12;
    --danger: #ff6b6b;
    --danger-bg: #4a1f1f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.25);
    --tabm-header-bg: #0b1019;
    --tabm-header-text: #ffffff;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 64px; }

.topnav { display: flex; gap: 18px; align-items: center; }
.topnav a {
  color: var(--tabm-header-text, #fff);
  opacity: 0.8; text-decoration: none; font-weight: 500; font-size: 15px;
}
.topnav a:hover, .topnav a.active { opacity: 1; }

h1 { font-size: 26px; margin: 0 0 4px; }
h2 { font-size: 19px; margin: 28px 0 10px; }
h3 { font-size: 16px; margin: 20px 0 8px; }
a { color: var(--link); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; box-shadow: var(--shadow); margin: 14px 0;
}
.error { color: var(--danger); font-weight: 500; }

button, .btn {
  background: var(--brand); color: #fff; border: none; border-radius: 6px;
  padding: 8px 14px; font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { background: var(--brand-dark); }
button.secondary { background: transparent; color: var(--ink); border: 1px solid var(--border); }
button.secondary:hover { background: var(--card-raised); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

input[type="text"], input[type="file"], select {
  font: inherit; padding: 7px 9px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--card); color: var(--ink);
}

table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }

/* Stage rail. Reads as a path, not tabs: these happen in order. */
.stages { display: flex; gap: 6px; margin: 16px 0 20px; flex-wrap: wrap; }
.stages a {
  padding: 8px 16px; border: 1px solid var(--border); border-radius: 999px;
  text-decoration: none; color: var(--muted); background: var(--card); font-weight: 500;
}
.stages a.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.pills { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.pills a {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 999px;
  text-decoration: none; color: var(--ink); background: var(--card); font-size: 13.5px;
}
.pills a.active { background: var(--card-raised); border-color: var(--muted); }

.tier { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.tier-exact { background: var(--ok-bg); color: var(--ok); }
.tier-probable { background: var(--warn-bg); color: var(--warn); }
.tier-none { background: var(--danger-bg); color: var(--danger); }
.tier-decided { background: var(--card-raised); color: var(--muted); }

.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.stat {
  flex: 1 1 150px; background: var(--card); border: 1px solid var(--border);
  border-left: 3px solid var(--border); border-radius: 8px; padding: 12px 14px;
}
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.stat.ok { border-left-color: var(--ok); }
.stat.warn { border-left-color: var(--warn); }
.stat.danger { border-left-color: var(--danger); }

.candidate { display: flex; align-items: baseline; gap: 8px; padding: 4px 0; }
.candidate label { cursor: pointer; }


/* ---------------------------------------------------------------- tables
   Both grids on the Check page are fixed-layout. Without it a <select>
   whose longest option is a 90-character system name sets the column width,
   and the column that actually needs the room -- the sheet heading -- gets
   squeezed into a ten-line vertical stack. Fixed layout plus width:100% on
   the controls means the option text can be as long as it likes without
   moving anything. */
table.grid { table-layout: fixed; width: 100%; }
table.grid th, table.grid td { padding: 6px 10px; vertical-align: middle; }
table.grid select, table.grid input[type="text"] { width: 100%; max-width: 100%; }

/* Long values truncate rather than wrap. The full text is on the title
   attribute, so nothing is lost -- a row that wraps to ten lines makes the
   table unreadable, and these are scanned, not read. */
.clip {
  display: block; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.two-line .a { font-weight: 500; }
.two-line .b { font-size: 12.5px; color: var(--muted); }

/* Sub-views inside a stage. */
.subnav { display: flex; gap: 4px; margin: 18px 0 10px; border-bottom: 1px solid var(--border); }
.subnav a {
  padding: 8px 16px; text-decoration: none; color: var(--muted); font-weight: 500;
  border: 1px solid transparent; border-bottom: none; border-radius: 8px 8px 0 0;
  margin-bottom: -1px;
}
.subnav a.active {
  color: var(--ink); background: var(--card);
  border-color: var(--border); border-bottom-color: var(--card);
}

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.toolbar .grow { flex: 1; }
.toolbar input[type="search"] { min-width: 260px; }

/* The per-row catalogue search sits under its dropdown, deliberately quiet
   until used -- most rows never need it. */
.row-search { display: flex; gap: 6px; align-items: center; margin-top: 3px; }
.row-search input.find { font-size: 12px; padding: 3px 6px; flex: 1; min-width: 0; }
.row-search .found { font-size: 11.5px; white-space: nowrap; }

/* The line grid carries more columns than a window is wide. It scrolls
   horizontally inside .table-wrap rather than squeezing every column to
   illegibility, so each one keeps a width that fits real content. */
/* No minimum width: everything fits the window, and the description gets
   its own row underneath rather than competing for a column. */
table.grid.lines th, table.grid.lines td { vertical-align: top; padding-top: 8px; }

/* A header label wider than its own column pushes the table past the window
   and brings back the horizontal scrollbar, which is easy to reintroduce by
   renaming a column. Clipping the header makes that impossible. */
table.grid.lines th { overflow: hidden; text-overflow: ellipsis; }

/* The description row belongs to the line above it, so it carries no top
   border and sits tight under its controls. */
table.grid.lines tr.line > td { border-bottom: none; padding-bottom: 4px; }
table.grid.lines tr.desc-row > td { border-top: none; padding-top: 0; padding-bottom: 10px; }

/* The sheet's description: three lines by default, full text on click.
   Long enough to judge a match, short enough to keep the row scannable. */
.desc {
  font-size: 12.5px; line-height: 1.45; color: var(--fg);
  white-space: pre-line; cursor: pointer;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
  overflow: hidden;
}
.desc.open { -webkit-line-clamp: unset; max-height: 340px; overflow-y: auto; }
.desc:hover { color: var(--accent); }

/* Commit progress. A long run needs to look like it is moving, or it is
   indistinguishable from a hang. */
.bar { height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; }
.bar-fill { height: 100%; background: var(--ok); transition: width .4s ease; }

/* Banding runs per item, not per row: an item is its controls plus its
   description, and they have to read as one block. */
table.grid.lines tr.line.alt > td,
table.grid.lines tr.desc-row.alt > td { background: rgba(127, 127, 127, 0.045); }

/* The catalogue search is offered quietly and opens only when asked. 150 of
   these standing open was the single heaviest thing on the page. */
.reveal-search {
  width: auto; background: none; border: none; padding: 2px 0; margin-top: 2px;
  color: var(--muted); font-size: 11.5px; text-align: left; cursor: pointer;
  text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px;
}
.reveal-search:hover { color: var(--accent); }

/* The per-row tick box only means something when the action is scoped to
   ticked rows, so it stays out of the way until that scope is chosen. */
table.grid.lines tr.line > td:first-child { visibility: hidden; }
table.grid.lines.show-pick tr.line > td:first-child { visibility: visible; }

/* An author display rule beats the [hidden] attribute, so .row-search needs
   to opt out of its own flex display when hidden -- otherwise the box the
   reveal button is supposed to open is on screen the whole time. */
.row-search[hidden] { display: none; }

/* Where the line came from in the spreadsheet. Two rows of the same model
   are two different line items, and without this the grid only ever showed
   where a line was going. */
.origin { margin: 0 0 3px; font-size: 11.5px; color: var(--muted); }
.origin .sep { opacity: 0.5; margin: 0 2px; }
.origin .uses {
  margin-left: 6px; padding: 1px 6px; border-radius: 999px;
  border: 1px solid var(--border); cursor: help;
}

/* A part's sheet lines, under its description: where each one came from and
   where it is going. The match is decided once above; these are the
   placements, and the same part legitimately sits in several rooms. */
.places { display: flex; flex-direction: column; gap: 4px; margin-top: 7px; }
.place {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--card);
}
.place.done { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.place-ok { display: flex; align-items: center; }
.place-from { flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place-qty { font-size: 12px; font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
/* Out-specifies table.grid select { width: 100% }, which otherwise blows each
   dropdown out to the full table width and crushes the origin text to zero. */
table.grid .place select { width: 200px; flex: 0 0 auto; font-size: 12.5px; padding: 3px 6px; }
@media (max-width: 900px) {
  .place { flex-wrap: wrap; }
  table.grid .place select { width: 46%; }
}
