/*
 * Capture screen styles.
 *
 * Same visual system as analytics/prototype/audit-dashboard-demo.html -- the
 * dashboards move into this app later (ADR-0009), and two visual systems in one
 * product is a thing we would then have to maintain twice.
 *
 * What differs from the prototype, and why: this is operated with gloves on a
 * tablet at arm's length, so the base size is 17px, every control is at least
 * 52px tall, and nothing important is conveyed by colour alone.
 */
:root {
  color-scheme: light;
  --page:#f9f9f7; --surface:#fcfcfb; --sunken:#f2f1ed;
  --ink:#0b0b0b; --ink-2:#52514e; --muted:#898781;
  --border:rgba(11,11,11,0.12); --hair:rgba(11,11,11,0.07);
  --series:#2a78d6; --series-ink:#ffffff;
  --critical:#d03b3b; --critical-wash:rgba(208,59,59,0.07);
  --good:#2f7d54; --good-wash:rgba(47,125,84,0.09);
  --chip:#f0efec;
  --warn-bg:#fdf6e3; --warn-line:#fab219;
  --radius:14px;
  --tap:52px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:#0d0d0d; --surface:#1a1a19; --sunken:#141413;
    --ink:#ffffff; --ink-2:#c3c2b7; --muted:#898781;
    --border:rgba(255,255,255,0.13); --hair:rgba(255,255,255,0.07);
    --series:#3987e5; --series-ink:#ffffff;
    --critical:#e05c5c; --critical-wash:rgba(224,92,92,0.12);
    --good:#57ab7d; --good-wash:rgba(87,171,125,0.12);
    --chip:#262623;
    --warn-bg:#2a2413; --warn-line:#fab219;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:#0d0d0d; --surface:#1a1a19; --sunken:#141413;
  --ink:#ffffff; --ink-2:#c3c2b7; --muted:#898781;
  --border:rgba(255,255,255,0.13); --hair:rgba(255,255,255,0.07);
  --series:#3987e5; --series-ink:#ffffff;
  --critical:#e05c5c; --critical-wash:rgba(224,92,92,0.12);
  --good:#57ab7d; --good-wash:rgba(87,171,125,0.12);
  --chip:#262623;
  --warn-bg:#2a2413; --warn-line:#fab219;
}

* { box-sizing:border-box; }
html { -webkit-text-size-adjust:100%; }
body {
  margin:0; background:var(--page); color:var(--ink);
  font-family:system-ui,-apple-system,"Segoe UI",sans-serif;
  font-size:17px; line-height:1.5;
  -webkit-tap-highlight-color:rgba(42,120,214,0.15);
}
.wrap { max-width:860px; margin:0 auto; padding:16px 16px 200px; }
[hidden] { display:none !important; }

/* ---------- banners ---------- */
.banner {
  display:flex; gap:12px; align-items:flex-start;
  border:1px solid var(--border); border-left-width:4px;
  border-radius:10px; padding:12px 14px; margin-bottom:16px;
}
.banner b { display:block; }
.banner p { margin:2px 0 0; font-size:15px; color:var(--ink-2); }
.banner svg { flex:none; margin-top:3px; }
.banner--demo { background:var(--warn-bg); border-left-color:var(--warn-line); }
.banner--saved { background:var(--good-wash); border-left-color:var(--good); }
.banner--error { background:var(--critical-wash); border-left-color:var(--critical); }

/* ---------- header ---------- */
header { margin:4px 0 22px; }
header h1 { font-size:clamp(22px,4.6vw,29px); margin:0 0 4px; letter-spacing:-0.02em; }
header .sub { color:var(--ink-2); font-size:15px; margin:0; }
.device {
  display:inline-flex; align-items:center; gap:7px; margin-top:10px;
  font-size:13px; font-weight:600; letter-spacing:0.04em; text-transform:uppercase;
  color:var(--ink-2); background:var(--chip); border-radius:999px; padding:5px 11px;
}

/* ---------- sections ---------- *
 * Numbered because the form IS a sequence: it follows the order of the fields
 * on the paper sheet it replaces, so a supervisor can work down the tablet the
 * same way they worked down the page. */
.card {
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius); padding:20px; margin-bottom:14px;
}
.card > h2 {
  font-size:13px; font-weight:700; letter-spacing:0.08em; text-transform:uppercase;
  color:var(--muted); margin:0 0 16px; display:flex; align-items:center; gap:10px;
}
.card > h2 .n {
  display:inline-grid; place-items:center; width:24px; height:24px; border-radius:50%;
  background:var(--chip); color:var(--ink-2); font-size:12px; letter-spacing:0;
  font-variant-numeric:tabular-nums;
}
.card > .note { color:var(--ink-2); font-size:15px; margin:-8px 0 18px; }

/* ---------- fields ---------- */
.row { display:flex; flex-wrap:wrap; gap:14px; }
.field { display:flex; flex-direction:column; gap:6px; flex:1 1 200px; min-width:0; }
.field--wide { flex:1 1 100%; }
label, .lbl {
  font-size:13px; font-weight:600; letter-spacing:0.05em; text-transform:uppercase;
  color:var(--ink-2);
}
label .opt { text-transform:none; letter-spacing:0; font-weight:400; color:var(--muted); }
input, select, textarea {
  font:inherit; color:var(--ink); background:var(--surface);
  border:1px solid var(--border); border-radius:10px;
  padding:0 12px; height:var(--tap); width:100%;
}
textarea { height:auto; min-height:76px; padding:12px; resize:vertical; }
select { appearance:none; padding-right:38px;
  background-image:linear-gradient(45deg,transparent 50%,currentColor 50%),
                   linear-gradient(135deg,currentColor 50%,transparent 50%);
  background-position:calc(100% - 19px) 22px, calc(100% - 13px) 22px;
  background-size:6px 6px, 6px 6px; background-repeat:no-repeat; }
input[type=number] { font-variant-numeric:tabular-nums; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible,
[tabindex]:focus-visible {
  outline:2px solid var(--series); outline-offset:2px;
}
input.bad, select.bad { border-color:var(--critical); background:var(--critical-wash); }
.hint { font-size:13.5px; color:var(--muted); }
.err { font-size:13.5px; color:var(--critical); font-weight:600; }

/* ---------- picker (bottle, defect) ---------- */
.picker { position:relative; }
.picker input { padding-right:44px; }
.picker .clear {
  position:absolute; right:6px; top:6px; width:40px; height:40px; border-radius:8px;
  border:0; background:transparent; color:var(--muted); cursor:pointer; font-size:20px;
}
.picker .clear:hover { background:var(--chip); color:var(--ink); }
.results {
  position:absolute; z-index:20; left:0; right:0; top:calc(var(--tap) + 4px);
  max-height:290px; overflow-y:auto;
  background:var(--surface); border:1px solid var(--border); border-radius:12px;
  box-shadow:0 12px 32px rgba(0,0,0,0.14);
}
.results li {
  list-style:none; padding:12px 14px; cursor:pointer; border-bottom:1px solid var(--hair);
  display:flex; align-items:center; gap:10px;
}
.results li:last-child { border-bottom:0; }
.results li[aria-selected="true"], .results li:hover { background:var(--chip); }
.results li.add { color:var(--series); font-weight:600; }
.results .empty { padding:14px; color:var(--muted); font-size:15px; }
.bn { font-weight:650; font-variant-numeric:tabular-nums; letter-spacing:0.01em; }
.swatch { flex:none; width:15px; height:15px; border-radius:50%; border:1px solid var(--border); }
.desc { color:var(--ink-2); font-size:14.5px; }
.chosen {
  display:flex; align-items:center; gap:10px; flex-wrap:wrap;
  background:var(--sunken); border:1px solid var(--border); border-radius:10px;
  padding:0 12px; min-height:var(--tap);
}

/* ---------- segmented control ---------- */
.seg { display:flex; gap:6px; padding:5px; background:var(--sunken);
       border:1px solid var(--border); border-radius:12px; }
.seg button {
  flex:1 1 0; font:inherit; font-weight:600; font-size:15.5px;
  min-height:calc(var(--tap) - 12px); border-radius:8px; cursor:pointer;
  background:transparent; color:var(--ink-2); border:1px solid transparent;
}
.seg button[aria-pressed="true"] { background:var(--series); color:var(--series-ink); border-color:var(--series); }

/* ---------- pallet lines ---------- */
.pallets { overflow-x:auto; margin:0 -20px; padding:0 20px; }
table.lines { border-collapse:collapse; width:100%; min-width:520px; }
table.lines th {
  text-align:left; font-size:12px; font-weight:700; letter-spacing:0.06em;
  text-transform:uppercase; color:var(--muted); padding:0 8px 8px; white-space:nowrap;
}
table.lines th.num, table.lines td.num { text-align:right; }
table.lines td { padding:4px 8px; vertical-align:middle; }
table.lines tr.saved td input { background:var(--sunken); }
table.lines input { height:46px; }
table.lines .lineno {
  font-variant-numeric:tabular-nums; color:var(--muted); font-size:14px;
  width:1%; white-space:nowrap; padding-left:0;
}
table.lines .state { width:1%; white-space:nowrap; padding-right:0; }
.dotstate { display:inline-block; width:9px; height:9px; border-radius:50%; }
.dotstate--clean { background:var(--good); }
.dotstate--found { background:var(--critical); }
.dotstate--unsaved { background:transparent; border:1.5px solid var(--muted); }
.rmline {
  border:0; background:transparent; color:var(--muted); cursor:pointer;
  font-size:20px; width:40px; height:40px; border-radius:8px;
}
.rmline:hover { background:var(--chip); color:var(--critical); }
.lockmsg { font-size:13px; color:var(--muted); padding:8px 0 0; }

/* Below roughly a tablet in portrait, a five-column table pushes the count --
 * the one number the line exists to carry -- off the right-hand edge, and the
 * supervisor has to scroll sideways to type it. So each line becomes its own
 * block instead. The deployment target is a tablet, but Alistair will open the
 * demo on a phone, and a first look that needs sideways scrolling is a first
 * look that says "this was not built for you". */
@media (max-width:620px) {
  .pallets { overflow-x:visible; margin:0; padding:0; }
  table.lines { min-width:0; display:block; }
  table.lines thead { display:none; }
  table.lines tbody { display:flex; flex-direction:column; gap:10px; }
  table.lines tr {
    display:grid; gap:8px 10px; align-items:center;
    grid-template-columns:18px 1fr 1fr 36px;
    grid-template-areas:
      "n num  date  state"
      "n found onp  state";
    background:var(--sunken); border:1px solid var(--border);
    border-radius:12px; padding:10px 8px;
  }
  table.lines tr.saved { background:var(--surface); }
  table.lines td, table.lines td.num { padding:0; display:block; text-align:left; }
  table.lines td.lineno { grid-area:n; width:auto; font-size:13px; align-self:start; padding-top:15px; }
  table.lines td:nth-child(2) { grid-area:num; }
  table.lines td:nth-child(3) { grid-area:date; }
  table.lines td:nth-child(4) { grid-area:found; }
  table.lines td:nth-child(5) { grid-area:onp; }
  table.lines td.state { grid-area:state; width:auto; text-align:center; align-self:start; padding-top:8px; }
  table.lines td.state .rmline { width:34px; height:34px; }
  /* With no header row each field has to say what it is. */
  table.lines td[data-label]::before {
    content:attr(data-label); display:block; margin-bottom:3px;
    font-size:11px; font-weight:700; letter-spacing:0.05em;
    text-transform:uppercase; color:var(--muted); white-space:nowrap;
  }
}

/* ---------- buttons ---------- */
button.btn {
  font:inherit; font-weight:650; font-size:16px; min-height:var(--tap);
  padding:0 20px; border-radius:11px; cursor:pointer;
  background:var(--surface); color:var(--ink); border:1px solid var(--border);
  display:inline-flex; align-items:center; justify-content:center; gap:9px;
}
button.btn:hover:not(:disabled) { background:var(--chip); }
button.btn--primary { background:var(--series); color:var(--series-ink); border-color:var(--series); }
button.btn--primary:hover:not(:disabled) { filter:brightness(1.08); background:var(--series); }
button.btn:disabled { opacity:0.45; cursor:not-allowed; }
button.btn--ghost { border-style:dashed; color:var(--ink-2); width:100%; }

/* ---------- the rate: sticky, because it is the whole output ---------- */
.dock {
  position:fixed; left:0; right:0; bottom:0; z-index:30;
  background:var(--surface); border-top:1px solid var(--border);
  box-shadow:0 -6px 24px rgba(0,0,0,0.08);
  padding:12px 16px calc(12px + env(safe-area-inset-bottom));
}
.dock .inner { max-width:860px; margin:0 auto; display:flex; flex-wrap:wrap; gap:14px 22px; align-items:center; }
.stats { display:flex; gap:22px; flex:1 1 auto; flex-wrap:wrap; }
.stat { display:flex; flex-direction:column; gap:1px; min-width:74px; }
.stat .k { font-size:11.5px; font-weight:700; letter-spacing:0.07em; text-transform:uppercase; color:var(--muted); }
.stat .v { font-size:23px; font-weight:650; line-height:1.15; letter-spacing:-0.02em; font-variant-numeric:tabular-nums; }
.stat .v small { font-size:14px; font-weight:500; color:var(--ink-2); letter-spacing:0; }
.stat--headline .v { color:var(--critical); }
.stat--headline.nothing-found .v { color:var(--ink); }
.stat .v.none { color:var(--muted); font-weight:500; font-size:19px; }
.dock .actions { display:flex; gap:10px; flex:0 0 auto; }
@media (max-width:600px) {
  /* Three buttons side by side wrap every label onto two lines. Secondary
   * actions share a row, and the primary one spans the full width underneath,
   * where a thumb reaches it. */
  .dock .actions { width:100%; display:grid; grid-template-columns:1fr 1fr; gap:8px; }
  .dock .actions button { padding:0 10px; font-size:15.5px; }
  .dock .actions #btn-save { grid-column:1 / -1; }
  .stat .v { font-size:20px; }
}

/* ---------- sign in ---------- */
.signin { max-width:400px; margin:8vh auto; }
.signin .card { padding:24px; }
.signin h1 { font-size:22px; margin:0 0 4px; }
.signin p.sub { color:var(--ink-2); font-size:15px; margin:0 0 20px; }
.signin .field { margin-bottom:14px; }

footer.foot { color:var(--muted); font-size:13px; margin-top:26px; text-align:center; }
footer.foot a { color:inherit; }

@media (prefers-reduced-motion:reduce) {
  * { transition:none !important; animation:none !important; }
}
