/* Finishing Quality Evaluation — shop-floor control sheet.
   Warm paper, ink, DIN-style numerals. Basket colours mirror the physical baskets
   (Alteration = yellow, B2 = red, Stain = green) and are always paired with a text label. */

:root {
  --paper: #f3efe6;
  --card: #fbf9f3;
  --ink: #1b2430;
  --ink-2: #4a5565;
  --ink-3: #7b8493;
  --line: #d9d2c1;
  --line-soft: #e8e2d3;
  --rail: #151c26;
  --rail-ink: #c9d1dc;
  --accent: #e8590c;

  --ok: #2b5fa8;
  --alt: #e0a100;
  --b2: #c2372c;
  --stain: #2f8f5b;

  --met: #0f766e;
  --near: #5b6676;
  --below: #8a2f6b;

  --font-display: Bahnschrift, "DIN Alternate", "Segoe UI Semibold", system-ui, sans-serif;
  --font-body: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;

  --radius: 6px;
  --shadow: 0 1px 0 rgba(27, 36, 48, 0.06), 0 6px 18px -12px rgba(27, 36, 48, 0.35);
  --rail-w: 220px;
  --control-h: 38px; /* one height for every input, dropdown, button and segmented control */
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.45 var(--font-body);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: 0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; top: 8px; }
.muted { color: var(--ink-3); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ---------------------------------------------------------------- shell */
.app { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100vh; }
.rail {
  background: var(--rail); color: var(--rail-ink);
  display: flex; flex-direction: column; padding: 22px 0 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 20px 20px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); margin-bottom: 14px; }
.brand b { display: block; font: 700 19px/1.1 var(--font-display); color: #fff; letter-spacing: 0.02em; }
.brand span { display: block; margin-top: 6px; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
.rail-group { padding: 12px 20px 6px; font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: #6f7a8b; }
.rail a {
  display: flex; align-items: center; gap: 10px; padding: 9px 20px; text-decoration: none;
  border-left: 3px solid transparent; color: var(--rail-ink);
}
.rail a:hover { background: rgba(255, 255, 255, 0.05); color: #fff; }
.rail a[aria-current="page"] { border-left-color: var(--accent); background: rgba(255, 255, 255, 0.07); color: #fff; font-weight: 600; }
.rail a svg { width: 17px; height: 17px; flex: none; opacity: 0.85; }
.rail-foot { margin-top: auto; padding: 14px 20px 0; font-size: 11.5px; color: #7d8898; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.rail-foot b { color: #fff; font-weight: 600; }
.rail-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.rail-user span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-user b { display: block; overflow: hidden; text-overflow: ellipsis; }
.rail-user .btn { padding: 0 8px; background: transparent; color: var(--rail-ink); border-color: rgba(255, 255, 255, 0.2); flex: none; }
.rail-user .btn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.main { padding: 26px 32px 60px; min-width: 0; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 28px; line-height: 1.05; }
.page-head p { margin: 6px 0 0; color: var(--ink-2); max-width: 62ch; }

/* ---------------------------------------------------------------- controls */
/* Bottom-aligned, so a label-less control (the 7/14/30 days buttons) sits level with the labelled date boxes. */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin-bottom: 18px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field > span, .field > label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 7px 9px; height: var(--control-h); min-width: 0;
}
input[type="number"] { text-align: right; }
input:disabled, select:disabled { background: var(--line-soft); color: var(--ink-3); }
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: var(--control-h); padding: 0 14px;
  border: 1px solid var(--ink); border-radius: var(--radius); background: var(--ink); color: #fff;
  font-weight: 600; cursor: pointer; text-decoration: none; transition: transform 0.12s, background 0.12s;
}
.btn:hover { background: #2a3646; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--line-soft); }
.btn.accent { background: var(--accent); border-color: var(--accent); }
.btn.accent:hover { background: #cf4d08; }
.btn.danger { background: transparent; color: var(--b2); border-color: var(--line); }
.btn.danger:hover { background: #f6dedb; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn svg { width: 15px; height: 15px; }

.segmented { display: inline-flex; height: var(--control-h); border: 1px solid var(--line); border-radius: var(--radius); background: #fff; overflow: hidden; }
.segmented button { border: 0; background: transparent; padding: 0 13px; cursor: pointer; height: 100%; border-right: 1px solid var(--line-soft); }
.segmented button:last-child { border-right: 0; }
.segmented button:hover { background: var(--line-soft); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: #fff; font-weight: 600; }

/* ---------------------------------------------------------------- panels */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 14px 18px 0; flex-wrap: wrap; }
.panel-head h2 { font-size: 17px; }
.panel-head .sub { color: var(--ink-3); font-size: 12.5px; }
.panel-body { padding: 14px 18px 18px; }
.grid { display: grid; gap: 18px; }
.grid > *, .stack > * { min-width: 0; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.two-one { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: grid; gap: 18px; }
.chart-box { position: relative; height: 270px; }
.chart-box.tall { height: 340px; }

/* KPI strip: first figure is the headline, the rest are supporting. */
.kpis { display: grid; grid-template-columns: minmax(0, 1.5fr) repeat(3, minmax(0, 1fr)); gap: 0; margin-bottom: 18px; }
.kpi { padding: 14px 20px; border-left: 1px solid var(--line); }
.kpi:first-child { border-left: 0; padding-left: 0; }
.kpi .label { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }
.kpi .value { font: 700 34px/1.1 var(--font-display); margin-top: 4px; }
.kpi:first-child .value { font-size: 52px; }
.kpi .sub { margin-top: 3px; color: var(--ink-2); font-size: 12.5px; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow: auto; max-width: 100%; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  position: sticky; top: 0; background: var(--card); text-align: left; font-size: 11px; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--ink-3); padding: 8px 10px; border-bottom: 2px solid var(--ink); white-space: nowrap;
}
table.data th.num { text-align: right; }
/* Fixed-width tables: headers may wrap onto two lines so narrow numeric columns stay readable. */
table.data.fixed { table-layout: fixed; }
table.data.fixed th, table.data.fixed td { overflow: hidden; text-overflow: ellipsis; padding-left: 7px; padding-right: 7px; }
table.data.fixed th { white-space: normal; vertical-align: bottom; font-size: 10.5px; letter-spacing: 0.04em; line-height: 1.25; }
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.data tbody tr:hover td { background: rgba(232, 89, 12, 0.05); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.selected td { background: rgba(232, 89, 12, 0.1); }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; background: var(--line-soft); }
table.data td.strong { font-weight: 600; }
.empty { padding: 34px 16px; text-align: center; color: var(--ink-3); }
.empty b { display: block; font: 600 16px var(--font-display); color: var(--ink-2); margin-bottom: 4px; }

/* ---------------------------------------------------------------- bands, baskets, meters */
.band { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.band.met { color: var(--met); }
.band.near { color: var(--near); }
.band.below { color: var(--below); }
.band.none { color: var(--ink-3); font-weight: 400; }
.band.good { color: var(--met); }
.band.watch { color: var(--near); }
.band.high { color: var(--below); }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.dot.ok { background: var(--ok); } .dot.alt { background: var(--alt); } .dot.b2 { background: var(--b2); } .dot.stain { background: var(--stain); }
.chip { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); background: #fff; }
.chip.alt { border-color: var(--alt); background: #fbf0cc; }
.chip.b2 { border-color: var(--b2); background: #f6dedb; }
.chip.stain { border-color: var(--stain); background: #d9eee2; }
.chip.btn-like { cursor: pointer; }
.chip.btn-like:hover { background: var(--line-soft); }

.meter { position: relative; height: 8px; background: var(--line-soft); border-radius: 4px; min-width: 50px; overflow: visible; }
.meter > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--ink); }
.meter.met > i { background: var(--met); } .meter.near > i { background: var(--near); } .meter.below > i { background: var(--below); }
.meter.progress > i { background: var(--ok); }
.meter > u { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); text-decoration: none; }
.basket-bar { display: flex; height: 14px; border-radius: 3px; overflow: hidden; background: var(--line-soft); }
.basket-bar > i { display: block; height: 100%; }
.basket-bar .alt { background: var(--alt); } .basket-bar .b2 { background: var(--b2); } .basket-bar .stain { background: var(--stain); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12.5px; color: var(--ink-2); margin-top: 8px; }

/* ---------------------------------------------------------------- work-order cards */
.wo-card { margin-bottom: 18px; }
.wo-head { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(180px, 1.2fr) auto; gap: 18px; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line-soft); }
.wo-head h3 { font-size: 22px; }
.wo-head .who { color: var(--ink-3); font-size: 12.5px; }
.wo-stat { display: flex; gap: 22px; }
.wo-stat div b { display: block; font: 700 20px var(--font-display); }
.wo-stat div span { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }

/* ---------------------------------------------------------------- entry form */
/* Checker and work order get double width; lot, target and the four baskets share one row. */
.entry-grid { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 12px; align-items: end; }
.entry-grid .wide { grid-column: span 2; }
@media (max-width: 1100px) { .entry-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); } }
.live-calc { display: flex; gap: 22px; flex-wrap: wrap; padding: 10px 0 0; color: var(--ink-2); }
.live-calc b { font: 700 18px var(--font-display); color: var(--ink); margin-left: 4px; }
.count-input { width: 100%; }
.count-label { display: flex; align-items: center; gap: 6px; }

/* ---------------------------------------------------------------- paper (report sheet) */
.paper { background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); padding: 28px 30px 24px; max-width: 1120px; }
.paper h2 { text-align: center; font-size: 21px; margin-bottom: 14px; }
.paper .form-head { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; margin-bottom: 14px; font-size: 13.5px; }
.paper .form-head b { font-weight: 700; }
.paper table.data { font-size: 12.5px; }
.paper table.data th { background: #fff; color: var(--ink); border: 1px solid var(--ink); text-align: center; white-space: normal; text-transform: none; letter-spacing: 0; font-size: 11.5px; }
.paper table.data td { border: 1px solid #aeb5bf; }
.paper table.data td:nth-child(3) { white-space: nowrap; }
.paper .sign { display: grid; grid-template-columns: 1fr 260px; gap: 24px; margin-top: 18px; }
.paper .remarks { border: 1px solid #aeb5bf; min-height: 82px; padding: 8px 10px; }
.paper .remarks span, .paper .sign-box span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.paper .sign-box { border-bottom: 1px solid var(--ink); min-height: 82px; padding: 8px 0; }
.paper .foot-note { margin-top: 14px; font-size: 11.5px; color: var(--ink-3); }

/* ---------------------------------------------------------------- account screen */
.account-form { display: grid; gap: 14px; max-width: 420px; }
.account-form input { width: 100%; }
.account-form .hint, dialog .field small { font-size: 12px; line-height: 1.35; }
.account-meta { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-bottom: 14px; color: var(--ink-2); }

/* ---------------------------------------------------------------- dialog & toast */
dialog { border: 1px solid var(--line); border-radius: 8px; padding: 0; background: var(--card); color: var(--ink); width: min(520px, 94vw); box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.5); }
dialog::backdrop { background: rgba(21, 28, 38, 0.55); }
dialog form { display: grid; gap: 14px; padding: 20px 22px 18px; }
dialog h2 { font-size: 20px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.form-error { color: var(--below); font-weight: 600; min-height: 18px; }

.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius); box-shadow: var(--shadow); border-left: 4px solid var(--met); max-width: 360px; }
.toast.error { border-left-color: var(--below); }

.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--ink); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 9px 16px; cursor: pointer; font-weight: 600; color: var(--ink-2); }
.tabs button:hover { background: var(--line-soft); }
.tabs button[aria-selected="true"] { background: var(--ink); color: #fff; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .grid.two, .grid.two-one { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 14px; }
  .kpi:nth-child(3) { border-left: 0; padding-left: 0; }
  .wo-head { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 8px; align-items: center; }
  .brand { border: 0; padding: 4px 10px; margin: 0; }
  .brand span, .rail-group, .rail-foot { display: none; }
  .rail a { padding: 7px 10px; border-left: 0; border-bottom: 3px solid transparent; }
  .rail a[aria-current="page"] { border-bottom-color: var(--accent); }
  .main { padding: 18px 14px 50px; }
  .kpis { grid-template-columns: 1fr; }
  .kpi, .kpi:nth-child(3) { border-left: 0; padding-left: 0; }
  .kpi:first-child .value { font-size: 42px; }
  .entry-grid .wide { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------------------------------------------------------------- print: only the paper sheet */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; }
  .rail, .no-print, .toasts, .skip-link { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  .paper { border: 0; box-shadow: none; padding: 0; max-width: none; }
}
