:root {
  --bg: #0f1220;
  --panel: #191d2e;
  --panel-2: #1f2438;
  --line: #2a3050;
  --text: #e7e9f3;
  --muted: #9aa0be;
  --accent: #6d5efc;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --amber: #f59e0b;
}
* { box-sizing: border-box; }
/* min-height, not height: a fixed 100% box would end one screen down, and the
   sticky sidebar — which can only stick inside that box — would scroll away
   with the page on any long list. */
html, body { margin: 0; min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  /* A short window (or a laptop in a small browser) still reaches the logout
     button instead of clipping it. */
  overflow-y: auto;
  flex: 0 0 240px;
}
/* Brand. The logo is a fixed two-colour lockup (red #d61518 on grey #737373),
   and grey on this dark panel goes muddy — so it keeps its own light plate
   instead of being recoloured or dropped straight onto the background. */
.brand { margin-bottom: 26px; }
.brand-full, .brand-mark {
  display: block; background: #fff; border-radius: 12px;
  padding: 10px 12px; width: 100%; height: auto;
}
.brand-mark { display: none; width: 42px; padding: 7px; } /* collapsed sidebar */
.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; color: var(--muted);
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
  font-size: 14.5px; text-align: left; width: 100%;
}
.nav-item span { font-size: 16px; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.sidebar-foot { margin-top: auto; }
.wa-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 12px; font-size: 12.5px; color: var(--muted);
}
.wa-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.wa-pill.on .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.wa-pill.off .dot { background: var(--red); }
.wa-pill.wait .dot { background: var(--amber); }

/* Content */
/* min-width:0 so a wide table scrolls inside its card instead of stretching
   the whole column. */
/* Fills the room left by the sidebar — a hard 1100px cap left a dead strip on
   the right of any wide monitor. On very large screens it stops widening and
   centres instead, so a line of text never runs the whole desk. */
.content { flex: 1; min-width: 0; width: 100%; padding: 32px 40px; max-width: 1680px; margin: 0 auto; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
/* Utility: must beat any later rule that sets display on the same element
   (.filters, .inline-fld … all come further down with equal specificity). */
.hidden { display: none !important; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 22px 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.card.stat { position: relative; overflow: hidden; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 34px; font-weight: 800; margin: 6px 0 2px; }
.stat-foot { color: var(--muted); font-size: 12px; }
.card.stat.green .stat-value { color: var(--green); }
.card.stat.red .stat-value { color: var(--red); }
.card.stat.blue .stat-value { color: var(--blue); }

.grid-2 { display: grid; grid-template-columns: 1fr 1.4fr; gap: 16px; }
.card-title { font-weight: 600; margin-bottom: 10px; }
.big { font-size: 40px; font-weight: 800; color: var(--accent); }
.activity { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; padding-right: 8px; }
.act-row { display: flex; align-items: center; gap: 10px; font-size: 13.5px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.act-code { font-weight: 700; flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.act-row .badge { flex: 0 0 auto; }
.act-meta { flex: 0 1 auto; max-width: 46%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }
.act-row:last-child { border-bottom: 0; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.badge.ok { background: rgba(34,197,94,.15); color: #4ade80; }
.badge.no { background: rgba(239,68,68,.15); color: #f87171; }

/* Filters + table */
.filters { display: flex; gap: 12px; margin: 20px 0 14px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 11px 14px; border-radius: 10px; font-size: 14px; min-width: 220px;
}
.filters .count { color: var(--muted); font-size: 13px; margin-left: auto; }
.table-wrap { padding: 0; overflow: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; vertical-align: top; padding: 13px 18px; border-bottom: 1px solid var(--line); font-size: 14px; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; position: sticky; top: 0; background: var(--panel); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr:hover td { background: var(--panel-2); }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; font-weight: 600; }
.pill.ok { background: rgba(34,197,94,.15); color: #4ade80; }
.pill.no { background: rgba(239,68,68,.15); color: #f87171; }

/* Profile */
.profile-card { display: flex; gap: 28px; align-items: center; flex-wrap: wrap; }
.qr-box { background: #fff; padding: 14px; border-radius: 14px; width: 320px; height: 320px; display: grid; place-items: center; }
.qr-box img { width: 100%; height: 100%; }
.profile-info { flex: 1; min-width: 240px; }
.profile-status { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; margin-bottom: 10px; }
.profile-status .dot { width: 11px; height: 11px; border-radius: 50%; }
.profile-status.on .dot { background: var(--green); }
.profile-status.off .dot { background: var(--red); }
.profile-status.wait .dot { background: var(--amber); }
.kv { display: flex; gap: 8px; margin: 6px 0; font-size: 14.5px; }
.kv .k { color: var(--muted); width: 130px; }
.btn { border: 0; border-radius: 10px; padding: 11px 18px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.hint { margin-top: 14px; color: var(--muted); font-size: 13px; line-height: 1.5; }

/* Buttons (shared) */
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn.block { width: 100%; display: block; }

/* ---- Auth-gated layout ---- */
.sidebar, .content { display: none; }
body.authed .sidebar { display: flex; }
body.authed .content { display: block; }

/* Login screen */
.login-screen { display: none; }
body.guest .login-screen {
  display: grid; place-items: center;
  position: fixed; inset: 0; z-index: 50;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2140, var(--bg));
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 30px 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,.4);
}
.login-brand { margin-bottom: 22px; text-align: center; }
.login-brand .brand-full { max-width: 250px; margin: 0 auto; padding: 12px 14px; }
.login-title { margin: 0 0 2px; font-size: 22px; }
.fld { display: block; margin: 16px 0 0; }
.fld > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.fld input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); padding: 12px 14px; border-radius: 10px; font-size: 14.5px;
}
.fld input:focus { outline: none; border-color: var(--accent); }
.login-card .btn.block { margin-top: 22px; padding: 12px; }
.form-error { color: #f87171; font-size: 13px; margin-top: 12px; min-height: 0; }
.form-error:empty { margin-top: 0; }
.form-ok { color: #4ade80; font-size: 13px; margin-top: 12px; }
.form-ok:empty { margin-top: 0; }

/* Sidebar admin box */
.admin-box { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.admin-id { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.admin-avatar {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 34px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: grid; place-items: center; font-weight: 700; text-transform: uppercase;
}
.admin-meta { min-width: 0; }
.admin-email { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-role { font-size: 11px; color: var(--muted); }

/* Settings */
.settings-card { max-width: 520px; margin-top: 22px; }
.fld-sep { margin: 22px 0 4px; font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; border-top: 1px dashed var(--line); padding-top: 16px; }
.fld-sep.danger-sep { color: var(--amber); }
.settings-card .btn.primary { margin-top: 20px; }

/* The responsive rules for every screen below the desktop layout live in one
   block at the bottom of this file. */

/* ---- Groups page ---- */
.banner {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.banner.warn {
  background: rgba(245, 158, 11, .12);
  border-color: rgba(245, 158, 11, .35);
  color: #fcd34d;
}

/* Auto-reply toggle */
.switch { display: inline-block; position: relative; width: 40px; height: 22px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background .15s ease, border-color .15s ease;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform .15s ease, background .15s ease;
}
.switch input:checked + span { background: rgba(34, 197, 94, .25); border-color: var(--green); }
.switch input:checked + span::after { transform: translateX(18px); background: var(--green); }
.switch input:disabled + span { opacity: .5; cursor: default; }

tr.grp-on td { background: rgba(34, 197, 94, .05); }

/* Groups page: table on the left, selected-groups panel on the right */
.groups-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 1180px) {
  .groups-layout { grid-template-columns: minmax(0, 1fr); }
}

.side-panel {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
}
.side-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.side-head .card-title { margin: 0; }
.side-head .pill { margin-left: auto; }

.side-search {
  width: 100%;
  padding: 9px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  margin-bottom: 10px;
}
.side-search:focus { outline: none; border-color: var(--accent); }

.side-list { overflow-y: auto; flex: 1; margin-right: -6px; padding-right: 6px; }
.side-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.side-row:last-child { border-bottom: none; }
.side-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-row .muted { margin-left: auto; flex-shrink: 0; }
.side-row .dot.on {
  width: 7px; height: 7px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--green);
}

/* ---- Stock by Location (dashboard) ---- */
.loc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.loc-cell {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
.loc-cell.total { border-color: var(--accent); background: rgba(109, 94, 252, .12); }
.loc-name { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.loc-units { font-size: 22px; font-weight: 700; margin-top: 4px; }

/* Zero stock reads as quiet, not as a real number */
.tbl td.num.zero { color: var(--muted); opacity: .55; }

/* ---- Users page ---- */
.user-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 14px;
  align-items: end;
}
.user-form .fld { margin: 0; }
.user-form-actions { display: flex; gap: 8px; }
.user-form .form-error,
.user-form .form-ok { grid-column: 1 / -1; }

.btn.sm { padding: 5px 11px; font-size: 12px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.tbl td.nowrap { white-space: nowrap; }
.tbl td.nowrap .btn + .btn { margin-left: 6px; }

/* The Users page belongs to super admins only */
.nav-item.super-only { display: none; }
body.is-super .nav-item.super-only { display: flex; }

/* Text-only link under the login buttons */
.link-btn {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 12px 0 0;
  width: 100%;
  text-align: center;
}
.link-btn:hover { color: var(--accent); }

/* ---- Replies page ---- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.inline-fld { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.inline-fld input[type="date"] {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}
.inline-fld input[type="date"]:focus { outline: none; border-color: var(--accent); }

/* Answers are multi-line; keep the line breaks but stop one row from
   stretching the whole table. */
.answer-cell {
  white-space: pre-line;
  max-width: 380px;
  font-size: 13px;
  line-height: 1.45;
}

/* Short = there is stock, just less than asked for */
.badge.warn { background: rgba(245, 158, 11, .15); color: #fcd34d; }
.pill.warn  { background: rgba(245, 158, 11, .15); color: #fcd34d; }

/* Replies table: keep long answers readable and columns aligned */
.tbl td.answer-cell { white-space: pre-line; }

/* What the client actually typed — kept line-for-line, but capped so a long
   message cannot push the answer column off the screen. */
.msg-cell {
  white-space: pre-line;
  max-width: 300px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted, #9aa4b2);
}

/* Inquiry column: several codes from one message stack in one cell, one per
   line. The <div> blocks let each code sit on its own row without pushing the
   full inquiry column too wide. */
.inquiry-cell {
  font-size: 13px;
  line-height: 1.5;
  max-width: 240px;
}
.inquiry-cell > div + div,
.answer-cell > div + div { margin-top: 4px; padding-top: 4px; border-top: 1px dashed rgba(255,255,255,.06); }

/* Developer-only "Show silent" toggle sits next to Export. Rows the bot chose
   to stay silent on are dimmed and get a subtle red-orange stripe so they read
   as skips instead of answers. */
.silent-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted, #9aa4b2); cursor: pointer; }
.silent-toggle input { cursor: pointer; }
.tbl tr.silent-row { opacity: .65; }
.tbl tr.silent-row td:first-child { border-left: 3px solid rgba(245, 158, 11, .55); }
.badge.silent {
  display: inline-block;
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(245, 158, 11, .18);
  color: #fcd34d;
  margin-left: 4px;
  text-transform: lowercase;
}
#view-replies .tbl td { line-height: 1.5; }

/* WhatsApp offline alert */
.banner.danger {
  background: rgba(239, 68, 68, .12);
  border-color: rgba(239, 68, 68, .4);
  color: #fca5a5;
}
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.banner .btn { margin-left: auto; }

/* ---- Sheets (inventory sources) ---- */
/* The add/edit form is wider than the account form: it carries a URL and a
   column map, and a 520px box makes both hard to read. */
#sheetFormCard { max-width: 720px; }
.fld select {
  width: 100%;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 14px; border-radius: 10px; font-size: 14px;
}
.fld select:focus { outline: none; border-color: var(--accent); }
.settings-card .btn.ghost { margin-top: 20px; margin-left: 10px; }

/* Sheet picker on Dashboard / Stock */
.sheet-pick { min-width: 240px; }

/* Per-group sheet choice. A group that is switched on with no sheet is the
   quiet failure case, so its dropdown is outlined until one is picked. */
.grp-sheet {
  width: 100%;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 7px 10px; border-radius: 8px; font-size: 13px;
}
.grp-sheet:focus { outline: none; border-color: var(--accent); }
.grp-sheet.needs-sheet { border-color: var(--amber); color: var(--amber); }
/* Per-group location choice: one tick per stock column, in sheet order. */
.grp-locs { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.grp-locs label { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text); cursor: pointer; white-space: nowrap; }
.grp-locs input { margin: 0; accent-color: var(--accent); }
.grp-locs.saving { opacity: .5; pointer-events: none; }
.side-row .dot.off {
  width: 7px; height: 7px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--amber);
}
.warn-text { color: var(--amber) !important; }

/* ==========================================================================
   RESPONSIVE SHELL — mobile top bar + off-canvas sidebar
   Presentation only. The markup keeps the same sidebar, the same nav buttons
   and the same ids; on small screens the sidebar simply slides in from the
   left instead of standing beside the content.
   ========================================================================== */

/* Hidden on desktop; the media queries below switch them on. */
.topbar { display: none; }
.nav-scrim { display: none; }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 60;
  align-items: center;
  gap: 12px;
  height: calc(60px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 14px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar-logo {
  height: 38px; width: auto;
  background: #fff; border-radius: 9px; padding: 5px 9px;
}
.topbar-status {
  margin-left: auto;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted); flex: 0 0 10px;
}
.topbar-status.on { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.topbar-status.off { background: var(--red); box-shadow: 0 0 0 3px rgba(239,68,68,.18); }
.topbar-status.wait { background: var(--amber); box-shadow: 0 0 0 3px rgba(245,158,11,.18); }

/* Hamburger — 44px so it is a comfortable thumb target. */
.nav-toggle {
  flex: 0 0 44px;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  cursor: pointer;
  padding: 0;
}
.nav-toggle:active { background: var(--line); }
.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  display: block;
  width: 19px; height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform .2s ease, opacity .2s ease;
}
.nav-toggle-bars { position: relative; }
.nav-toggle-bars::before { position: absolute; top: -6px; left: 0; }
.nav-toggle-bars::after { position: absolute; top: 6px; left: 0; }
body.nav-open .nav-toggle-bars { background: transparent; }
body.nav-open .nav-toggle-bars::before { transform: translateY(6px) rotate(45deg); }
body.nav-open .nav-toggle-bars::after { transform: translateY(-6px) rotate(-45deg); }

/* ---- Tablet and phone: sidebar becomes a drawer ---- */
@media (max-width: 1024px) {
  body.authed .topbar { display: flex; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: 100%;
    width: 272px; max-width: 82vw;
    z-index: 70;
    padding: calc(18px + env(safe-area-inset-top)) 16px calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(-100%);
    transition: transform .25s ease;
    border-right: 1px solid var(--line);
  }
  body.nav-open .sidebar {
    transform: translateX(0);
    box-shadow: 0 0 48px rgba(0,0,0,.55);
  }
  /* The drawer is wide enough for the full lockup and the labels. */
  .brand { margin-bottom: 18px; }
  .brand-full { display: block; }
  .brand-mark { display: none; }

  body.authed .nav-scrim {
    display: block;
    position: fixed; inset: 0; z-index: 65;
    background: rgba(6, 8, 18, .62);
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  body.nav-open .nav-scrim { opacity: 1; pointer-events: auto; }
  /* The page behind the drawer must not scroll under the finger. */
  body.nav-open { overflow: hidden; }

  body.authed .content {
    max-width: 100%;
    padding: calc(78px + env(safe-area-inset-top)) 20px 40px;
  }

  /* Roomier rows for touch */
  .nav-item { padding: 13px 12px; font-size: 15px; }
  .sidebar-foot { padding-top: 18px; }

  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .activity { max-height: 320px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .nav-scrim, .nav-toggle-bars,
  .nav-toggle-bars::before, .nav-toggle-bars::after { transition: none; }
}

/* ---- Phones ---- */
@media (max-width: 720px) {
  body.authed .content { padding: calc(76px + env(safe-area-inset-top)) 16px 34px; }
  .page-head h1 { font-size: clamp(20px, 5.4vw, 24px); }
  .page-head .muted { font-size: 13px; }

  .cards { gap: 12px; margin: 18px 0; }
  .card { padding: 16px; border-radius: 14px; }
  .stat-value { font-size: clamp(24px, 7.6vw, 34px); }
  .stat-label { font-size: 12.5px; }
  .stat-foot { font-size: 11.5px; }
  .big { font-size: clamp(30px, 9vw, 40px); }

  /* Filters stack full width so nothing is cut off */
  .filters { gap: 10px; margin: 16px 0 12px; }
  .filters input,
  .filters select,
  .sheet-pick { min-width: 0; width: 100%; flex: 1 1 100%; }
  .filters .btn { flex: 1 1 auto; }
  .filters .count { margin-left: 0; width: 100%; }

  .loc-grid { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 8px; }
  .loc-cell { padding: 10px 12px; }
  .loc-units { font-size: 19px; }

  /* Activity: the meta line moves under the code instead of being squeezed */
  .act-row { flex-wrap: wrap; gap: 8px; }
  .act-code { flex: 1 1 auto; }
  .act-meta { flex: 1 1 100%; max-width: 100%; text-align: left; white-space: normal; }

  .banner { font-size: 12.5px; padding: 11px 13px; }
  .banner .btn { margin-left: 0; width: 100%; }

  /* Tables keep their columns and scroll sideways inside the card */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .tbl th, .tbl td { padding: 11px 12px; font-size: 13.5px; }

  .settings-card, #sheetFormCard { max-width: 100%; }
  .settings-card .btn.primary,
  .settings-card .btn.ghost { width: 100%; margin-left: 0; }
  .settings-card .btn.ghost { margin-top: 10px; }

  /* Profile QR must never push the page sideways */
  .qr-box { width: min(300px, 100%); height: auto; aspect-ratio: 1 / 1; }
  .profile-card { gap: 18px; }
  .kv { flex-wrap: wrap; font-size: 13.5px; }
  .kv .k { width: 120px; }

  .side-panel { position: static; max-height: none; }
}

/* ---- Small phones ---- */
@media (max-width: 400px) {
  body.authed .content { padding-left: 13px; padding-right: 13px; }
  .cards { gap: 10px; }
  .card { padding: 14px; }
  .loc-grid { grid-template-columns: repeat(2, 1fr); }
  .chip { padding: 6px 12px; font-size: 12.5px; }
  .topbar-logo { height: 34px; }
}

/* ---- Login screen on small screens ---- */
@media (max-width: 480px) {
  body.guest .login-screen { padding: 16px; align-content: center; }
  .login-card { padding: 24px 18px; border-radius: 14px; }
  .login-brand .brand-full { max-width: 210px; }
  .login-title { font-size: 20px; }
}

/* ---- Short landscape phones: let the drawer scroll, keep rows compact ---- */
@media (max-width: 1024px) and (max-height: 520px) {
  .nav-item { padding: 10px 12px; }
  .brand { margin-bottom: 12px; }
  .sidebar-foot { padding-top: 12px; }
}
