:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1d212b; --line: #2a2f3a;
  --text: #e6e9ef; --muted: #8b93a3; --accent: #4ea1ff;
  --high: #3ddc84; --medium: #ffb14e; --low: #ff6b6b; --warn: #ffb14e; --ok: #3ddc84;
  --radius: 9px; --mono: ui-monospace, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
/* a display: rule beats the [hidden] attribute -- force hidden to win */
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
.muted { color: var(--muted); } .warn { color: var(--warn); } .ok { color: var(--ok); }
kbd { font: 11px var(--mono); background: #00000055; border: 1px solid var(--line);
  border-radius: 4px; padding: 0 5px; margin-right: 5px; }

/* app shell: flex column so the board fills remaining height regardless of
   whether the tabs / legend rails are present (no hardcoded 100vh-55px). */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* topbar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; flex: none;
  background: var(--panel); border-bottom: 1px solid var(--line); z-index: 5; }
.brand { font-weight: 700; letter-spacing: .3px; }
.brand span { color: var(--muted); font-weight: 400; font-size: 12px; }
.spacer { flex: 1; }
.docStatus { font-size: 14px; color: var(--text); font-weight: 500; }
.docStatus b { color: #fff; font-weight: 700; }
.docStatus .warn { color: var(--warn); } .docStatus .ok { color: var(--ok); }
.upload { background: var(--accent); color: #06121f; padding: 7px 13px; border-radius: var(--radius);
  cursor: pointer; font-weight: 600; white-space: nowrap; }
.upload:hover { filter: brightness(1.08); }
.upload.big { font-size: 16px; padding: 13px 26px; }
.bayWrap { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.bayWrap input { background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  padding: 7px 10px; border-radius: 6px; font: inherit; font-size: 14px; width: 170px; }
button { font: inherit; cursor: pointer; }
/* amber is RESERVED for the review action -- the one thing that may need attention */
.review { background: var(--warn); color: #1a1100; border: none;
  padding: 8px 14px; border-radius: var(--radius); font-weight: 700; }
.review:hover { filter: brightness(1.06); }
/* neutral secondary actions (cutout, export-all) -- muted, never amber */
.neutral, .reset { background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 7px 12px; border-radius: var(--radius); font-weight: 600; }
.neutral:hover { border-color: var(--accent); color: var(--text); }
.reset:hover { border-color: var(--low); color: var(--low); }
#exportBtn { background: var(--panel2); color: var(--muted); border: 1px solid var(--line);
  padding: 8px 18px; border-radius: var(--radius); font-weight: 700; }
#exportBtn.ready { background: var(--ok); color: #04130a; border-color: var(--ok); }
#exportBtn:disabled { opacity: .5; }

/* More dropdown menu */
.menuWrap { position: relative; }
#menuBtn.open { border-color: var(--accent); color: var(--text); }
.menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 20;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px #000a; padding: 6px; min-width: 210px; display: flex; flex-direction: column; gap: 2px; }
.menu button { display: block; width: 100%; text-align: left; background: transparent; border: none;
  color: var(--text); padding: 9px 12px; border-radius: 7px; font-size: 13px; font-weight: 500; }
.menu button:hover { background: var(--panel2); }
.menu button.danger { color: var(--low); }
.menu button.danger:hover { background: #2a1416; }
.menuSep { height: 1px; background: var(--line); margin: 4px 2px; }

/* legend / key strip */
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; flex: none;
  padding: 7px 16px; background: var(--panel2); border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--muted); }
.legend .lg { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend .lg b { color: var(--text); } .legend .bw { color: var(--warn); } .legend .ba { color: var(--low); }
.legend .lgsep { width: 1px; height: 14px; background: var(--line); }

/* bay tabs */
.bayTabs { display: flex; gap: 8px; padding: 10px 16px; background: var(--panel);
  border-bottom: 1px solid var(--line); overflow-x: auto; }
.bayTab { display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background: #28303d; border: 1px solid #3a4453; border-radius: 8px;
  padding: 8px 13px; min-width: 150px; text-align: left; color: var(--text);
  opacity: .82; transition: opacity .12s, border-color .12s, background .12s; }
.bayTab:hover { opacity: 1; border-color: var(--accent); }
.bayTab.on { opacity: 1; background: #313c4d; border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent); }
.tabName { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 200px; }
.tabStat { font-size: 11px; color: var(--muted); }
.tabFlag { color: var(--warn); font-weight: 600; } .tabOk { color: var(--ok); }

/* welcome */
.welcome { flex: 1; min-height: 0; display: grid; place-items: center; padding: 24px; }
.welcomeCard { max-width: 560px; text-align: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 48px 40px; }
.welcomeCard h1 { font-size: 26px; margin: 0 0 14px; }
.welcomeCard p { color: var(--muted); font-size: 15px; margin: 0 0 26px; }
.welcomeCard b { color: var(--text); }

/* single-cabinet banner (full-width bar above the board) */
.singleBanner { flex: none; display: flex; align-items: center; gap: 12px; margin: 12px 16px 0;
  background: color-mix(in oklab, var(--ok) 12%, var(--panel)); border: 1px solid var(--ok);
  border-radius: 12px; padding: 12px 16px; }
.singleBanner .tick { font-size: 22px; color: var(--ok); }
.singleBanner b { color: #fff; }
.singleBanner .sb-sub { color: var(--muted); font-size: 13px; }

/* board: columns per section */
.board { flex: 1; min-height: 0; display: flex; gap: 14px; padding: 16px; overflow-x: auto;
  align-items: flex-start; }
.col { flex: 0 0 270px; background: var(--panel); border: 1px solid var(--line);
  border-top: 3px solid var(--accent); border-radius: 12px; display: flex; flex-direction: column;
  max-height: 100%; }
.colHead { display: flex; align-items: center; gap: 8px; padding: 11px 13px; border-bottom: 1px solid var(--line); }
.colName { font-family: var(--mono); font-weight: 700; color: var(--accent); }
.colName small { color: var(--muted); font-weight: 400; }
.colCount { background: var(--panel2); border-radius: 20px; padding: 1px 9px; font-size: 12px; color: var(--muted); }
.colFlag { color: var(--warn); font-size: 12px; font-weight: 600; }
.p2x { margin-left: auto; font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 4px; cursor: pointer; }
.colGrid { overflow-y: auto; padding: 10px; display: grid;
  grid-template-columns: repeat(2, 1fr); gap: 8px; align-content: start; }
.colEmpty { grid-column: 1/-1; text-align: center; padding: 20px; }

.pcard { position: relative; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 7px; overflow: hidden; cursor: pointer; transition: border-color .12s, transform .08s; }
.pcard:hover { border-color: var(--accent); transform: translateY(-1px); }
.pcard.flag { border-color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.pcard.anomaly { border-color: var(--low); box-shadow: inset 0 0 0 2px var(--low); }
.pcard.cand { border-color: var(--accent); border-style: dashed; }
.pcard.orphan { border-color: var(--low); box-shadow: inset 0 0 0 2px var(--low); background: #2a1416; }
.flagBadge.anom { background: var(--low); color: #fff; }
.flagBadge.softb { background: var(--accent); color: #06121f; }
.flagBadge.orphanb { background: var(--low); color: #fff; }
.docStatus .cand, .legend .bc { color: var(--accent); }
.docStatus .orphan { color: var(--low); font-weight: 700; }
.pcard .thumb { width: 100%; aspect-ratio: 1.46; background: #0e1219 center/contain no-repeat;
  background-color: #0e1219; }
/* static placeholder (no animation -- a moving shimmer across a 255-tile board
   reads as the whole view "crawling"). */
.pcard .thumb:empty { background-color: #11161f; }
.pmeta { display: flex; align-items: center; justify-content: space-between; padding: 4px 7px; }
.pno { font-size: 11px; font-weight: 600; }
/* confidence chip: bigger + a letter so it survives small size / colorblindness */
.dot { width: 15px; height: 15px; border-radius: 4px; display: inline-flex; align-items: center;
  justify-content: center; font-size: 9px; font-weight: 800; color: #06121f; }
.dot.high { background: var(--high); } .dot.high::after { content: "C"; }
.dot.medium { background: var(--medium); } .dot.medium::after { content: "?"; }
.dot.low { background: var(--low); color: #fff; } .dot.low::after { content: "!"; }
.flagBadge { position: absolute; top: 4px; right: 4px; background: var(--warn); color: #1a1100;
  font-size: 10px; font-weight: 700; border-radius: 4px; padding: 0 4px; }

/* coverage / accounting ledger */
.coverage { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; }
.covSum { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 12px; font-size: 14px; line-height: 1.8; }
.covOk { color: var(--ok); font-weight: 700; } .covBad { color: var(--low); font-weight: 700; }
.covCounts { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); }
.covCounts b { font-family: var(--mono); }
.covTable { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.covHead, .covRow { display: grid; grid-template-columns: 90px 70px 110px 1fr 60px; gap: 12px;
  align-items: center; padding: 8px 14px; }
.covHead { background: var(--panel2); font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); position: sticky; top: 0; }
.covRow { border-top: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.covRow:hover { background: var(--panel2); }
.covRow.flag { border-left: 3px solid var(--warn); }
.covRow.orphan { border-left: 3px solid var(--low); background: #2a141633; }
.cpno { font-weight: 700; display: flex; align-items: center; gap: 7px; }
.cpno .dot { width: 12px; height: 12px; font-size: 8px; }
.cmuted { color: var(--muted); } .cmk { color: var(--warn); }
.cdst { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.dchip { font-family: var(--mono); font-size: 12px; padding: 2px 8px; border-radius: 5px;
  border: 1px solid var(--line); }
.dchip.dst-cab { color: var(--c, var(--accent)); border-color: color-mix(in oklab, var(--c, var(--accent)) 50%, var(--line)); }
.dchip.dst-shared { color: var(--c, var(--accent)); border-color: var(--c, var(--accent)); }
.dchip.dst-approval { color: #ff7fc4; border-color: #5a2a45; }
.dchip.dst-orphan { color: #fff; background: var(--low); border-color: var(--low); }
.dnote { font-size: 11px; color: var(--accent2); }

/* overlay */
.overlay { position: fixed; inset: 0; z-index: 30; }
.ovBackdrop { position: absolute; inset: 0; background: #000a; }
.ovPanel { position: absolute; inset: 3% 3%; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; display: grid; grid-template-columns: 1fr 340px; overflow: hidden; }
.ovImageWrap { background: #0a0c10; display: grid; place-items: center; overflow: auto; padding: 14px; }
.ovImageWrap img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 6px; }
.ovSide { border-left: 1px solid var(--line); padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.ovHead { display: flex; align-items: center; justify-content: space-between; }
.ovPageNo { font-size: 18px; font-weight: 700; }
.ovPageNo .src { font-size: 12px; color: var(--muted); font-weight: 400; }
.ovClose { background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; width: 30px; height: 30px; }
.ovWhy { font-size: 13px; color: var(--muted); background: var(--panel2); border-radius: 8px;
  padding: 11px 13px; line-height: 1.6; }
.whyFlag { color: var(--warn); font-weight: 700; } .whyOk { color: var(--ok); font-weight: 700; font-family: var(--mono); }
.ovQ { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.ovQsub { text-transform: none; letter-spacing: 0; font-size: 11px; color: var(--accent2); margin-left: 6px; }
.pileBtn .chk { font-size: 15px; margin: 0 4px; }
.pileBtn.quick { border-style: dashed; }
.ovPiles { display: flex; flex-direction: column; gap: 8px; }
.pileBtn { text-align: left; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 11px 12px; font-size: 14px; font-weight: 600; }
.pileBtn:hover { border-color: var(--accent); }
.pileBtn.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent);
  background: color-mix(in oklab, var(--accent) 16%, var(--panel2)); }
.pileBtn small { color: var(--muted); font-weight: 400; }
.ovNav { display: flex; gap: 8px; margin-top: auto; }
.ovNav button { flex: 1; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px; font-size: 13px; }
.ovNav button.primary { background: var(--warn); color: #1a1100; border: none; font-weight: 700; }
.ovHint { font-size: 11px; color: var(--muted); text-align: center; }

/* loading overlay */
.loading { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: #000a; }
.loadCard { background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 30px 40px; text-align: center; min-width: 280px; }
.spinner { width: 38px; height: 38px; margin: 0 auto 16px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loadMsg { font-size: 15px; font-weight: 600; }
.loadSub { font-size: 12px; margin-top: 6px; max-width: 320px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }

/* themed confirm dialog */
.confirm { position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; }
.cfBackdrop { position: absolute; inset: 0; background: #000b; }
.cfCard { position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 24px; max-width: 420px; box-shadow: 0 10px 40px #000a; }
.cfMsg { font-size: 15px; line-height: 1.5; margin-bottom: 20px; }
.cfBtns { display: flex; justify-content: flex-end; gap: 10px; }
.cfBtns button { padding: 8px 18px; border-radius: 8px; font-weight: 600; }
#cfOk { background: var(--accent); color: #06121f; border: none; }

/* error banner */
.errbar { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 45;
  display: flex; align-items: center; gap: 14px; max-width: 80vw;
  background: #2a1416; border: 1px solid var(--low); color: #ffd7d7;
  padding: 10px 14px; border-radius: 10px; font-size: 13px; box-shadow: 0 6px 24px #0008; }
.errClose { background: transparent; border: none; color: #ffd7d7; font-size: 14px; }

/* toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 9px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 40; }
.toast.show { opacity: 1; }
