/* Layout: one column for phones, wider tables for managers on a laptop. */
:root {
  --bg: #f4f6f9; --surface: #ffffff; --fg: #18202c; --muted: #5d6878; --line: #d8dee8;
  --brand: #1d3f72; --brand-soft: #e4ebf6; --accent: #2c6bd1;
  --good: #1f7a4d; --good-soft: #e3f3ea; --warn: #9a5b00; --warn-soft: #fbf0de; --bad: #b0322a; --bad-soft: #f9e6e4;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151d; --surface: #18202b; --fg: #e6eaf0; --muted: #9aa5b5; --line: #2b3646;
    --brand: #8fb3ec; --brand-soft: #1e2c43; --accent: #7aa7f0;
    --good: #6fcf9e; --good-soft: #17301f; --warn: #f0b86a; --warn-soft: #33270f; --bad: #f08a80; --bad-soft: #3a1a17;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 16px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .bar { background: #142640; } }
.brand { color: #fff; font-weight: 700; text-decoration: none; margin-right: auto; }
.who { font-size: 14px; opacity: .9; }
.sync { font-size: 13px; padding: 2px 9px; border-radius: 999px; background: rgba(255,255,255,.18); white-space: nowrap; }
.sync.pending { background: #f0b86a; color: #2b1a00; }
.sync.off { background: #6b7686; }

.wrap { max-width: 980px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 96px); display: grid; gap: 16px; }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spacer { margin-left: auto; }
.stack { display: grid; gap: 10px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; min-width: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { display: grid; gap: 4px; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  text-decoration: none; color: var(--fg); }
.tile b { font-size: 1.05rem; }
.tile span { font-size: 14px; color: var(--muted); }
.tile.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.tile.primary span { color: rgba(255,255,255,.85); }
@media (prefers-color-scheme: dark) { .tile.primary { background: #234a85; border-color: #234a85; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--fg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], select, textarea {
  min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); width: 100%; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }

/* sign in */
.names { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.names button { min-height: 56px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; }
.pinbox { display: grid; gap: 14px; justify-items: center; }
.dots { display: flex; gap: 12px; }
.dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.dots i.on { background: var(--fg); border-color: var(--fg); }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 10px; }
.keypad button { height: 64px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-size: 1.4rem; cursor: pointer; }

/* counting */
.count-head { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 50px); z-index: 5; background: var(--bg); padding: 8px 0; display: grid; gap: 8px; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--good); }
.group { display: grid; gap: 0; }
.group > h3 { padding: 14px 2px 6px; }
.line { display: grid; grid-template-columns: auto 1fr auto; gap: 8px 12px; align-items: center; padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--line); border-bottom-width: 0; min-width: 0; }
.line:first-of-type { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.line:last-child { border-bottom-width: 1px; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.line .name { font-weight: 600; min-width: 0; }
.line .sub { font-size: 13px; color: var(--muted); }
.line.done { background: var(--good-soft); }
.line.diff .was { color: var(--warn); font-weight: 600; }
.stepper { display: grid; grid-template-columns: 44px 70px 44px; gap: 4px; }
.stepper button { height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 1.3rem; cursor: pointer; }
.stepper input { text-align: center; font-size: 1.15rem; font-weight: 700; padding: 0; font-variant-numeric: tabular-nums; }
.bottombar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--line);
  padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 10px); display: flex; gap: 10px; align-items: center; justify-content: flex-end; }

/* tables */
.tbl { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--bg); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--brand-soft); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--brand-soft); color: var(--accent); }
.up { color: var(--good); font-weight: 700; }
.down { color: var(--bad); font-weight: 700; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 84px); z-index: 20;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px; max-width: calc(100% - 32px); }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--fg); }
.notice.bad { background: var(--bad-soft); }
.notice.good { background: var(--good-soft); }
@media (prefers-reduced-motion: no-preference) { .btn, .chip, .tile { transition: background .15s, border-color .15s; } }

/* Phones: each table row becomes a small card, cells labelled by their column. */
@media (max-width: 640px) {
  .tbl { border: 0; background: transparent; overflow: visible; }
  table.resp, table.resp tbody { display: block; }
  table.resp tr:first-child { display: none; }
  table.resp tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; padding: 10px 12px; margin-bottom: 8px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
  table.resp td { display: block; border: 0; padding: 2px 0; text-align: left; min-width: 0; }
  table.resp td.n { text-align: left; }
  table.resp td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
  table.resp td:first-child { grid-column: 1 / -1; font-weight: 600; }
  table.resp td:first-child::before { display: none; }
  table.resp td:empty { display: none; }
  table.resp td.row { grid-column: 1 / -1; }
}

/* patterns and photos */
.pattern { display: grid; margin-bottom: 12px; }
.pat-head { display: flex; gap: 10px; align-items: center; padding: 8px 12px; background: var(--brand-soft); border: 1px solid var(--line);
  border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; }
.pat-name { font-weight: 700; }
.pattern .line:first-of-type { border-radius: 0; }
.pattern .line:last-child { border-bottom-width: 1px; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.group > h3 { padding: 16px 2px 8px; }
.line .body { min-width: 0; }
.thumb { width: 52px; height: 52px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); padding: 0; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); flex: none; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.empty { cursor: default; border-style: dashed; background: transparent; }
.thumb.add { border-style: dashed; }
.withthumb { display: flex; gap: 10px; align-items: center; min-width: 0; }
.withthumb .thumb { width: 40px; height: 40px; }
.pchip { display: inline-flex; align-items: center; gap: 6px; }
.pchip img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; margin-left: -6px; }
.lightbox { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.85); display: grid; place-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px); align-content: center; }
.lightbox img { max-width: 100%; max-height: 72vh; border-radius: 8px; }
@media (max-width: 400px) { .line { grid-template-columns: auto 1fr; } .line .stepper { grid-column: 1 / -1; justify-self: end; } }
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }

.backbtn { display: inline-flex; align-items: center; gap: 2px; min-height: 40px; padding: 0 10px 0 4px; margin-left: -6px;
  border: 0; border-radius: 8px; background: rgba(255,255,255,.14); color: #fff; font-weight: 600; cursor: pointer; }
.backbtn[hidden] { display: none; }
.backbtn:active { background: rgba(255,255,255,.28); }
@media (max-width: 420px) { .backbtn + .brand span, .backbtn:not([hidden]) + .brand { font-size: 0; gap: 0; } .backbtn:not([hidden]) + .brand img { margin-right: 0; } }

.card.install { border-color: var(--accent); background: var(--brand-soft); }
.steps { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }

/* item card: photos + size */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 16px); display: grid; gap: 12px; }
@media (min-width: 700px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 16px; } }
.sheet .big { position: relative; }
.sheet .big img { width: 100%; max-height: 52vh; object-fit: contain; background: #000; border-radius: 10px; display: block; }
.sheet .big .pill { position: absolute; left: 10px; top: 10px; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.strip .thumb { width: 72px; height: 72px; position: relative; }
.strip .thumb.on { outline: 3px solid var(--accent); outline-offset: 1px; }
.strip .lab { position: absolute; left: 0; right: 0; bottom: 0; font-size: 10px; background: rgba(0,0,0,.6); color: #fff; text-align: center; padding: 1px 0; }
.thumb { position: relative; }
.thumb .count { position: absolute; right: 2px; bottom: 2px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
