/* Mobile-first admin styles. No external dependencies.
   Goals: readable on phones (>=16px text, big tap targets), tables that
   collapse to cards on small screens, light/dark aware with a manual toggle.

   Visual language: calm, crisp, soft depth (Linear/Stripe-dashboard feel).
   Depth + interaction come from CSS tokens (shadows, focus ring, hover tint,
   radii) defined for BOTH themes so nothing is undefined in either.

   Theme resolution:
   - default     -> light values in :root
   - system dark -> dark values, UNLESS the user forced light (data-theme=light)
   - data-theme="dark"/"light" (set by the toggle) always wins. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --border: #e2e5ea;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --ok-bg: #e7f6ed;
  --ok-text: #14633a;
  --err-bg: #fdeaea;
  --err-text: #9b1c1c;
  --badge-bg: #e8eefc;
  --badge-text: #1e40af;

  --radius: 12px;
  --radius-sm: 8px;

  /* soft depth — neutral navy-tinted so cards separate on the light page */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
  --shadow: 0 4px 12px rgba(16, 24, 40, 0.08), 0 2px 6px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);

  /* interaction tokens */
  --hover: rgba(15, 23, 42, 0.04);        /* faint surface tint on hover */
  --ring: rgba(37, 99, 235, 0.35);        /* focus ring = primary @ ~35% */
  --shadow-primary: 0 1px 2px rgba(37, 99, 235, 0.35), 0 2px 8px rgba(37, 99, 235, 0.18);
  --shadow-danger: 0 1px 2px rgba(220, 38, 38, 0.35), 0 2px 8px rgba(220, 38, 38, 0.18);
}

/* dark values, shared by system-dark (unless forced light) and explicit dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #181c22;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --border: #2a2f37;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --danger: #dc2626;
    --danger-hover: #ef4444;
    --badge-bg: #1e293b;
    --badge-text: #93c5fd;
    --ok-bg: #102a1c;
    --ok-text: #6ee7a8;
    --err-bg: #2a1414;
    --err-text: #f7a8a8;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
    --hover: rgba(255, 255, 255, 0.05);
    --ring: rgba(59, 130, 246, 0.4);
    --shadow-primary: 0 1px 2px rgba(0, 0, 0, 0.5), 0 2px 10px rgba(59, 130, 246, 0.28);
    --shadow-danger: 0 1px 2px rgba(0, 0, 0, 0.5), 0 2px 10px rgba(220, 38, 38, 0.3);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #181c22;
  --text: #e8eaed;
  --muted: #9aa3ad;
  --border: #2a2f37;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --danger: #dc2626;
  --danger-hover: #ef4444;
  --badge-bg: #1e293b;
  --badge-text: #93c5fd;
  --ok-bg: #102a1c;
  --ok-text: #6ee7a8;
  --err-bg: #2a1414;
  --err-text: #f7a8a8;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
  --hover: rgba(255, 255, 255, 0.05);
  --ring: rgba(59, 130, 246, 0.4);
  --shadow-primary: 0 1px 2px rgba(0, 0, 0, 0.5), 0 2px 10px rgba(59, 130, 246, 0.28);
  --shadow-danger: 0 1px 2px rgba(0, 0, 0, 0.5), 0 2px 10px rgba(220, 38, 38, 0.3);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- scrollbars ----------
   Thin, themed, semi-transparent — replaces the chunky default (which looked
   dated on the white sidebar). Neutral rgba so it reads on any background in
   both light and dark. */
* { scrollbar-width: thin; scrollbar-color: rgba(130, 140, 150, 0.45) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(130, 140, 150, 0.45);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(130, 140, 150, 0.7);
  background-clip: padding-box;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 0.75rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; letter-spacing: -0.01em; }
h3 { font-size: 1rem; margin: 1rem 0 0.4rem; }

.muted { color: var(--muted); font-size: 0.92rem; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.navlinks {
  display: flex;
  align-items: center;
  gap: 0.25rem 0.5rem;
  flex-wrap: wrap;
  margin-left: auto;
}
/* Nav items read as quiet pills; hover/active are intentional at every width. */
.navlinks a {
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: background .15s, color .15s;
}
.navlinks a:hover { background: var(--hover); text-decoration: none; }
.navlinks a.active { background: var(--badge-bg); color: var(--badge-text); font-weight: 700; }
.inline-form { display: inline; margin: 0; }

/* Master vendor-scope selector — pinned at the top of the nav (see base.html). */
.vendor-scope { margin: 0; }
.vendor-scope select { margin-top: 0; min-height: 40px; }

/* ---------- layout ---------- */
.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem;
  margin-bottom: 1rem;
}

.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: 1fr; }
.grid.stats { grid-template-columns: repeat(2, 1fr); }

.auth-card {
  max-width: 380px;
  margin: 2rem auto;
}

/* ---------- stat cards ---------- */
.stat { text-align: center; padding: 1rem 0.5rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.2rem;
}

/* ---------- forms ---------- */
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
label { display: block; font-weight: 600; font-size: 0.95rem; }
input, select, textarea {
  width: 100%;
  font-size: 16px; /* prevents iOS zoom on focus */
  padding: 0.65rem 0.7rem;
  margin-top: 0.3rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
  transition: border-color .15s, box-shadow .15s;
}
/* Replace the native outline with a soft primary ring on focus. */
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}
::placeholder { color: var(--muted); opacity: 1; }
textarea { min-height: 96px; resize: vertical; line-height: 1.4; }
label .muted { font-weight: 400; }

/* Tinted checkboxes / radios instead of the grey OS default. */
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }

/* Custom chevron for selects — drops the dated native arrow (a data-URI SVG so
   the file stays self-contained). Neutral grey reads in light and dark. */
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a94a0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 14px;
}

/* "Choose file" control — style the native file-selector button as a real
   button (standard ::file-selector-button + the older -webkit- alias). Covers
   every <input type=file> in the panel: product image, vendor logo, broadcast
   media, web background, ticket attachment. */
input[type="file"] { padding: 0.45rem 0.6rem; cursor: pointer; }
input[type="file"]::file-selector-button {
  margin-right: 0.7rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
input[type="file"]::-webkit-file-upload-button {
  margin-right: 0.7rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
input[type="file"]::file-selector-button:hover { background: var(--hover); border-color: var(--primary); }
input[type="file"]::-webkit-file-upload-button:hover { background: var(--hover); border-color: var(--primary); }

/* Groups a table cell's contents into ONE flex item. On phones .rtable
   collapses to cards where `td` is display:flex/space-between, so a cell with a
   name AND a bar would fling them to opposite edges. Wrapping keeps the pair
   together and lets it wrap onto a second line when the screen is narrow. */
.cellwrap {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}
.cellwrap--col { flex-direction: column; align-items: flex-end; gap: 0.15rem; }
/* Back to normal reading order once the table is a real table again. */
@media (min-width: 900px) {
  .cellwrap { justify-content: flex-start; }
  .cellwrap--col { align-items: flex-start; }
}

/* ---------- rating bars (client trust / staff support quality) ----------
   Tone carries meaning, so it is never the ONLY signal: the percentage is always
   printed beside the bar and the title attribute spells out the raw counts. */
.rate {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  vertical-align: middle;
}
.rate-track {
  width: 3.5rem;
  height: 0.4rem;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  flex: none;
}
.rate-fill { display: block; height: 100%; border-radius: 999px; background: currentColor; }
.rate-pct { font-size: 0.85rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.rate--good { color: #16a34a; }
.rate--warn { color: #d97706; }
.rate--bad  { color: #dc2626; }
.rate--none { color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .rate--good { color: #4ade80; }
  .rate--warn { color: #fbbf24; }
  .rate--bad  { color: #f87171; }
}
:root[data-theme="dark"] .rate--good { color: #4ade80; }
:root[data-theme="dark"] .rate--warn { color: #fbbf24; }
:root[data-theme="dark"] .rate--bad  { color: #f87171; }
:root[data-theme="light"] .rate--good { color: #16a34a; }
:root[data-theme="light"] .rate--warn { color: #d97706; }
:root[data-theme="light"] .rate--bad  { color: #dc2626; }

.client-card__top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.client-card__lastref { margin-top: 0.5rem; }

/* ---------- quick-reply "/" menu ----------
   Floats ABOVE the composer rather than below it: the composer already sits at
   the bottom of a long thread, so a downward menu would open off-screen. */
.qr-anchor { position: relative; display: block; }
.qr-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 4px);
  z-index: 30;
  max-height: 15rem;
  overflow-y: auto;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.qr-menu[hidden] { display: none; }
.qr-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.qr-item.is-active, .qr-item:hover { background: var(--hover); }
.qr-slug {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  color: var(--primary);
  flex: none;
}
.qr-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qr-tag {
  flex: none;
  font-size: 0.72rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--hover);
  color: var(--muted);
}

/* ---------- password show/hide ----------
   The wrapper is injected by base.html around every input[type=password], so
   this styles a DOM that only exists once the script has run — with JS off the
   field stays an ordinary password input and none of these rules apply.
   The wrapper takes over the input's margin-top so the button can centre on the
   field itself rather than on the field plus its gap. */
.pw-wrap { position: relative; display: block; margin-top: 0.3rem; }
.pw-wrap > input { margin-top: 0; padding-right: 2.6rem; }
.pw-eye {
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* The icon stays small, but the HIT AREA matches the 44px field height —
     a 32px target is below the touch guideline and this is used on a phone. */
  width: 2.5rem;
  min-height: 0;
  height: 2.5rem;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, background .15s;
}
.pw-eye:hover { color: var(--text); background: var(--hover); }
.pw-eye:focus-visible { outline: none; color: var(--text); box-shadow: 0 0 0 3px var(--ring); }
.pw-eye.is-on { color: var(--primary); }
.pw-eye svg { width: 1.15rem; height: 1.15rem; display: block; }

.field-row { display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; }

.searchbar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.searchbar input { margin-top: 0; }

.checkbox { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.checkbox input { width: auto; min-height: 0; margin: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: background .15s, box-shadow .15s, transform .05s, border-color .15s;
}
.btn:hover { text-decoration: none; background: var(--hover); box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); box-shadow: var(--shadow-sm); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn:disabled, .btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}
.btn:disabled:hover, .btn[disabled]:hover { background: var(--surface); box-shadow: none; }

.btn-primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); box-shadow: var(--shadow-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); box-shadow: var(--shadow); }
.btn-primary:disabled, .btn-primary[disabled], .btn-primary:disabled:hover, .btn-primary[disabled]:hover {
  background: var(--primary); border-color: var(--primary); box-shadow: none;
}

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); box-shadow: var(--shadow-danger); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); box-shadow: var(--shadow); }
.btn-danger:disabled, .btn-danger[disabled], .btn-danger:disabled:hover, .btn-danger[disabled]:hover {
  background: var(--danger); border-color: var(--danger); box-shadow: none;
}

.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); padding: 0.4rem 0.5rem; box-shadow: none; }
.btn-ghost:hover { background: var(--hover); box-shadow: none; }

.btn-sm { min-height: 36px; padding: 0.35rem 0.7rem; font-size: 0.9rem; }

/* ---------- alerts ---------- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.alert-ok { background: var(--ok-bg); color: var(--ok-text); border-left-color: var(--ok-text); }
.alert-error { background: var(--err-bg); color: var(--err-text); border-left-color: var(--err-text); }

/* ---------- badges ---------- */
/* Soft pill tags: tinted background, medium weight. */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.4;
  background: var(--badge-bg);
  color: var(--badge-text);
}
.badge-danger { background: var(--err-bg); color: var(--err-text); }
.badge-muted { background: var(--border); color: var(--muted); }

/* ---------- key/value ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; word-break: break-word; }

/* ---------- pager ---------- */
.pager { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }

/* ---------- code / mono ---------- */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; }
.cred { background: var(--bg); border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 0.5rem 0.7rem; word-break: break-all; }

/* ---------- responsive table ---------- */
.rtable { width: 100%; border-collapse: collapse; }
.rtable thead { display: none; }
.rtable tr {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.6rem;
}
.rtable td {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.3rem 0;
  border: none;
  text-align: right;
}
.rtable td::before {
  content: attr(data-label);
  font-weight: 600;
  color: var(--muted);
  text-align: left;
}

/* ---------- multi-select checkbox dropdown ----------
   A <details> that toggles a checkbox list on a plain click — works the same on
   desktop and mobile (unlike a native <select multiple>, which needs Ctrl-click
   on desktop). The menu floats over content so it doesn't shove the layout.
   The summary mirrors the input styling; the menu uses the shared --shadow. */
.msel-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.msel { position: relative; }
.msel > summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  transition: border-color .15s, box-shadow .15s;
}
.msel > summary::-webkit-details-marker { display: none; }
.msel > summary::after { content: "▾"; color: var(--muted); margin-left: 0.4rem; }
.msel > summary:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.msel[open] > summary { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.msel-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  min-width: 100%;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  box-shadow: var(--shadow-lg);
}
.msel-opt {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  font-weight: 400;
  white-space: nowrap;
  border-radius: 6px;
}
.msel-opt:hover { background: var(--hover); }
.msel-opt input { width: auto; min-height: 0; margin: 0; }

/* ---------- sortable headers ---------- */
.rtable th a { color: var(--muted); white-space: nowrap; }
.rtable th a:hover { color: var(--text); text-decoration: none; }

/* ---------- flat tables (sortable lists: stay tabular + scroll on mobile) ----------
   Unlike the default .rtable (which collapses to cards on phones), .rtable.flat
   stays a real table so the column headers remain visible and tappable for
   sorting. The wrapper scrolls horizontally on narrow screens. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 719px) {
  .rtable.flat { display: table; width: max-content; min-width: 100%; box-shadow: none; }
  .rtable.flat thead { display: table-header-group; }
  .rtable.flat tr {
    display: table-row;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    margin: 0;
  }
  .rtable.flat th, .rtable.flat td {
    display: table-cell;
    text-align: left;
    padding: 0.5rem 0.6rem;
    white-space: nowrap;
  }
  .rtable.flat th {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--border);
  }
  .rtable.flat td::before { content: none; }
  .rtable.flat tbody tr { transition: background .12s; }
  .rtable.flat tbody tr:hover { background: var(--hover); }
}

/* ---------- theme toggle ---------- */
.theme-toggle {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background .15s, box-shadow .15s, transform .05s;
  z-index: 50;
}
.theme-toggle:hover { background: var(--hover); box-shadow: var(--shadow-lg); }
.theme-toggle:active { transform: translateY(1px); }
.theme-toggle:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

/* ---------- wider screens ---------- */
@media (min-width: 720px) {
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.stats { grid-template-columns: repeat(5, 1fr); }

  .rtable thead { display: table-header-group; }
  .rtable tr {
    display: table-row;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    margin: 0;
    background: transparent;
  }
  .rtable th, .rtable td {
    display: table-cell;
    text-align: left;
    padding: 0.7rem 0.85rem;
    vertical-align: top;
  }
  .rtable th {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--border);
  }
  .rtable td::before { content: none; }
  /* subtle row hover in real-table mode */
  .rtable tbody tr { transition: background .12s; }
  .rtable tbody tr:hover { background: var(--hover); }
}

/* ---------- desktop: left sidebar + wide content (landscape) ----------
   At this width the SAME top bar becomes a fixed-width vertical sidebar and the
   content area widens out so lines breathe. Phones/tablets keep the top bar. */
@media (min-width: 1024px) {
  .shell { display: flex; align-items: flex-start; min-height: 100vh; }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 0.15rem;
    width: 240px;
    flex: 0 0 240px;
    height: 100vh;
    overflow-y: auto;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 1rem 0.75rem;
  }
  .topbar .brand {
    font-size: 1.2rem;
    padding: 0.25rem 0.5rem 1rem;
  }
  .navlinks {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 0.1rem;
    margin-left: 0;
    width: 100%;
  }
  .navlinks a {
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius-sm);
  }
  .navlinks a:hover { background: var(--hover); text-decoration: none; }
  .navlinks a.active { background: var(--badge-bg); color: var(--badge-text); }
  .navlinks .inline-form { display: block; margin-top: 0.75rem; }
  .navlinks .inline-form .btn { width: 100%; justify-content: flex-start; }

  /* In the sidebar the scope selector is a full-width block right under the
     brand, set off from the nav links by a divider. */
  .navlinks .vendor-scope { width: 100%; margin: 0.1rem 0 0.55rem; padding-bottom: 0.6rem; border-bottom: 1px solid var(--border); }
  .vendor-scope select { width: 100%; }

  .container {
    flex: 1;
    max-width: 1280px;
    margin: 0;
    padding: 1.75rem 2.5rem;
  }

  /* More room → denser, multi-column cards on the big forms. */
  .grid.three { grid-template-columns: repeat(3, 1fr); }
}
