/* =========================================================================
 * notebook.css — the Engineer's Notebook design system
 *
 * Fraunces display / DM Sans UI / JetBrains Mono data, warm paper with a rust
 * accent. The :root block below is shared byte-for-byte with doka-platform-
 * manager, Doka Pocket CRM and TiplistToGo — never retune it per app. Add
 * app-local tokens below it, clearly marked.
 *
 * Copy to css/app.css and delete what this app does not use. Full rulebook:
 * ../engineers-notebook-style/DESIGN-SYSTEM.md
 * ========================================================================= */

:root {
  --paper: #F6F2E9;
  --card: #FFFDF7;
  --ink: #2B2A26;
  --ink-soft: #6B675C;
  --line: #DDD5C4;
  --line-soft: #EAE3D4;
  --rust: #B3502D;
  --rust-deep: #8F3E21;
  --amber: #E0A41B;
  --teal: #1F6F9C;
  --green: #4A7A43;
  --purple: #6E4FA3;
  --warn-bg: #F6E3DC;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "DM Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;

  --nav-h: 58px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(43, 42, 38, .10), 0 4px 14px rgba(43, 42, 38, .06);
}

* { box-sizing: border-box; }

/* Load-bearing. View switching uses the hidden attribute; an author
 * display:flex on a hidden pane paints an empty overlay over the whole app. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body.no-scroll { overflow: hidden; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
a { color: var(--teal); }

h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 640; }
h1 { font-size: 26px; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }

.mono, code, kbd, pre, .kv dt, .kv dd { font-family: var(--font-mono); }
.muted { color: var(--ink-soft); }
.pad { padding: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* The signature small-caps label: field labels, section heads, KPI captions. */
.label, .ctl-label, .panel-sub {
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-soft);
}

.hint { font-size: 12.5px; color: var(--ink-soft); margin: 6px 0 0; }
.hint-warn { color: var(--rust-deep); }

/* ------------------------------------------------------------ buttons ---- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-body); font-size: 14px; font-weight: 500;
  padding: 7px 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink);
  cursor: pointer; white-space: nowrap;
  transition: border-color .15s, background .15s, color .15s;
}
.btn:hover { border-color: var(--ink-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--rust); border-color: var(--rust-deep); color: #fff; font-weight: 600; }
.btn-primary:hover, .btn-primary:active { background: var(--rust-deep); }
.btn-ghost { border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { color: var(--ink); background: var(--paper); border-color: var(--line); }
.btn-ghost.danger { color: var(--rust-deep); border-color: var(--rust); }
.btn-link { border-color: var(--teal); color: var(--teal); text-decoration: none; }
.btn-tiny { font-size: 12px; padding: 3px 8px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 6px;
  color: var(--ink-soft); font-size: 14px; line-height: 1;
}
.icon-btn:hover { background: var(--paper); color: var(--ink); }
.icon-btn.danger:hover { color: var(--rust-deep); }

/* Touch targets. Apply to the whole app on a mobile-first build. */
.touch .btn { min-height: 42px; padding: 10px 16px; border-width: 1.5px; }
.touch .icon-btn { width: 40px; height: 40px; border-radius: 50%; font-size: 20px; }

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

.text-input, input[type=text], input[type=search], input[type=number],
input[type=email], select, textarea {
  width: 100%;
  font-family: var(--font-body); font-size: 13px;
  padding: 6px 9px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--card); color: var(--ink);
}
input[type=text], input[type=number], input[type=email], select { height: 36px; }
textarea { resize: vertical; min-height: 52px; line-height: 1.5; }
.text-input:focus, input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--teal); outline-offset: -1px; border-color: var(--teal);
}
.touch .text-input, .touch input, .touch select, .touch textarea {
  font: inherit; padding: 10px 12px; border-width: 1.5px; border-radius: var(--radius);
}
.touch .text-input:focus, .touch input:focus { outline: none; border-color: var(--rust); }

.search-input {
  flex: 1; min-width: 0; font: inherit;
  padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: 22px;
  background: var(--card);
}
.search-input:focus { border-color: var(--rust); outline: none; }

/* Labelled control in a toolbar row. */
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.ctl { display: flex; flex-direction: column; gap: 3px; flex: 1 1 150px; }
.ctl-narrow { flex: 0 0 84px; }
.ctl-wide { flex: 2 1 320px; }
.ctl-actions { display: flex; gap: 7px; }
.controls.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px 12px; align-items: end;
}
.controls.form-grid .ctl, .controls.form-grid .ctl-narrow { flex: none; min-width: 0; }
.controls.form-grid .ctl-wide { flex: none; grid-column: 1 / -1; }

/* -------------------------------------------------- chips & segments ---- */

.chip-row {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  border: 1.5px solid var(--line); border-radius: 16px;
  background: var(--card);
  font-size: 13px; font-weight: 500; color: var(--ink-soft);
  white-space: nowrap;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip.st-a.on { background: var(--amber); border-color: var(--amber); color: var(--ink); }
.chip.st-b.on { background: var(--teal); border-color: var(--teal); color: #FFF8F0; }
.chip.st-c.on { background: var(--green); border-color: var(--green); color: #FFF8F0; }

.status-badge {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  padding: 2px 7px; border-radius: 4px;
  background: var(--ink-soft); color: #FFFDF7;
}
.status-badge.st-a { background: var(--amber); color: var(--ink); }
.status-badge.st-b { background: var(--teal); }
.status-badge.st-c { background: var(--green); }

.pill {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  border: 1px solid var(--teal); color: var(--teal);
  border-radius: 999px; padding: 1px 8px;
}
.pill-warn { border-color: var(--rust); color: var(--rust-deep); background: var(--warn-bg); }

.segmented {
  display: inline-flex; gap: 2px; padding: 3px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card);
}
.segmented button {
  padding: 6px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--ink-soft);
}
.segmented button.active { background: var(--ink); color: var(--paper); }

.env-chip {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600; letter-spacing: .08em;
  padding: 4px 9px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink-soft);
  cursor: pointer; flex-shrink: 0;
}
.env-chip.is-dev { background: var(--amber); border-color: var(--amber); color: var(--ink); }

/* ------------------------------------------------- cards & the spine ---- */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 17px; margin-bottom: 14px;
}
.card-title { font-family: var(--font-display); font-size: 17px; font-weight: 640; margin: 0 0 8px; }
.card-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* The record card: a filed ticket stub with a colored spine. */
.record-list { display: flex; flex-direction: column; gap: 10px; padding: 10px 12px 0; }
.record-card {
  position: relative; display: flex; overflow: hidden; cursor: pointer;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-spine { flex: 0 0 5px; background: var(--ink-soft); }
.record-card.st-a .card-spine { background: var(--amber); }
.record-card.st-b .card-spine { background: var(--teal); }
.record-card.st-c .card-spine { background: var(--green); }
.card-body { flex: 1; min-width: 0; padding: 10px 44px 10px 12px; }
.card-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-num { font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); letter-spacing: .04em; }
.card-name {
  font-size: 16.5px; line-height: 1.2; margin: 4px 0 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--ink-soft); }
.card-flag {
  font-size: 10.5px; font-weight: 700;
  background: var(--warn-bg); color: var(--rust-deep);
  border: 1px solid var(--rust); border-radius: 9px; padding: 1px 7px; white-space: nowrap;
}

/* The figure block: mono value over a small-caps caption. Used everywhere. */
.card-figures, .kpi-strip { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 7px; }
.kpi-strip { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 14px; }
.kpi-strip::-webkit-scrollbar { display: none; }
.fig, .kpi { display: flex; flex-direction: column; line-height: 1.1; flex: 0 0 auto; }
.fig, .kpi-value { font-family: var(--font-mono); font-size: 13px; font-weight: 600; }
.fig i, .kpi-label {
  font-style: normal; font-family: var(--font-body); font-weight: 400;
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-soft);
}
.fig.warn, .kpi.warn .kpi-value { color: var(--rust-deep); }

/* ------------------------------------------------------ key/value rows ---- */

.dgroup { margin-bottom: 20px; }
.dgroup h3 {
  font-family: var(--font-body); font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em; color: var(--rust);
  border-bottom: 1px solid var(--line); padding-bottom: 5px; margin-bottom: 2px;
}
.dgroup-rows {
  background: var(--card); border: 1px solid var(--line-soft);
  border-radius: var(--radius); overflow: hidden;
}
.drow {
  display: flex; justify-content: space-between; align-items: baseline; gap: 14px;
  padding: 10px 12px; border-bottom: 1px solid var(--line-soft);
}
.drow:last-child { border-bottom: 0; }
.drow.editable { cursor: pointer; }
.drow.editable:active, .drow.editable:hover { background: var(--paper); }
.drow-label { font-size: 13px; color: var(--ink-soft); flex: 0 1 46%; }
.drow-value {
  font-family: var(--font-mono); font-size: 13.5px; font-weight: 500;
  text-align: right; flex: 1; min-width: 0; overflow-wrap: anywhere;
}
.drow-value.warn { color: var(--rust-deep); }
.drow.has-pending { background: #FBF4E4; }
.q-old { font-family: var(--font-mono); text-decoration: line-through; color: var(--ink-soft); }
.q-arrow { color: var(--rust); }
.q-new { font-family: var(--font-mono); font-weight: 600; color: var(--rust-deep); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 13px; }
.kv dt { color: var(--ink-soft); font-size: 11.5px; white-space: nowrap; }
.kv dd { margin: 0; word-break: break-all; }
.kv dd.is-null { color: var(--ink-soft); font-style: italic; }

/* -------------------------------------------------------- data tables ---- */

.tablewrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: 7px; margin-top: 10px; }
table.data { border-collapse: collapse; width: 100%; font-family: var(--font-mono); font-size: 12px; }
table.data th, table.data td {
  padding: 5px 9px; border-bottom: 1px solid var(--line-soft); text-align: left; white-space: nowrap;
}
table.data th {
  position: sticky; top: 0; background: var(--paper); cursor: pointer; user-select: none;
  font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-soft); border-bottom: 1px solid var(--line);
}
table.data th:hover { color: var(--rust); }
table.data th.is-sorted { color: var(--rust-deep); }
table.data tbody tr:nth-child(even) { background: #FBF7EE; }
table.data td.is-null { color: var(--ink-soft); font-style: italic; }
table.data td.is-num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-clip { display: inline-block; max-width: 340px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }

/* ----------------------------------------------------- result / tone ---- */

.result { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); margin-bottom: 14px; overflow: hidden; }
.result-head { display: flex; align-items: flex-start; gap: 12px; padding: 12px 15px; border-bottom: 1px solid var(--line-soft); }
.result-body { padding: 12px 15px; }
.result-headline { font-size: 14.5px; font-weight: 700; margin: 0 0 3px; }
.result-plain { font-size: 13px; margin: 0; }
.result-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-soft); margin-top: 8px; }

/* Tone drives every colour here. Nothing else sets them. */
.tone-ok     { border-left: 5px solid var(--green); }
.tone-empty  { border-left: 5px solid var(--teal); }
.tone-denied { border-left: 5px solid var(--rust); }
.tone-broken { border-left: 5px solid var(--amber); }
.tone-fatal  { border-left: 5px solid var(--rust-deep); }
.tone-denied .result-head, .tone-fatal .result-head { background: var(--warn-bg); }

.status-chip {
  font-family: var(--font-mono); font-size: 15px; font-weight: 600;
  padding: 3px 10px; border-radius: 6px; color: #fff; white-space: nowrap;
  background: var(--ink-soft);
}
.tone-ok .status-chip { background: var(--green); }
.tone-empty .status-chip { background: var(--teal); }
.tone-denied .status-chip, .tone-fatal .status-chip { background: var(--rust-deep); }
.tone-broken .status-chip { background: var(--amber); color: var(--ink); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot-ok { background: var(--green); }
.dot-empty { background: var(--teal); }
.dot-denied { background: var(--rust); }
.dot-broken { background: var(--amber); }
.dot-fatal { background: var(--rust-deep); }

.raw {
  font-family: var(--font-mono); font-size: 12px; line-height: 1.45; margin: 0;
  background: #FBF7EE; border: 1px solid var(--line-soft); border-radius: 7px;
  padding: 10px 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-word;
}
.cmd {
  font-family: var(--font-mono); font-size: 12px; line-height: 1.5;
  background: var(--ink); color: #F1EADC; border-radius: 7px;
  padding: 10px 12px; margin: 8px 0 4px; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
}
details.raw-wrap { margin-top: 10px; }
details.raw-wrap > summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--ink-soft); padding: 4px 0; }
details.raw-wrap > summary:hover { color: var(--ink); }

/* --------------------------------------------- empty / loading / boot ---- */

.empty-state { text-align: center; padding: 56px 28px; color: var(--ink-soft); }
.empty-mark { font-size: 34px; color: var(--line); margin-bottom: 10px; }
.empty-state h2 { color: var(--ink); font-size: 21px; margin-bottom: 6px; }

.spinner {
  width: 22px; height: 22px; margin: 0 auto 10px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--rust);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.view { min-height: 100%; }
.view-center { display: flex; justify-content: center; padding: 32px 20px; }
.boot-card { text-align: center; color: var(--ink-soft); font-size: 13px; margin: auto; }
.fatal-card {
  max-width: 760px; margin: auto;
  background: var(--card); border: 1px solid var(--line);
  border-left: 5px solid var(--rust-deep); border-radius: var(--radius);
  padding: 24px 28px; box-shadow: var(--shadow);
}
.fatal-title { font-family: var(--font-display); font-size: 24px; margin: 0 0 10px; color: var(--rust-deep); }

/* ---------------------------------------------------------- topbar ------ */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 20px;
  height: var(--nav-h); padding: 0 18px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar-brand { display: flex; flex-direction: column; line-height: 1.15; flex-shrink: 0; }
.topbar-name { font-family: var(--font-mono); font-size: 14px; font-weight: 600; margin: 0; }
.topbar-sub { font-size: 9.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--rust); }
.topbar-nav { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; min-width: 0; }
.topbar-right { margin-left: 10px; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.tabnav-btn {
  font-size: 13px; font-weight: 500; padding: 7px 13px;
  border: 1px solid transparent; border-radius: 7px; color: var(--ink-soft);
}
.tabnav-btn:hover { color: var(--ink); background: var(--paper); }
.tabnav-btn.is-active { color: var(--rust-deep); background: var(--paper); border-color: var(--line); font-weight: 700; }

.menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 40;
  min-width: 200px; display: flex; flex-direction: column; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 8px;
}

/* Mobile search/filter header (sticky, above the list). */
.mobile-topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--paper); border-bottom: 1px solid var(--line);
  padding: 10px 12px 8px;
}

/* ------------------------------------------------------ bottom nav ------ */

.tab { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1500;
  display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  position: relative; flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 11px; font-weight: 500; color: var(--ink-soft);
}
.nav-btn .nav-ico { font-size: 18px; line-height: 1; }
.nav-btn.active { color: var(--rust); }
.nav-btn.active::after {
  content: ""; position: absolute; top: 0; left: 28%; right: 28%;
  height: 2.5px; background: var(--rust); border-radius: 0 0 3px 3px;
}
.nav-badge {
  position: absolute; top: 6px; right: calc(50% - 26px);
  min-width: 17px; height: 17px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
  background: var(--rust); color: #FFF8F0; border-radius: 9px;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
}

/* ------------------------------------------------ overlays & toast ------
 * z-index ladder — keep every overlay inside it:
 *   map / canvas internals  <= 1000
 *   bottom nav                 1500
 *   full-screen detail         2000
 *   sheet / modal              2100
 *   toast                      2200
 */

.overlay { position: fixed; inset: 0; z-index: 2100; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(43, 42, 38, .42); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 86dvh;
  display: flex; flex-direction: column;
  background: var(--paper); border-radius: 16px 16px 0 0;
  animation: sheet-up .22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-grip { width: 38px; height: 4px; background: var(--line); border-radius: 2px; margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px 4px; }
.sheet-scroll { overflow-y: auto; padding: 4px 16px 12px; }
.sheet-foot { padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-foot .btn { width: 100%; }

.modal-panel {
  position: absolute; left: 14px; right: 14px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 12px;
  max-width: 640px; margin: 0 auto; max-height: 80dvh; overflow-y: auto;
  background: var(--paper); border-radius: 14px; padding: 20px 16px;
  box-shadow: 0 12px 40px rgba(43, 42, 38, .3);
}
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

.detail-view { position: fixed; inset: 0; z-index: 2000; display: flex; flex-direction: column; background: var(--paper); }
.detail-head {
  display: flex; align-items: flex-start; gap: 8px; padding: 10px 10px 12px;
  background: var(--card); border-bottom: 4px solid var(--ink-soft);
}
.detail-head.st-a { border-bottom-color: var(--amber); }
.detail-head.st-b { border-bottom-color: var(--teal); }
.detail-head.st-c { border-bottom-color: var(--green); }
.detail-scroll { flex: 1; overflow-y: auto; padding: 12px 14px; }

.toast {
  position: fixed; left: 14px; right: 14px;
  bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom));
  z-index: 2200;
  background: var(--ink); color: var(--paper);
  border-radius: var(--radius); padding: 11px 14px; font-size: 13.5px;
  box-shadow: 0 6px 22px rgba(43, 42, 38, .32);
  opacity: 0; transform: translateY(8px);
  transition: opacity .22s, transform .22s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

/* ------------------------------------------------ desktop tool layout ---- */

.workspace {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: minmax(360px, 440px) 1fr;
  gap: 16px; padding: 16px;
}
.panel {
  min-height: 0; overflow: auto;
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px; box-shadow: var(--shadow);
}
.panel-scroll { flex: 1; min-height: 0; overflow: auto; }
.page { padding: 18px; max-width: 1400px; margin: 0 auto; }

/* ---- setup: sign-in and every other full-screen state -------------------
 * Shape copied from the Locations Hub: one centred card on the paper. */
.setup {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 18px;
}
.setup-card { width: 100%; max-width: 420px; text-align: center; }
.brand {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--rust); margin-bottom: 18px;
}
.brand-rule { flex: 0 0 34px; height: 1px; background: var(--rust); opacity: .5; }
.setup-card h1 { font-size: 34px; line-height: 1.1; margin-bottom: 12px; }
.setup-sub { color: var(--ink-soft); margin: 0 0 22px; }
.setup-status { margin-top: 16px; min-height: 24px; font-family: var(--font-mono); font-size: 13px; }
.setup-error { color: var(--rust-deep); }
.setup-choice { width: 100%; margin-top: 8px; }
.setup-card .credit-line { margin-top: 28px; }
.clerk-mount { display: flex; justify-content: center; margin: 6px 0 14px; min-height: 320px; }

/* ------------------------------------------------------- credit tag ------
 * The maker's mark. Identical in every app in the family — do not reword it.
 * <a class="credit" href="https://josiahmdavidson.com" target="_blank"
 *    rel="noopener">Built by Claude + Josiah in Illinois 🌽</a>
 * Mobile: bottom of the More tab. Desktop: footer strip or the welcome state. */

.credit-line {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline;
  margin: 14px 0 0; padding-bottom: 20px; text-align: center;
}
.credit {
  font-family: var(--font-body); font-size: 11.5px; font-weight: 600;
  color: var(--ink-soft); opacity: .6; text-decoration: none; white-space: nowrap;
}
.credit:hover, .credit:active { opacity: .85; }
/* Punctuation, not content: border tone, a little air, never selected. */
.credit-sep {
  font-family: var(--font-body); font-size: 11.5px; color: var(--line);
  margin: 0 8px; user-select: none; -webkit-user-select: none;
}

/* -------------------------------------------------------- a11y & motion -- */

:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 4px; }
.tabnav-btn:focus-visible, .btn:focus-visible { outline-offset: 1px; }
table.data th:focus-visible { outline-offset: -2px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .spinner { animation: none; border-top-color: var(--line); }
}

/* ------------------------------------------------------------ widths ----- */

/* Centre the reading column once there's room, with paper edges. */
@media (min-width: 740px) {
  .record-list, .mobile-topbar { max-width: 720px; margin-left: auto; margin-right: auto; }
  .mobile-topbar { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .workspace { grid-template-columns: 1fr; }
  .topbar { padding: 0 10px; gap: 8px; }
  .page { padding: 12px; }
  .cell-clip { max-width: 180px; }
}

@media (max-width: 600px) {
  .page { padding: 10px; }
  .card { padding: 12px; }
  .controls { gap: 8px; }
  .controls.form-grid { grid-template-columns: 1fr; }
  .ctl, .ctl-narrow, .ctl-wide { flex: 1 1 100%; }
  .ctl-actions, .ctl-actions .btn, .card-foot .btn { flex: 1 1 auto; width: 100%; }
  .result-head { flex-direction: column; gap: 8px; }
  .status-chip { align-self: flex-start; }
  .kv { grid-template-columns: 1fr; gap: 1px 0; }
  .kv dt { margin-top: 8px; }
}

/* =========================================================================
 * App-local — Doka Region Explorer
 *
 * One local rule, and everything below follows from it:
 *
 *   THE REGION CARRIES THE HUE, THE BRANCH CARRIES THE TINT.
 *
 * Northern is teal, Southern is amber, Western is green — three of the
 * notebook accents, used here as categories. Each branch inside a region is
 * that token mixed toward paper in fixed steps (js/data.js, TINT_STEPS), so
 * ten areas stay apart without inventing ten hues, and the three regions
 * still read at a glance from across the room.
 *
 * The steps are judged as rendered — translucent over OSM land — not as
 * hex. Every tint clears the unassigned wash by ≥ 55 and its region-mates
 * by ≥ 25 (js/data.js RENDER_FLOOR, held by npm test). Paper-ward tints
 * over a near-paper basemap only have as much range as the fill opacity
 * gives them, so owned fills are 0.65 on counties and 0.70 on zips; at 0.5
 * the palest amber branch vanished into unassigned land. Tints are never
 * shaded toward ink to gain range: darkened amber turns into rust.
 *
 * Rust is NOT a territory colour. It stays what it is everywhere else in
 * the system: action. The armed brush, the primary button, the lasso.
 * A territory sharing the colour of the cursor would be unreadable.
 *
 * Unassigned land is a faint wash, never a warning: a country that has not
 * been divided up yet is a starting condition, not an error.
 * ========================================================================= */

:root {
  --region-northern: #1F6F9C;   /* --teal  */
  --region-southern: #E0A41B;   /* --amber */
  --region-western:  #4A7A43;   /* --green */
  --panel-w: 400px;
}

html, body { height: 100%; }
body { overflow: hidden; }          /* the panel and map scroll, the page never does */

#app { display: flex; flex-direction: column; height: 100dvh; }

/* ---- workspace ----------------------------------------------------------- */

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(340px, var(--panel-w)) 1fr;
  gap: 14px;
  padding: 14px;
}

.panel { gap: 0; }
.panel-section { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line-soft); }
.panel-section:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.panel-section .panel-sub { margin: 0 0 10px; }

/* ---- map ------------------------------------------------------------------
 * isolation: isolate is load-bearing. Leaflet's panes climb to z-index 1000
 * INSIDE this container; without a stacking context here they would sit
 * above the sticky topbar and the account menu. */
.map-wrap {
  position: relative;
  isolation: isolate;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #E8E4D8;              /* map dead space, per the design system */
}
.map { position: absolute; inset: 0; }

.leaflet-container { background: #E8E4D8; }
/* The paint cursor must say "this click assigns", not "this click drags". */
.leaflet-container .leaflet-interactive { cursor: crosshair; }

.branch-pin { filter: drop-shadow(0 1px 2px rgba(43, 42, 38, .35)); }

.map-tip .tip-sub {
  display: block;
  font-size: 9.5px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-soft);
}

/* ---- legend + footer readout ---------------------------------------------- */

.legend {
  position: absolute; left: 10px; bottom: 10px; z-index: 500;
  background: rgba(255, 253, 247, .93);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 11.5px;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.legend-title {
  font-size: 9.5px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-soft); margin-bottom: 5px;
}
.legend-row { display: flex; align-items: center; gap: 7px; line-height: 1.7; }
.legend-sep { margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--line-soft); }
.legend-swatch { width: 11px; height: 11px; border-radius: 2px; flex: 0 0 11px; }
.legend-swatch.swatch-none { background: var(--line-soft); border: 1px solid var(--line); }
.legend-line { width: 16px; border-top: 1.4px solid var(--ink-soft); flex: 0 0 16px; }
.legend-line.heavy { border-top-width: 2.6px; border-top-color: var(--ink); }

.map-footer {
  /* Clear of the zoom buttons (top right). */
  position: absolute; left: 10px; right: 56px; top: 10px; z-index: 500;
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  pointer-events: none;
}
.hover-tip, .status-line {
  font-family: var(--font-mono); font-size: 11.5px;
  background: rgba(255, 253, 247, .93);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hover-tip { color: var(--ink); min-width: 0; }
.status-line { color: var(--ink-soft); flex: 0 0 auto; }

/* ---- brush list ------------------------------------------------------------ */

.region-group { margin-bottom: 12px; }
.region-head {
  display: flex; align-items: center; gap: 7px;
  margin-bottom: 5px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-soft);
}
.region-swatch { width: 10px; height: 10px; border-radius: 2px; }
.region-name { flex: 1; }
.region-count { font-family: var(--font-mono); letter-spacing: 0; }

.brush {
  display: flex; align-items: stretch; width: 100%;
  margin-bottom: 5px; padding: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer; text-align: left;
  font-family: var(--font-body);
  transition: border-color .12s, box-shadow .12s;
}
.brush:hover { border-color: var(--ink-soft); }
/* The armed brush is the only rust thing in the list — action, not category. */
.brush.is-armed { border-color: var(--rust); box-shadow: inset 0 0 0 1px var(--rust); }
.brush-spine { flex: 0 0 5px; }
.brush-spine.spine-none { background: var(--line-soft); }
.brush-body { flex: 1; min-width: 0; padding: 7px 10px; display: flex; align-items: baseline; gap: 8px; }
.brush-code { font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; color: var(--ink); }
.brush-name { font-size: 13px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brush-count {
  flex: 0 0 auto; align-self: center; padding-right: 10px;
  font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.brush-clear { margin-top: 8px; }

/* ---- segmented mode switch -------------------------------------------------- */

/* Every toggle, in the topbar and the Tools panel, carries no outline and no
 * dividers: only the selected option is marked, with the dark pill. The kit's
 * .segmented has a border, padding and a card background, and its
 * `.segmented button` sets padding and radius; `.segmented .seg` outranks
 * both. The selected rule comes after the transparent background, or the
 * selected option's light text vanishes. */
.segmented { display: inline-flex; gap: 2px; border: 0; padding: 0; background: transparent; overflow: visible; margin-bottom: 8px; }
.segmented .seg {
  font-family: var(--font-body); font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; height: 30px;
  padding: 0 12px; border: 0; border-radius: 999px;
  background: transparent; color: var(--ink-soft); cursor: pointer; white-space: nowrap;
}
.segmented .seg:not(.is-on):not(.is-disabled):hover { color: var(--ink); }
.segmented .seg.is-on { background: var(--ink); color: #F1EADC; }

.undo-label { align-self: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ctl-actions { margin-top: 8px; flex-wrap: wrap; }

/* ---- topbar: view switch after the name, account at the far right --------- */

.topbar-right { margin-left: auto; }
/* A faint rule sets the controls apart from the app's name. */
.view-modes {
  display: flex; align-items: center; gap: 22px; min-width: 0;
  margin-left: 8px; padding-left: 24px; height: 30px;
  border-left: 1px solid var(--line);
}
.topbar-group { display: flex; align-items: center; gap: 8px; }
.topbar-group .ctl-label { white-space: nowrap; }
.view-modes .segmented { margin-bottom: 0; }

/* Tools: one grid, one row per tool, its name then its control, so every
 * name lines up and a toggle and a button read as the same kind of thing. */
.tool-grid { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: 8px 14px; }
.tool-grid > .hint { grid-column: 1 / -1; margin: 0; }
.tool-name { white-space: nowrap; }
.tool-control { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-width: 0; }
.tool-control .segmented { margin-bottom: 0; }
.undo-label { margin: 8px 0 0; }

/* A button shaped to sit beside the toggles: the same pill, type and height.
 * A hairline keeps it reading as something to press rather than a choice. */
.pill-btn {
  font-family: var(--font-body); font-size: 13px; font-weight: 500; line-height: 1;
  display: inline-flex; align-items: center; height: 30px;
  padding: 0 12px; border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--ink); cursor: pointer; white-space: nowrap;
}
.pill-btn:hover:not(:disabled) { border-color: var(--ink-soft); background: var(--paper); }
.pill-btn:active:not(:disabled) { background: var(--ink); border-color: var(--ink); color: #F1EADC; }
.pill-btn:disabled { color: var(--ink-soft); opacity: .45; cursor: not-allowed; }
.pill-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }

/* Viewer mode, while the edit panel is hidden: the map reads, it does not
 * write, so the cursor is a hand and the facts follow it. */
.map-wrap.is-viewing .leaflet-container .leaflet-interactive { cursor: grab; }
.cursor-tip {
  position: absolute; left: 0; top: 0; z-index: 700; pointer-events: none;
  max-width: 280px; padding: 8px 10px;
  background: rgba(255, 253, 247, .97);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  font-size: 12px; color: var(--ink);
}
.cursor-tip-title { margin-bottom: 6px; font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.cursor-tip-title span { margin-left: 7px; font-family: var(--font-body); font-weight: 400; color: var(--ink-soft); }
.cursor-tip dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center; }
.cursor-tip dt { margin: 0; font-size: 9.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; }
.cursor-tip dd { margin: 0; display: flex; align-items: center; gap: 5px; }
.cursor-tip dd.is-empty { color: var(--ink-soft); }
/* Greyed out, as the kit does disabled buttons. Still clickable, so it can
 * say why it is unavailable. */
.seg.is-disabled { opacity: .45; cursor: not-allowed; }
.seg:focus-visible { outline: 2px solid var(--teal); outline-offset: -2px; }

/* ---- map controls: zoom, panel toggle, search ------------------------------- */

.leaflet-container .leaflet-bar { border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.leaflet-container .leaflet-bar a { background: var(--card); color: var(--ink); border-bottom-color: var(--line-soft); }
.leaflet-container .leaflet-bar a:hover { background: var(--paper); color: var(--rust-deep); }

.map-ctl-btn {
  width: 34px; height: 34px; padding: 0;
  display: grid; place-items: center;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  cursor: pointer;
}
.map-ctl-btn:hover { color: var(--rust-deep); border-color: var(--ink-soft); }
.map-ctl-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
.map-ctl-btn svg, .map-search-row svg {
  width: 16px; height: 16px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.leaflet-container .leaflet-control .map-ctl-btn { cursor: pointer; }

.workspace.panel-hidden { grid-template-columns: 1fr; }
/* Halfway down the map's left edge, where the panel attaches. */
.panel-toggle { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); z-index: 800; }

.map-search { display: flex; flex-direction: column; align-items: flex-end; }
.map-search-toggle { width: 38px; height: 38px; border-radius: 999px; }
.map-search-panel {
  width: min(320px, calc(100vw - 96px));
  padding: 8px;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  font-family: var(--font-body); cursor: default;
}
.map-search-row { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); padding-left: 4px; }
.map-search-row svg { flex: 0 0 16px; }
.map-search-input { flex: 1; min-width: 0; height: 34px; font-size: 13px; }
.map-search-close {
  flex: 0 0 28px; width: 28px; height: 28px; padding: 0;
  border: 0; border-radius: 999px; background: transparent;
  color: var(--ink-soft); font-size: 19px; line-height: 1; cursor: pointer;
}
.map-search-close:hover { background: var(--paper); color: var(--ink); }
.map-search-result:not(:empty) { margin-top: 8px; padding: 8px 4px 2px; border-top: 1px solid var(--line-soft); }
.search-label { margin: 0 0 2px; font-size: 13px; line-height: 1.35; color: var(--ink); }
.search-zip { margin: 0 0 9px; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-soft); }
.search-fields { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; }
.search-fields dt {
  margin: 0; font-size: 10px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-soft);
}
.search-fields dd { margin: 0; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
.search-fields dd.is-empty { color: var(--ink-soft); }
.search-swatch { flex: 0 0 10px; width: 10px; height: 10px; border-radius: 2px; }
.search-note { margin: 8px 0 0; font-size: 12px; line-height: 1.4; color: var(--ink-soft); }
.search-note:first-child { margin-top: 0; }
.search-note.hint-warn { color: var(--rust-deep); }
.search-source { margin: 8px 0 0; font-size: 10.5px; color: var(--ink-soft); }
.search-pin { filter: drop-shadow(0 1px 2px rgba(43, 42, 38, .35)); }

/* ---- account-manager view ---------------------------------------------------
 * The legend lists what is drawn: one row per seller with territory or dots,
 * so it can grow past the map on a small screen and must scroll. The AM
 * border is dashed; the sold-job dots are shown as they draw. */
/* The seller list can outgrow a short map, so the AM legend scrolls (and so
 * must take the pointer, which the plain legend never does). With the panel
 * hidden it steps right of the panel toggle at the map's left edge. */
.legend.is-am { max-height: calc(100% - 20px); overflow: auto; pointer-events: auto; }
@media (min-width: 901px) { .workspace.panel-hidden .legend.is-am { left: 46px; } }
.legend-line.dashed { border-top-style: dashed; border-top-color: var(--ink); }
.legend-dot {
  flex: 0 0 10px; width: 10px; height: 10px; border-radius: 999px;
  background: var(--ink-soft); border: 1.5px solid var(--card);
}
.legend-dot.hollow { background: transparent; border: 1.6px solid var(--ink-soft); }
.legend-focus { margin-bottom: 6px; }
.legend-focus select, .am-focus select { width: 100%; }
.legend-focus .ctl-label { display: block; margin-bottom: 3px; }
.legend-note { font-size: 10.5px; color: var(--ink-soft); line-height: 1.4; margin: 4px 0 2px; }

.am-focus { margin-bottom: 10px; }
.am-focus .ctl-label { display: block; margin-bottom: 4px; }
.brush.is-inactive { opacity: .55; cursor: not-allowed; }
.brush-note { display: block; font-size: 10.5px; color: var(--ink-soft); }

/* ---- zoom hint -------------------------------------------------------------
 * Bottom centre: the current zoom, when zips appear, and the two mouse moves
 * nobody guesses. It stays one line: when the map is too narrow, ui.js
 * drops the mouse tips from the end (fitMapHint). On narrow screens it moves
 * between the legend and the search button. */
.map-hint {
  position: absolute; left: 50%; bottom: 10px; z-index: 500;
  transform: translateX(-50%);
  max-width: calc(100% - 360px);
  padding: 4px 11px;
  background: rgba(255, 253, 247, .93);
  border: 1px solid var(--line); border-radius: 999px;
  font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
}
.map-hint span + span::before { content: '\00b7'; margin: 0 7px; }
.map-hint-zoom { color: var(--ink); font-weight: 600; }
@media (max-width: 900px) {
  .map-hint { left: auto; right: 58px; transform: none; max-width: calc(100% - 230px); }
}

/* ---- view-only narrow screens ---------------------------------------------------
 * At RX_CONFIG.VIEW_ONLY_MAX_WIDTH and below, ui.js marks the app view only:
 * no edit panel, no toggle for it, and the map fills the screen under the
 * topbar instead of scrolling below a panel. */
body.is-view-only { overflow: hidden; }
#app.is-view-only { height: calc(100dvh - var(--harness-offset, 0px)); }
.is-view-only .workspace { flex: 1; min-height: 0; grid-template-rows: minmax(0, 1fr); }
.is-view-only .map-wrap { height: auto; min-height: 0; }

/* ---- toast ------------------------------------------------------------------ */

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(8px);
  z-index: 2200;
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 16px;
  background: var(--ink); color: #F1EADC;
  border-radius: 8px; font-size: 13px; line-height: 1.45;
  box-shadow: 0 12px 40px rgba(43, 42, 38, .3);
  opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- responsive -------------------------------------------------------------
 * This is a desktop instrument: painting 33,000 zip codes is not a phone
 * task. Below 900px the panel moves above the map and both scroll, so the
 * map can still be read and a branch still armed — but the tool does not
 * pretend to be mobile-first. */
@media (max-width: 900px) {
  body { overflow: auto; }
  #app { height: auto; }
  .workspace { grid-template-columns: 1fr; gap: 12px; padding: 12px; }
  .panel { max-height: 46dvh; }
  .map-wrap { height: 62dvh; }
  .map-footer { flex-direction: column; align-items: flex-start; gap: 5px; }
  .hover-tip, .status-line { max-width: 100%; }
}

/* The maker's mark, page wide under the workspace and not only on the gate.
 * One line at desktop width; on a phone the two credits stack and the pipe
 * goes. It stays in the view-only layout too: #app is a flex column and the
 * workspace flexes, so the footer keeps its own row under the map. */
.app-footer { flex: 0 0 auto; padding: 0 14px 8px; }
.app-footer .credit-line { margin: 0; padding: 0; }
@media (max-width: 600px) {
  .app-footer .credit-line { flex-direction: column; align-items: center; gap: 2px; }
  .app-footer .credit-sep { display: none; }
}

/* The topbar keeps one line down to a narrow laptop, then lets the view
 * switch drop to its own row rather than push the account menu off screen. */
@media (max-width: 900px) {
  .view-modes { gap: 14px; margin-left: 0; padding-left: 14px; }
  .topbar-group-view .ctl-label { display: none; }
  .view-modes .seg { padding: 5px 9px; font-size: 12px; }
}
@media (max-width: 760px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar-sub { display: none; }
}
@media (max-width: 680px) {
  /* The controls take their own row; the rule has nothing to separate there. */
  .topbar { height: auto; flex-wrap: wrap; row-gap: 8px; padding: 8px 12px; }
  .view-modes { order: 3; flex: 1 0 100%; height: auto; flex-wrap: wrap; row-gap: 6px;
                border-left: 0; padding-left: 0; margin-left: 0; }
}
