/*
 * Built for a phone held in one hand, in a shop, with a device in the other.
 * Everything that follows is downstream of that: 48px targets, a numeric
 * keypad on the field that matters, one column, and the save button always
 * within thumb reach rather than at the bottom of 86 fields.
 */

/*
 * Dupno CRM — the brand, and the single place it is defined.
 *
 * Every page imports this file, so a colour or a typeface set here is set
 * everywhere: the form, the lookup, the admin page, the landing page and the
 * denied page.
 *
 * Fonts are served from this server rather than Google's, for two reasons that
 * both matter here: the app has to render with no network at all once it is on
 * a home screen, and a phone in Bangladesh should not wait on a round trip to a
 * CDN to draw its first screen.
 */

/* Latin. */
@font-face {
  font-family: 'Bai Jamjuree';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/brand/fonts/bai-jamjuree-latin-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Bai Jamjuree';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/brand/fonts/bai-jamjuree-latin-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Bai Jamjuree';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/brand/fonts/bai-jamjuree-latin-700.woff2') format('woff2');
}

/* Bengali. One variable file covers every weight, so there is nothing to gain
   from shipping three copies of it. */
@font-face {
  font-family: 'Anek Bangla';
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url('/brand/fonts/anek-bangla-bengali.woff2') format('woff2');
  unicode-range: U+0964-0965, U+0980-09FE, U+1CD0, U+1CD2, U+1CD5-1CD6, U+1CD8, U+1CE1, U+1CEA, U+1CED, U+1CF2, U+1CF5-1CF7, U+200C-200D, U+20B9, U+25CC, U+A8F1;
}
@font-face {
  font-family: 'Anek Bangla';
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url('/brand/fonts/anek-bangla-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* Dupno blue. The deep one carries text on white; the lighter one is the
     brand's own and is used for fills and marks. */
  --brand: #1c75bc;
  --brand-deep: #045cb4;
  --brand-red: #ec1c24;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #e2e5ea;
  --text: #14161a;
  --muted: #6b7280;
  --accent: #045cb4;
  --accent-soft: #e6f0fa;
  --ok: #067647;
  --ok-soft: #e7f6ee;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --danger: #ec1c24;
  --danger-soft: #fdecec;
  --changed: #fff8e1;
  /* The third state: asked for, not yet true. Deliberately a different hue
     from --changed, which means "typed here and not sent". */
  --waiting: #6941c6;
  --waiting-soft: #f2ecff;
  --radius: 14px;
  --tap: 48px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  /* Only the full screen image viewer needs this: it is the one thing that
     draws under the notch. */
  --safe-t: env(safe-area-inset-top, 0px);
}

/*
 * Dark is written twice, on purpose, and the two are not interchangeable.
 *
 * The media query is the device's opinion, and it must lose to a person who has
 * said otherwise — hence `:not([data-theme='light'])`. The attribute rule is
 * that person's choice, and it has to win on a device set to light as well, so
 * it cannot live inside the media query.
 *
 * With no attribute at all the media query decides, which is what "Auto" means.
 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0e1116;
    --surface: #171b22;
    --surface-2: #1e232b;
    --line: #2b323d;
    --text: #e8eaed;
    --muted: #9aa3af;
    --accent: #5cabe8;
    --accent-soft: #10263c;
    --ok: #5bd6a0;
    --ok-soft: #123326;
    --warn: #e5a54b;
    --warn-soft: #33260f;
    --danger: #ff7b73;
    --danger-soft: #3a1513;
    --changed: #33301c;
    --waiting: #c4b0ff;
    --waiting-soft: #27204a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme='dark'] {
  --bg: #0e1116;
  --surface: #171b22;
  --surface-2: #1e232b;
  --line: #2b323d;
  --text: #e8eaed;
  --muted: #9aa3af;
  --accent: #5cabe8;
  --accent-soft: #10263c;
  --ok: #5bd6a0;
  --ok-soft: #123326;
  --warn: #e5a54b;
  --warn-soft: #33260f;
  --danger: #ff7b73;
  --danger-soft: #3a1513;
  --changed: #33301c;
  --waiting: #c4b0ff;
  --waiting-soft: #27204a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
}

/* The native controls — the date picker's calendar, the select arrow, the
   search field's clear button — are drawn by the browser, and it needs telling
   which way round the page is or they come out black on black. */
:root { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) { color-scheme: dark; }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* Bai Jamjuree first for Latin, Anek Bangla behind it for Bengali: a browser
     falls through to the next family per character, so mixed Bengali and
     English in one sentence renders correctly without any markup. */
  font: 15px/1.5 'Bai Jamjuree', 'Anek Bangla', -apple-system, BlinkMacSystemFont,
    'Segoe UI', system-ui, sans-serif;
  /* The page scrolls in one place; nothing else does. */
  overscroll-behavior-y: contain;
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 0;
  background: none;
  /* Kills the 300ms tap delay and the grey flash on iOS. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- shell ---------- */

.app { max-width: 720px; margin: 0 auto; min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
/* Long addresses must not push the buttons off a 390px screen, and a wrapped
   title must not make the bar taller than the buttons in it. */
.topbar h1,
.topbar .sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .sub { font-size: 12px; color: var(--muted); }
.topbar .grow { flex: 1; min-width: 0; }

/* A label rather than a glyph: "My changes" and "Queue" have no icon anybody
   would read the same way twice. Full tap height, no hover needed. */
.pill-btn {
  display: inline-grid;
  place-items: center;
  min-height: var(--tap);
  padding: 0 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.pill-btn:active { background: var(--accent-soft); }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 19px;
  color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }

main { padding: 14px; padding-bottom: calc(120px + var(--safe-b)); }

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}

.card-pad { padding: 16px; }

/* ---------- inputs ---------- */

label.field { display: block; padding: 12px 16px; border-top: 1px solid var(--line); }
.group-body > label.field:first-child { border-top: 0; }

.field .name {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: none;
}
.field .col { font-size: 11px; color: var(--muted); opacity: 0.7; font-variant-numeric: tabular-nums; }

.control {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  /* 16px or iOS zooms the whole page on focus. */
  font-size: 16px;
  appearance: none;
}
.control:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea.control { min-height: 84px; resize: vertical; line-height: 1.4; }
select.control {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 38px;
}

.field.is-changed { background: var(--changed); }
.field.is-changed .name::after {
  content: 'changed';
  font-size: 10px;
  font-weight: 700;
  color: var(--warn);
  background: var(--warn-soft);
  padding: 2px 6px;
  border-radius: 999px;
}
/* The third state. `is-changed` is a value typed here and not sent; this is a
   value somebody has asked for and nobody has approved. Different hue, a rail
   down the edge instead of a fill, so a field can honestly be both at once. */
.field.is-pending { box-shadow: inset 3px 0 0 var(--waiting); }

.field .name .tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
}
.field .name .tag.waiting { color: var(--waiting); background: var(--waiting-soft); }

.field .was {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}
.field .was b { font-weight: 600; color: var(--text); }

/* Beside the control, never inside it: the box shows what the sheet has, this
   shows what has been asked for. Merging them would claim a write happened. */
.field .awaiting {
  display: block;
  margin-top: 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--waiting);
  border-radius: 0 10px 10px 0;
  background: var(--waiting-soft);
  font-size: 12px;
}
.field .awaiting .k {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--waiting);
}
.field .awaiting b { font-weight: 650; }
.field .awaiting .meta { display: block; margin-top: 2px; color: var(--muted); }
.field .err { margin-top: 6px; font-size: 12.5px; color: var(--danger); font-weight: 550; }
.field.is-error .control { border-color: var(--danger); }

/* ---------- groups ---------- */

.group summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  min-height: var(--tap);
  font-weight: 650;
  cursor: pointer;
  list-style: none;
  background: var(--surface);
}
.group summary::-webkit-details-marker { display: none; }
.group summary::after {
  content: '›';
  margin-left: auto;
  font-size: 20px;
  color: var(--muted);
  transform: rotate(90deg);
  transition: transform 0.15s;
}
.group[open] summary::after { transform: rotate(-90deg); }
.group summary .count {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: 999px;
}
.group summary .count.hot { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.group summary .count.wait { color: var(--waiting); background: var(--waiting-soft); border-color: transparent; }

/* ---------- search screen ---------- */

.hero { padding: 8vh 4px 0; text-align: center; }
.hero h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -0.02em; }
.hero p { margin: 0 0 22px; color: var(--muted); font-size: 14px; }

.imei-input {
  width: 100%;
  min-height: 60px;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.imei-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.btn {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 650;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}
.btn:disabled { opacity: 0.45; }
.btn.ghost { background: var(--surface); color: var(--text); border: 1.5px solid var(--line); }
.btn.quiet { background: transparent; color: var(--accent); min-height: var(--tap); }
.btn.danger { background: var(--danger); }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row .btn { flex: 1; }

.recents { margin-top: 26px; }
.recents h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 8px; }
.recent {
  width: 100%;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 8px;
  text-align: left;
}
.recent .imei { font-weight: 650; font-variant-numeric: tabular-nums; }
.recent .meta { font-size: 12px; color: var(--muted); }

/* ---------- record header ---------- */

.record-head { padding: 14px 16px; }
.record-head .imei { font-size: 19px; font-weight: 700; letter-spacing: 0.03em; font-variant-numeric: tabular-nums; }
.record-head .line { color: var(--muted); font-size: 13px; margin-top: 3px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.chip.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.chip.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.chip.new { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.chip.pending { color: var(--waiting); background: var(--waiting-soft); border-color: transparent; }
.chip.via-form { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.chip.via-odoo { color: var(--muted); }
.chip.via-sheet { color: var(--warn); background: var(--warn-soft); border-color: transparent; }

/* ---------- filter bar ---------- */

.filters {
  position: sticky;
  top: 62px;
  z-index: 15;
  display: flex;
  gap: 8px;
  padding: 10px 0;
  background: var(--bg);
}
.filters { flex-wrap: wrap; }

.filters input {
  flex: 1 1 140px;
  /* A flex item will not shrink below its content width unless told to, and
     without this the box pushed the whole page 29px wider than a 360px phone —
     taking the fixed save bar with it, because a fixed element sizes to the
     document. */
  min-width: 0;
  min-height: 44px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px;
}
.toggle {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.toggle[aria-pressed='true'] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- save bar ---------- */

.savebar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  padding: 10px 14px calc(10px + var(--safe-b));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.savebar-inner { max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.savebar .status { flex: 1; font-size: 13px; color: var(--muted); min-width: 0; }
.savebar .status b { color: var(--text); }
.savebar .btn { width: auto; padding: 0 24px; }

/* ---------- sheet ---------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(9, 12, 18, 0.5);
  display: flex;
  align-items: flex-end;
}
.sheet {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + var(--safe-b));
  animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes rise { from { transform: translateY(14px); opacity: 0.4; } }
.sheet .grab { width: 38px; height: 4px; border-radius: 99px; background: var(--line); margin: 6px auto 14px; }
.sheet h3 { margin: 0 0 4px; font-size: 17px; }
.sheet .note { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

.diff { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.diff-row { padding: 11px 13px; border-top: 1px solid var(--line); }
.diff-row:first-child { border-top: 0; }
.diff-row .h { font-size: 12px; color: var(--muted); font-weight: 600; }
.diff-row .v { display: flex; align-items: center; gap: 8px; margin-top: 3px; flex-wrap: wrap; }
.diff-row .old { color: var(--muted); text-decoration: line-through; }
.diff-row .new { font-weight: 650; }
.diff-row .arrow { color: var(--muted); }
/* The sheet moved under a request that is still waiting. Said, not hidden. */
.diff-row .moved { margin-top: 4px; font-size: 12px; color: var(--warn); }
.diff-row .moved b { font-weight: 650; }

/* ---------- pending on the record ---------- */

.pending-banner {
  border-radius: 12px;
  margin-bottom: 12px;
  background: var(--waiting-soft);
  overflow: hidden;
}
.pending-banner > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 12px 14px;
  font-size: 13.5px;
  font-weight: 650;
  color: var(--waiting);
  cursor: pointer;
  list-style: none;
}
.pending-banner > summary::-webkit-details-marker { display: none; }
.pending-banner > summary::after {
  content: '›';
  margin-left: auto;
  font-size: 20px;
  transform: rotate(90deg);
  transition: transform 0.15s;
}
.pending-banner[open] > summary::after { transform: rotate(-90deg); }
.pending-banner .dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--waiting);
}
.pending-banner .lead { min-width: 0; }
.pending-banner .count { font-size: 11.5px; font-weight: 600; color: var(--muted); }

.pending-list { display: grid; gap: 10px; padding: 0 12px 12px; }
.pending-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.pending-head { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.pending-head .who { flex: 1; min-width: 0; font-size: 13px; }
.pending-head .meta { color: var(--muted); }
.pending-head .chips { margin-top: 0; }
.pending-card .diff { border: 0; border-radius: 0; }
.pending-card .diff-row { padding: 8px 0; }
/* Withdraw is a rare, deliberate act: full tap height, but not the widest
   thing on the card — the change itself is what the eye should land on. */
.pending-card .btn-row { margin-top: 6px; justify-content: flex-end; }
.pending-card .btn-row .btn { flex: 0 0 auto; min-height: var(--tap); padding: 0 20px; }

/* ---------- my changes ---------- */

.act {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}
.act:first-child { border-top: 0; }
.act.tappable { min-height: var(--tap); }
.act.tappable:active { background: var(--surface-2); }
.act-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.act-top .when { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); }
.act-field { font-size: 12.5px; font-weight: 650; }
.act .v { display: flex; align-items: center; gap: 8px; margin-top: 2px; flex-wrap: wrap; }
.act .old { color: var(--muted); text-decoration: line-through; }
.act .new { font-weight: 650; }
.act .arrow { color: var(--muted); }
.act-foot { display: flex; flex-wrap: wrap; gap: 2px 6px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.act-foot .imei { font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.act-foot > * + *::before { content: '· '; }

.foot-note {
  margin: 6px 2px 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* ---------- misc ---------- */

.banner {
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13.5px;
  margin-bottom: 12px;
  border: 1px solid transparent;
}
.banner.err { background: var(--danger-soft); color: var(--danger); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner ul { margin: 6px 0 0; padding-left: 18px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(92vw, 560px);
  padding: 12px 18px;
  border-radius: 12px;
  background: #14161a;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: rise 0.2s;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

.spin {
  width: 17px;
  height: 17px;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; font-size: 14px; }

.combo { position: relative; }
.combo-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 25;
  max-height: 46dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.combo-list button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  min-height: var(--tap);
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.combo-list button:last-child { border-bottom: 0; }
.combo-list button:active { background: var(--accent-soft); }

.row-choice {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  min-height: var(--tap);
}
.row-choice:first-of-type { border-top: 0; }
.row-choice .r { font-weight: 650; }
.row-choice .d { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

/* ---------- wider screens ---------- */

@media (min-width: 640px) {
  main { padding: 18px; }
  .hero { padding-top: 10vh; }
}

/*
 * A phone gets one column because there is one column of room. A desktop has
 * three times that, and 86 fields in a 720px ribbon means scrolling past most
 * of the record to reach the rest of it.
 *
 * Only the field grid widens. The search screen, the sign in card and the
 * confirmation sheet stay narrow, because a login box stretched across a
 * 27 inch monitor is harder to use, not easier.
 */
@media (min-width: 920px) {
  .app { max-width: 1100px; }

  .group-body {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  /* The grid draws its own separators; the per-field top border would double
     them up along the seam between the columns. */
  .group-body > label.field { border-top: 1px solid var(--line); }
  .group-body > label.field:nth-child(-n + 2) { border-top: 0; }
  .group-body > label.field:nth-child(odd) { border-right: 1px solid var(--line); }

  /* A note or an address needs the whole width; a date does not. */
  .group-body > label.field:has(textarea) {
    grid-column: 1 / -1;
    border-right: 0;
  }

  .record-head .imei { font-size: 22px; }
  .savebar-inner { max-width: 1100px; }
}

@media (min-width: 1280px) {
  .app { max-width: 1240px; }
  .group-body { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .group-body > label.field:nth-child(-n + 2) { border-top: 1px solid var(--line); }
  .group-body > label.field:nth-child(-n + 3) { border-top: 0; }
  .group-body > label.field:nth-child(odd) { border-right: 0; }
  .group-body > label.field:not(:nth-child(3n)) { border-right: 1px solid var(--line); }
  .savebar-inner { max-width: 1240px; }
}

/* Pointer devices get hover affordances; touch devices must never depend on
   them, so they are declared only where they can actually happen. */
@media (hover: hover) {
  .btn:hover { filter: brightness(1.06); }
  .icon-btn:hover, .pill-btn:hover { background: var(--surface-2); }
  .recent:hover, .row-choice:hover { border-color: var(--accent); }
  .group summary:hover { background: var(--surface-2); }
}

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

/* ---------------- scanned pages ----------------
 * Two tiles, side by side even on the narrowest phone, because "front" and
 * "back" only make sense as a pair. Nothing here relates to a sheet column —
 * these images live on the server and are read by whoever approves.
 */

.docs { margin-bottom: 12px; }
.docs-head { margin-bottom: 12px; }
.docs-head h3 { margin: 0 0 3px; font-size: 14px; }
.docs-head .sub { font-size: 12px; color: var(--muted); }

.doc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.doc {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

/* The empty tile is the button. A tap target the size of the tile is what makes
   this usable one-handed with a phone in the other hand. */
.doc.empty {
  align-items: stretch;
  padding: 0;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.doc-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  aspect-ratio: 4 / 3;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  text-align: center;
  padding: 8px;
}
.doc-empty .doc-ico { font-size: 24px; line-height: 1; color: var(--accent); }
.doc-empty .doc-hint { font-size: 11px; font-weight: 500; opacity: 0.8; }
.doc.busy .doc-empty { border-style: solid; }

.doc-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background-color: var(--surface-2);
  background-size: cover;
  background-position: center;
  cursor: zoom-in;
  padding: 0;
}

.doc-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.doc-meta b { font-size: 12.5px; }
.doc-meta span {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-actions { display: flex; gap: 6px; }
.doc-actions .btn { flex: 1 1 0; min-width: 0; min-height: 36px; font-size: 12.5px; padding: 0 8px; }

/* Full screen, black, and above everything — a scan is unreadable in a box. */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  background: #000;
}
.viewer[hidden] { display: none; }
.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(8px + var(--safe-t)) 10px 8px 16px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.viewer-bar .icon-btn { color: #fff; background: rgba(255, 255, 255, 0.12); border-color: transparent; }
.viewer img {
  flex: 1;
  min-height: 0;
  width: 100%;
  object-fit: contain;
  padding: 0 8px calc(8px + var(--safe-b));
}

@media (min-width: 760px) {
  .doc-grid { grid-template-columns: repeat(2, minmax(0, 320px)); }
}

/* ---------------- write-once fields ----------------
 * A value that is already in the sheet and may not be rewritten here. Drawn as
 * text rather than a disabled input: a greyed out box invites a tap and says
 * nothing, and "why can I not type here" has to be answerable on the spot.
 */

.field.is-locked { box-shadow: inset 3px 0 0 var(--muted); }
.field .name .tag.locked { color: var(--muted); background: var(--surface-2); }

.field .locked-value {
  display: block;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  cursor: default;
}
