/* styles.css — Maxim Field Service Assistant
 * Visual system blends three references:
 *   • Mercury (mercury.com) — drives LIGHT mode. Whitespace-forward, near-black
 *     text on a cool near-white canvas, true hairline borders, depth from lines
 *     rather than shadow, restrained weights, tabular numerics. Quiet precision.
 *   • Cosmos (cosmos.so)   — drives DARK mode. A deep near-black gallery canvas
 *     where the chrome recedes and content floats on softly lifted surfaces,
 *     generous corner radii, muted low-contrast furniture, no heavy shadows.
 *   • Claude               — drives LAYOUT (unchanged): left sidebar, centered
 *     main column, prominent composer, results feed flowing beneath it.
 *
 * Maxim navy remains the brand anchor in both themes.
 *
 * THEMING: follows the device via `prefers-color-scheme`. Every color lives in
 * a token below; the dark block redefines values only — no rule is duplicated.
 * When adding a rule, reference tokens, never a literal color, or you will
 * silently break dark mode.
 *
 * OR-FIELD CONSTRAINTS (functional, not aesthetic — do not soften):
 *   • --tap 52px minimum touch targets (gloved hands)
 *   • high text contrast in both themes (bright OR light / face shields)
 *   • the red safety banner must stay the most visually dominant element
 *   • amber guardrail + not-found banners must stay distinct from result cards
 *   • the active-unit scope bar must never truncate (wrong-manual safeguard)
 */

:root {
  color-scheme: light dark;

  /* ---- shape & metrics (theme-independent) ---- */
  --radius:    14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --tap:       52px;
  --side-w:    288px;
  --topbar-h:  65px;   /* phone top bar: 44px control + 2×10px pad + 1px hairline */
  --tabbar-h:  68px;   /* phone bottom tab bar, excluding the safe-area inset */

  /* ---- Maxim navy — brand anchor ---- */
  --navy:        #12325a;   /* solid brand block; always carries white text */
  --navy-hover:  #0e2a47;
  --navy-700:    #0e2a47;   /* navy AS TEXT on a light surface — flips in dark */
  --navy-50:     #eaf0f7;   /* navy tint fill */
  --navy-border: #cddcee;

  /* Solid primary fills (New search / Search / primary buttons). Anchored to
     navy rather than the violet accent — the saturated violet read too loud
     against Mercury's restraint. Violet stays a small accent only. */
  --accent:       #12325a;
  --accent-hover: #1c4a80;

  /* ---- Mercury violet — interactive accent ---- */
  --violet:        #5b50e5;
  --violet-hover:  #4c42cc;  /* darker violet for :hover on solid violet fills */
  --violet-fg:     #4c42cc;  /* violet AS TEXT on a violet tint — flips in dark */
  --violet-50:     #eeecff;
  --violet-border: #d9d4ff;

  /* ---- Mercury neutrals ---- */
  --bg:        #f7f7f9;   /* app canvas */
  --surface:   #ffffff;   /* cards / sidebar */
  --surface-2: #f1f2f5;   /* subtle fills */
  --border:    #e8e9ee;   /* hairline */
  --border-2:  #dcdee5;

  --text:      #101114;
  --text-2:    #5a6070;
  --text-3:    #8c92a0;

  /* ---- safety / status ---- */
  --danger: #d92d20; --danger-bg: #fef3f2; --danger-border: #fda29b;
  --warn:   #b54708; --warn-bg:   #fffaeb; --warn-border:   #fec84b; --warn-fg: #7a4a12;
  --ok:     #067647; --ok-bg:     #ecfdf3; --ok-border:     #a6f4c5;

  /* ---- favourite star ---- */
  --star: #d98f00; --star-border: #f0c250; --star-bg: #fffaf0;

  /* ---- elevation & scrim ---- */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, .07);
  --shadow-lg: 0 20px 60px rgba(16, 24, 40, .28);
  --shadow-focus: 0 4px 22px rgba(91, 80, 229, .14);
  --overlay: rgba(16, 18, 24, .42);
  --ring: 0 0 0 3px var(--violet-50);

  /* ---- toast (inverted chip) ---- */
  --toast-bg: #16181d; --toast-fg: #ffffff;

  /* Company wordmark ink. Brand navy on light; the official white treatment on
     dark — NOT --navy-700, which would tint the logo azure. */
  --logo-ink: #12325a;

  font-size: 17px;
}

/* ============================================================
   DARK — Cosmos. Deep gallery canvas, softly lifted surfaces,
   muted furniture, borders as light films rather than lines.
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root {
    /* navy lifts so it still reads as "navy" against near-black */
    --navy:        #1b4a80;
    --navy-hover:  #235b9b;
    --navy-700:    #8fb6e8;
    --navy-50:     rgba(84, 140, 210, .14);
    --navy-border: rgba(120, 168, 226, .30);

    --accent:       #2a5c99;
    --accent-hover: #366eb4;

    --violet:        #6f63f0;
    --violet-hover:  #8175f5;
    --violet-fg:     #b3aaff;
    --violet-50:     rgba(122, 108, 245, .18);
    --violet-border: rgba(140, 126, 250, .34);

    --bg:        #0a0a0c;
    --surface:   #131316;
    --surface-2: #1b1b1f;
    --border:    rgba(255, 255, 255, .085);
    --border-2:  rgba(255, 255, 255, .155);

    --text:      #f2f2f4;
    --text-2:    #a9acb6;
    --text-3:    #767a85;

    --danger: #ff6f61; --danger-bg: #2c1411; --danger-border: #7d2c23;
    --warn:   #f0b34a; --warn-bg:   #291e0d; --warn-border:   #6d4c17; --warn-fg: #e6c68c;
    --ok:     #45d996; --ok-bg:     #0d2418; --ok-border:     #1f5c3f;

    --star: #f5c451; --star-border: #6b5312; --star-bg: #241c0c;

    /* Cosmos leans on surface lift, not drop shadow */
    --shadow-sm: none;
    --shadow-md: 0 4px 20px rgba(0, 0, 0, .50);
    --shadow-lg: 0 24px 70px rgba(0, 0, 0, .70);
    --shadow-focus: 0 4px 24px rgba(111, 99, 240, .28);
    --overlay: rgba(0, 0, 0, .66);

    --toast-bg: #26262b; --toast-fg: #f2f2f4;

    --logo-ink: #ffffff;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button { font-family: inherit; }
::selection { background: var(--violet-50); color: var(--violet-fg); }

/* ============================ layout ============================ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--side-w); flex: 0 0 var(--side-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px; padding: 18px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.backdrop { display: none; }

/* ============================ sidebar ============================ */
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 12px; }
.brand .mark {
  width: 34px; height: 34px; border-radius: var(--radius-sm); flex: 0 0 34px;
  background: var(--navy); display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.brand .mark svg { width: 20px; height: 20px; }
.brand .name { font-weight: 700; font-size: 1.02rem; letter-spacing: -.015em; color: var(--navy-700); line-height: 1.1; }
.brand .name small { display: block; font-weight: 600; font-size: .64rem; letter-spacing: .09em; color: var(--text-3); text-transform: uppercase; margin-top: 4px; }

/* Company wordmark (icons/maxim-wordmark.png). The source is a white silhouette
   on transparency, so its ALPHA is used as a mask and painted with --logo-ink.
   One asset serves both themes — no second, recoloured file to keep in sync.
   aspect-ratio matches the 900×384 source, so only height needs setting. */
.brand-logo {
  display: block;
  aspect-ratio: 900 / 384;
  background-color: var(--logo-ink);
  -webkit-mask: url('../icons/maxim-wordmark.png') no-repeat left center;
          mask: url('../icons/maxim-wordmark.png') no-repeat left center;
  -webkit-mask-size: contain;
          mask-size: contain;
}
.brand .brand-logo { height: 34px; }
.topbar .brand-logo { height: 36px; }

.side-new {
  width: 100%; min-height: 48px; margin-bottom: 6px;
  background: var(--accent); color: #fff; border: none; border-radius: 12px;
  font-weight: 650; font-size: .98rem; cursor: pointer; letter-spacing: -.005em;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .14s ease;
}
.side-new:hover { background: var(--accent-hover); }
.side-new:active { transform: translateY(1px); }

.side-label { font-size: .68rem; font-weight: 600; letter-spacing: .09em; color: var(--text-3); text-transform: uppercase; padding: 14px 10px 6px; }
.unit-filter { width: 100%; min-height: 40px; margin: 0 0 6px; border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 8px 12px; font-size: .9rem; background: var(--surface-2); color: var(--text); }
.unit-filter:focus { outline: none; border-color: var(--violet); box-shadow: var(--ring); }
.unit-group { font-size: .64rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); padding: 12px 10px 3px; }

.unit-list { display: flex; flex-direction: column; gap: 3px; }
.unit-item {
  width: 100%; text-align: left; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: 11px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 2px;
  transition: background .12s ease;
}
.unit-item:hover { background: var(--surface-2); }
.unit-item.active { background: var(--navy-50); border-color: var(--navy-border); }
.unit-item .u-model { font-weight: 650; font-size: .95rem; color: var(--text); line-height: 1.25; }
.unit-item.active .u-model { color: var(--navy-700); }
.unit-item .u-oem { font-size: .78rem; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.unit-item .u-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--violet); flex: 0 0 6px; }
.unit-item .u-count { font-size: .74rem; color: var(--text-3); margin-top: 1px; font-variant-numeric: tabular-nums; }

.side-add {
  margin-top: 6px; min-height: 44px; width: 100%;
  background: transparent; border: 1px dashed var(--border-2); border-radius: 11px;
  color: var(--text-2); font-weight: 650; font-size: .9rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: border-color .14s ease, color .14s ease, background .14s ease;
}
.side-add:hover { border-color: var(--violet); color: var(--violet-fg); background: var(--violet-50); }

.side-spacer { flex: 1 1 auto; }
.side-nav { display: flex; flex-direction: column; gap: 3px; border-top: 1px solid var(--border); padding-top: 10px; }
.side-nav-item {
  width: 100%; text-align: left; cursor: pointer; background: transparent; border: none;
  border-radius: var(--radius-sm); padding: 11px 12px; color: var(--text-2); font-weight: 650; font-size: .92rem;
  display: flex; align-items: center; gap: 10px;
  transition: background .12s ease, color .12s ease;
}
.side-nav-item:hover { background: var(--surface-2); color: var(--text); }
.side-nav-item.active { background: var(--navy-50); color: var(--navy-700); }
.side-nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .8; }

/* ============================ main top bar (mobile) ============================ */
.topbar {
  display: none; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.hamburger {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; display: grid; place-items: center;
}
.hamburger svg { width: 22px; height: 22px; }
.topbar .tb-title { font-weight: 700; color: var(--navy-700); font-size: 1rem; letter-spacing: -.015em; }

/* ============================ content column ============================ */
.content { width: 100%; max-width: 820px; margin: 0 auto; padding: 26px 22px 40px; flex: 1 1 auto; }

.scope-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 20px;
}
.scope-bar .lbl { font-size: .72rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.scope-bar .val { font-weight: 650; color: var(--navy-700); }
.scope-bar .val .oem { color: var(--violet-fg); }
.scope-bar .tag { font-size: .76rem; color: var(--text-2); background: var(--surface-2); border-radius: 20px; padding: 3px 10px; }
.serial-chip { background: var(--surface-2); border: 1px solid var(--border-2); color: var(--text-2); font-weight: 650; font-size: .74rem; padding: 3px 10px; border-radius: 20px; font-variant-numeric: tabular-nums; }

/* warranty status chip (scope bar + library card): green while covered, amber once expired */
.warranty-chip { background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok); font-weight: 650; font-size: .74rem; padding: 3px 10px; border-radius: 20px; white-space: nowrap; }
.warranty-chip.expired { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); }
.fav-btn { min-width: 40px; height: 40px; border: 1px solid var(--border-2); background: var(--surface); border-radius: var(--radius-sm); cursor: pointer; font-size: 1.15rem; line-height: 1; color: var(--text-3); }
.fav-btn:hover { border-color: var(--star-border); color: var(--star); }
.fav-btn.on { color: var(--star); border-color: var(--star-border); background: var(--star-bg); }
.u-star { color: var(--star); font-size: .85em; }
.u-await { display: block; font-size: .7rem; color: var(--warn); font-weight: 650; margin-top: 2px; }
.await-note { padding: 11px 14px; font-size: .85rem; color: var(--warn-fg); background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: var(--radius-sm); }
.btn.star { min-width: 44px; font-size: 1.1rem; padding: 0 12px; }
.btn.star.on { color: var(--star); border-color: var(--star-border); }
.np-btn { min-width: 40px; height: 40px; border: 1px solid var(--border-2); background: var(--surface); border-radius: var(--radius-sm); cursor: pointer; font-size: 1.05rem; line-height: 1; }
.np-btn:hover { border-color: var(--violet); }

/* per-unit nameplate photo + service log */
.unit-log { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.log-label { font-size: .72rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin-bottom: 8px; }
.nameplate-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.nameplate-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border-2); cursor: pointer; }
.note-row { display: flex; gap: 8px; }
.note-row input { flex: 1; min-height: 44px; }
.note-row .btn { min-height: 44px; }
.log-list { margin-top: 10px; display: grid; gap: 6px; }
.log-entry { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; font-size: .88rem; }
.log-ts { color: var(--text-3); font-size: .74rem; white-space: nowrap; padding-top: 1px; font-variant-numeric: tabular-nums; }
.log-text { color: var(--text); flex: 1; }
.log-del { margin-left: auto; border: none; background: transparent; color: var(--text-3); font-size: 1.15rem; cursor: pointer; line-height: 1; padding: 0 4px; }
.log-del:hover { color: var(--danger); }

/* hero (empty state, Claude-like greeting) */
.hero { text-align: center; padding: 18px 0 22px; }
.hero h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.028em; margin: 0 0 6px; color: var(--text); }
.hero p { margin: 0; color: var(--text-2); font-size: 1rem; }

/* ============================ composer ============================ */
.composer {
  background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-lg);
  padding: 12px 12px 10px; box-shadow: var(--shadow-md);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--violet); box-shadow: var(--shadow-focus); }
.composer textarea {
  width: 100%; border: none; outline: none; resize: none;
  font-family: inherit;
  font-size: 1.12rem; font-weight: 400; color: var(--text); background: transparent;
  min-height: 30px; max-height: 200px; line-height: 1.45; padding: 6px 6px 2px;
  overflow-y: auto;
}
.composer textarea::placeholder { color: var(--text-3); font-weight: 400; }

/* Entry fields never render a visible scrollbar. autosize() in app.js grows the
   composer to its 200px cap; past that it still scrolls by wheel/touch, just
   silently. Also suppresses the spurious bar scrollHeight rounding can produce
   on a single line of text. */
textarea, input[type="text"], .unit-filter {
  scrollbar-width: none; -ms-overflow-style: none;
}
textarea::-webkit-scrollbar,
input[type="text"]::-webkit-scrollbar,
.unit-filter::-webkit-scrollbar { width: 0; height: 0; display: none; }
.composer-actions { display: flex; align-items: center; gap: 8px; padding-top: 6px; }
.composer-actions .grow { flex: 1 1 auto; }

.icon-btn {
  height: 44px; min-width: 44px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text-2);
  cursor: pointer; display: inline-flex; align-items: center; gap: 8px; font-weight: 650; font-size: .9rem;
  transition: border-color .14s ease, color .14s ease, background .14s ease;
}
.icon-btn:hover { border-color: var(--violet); color: var(--violet-fg); background: var(--violet-50); }
.icon-btn svg { width: 20px; height: 20px; }
.send-btn {
  height: 44px; min-width: 48px; padding: 0 20px; border-radius: 12px; border: none;
  background: var(--accent); color: #fff; cursor: pointer; font-weight: 650; font-size: 1rem;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background .14s ease;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: .45; cursor: default; }
.send-btn svg { width: 20px; height: 20px; }

.hint { text-align: center; font-size: .8rem; color: var(--text-3); margin-top: 10px; }

/* ===================== first-run legal gate ===================== */
/* Covers everything (above modals and toasts); hidden only after the current
   terms version is accepted on this device. */
.tos-gate {
  position: fixed; inset: 0; z-index: 400;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 18px; padding-bottom: calc(18px + env(safe-area-inset-bottom));
  overflow: auto;
}
.tos-panel {
  width: 100%; max-width: 680px; max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius-lg); padding: 22px 24px;
}
.tos-brand .brand-logo { height: 26px; }
.tos-panel h1 { margin: 12px 0 12px; font-size: 1.25rem; color: var(--text); }
.tos-ownership {
  padding: 12px 14px; margin-bottom: 12px;
  font-size: .88rem; line-height: 1.55; color: var(--text);
  background: var(--navy-50); border: 1.5px solid var(--navy-border);
  border-left: 4px solid var(--navy); border-radius: var(--radius-sm);
}
.tos-scroll {
  flex: 1; min-height: 120px; max-height: 38vh; overflow-y: auto;
  padding: 4px 14px 10px; margin-bottom: 12px;
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: .84rem; line-height: 1.55; color: var(--text-2);
}
.tos-scroll h2 { font-size: .95rem; color: var(--text); margin: 10px 0 2px; }
.tos-scroll h3 { font-size: .82rem; color: var(--text); margin: 12px 0 3px; }
.tos-scroll p { margin: 3px 0; }
.tos-meta { color: var(--text-3); font-size: .78rem; }
.tos-check {
  display: flex; gap: 10px; align-items: flex-start; font-size: .85rem; color: var(--text);
  margin-bottom: 12px; cursor: pointer;
  /* it's a <label>, so undo the global uppercase form-label treatment */
  text-transform: none; letter-spacing: normal; font-weight: 500;
}
.tos-check input { width: 20px; height: 20px; margin-top: 1px; flex: none; accent-color: var(--navy); }
.tos-actions { display: flex; gap: 10px; }
.tos-actions .btn { min-height: var(--tap); flex: 1; }
.tos-note { margin-top: 10px; font-size: .78rem; color: var(--text-3); text-align: center; }

/* first-run technician picker (team roster) */
.team-modal { max-width: 460px; }
.team-list { max-height: 46vh; overflow-y: auto; border: 1px solid var(--border-2); border-radius: var(--radius-sm); background: var(--surface-2); padding: 4px; }
.team-group { font-size: .7rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); padding: 10px 10px 4px; }
.team-row {
  display: flex; align-items: baseline; gap: 10px; width: 100%; text-align: left; cursor: pointer;
  padding: 10px 12px; min-height: var(--tap); border: none; background: transparent; border-radius: 8px;
}
.team-row:hover { background: var(--violet-50); }
.team-name { font-weight: 650; color: var(--text); font-size: .92rem; }
.team-title { font-size: .76rem; color: var(--text-3); }

/* PM status chips */
.pm-chip { display: inline-block; margin-left: 6px; padding: 2px 9px; border-radius: 20px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.pm-chip.ok { background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok); }
.pm-chip.soon { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn); }
.pm-chip.overdue { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger); }
.pm-sel { min-height: 44px; padding: 0 8px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border-2); color: var(--text); font-size: .88rem; }
.pm-done { white-space: nowrap; }

/* sidebar worklist rows */
.wl-row { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 8px; }
.wl-row:hover { background: var(--surface-2); }
.wl-chk { border: none; background: transparent; cursor: pointer; font-size: 1.1rem; color: var(--text-2); padding: 6px 4px; }
.wl-row.done .wl-chk { color: var(--ok); }
.wl-name { flex: 1; text-align: left; border: none; background: transparent; cursor: pointer; color: var(--text); font-size: .88rem; padding: 6px 2px; }
.wl-row.done .wl-name { text-decoration: line-through; color: var(--text-3); }
.wl-rm { border: none; background: transparent; cursor: pointer; color: var(--text-3); font-size: 1.05rem; padding: 6px 6px; }
.wl-rm:hover { color: var(--danger); }
.wl-clear { border: none; background: transparent; cursor: pointer; color: var(--violet-fg); font-size: .78rem; font-weight: 650; padding: 4px 8px 8px; text-align: left; }

/* pinned-passage "Following" tray — compact, collapsible, sits under the scope bar */
.pin-tray { margin-top: 10px; border: 1px solid var(--navy-border); background: var(--navy-50); border-radius: var(--radius); overflow: hidden; }
.pin-head {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; cursor: pointer;
  padding: 10px 14px; background: transparent; border: none;
  font-size: .85rem; font-weight: 650; color: var(--navy-700);
}
.pin-caret { margin-left: auto; }
.pin-item { padding: 10px 14px; border-top: 1px solid var(--navy-border); background: var(--surface); }
.pin-cite { font-size: .74rem; font-weight: 650; color: var(--text-2); margin-bottom: 4px; }
.pin-text { white-space: pre-wrap; font-size: .92rem; line-height: 1.55; color: var(--text); max-height: 180px; overflow: auto; }
.pin-item .row-actions { margin-top: 8px; }

/* photo evidence on service notes */
.note-photo-btn { min-width: 44px; }
.note-pending { width: 56px; height: 56px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border-2); margin-top: 8px; }
.log-photo { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border-2); cursor: pointer; flex: none; }

/* parts list + add-to-parts "+" beside detected code chips */
.parts-label { margin-top: 14px; }
.code-wrap { display: inline-flex; align-items: stretch; }
.code-add {
  border: 1px solid var(--border-2); border-left: none; background: var(--surface);
  color: var(--text-2); font-weight: 700; cursor: pointer; padding: 0 9px;
  border-radius: 0 8px 8px 0; margin-right: 6px;
}
.code-add:hover { color: var(--violet-fg); border-color: var(--violet); }

/* scope-bar toggle buttons (field-reading mode) */
.np-btn.on { background: var(--navy); color: #fff; border-color: var(--navy); }

/* field-reading mode: content text scales up (chrome untouched); the safety
   banner heading scales WITH it so it stays the loudest element on the page */
html.field-read .passage { font-size: 1.3rem; line-height: 1.75; }
html.field-read .steps li { font-size: 1.18rem; }
html.field-read .safety-item .txt { font-size: 1.24rem; line-height: 1.6; }
html.field-read .banner-safety h3 { font-size: 1.35rem; }
html.field-read .banner-scope h3 { font-size: 1.4rem; }
html.field-read .banner-scope p { font-size: 1.12rem; }
html.field-read .banner-wrongunit p, html.field-read .banner-notfound p { font-size: 1.08rem; }
html.field-read .ocr-text { font-size: 1.12rem; max-height: 220px; }
html.field-read .pin-text { font-size: 1.15rem; }
html.field-read .spec-tag { font-size: 1.02rem; }
html.field-read .grounding { font-size: .98rem; }

/* field unit converter — a calculator, deliberately styled unlike result cards */
.converter {
  margin: 14px auto 0; max-width: 560px; padding: 13px 16px;
  background: var(--surface); border: 1px dashed var(--border-2); border-radius: var(--radius);
}
.conv-lead { font-size: .78rem; color: var(--text-3); margin-bottom: 10px; }
.conv-row { display: flex; gap: 9px; }
.conv-row input, .conv-row select {
  min-height: 44px; padding: 0 12px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border-2); color: var(--text);
  font-size: .95rem; font-variant-numeric: tabular-nums;
}
.conv-row input { flex: 1; min-width: 0; }
.conv-out { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; font-size: .87rem; }
.conv-out:empty { margin-top: 0; }

/* per-unit "asked on this unit" history + shared chips lead-in label */
.chips-lead { align-self: center; font-size: .74rem; font-weight: 650; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.chips-history .chip-history { border-style: dashed; color: var(--text-2); }

/* "flag missing documentation" on the not-found banner */
.gap-btn { margin-top: 12px; }
.gap-btn:disabled { opacity: .55; cursor: default; }

/* quick-symptom chips */
.chips { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; margin: 18px 0 4px; }
.chip {
  min-height: 42px; padding: 0 15px; border-radius: 21px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border-2); color: var(--text);
  font-weight: 500; font-size: .9rem;
  transition: border-color .14s ease, color .14s ease, background .14s ease;
}
.chip:hover { border-color: var(--violet); color: var(--violet-fg); background: var(--violet-50); }

/* ============================ results ============================ */
.results { margin-top: 26px; display: grid; gap: 16px; }

.banner { border-radius: var(--radius); padding: 16px 18px; border: 1px solid; }
/* Banner loudness hierarchy (top to bottom, enforced in renderResults order):
   1. .banner-scope  — STOP-WORK, out-of-scope work (heaviest of all)
   2. .banner-safety — hazards inside the matched material
   3. .banner-wrongunit / .banner-notfound / .banner-weak
   Keep the weights in this order or the page lies about severity. */
.banner-scope { background: var(--danger-bg); border: 3px solid var(--danger); }
.banner-scope h3 {
  margin: -16px -18px 12px; padding: 12px 18px;
  background: var(--danger); color: #fff;
  font-size: 1.1rem; font-weight: 800; letter-spacing: .01em;
  border-radius: calc(var(--radius) - 3px) calc(var(--radius) - 3px) 0 0;
  display: flex; align-items: center; gap: 8px;
}
.banner-scope p { margin: 8px 0 0; color: var(--text); line-height: 1.55; }
.banner-scope .scope-matched { color: var(--text-2); font-size: .8rem; }

/* compact standing notice after an acknowledged override */
.banner-scope-ov { border-width: 2px; }
.banner-scope-ov h3 { margin: 0 0 6px; padding: 0; background: transparent; color: var(--danger); font-size: 1rem; border-radius: 0; }
.banner-scope-ov p { margin: 0; font-size: .88rem; }

/* the override control under the gate */
.scope-ov { display: grid; gap: 10px; }
.scope-ack {
  padding: 14px 16px; background: var(--surface); border: 1.5px dashed var(--danger-border);
  border-radius: var(--radius); display: grid; gap: 12px;
}
.scope-ack-check {
  display: flex; gap: 10px; align-items: flex-start; cursor: pointer;
  font-size: .88rem; line-height: 1.55; color: var(--text);
  /* it's a <label> — undo the global uppercase form-label treatment */
  text-transform: none; letter-spacing: normal; font-weight: 500;
}
.scope-ack-check input { width: 20px; height: 20px; margin-top: 1px; flex: none; accent-color: var(--danger); }
.scope-ack .btn-danger:disabled { opacity: .5; cursor: default; }

.banner-safety { background: var(--danger-bg); border-color: var(--danger); border-width: 2.5px; }
.banner-safety h3 { margin: 0 0 10px; color: var(--danger); font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.banner-notfound { background: var(--warn-bg); border-color: var(--warn-border); }
.banner-notfound h3 { margin: 0 0 8px; color: var(--warn); font-size: 1.05rem; font-weight: 700; }
.banner-notfound p { margin: 6px 0 0; color: var(--warn-fg); }
.banner-weak { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-fg); }
.banner-wrongunit { background: var(--warn-bg); border-color: var(--warn); border-width: 1.5px; }
.banner-wrongunit h3 { margin: 0 0 8px; color: var(--warn); font-size: 1rem; font-weight: 700; }
.banner-wrongunit p { margin: 0 0 12px; color: var(--warn-fg); }

.guardrail-note {
  padding: 10px 14px; font-size: .83rem; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--warn); border-radius: var(--radius-sm);
}
.guardrail-note b { color: var(--text); }

.safety-item { padding: 9px 0; border-top: 1px solid var(--danger-border); }
.safety-item:first-of-type { border-top: none; }
.safety-item .cat { display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--danger); margin-bottom: 2px; }
.safety-item .txt { color: var(--text); }
.safety-item .src { color: var(--text-2); font-size: .8rem; margin-top: 2px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.cite {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
  padding: 11px 15px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: .85rem;
}
.pill { padding: 3px 10px; border-radius: 20px; font-weight: 650; font-size: .77rem; }
.pill-oem { background: var(--violet-50); color: var(--violet-fg); border: 1px solid var(--violet-border); }
.pill-doc { background: var(--surface); color: var(--text-2); border: 1px solid var(--border-2); }
.pill-loc { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok-border); }
.cite .spacer { flex: 1; }
.cite .score { color: var(--text-3); font-size: .74rem; font-variant-numeric: tabular-nums; }

/* one-tap "copy passage + citation" on every result card */
.copy-btn {
  margin-left: 10px; padding: 3px 11px; border-radius: 20px; cursor: pointer;
  font-size: .74rem; font-weight: 650; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--border-2);
  transition: border-color .14s ease, color .14s ease;
}
.copy-btn:hover { border-color: var(--violet); color: var(--violet-fg); }

.card .body { padding: 16px; }
.passage { white-space: pre-wrap; font-size: 1.02rem; line-height: 1.6; color: var(--text); }
.passage mark { background: var(--violet-50); color: var(--violet-fg); padding: 0 2px; border-radius: 3px; font-weight: 600; }

.steps { margin: 12px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.steps li { padding: 9px 13px; background: var(--surface-2); border-left: 3px solid var(--violet); border-radius: 8px; }

.specs { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.specs .label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); font-weight: 600; }
.spec-tag { background: var(--navy-50); border: 1px solid var(--navy-border); color: var(--navy-700); padding: 4px 10px; border-radius: 8px; font-weight: 650; font-variant-numeric: tabular-nums; }
.verify-note { margin-top: 9px; color: var(--warn); font-size: .82rem; }

.grounding { padding: 13px 16px; color: var(--text-2); font-size: .85rem; border: 1px dashed var(--border-2); border-radius: 12px; background: var(--surface); }
.grounding b { color: var(--navy-700); }

/* first-run seeding / loading state */
.seeding-card { text-align: center; padding: 40px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); max-width: 520px; margin: 24px auto; }
.seeding-card h3 { margin: 16px 0 6px; font-size: 1.15rem; font-weight: 700; letter-spacing: -.02em; color: var(--navy-700); }
.seeding-card p { margin: 0 0 18px; color: var(--text-2); font-size: .92rem; }
.seeding-spinner { width: 40px; height: 40px; margin: 0 auto; border-radius: 50%; border: 3px solid var(--border-2); border-top-color: var(--accent); animation: maxim-spin .8s linear infinite; }
@keyframes maxim-spin { to { transform: rotate(360deg); } }
.seeding-bar { height: 8px; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.seeding-bar-fill { height: 100%; background: var(--accent); border-radius: 8px; transition: width .3s ease; }
.seeding-count { margin-top: 10px; font-size: .82rem; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* photo OCR panel */
.ocr-panel { background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius); padding: 14px 16px; }
.ocr-panel h3 { margin: 0 0 4px; font-size: .95rem; font-weight: 700; color: var(--navy-700); display: flex; align-items: center; gap: 8px; }
.ocr-panel .sub { font-size: .8rem; color: var(--text-3); margin-bottom: 10px; }
.ocr-text { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .92rem; color: var(--text); max-height: 150px; overflow: auto; white-space: pre-wrap; }
.ocr-codes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ocr-codes .lead { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); align-self: center; }
.code-tag { background: var(--accent); color: #fff; border: none; padding: 5px 12px; border-radius: 20px; font-weight: 650; cursor: pointer; font-variant-numeric: tabular-nums; transition: background .14s ease; }
.code-tag:hover { background: var(--accent-hover); }
.ocr-thumb { max-height: 120px; border-radius: var(--radius-sm); border: 1px solid var(--border); margin-top: 10px; }

/* ================= AI visual suggestion (online only) =================
   Deliberately NOT a result card. Result cards are solid-bordered with
   citation pills; this is dashed, tinted, and carries a standing badge. A
   tech glancing at the screen must never confuse this with a manual quote.
   Keep the dashed border and the badge if you restyle. */
.ai-launch { margin-top: 12px; }

.ai-suggest {
  margin-top: 12px; padding: 14px 16px;
  border: 1.5px dashed var(--violet-border); border-radius: var(--radius);
  background: var(--violet-50); display: grid; gap: 12px;
}
.ai-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.ai-badge {
  font-size: .64rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: #fff; background: var(--warn); padding: 3px 9px; border-radius: 20px; white-space: nowrap;
}
.ai-title { font-size: .84rem; font-weight: 650; color: var(--violet-fg); }

.ai-safety {
  font-size: .87rem; font-weight: 600; color: var(--warn-fg);
  background: var(--warn-bg); border: 1px solid var(--warn-border);
  border-radius: var(--radius-sm); padding: 9px 12px;
}
.ai-sec { display: grid; gap: 5px; }
.ai-lbl { font-size: .66rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--text-3); }
.ai-sec p { margin: 0; font-size: .92rem; color: var(--text); line-height: 1.5; }

.ai-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ai-checks li {
  padding: 9px 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); display: grid; gap: 2px;
}
.ai-checks li b { font-size: .91rem; font-weight: 650; color: var(--text); }
.ai-checks li span { font-size: .82rem; color: var(--text-2); }

.ai-terms { display: flex; flex-wrap: wrap; gap: 7px; }
.chip.ai-term { min-height: 38px; font-size: .84rem; padding: 0 13px; }

.ai-foot { font-size: .78rem; color: var(--text-2); line-height: 1.5; border-top: 1px dashed var(--violet-border); padding-top: 10px; }

.ai-suggest.ai-error { display: grid; gap: 3px; border-color: var(--border-2); background: var(--surface-2); }
.ai-suggest.ai-error b { font-size: .9rem; color: var(--text); }
.ai-suggest.ai-error span { font-size: .85rem; color: var(--text-2); }

@media (max-width: 560px) { .chip.ai-term { min-height: var(--tap); } }

/* ============================ library ============================ */
.lib-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.lib-head h2 { margin: 0; font-size: 1.35rem; font-weight: 700; letter-spacing: -.025em; }
.lib-grid { display: grid; gap: 16px; }
.profile-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.profile-card.active { border-color: var(--navy-border); box-shadow: 0 0 0 3px var(--navy-50); }
.profile-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.profile-head h3 { margin: 0; font-size: 1.12rem; font-weight: 700; letter-spacing: -.02em; color: var(--navy-700); }
.profile-head .meta { color: var(--text-2); font-size: .84rem; }
.profile-head .spacer { flex: 1; }
.doc-list { margin: 14px 0 0; display: grid; gap: 8px; max-height: 340px; overflow: auto; }
.doc-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.doc-row .name { font-weight: 650; font-size: .92rem; }
.doc-row .meta { color: var(--text-2); font-size: .8rem; }
.doc-row .spacer { flex: 1; }

/* ============================ profile (technician) ============================ */
#profileBody { display: grid; gap: 16px; }
#profileBody .profile-card { display: grid; gap: 12px; }

.tech-head { display: flex; align-items: center; gap: 13px; }
.tech-avatar {
  width: 52px; height: 52px; flex: 0 0 52px; border-radius: 50%;
  background: var(--navy-50); color: var(--navy-700);
  display: grid; place-items: center; font-weight: 700; font-size: 1.05rem;
  border: 1px solid var(--navy-border); letter-spacing: .02em;
}
.tech-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tech-id b { font-size: 1.08rem; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.tech-id span { font-size: .85rem; color: var(--text-2); }

.tech-muted { font-size: .87rem; color: var(--text-2); line-height: 1.5; }
.tech-foot { font-size: .82rem; color: var(--text-3); }
.tech-foot b { color: var(--text-2); }
.save-note { align-self: center; font-size: .85rem; color: var(--ok); font-weight: 650; }

/* coverage tiles */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 13px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.stat b { font-size: 1.5rem; font-weight: 700; letter-spacing: -.03em; color: var(--navy-700); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { font-size: .76rem; color: var(--text-2); }

/* offline readiness */
.ready-list { display: grid; gap: 8px; }
.ready-row {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.ready-dot {
  width: 26px; height: 26px; flex: 0 0 26px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: .85rem; line-height: 1;
}
.ready-row.ok .ready-dot { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok-border); }
.ready-row.warn .ready-dot { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-border); }
.ready-txt { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.ready-txt b { font-size: .93rem; font-weight: 650; color: var(--text); }
.ready-txt span { font-size: .78rem; color: var(--text-3); }
.ready-state { font-size: .8rem; font-weight: 650; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ready-row.ok .ready-state { color: var(--ok); }
.ready-row.warn .ready-state { color: var(--warn); }

/* a service-note row in the profile is tappable — it jumps to that unit */
#profileBody .log-entry { cursor: pointer; align-items: center; }
#profileBody .log-entry:hover { background: var(--navy-50); }
.log-unit { display: block; font-size: .74rem; color: var(--text-3); margin-top: 2px; }

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat b { font-size: 1.3rem; }
}

.dropzone { border: 1.5px dashed var(--border-2); border-radius: 12px; padding: 22px; text-align: center; color: var(--text-2); margin-top: 14px; cursor: pointer; background: var(--surface); transition: border-color .14s ease, color .14s ease, background .14s ease; }
.dropzone.drag { border-color: var(--violet); color: var(--violet-fg); background: var(--violet-50); }
.dropzone strong { color: var(--text); }

/* ============================ buttons ============================ */
.btn { min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--border-2);
  font-size: .95rem; font-weight: 650; cursor: pointer; background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .14s ease, border-color .14s ease, color .14s ease; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-navy { background: var(--accent); color: #fff; border-color: transparent; }
.btn-navy:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); color: var(--text-2); }
.btn-ghost:hover { border-color: var(--violet); color: var(--violet-fg); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover { background: var(--danger-bg); }
.btn:disabled { opacity: .45; cursor: default; }
.row-actions { display: flex; gap: 8px; }

input[type="text"], select {
  width: 100%; min-height: var(--tap); background: var(--surface); color: var(--text);
  border: 1px solid var(--border-2); border-radius: 11px; padding: 12px 14px; font-size: 1rem; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--violet); box-shadow: var(--ring); }
label { display: block; font-weight: 600; margin: 0 0 6px; color: var(--text-2); font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; }
.form-row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; margin-bottom: 12px; }
.form-row .full { grid-column: 1 / -1; }

.empty { text-align: center; color: var(--text-2); padding: 46px 16px; }
.empty .big { font-size: 2.6rem; margin-bottom: 10px; }

/* disclaimer */
.disclaimer { color: var(--text-3); font-size: .8rem; text-align: center; padding: 18px 22px 26px; max-width: 820px; margin: 0 auto; }
.disclaimer b { color: var(--warn); }

/* modal / toast */
.modal-back { position: fixed; inset: 0; background: var(--overlay); backdrop-filter: blur(3px); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px; width: 100%; max-width: 560px; box-shadow: var(--shadow-lg); }
.modal h2 { margin: 0 0 16px; font-size: 1.2rem; font-weight: 700; letter-spacing: -.02em; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--toast-bg); color: var(--toast-fg); padding: 12px 20px; border-radius: 24px; font-weight: 650; z-index: 70; box-shadow: var(--shadow-lg); max-width: 90vw; text-align: center; }
.hidden { display: none !important; }

/* ============================================================================
   TWO LAYOUTS, CHOSEN BY VIEWPORT
   ----------------------------------------------------------------------------
   DESKTOP (≥901px) — persistent sidebar, centered reading column, hover states.
   PHONE   (≤900px) — sidebar becomes a drawer for equipment only, primary nav
                      moves to a thumb-reachable bottom tab bar, the unit scope
                      pins under the top bar, and all fixed chrome respects the
                      device safe-area insets.
   The phone tab bar is hidden on desktop, so a single build serves both.
   ============================================================================ */

/* the bottom tab bar exists only in the phone layout */
.tabbar { display: none; }

/* ---------------------------- desktop ---------------------------- */
@media (min-width: 1280px) {
  :root { --side-w: 300px; }
  .content { max-width: 880px; padding: 34px 28px 52px; }
  .results { gap: 18px; }
}

/* ---------------------------- phone ---------------------------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 50; height: 100vh;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg);
    padding-top: calc(18px + env(safe-area-inset-top));
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
  .app.nav-open .sidebar { transform: translateX(0); }
  .app.nav-open .backdrop { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 45; }

  /* every control a gloved hand actually taps is raised to the --tap floor.
     Desktop keeps its tighter density; this is the phone build only.
     --topbar-h is re-derived here because the hamburger grows to 52px:
     52 + 2×10 padding + 1px hairline = 73px. The sticky scope bar below
     depends on this staying accurate. */
  :root { --topbar-h: 73px; }

  .topbar {
    display: flex;
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-left: calc(14px + env(safe-area-inset-left));
    padding-right: calc(14px + env(safe-area-inset-right));
  }
  .hamburger { width: var(--tap); height: var(--tap); flex: 0 0 var(--tap); }
  .icon-btn, .send-btn { height: var(--tap); }
  .chip { min-height: var(--tap); border-radius: 26px; }
  .fav-btn, .np-btn { min-width: var(--tap); height: var(--tap); }
  .side-new, .side-add, .unit-filter { min-height: var(--tap); }
  .unit-item { min-height: var(--tap); padding: 13px 12px; justify-content: center; }
  .note-row input, .note-row .btn { min-height: var(--tap); }

  /* leave room for the fixed tab bar so the disclaimer is never covered */
  .content {
    padding: 16px calc(16px + env(safe-area-inset-left)) calc(var(--tabbar-h) + 26px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-right));
  }

  /* the drawer is equipment-only on phone — primary nav lives in the tab bar */
  .side-nav { display: none; }

  /* the active unit is the wrong-manual safeguard: keep it on screen while scrolling */
  .scope-bar {
    position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top)); z-index: 15;
    box-shadow: var(--shadow-sm);
  }

  .tabbar {
    display: flex; gap: 4px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 55;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px calc(8px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  }
  .tabbar .tabbar-item {
    flex: 1 1 0; min-height: 56px; padding: 6px 4px; gap: 4px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: transparent; border: none; border-radius: 12px; cursor: pointer;
    color: var(--text-3); font-weight: 600; font-size: .7rem; line-height: 1;
    -webkit-tap-highlight-color: transparent;
  }
  .tabbar .tabbar-item svg { width: 23px; height: 23px; opacity: 1; }
  .tabbar .tabbar-item.active { color: var(--navy-700); background: var(--navy-50); }
  .tabbar .tabbar-item:active { transform: translateY(1px); }

  /* toast clears the tab bar */
  .toast { bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom)); }

  /* chips scroll sideways rather than stacking into a tall block */
  .chips {
    flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; }
}

@media (max-width: 560px) {
  :root { font-size: 16px; }
  .hero { padding: 12px 0 18px; }
  .hero h1 { font-size: 1.35rem; }
  .composer textarea { font-size: 1.05rem; }
  .form-row { grid-template-columns: 1fr; }
  .scope-bar { gap: 8px; padding: 9px 12px; }
  .scope-bar .tag { margin-left: 0; }
  .card .body { padding: 14px; }
  .banner { padding: 14px 15px; }
  .modal { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
