/* ============================================================
   Components — buttons, inputs, badges, tables, cards
   ============================================================ */

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-3);
  height: 32px; padding: 0 var(--s-5);
  font-size: var(--fs-md); font-weight: var(--fw-medium);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer; user-select: none;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast);
  white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; }
.btn-xs { height: 24px; padding: 0 var(--s-4); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-sm { height: 28px; padding: 0 var(--s-4); font-size: var(--fs-sm); }
.btn-lg { height: 38px; padding: 0 var(--s-6); font-size: var(--fs-base); }

.btn-primary { background: var(--brand-500); color: #fff; border-color: var(--brand-500); box-shadow: 0 1px 0 rgba(255,255,255,0.15) inset, 0 1px 2px rgba(0,0,0,0.2); }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn-primary:active { background: var(--brand-700); }

.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-default); }
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger { background: var(--danger-strong); color: #fff; border-color: var(--danger-strong); }
.btn-danger:hover { filter: brightness(1.08); }

.btn-ico {
  width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  color: var(--text-secondary);
  background: transparent;
}
.btn-ico:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-ico svg { width: 16px; height: 16px; }
.btn-ico.sm { width: 24px; height: 24px; }
.btn-ico.sm svg { width: 13px; height: 13px; }

/* ── Inputs ──────────────────────────────────────────── */
.input {
  height: 32px; padding: 0 var(--s-5);
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  width: 100%;
}
.input::placeholder { color: var(--text-tertiary); }
.input:hover { border-color: var(--border-strong); }
.input:focus { border-color: var(--brand-500); box-shadow: var(--shadow-focus); }
.input-lg { height: 38px; font-size: var(--fs-base); }
.input-group { display: flex; align-items: center; position: relative; }
.input-group .input-prefix,
.input-group .input-suffix {
  position: absolute; display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary); width: 28px; height: 100%; pointer-events: none;
}
.input-prefix { left: 0; } .input-prefix svg { width: 14px; height: 14px; }
.input-suffix { right: 0; } .input-suffix svg { width: 14px; height: 14px; }
.input-group .input { padding-left: 30px; }
.input-group.has-suffix .input { padding-right: 30px; }

textarea.input { height: auto; padding: var(--s-4) var(--s-5); resize: vertical; line-height: var(--lh-normal); }

.label {
  display: block; font-size: var(--fs-sm); font-weight: var(--fw-medium);
  color: var(--text-secondary); margin-bottom: var(--s-3);
}
.hint { font-size: var(--fs-xs); color: var(--text-tertiary); margin-top: var(--s-2); }

.select {
  height: 32px; padding: 0 var(--s-8) 0 var(--s-4);
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7389' stroke-width='2.5'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--s-4) center;
  cursor: pointer;
}

/* Native checkbox / radio variant — used by the React forms where we need
   real form semantics (controlled inputs, native focus, screen readers).
   The `.checkbox` div pattern below stays for design-prototype pages. */
input[type="checkbox"].checkbox-native,
input[type="radio"].checkbox-native {
  appearance: none;
  width: 15px; height: 15px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-xs);
  background: var(--bg-inset);
  cursor: pointer; transition: all var(--dur-fast);
  flex-shrink: 0;
  position: relative;
  margin: 0;
  vertical-align: middle;
}
input[type="radio"].checkbox-native { border-radius: 50%; }
input[type="checkbox"].checkbox-native:checked,
input[type="radio"].checkbox-native:checked {
  background: var(--brand-500); border-color: var(--brand-500);
}
input[type="checkbox"].checkbox-native:checked::after {
  content: ""; position: absolute;
  left: 50%; top: 45%;
  width: 8px; height: 5px;
  border-left: 1.5px solid #fff; border-bottom: 1.5px solid #fff;
  transform: translate(-50%, -50%) rotate(-45deg);
}
input[type="radio"].checkbox-native:checked::after {
  content: ""; position: absolute;
  left: 50%; top: 50%;
  width: 5px; height: 5px; border-radius: 50%; background: #fff;
  transform: translate(-50%, -50%);
}
input[type="checkbox"].checkbox-native:focus-visible,
input[type="radio"].checkbox-native:focus-visible {
  outline: none; box-shadow: var(--shadow-focus); border-color: var(--brand-500);
}

.checkbox, .radio {
  width: 15px; height: 15px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-xs);
  background: var(--bg-inset);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--dur-fast);
  flex-shrink: 0;
  /* When rendered as <button> by DataTable's selection column. */
  padding: 0; font: inherit;
}
button.checkbox:hover, button.radio:hover { border-color: var(--brand-500); }
.radio { border-radius: 50%; }
.checkbox.checked, .radio.checked { background: var(--brand-500); border-color: var(--brand-500); }
.checkbox.checked::after {
  content: ""; width: 8px; height: 5px;
  border-left: 1.5px solid #fff; border-bottom: 1.5px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
}
.radio.checked::after {
  content: ""; width: 5px; height: 5px; border-radius: 50%; background: #fff;
}

/* The native <input type="number"> spinner buttons clash with `.input`'s
   compact 32px height; hide them by default and let users type directly. */
.input[type="number"]::-webkit-inner-spin-button,
.input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none; margin: 0;
}
.input[type="number"] { -moz-appearance: textfield; }

/* The native <input type="date"> / <input type="datetime-local"> calendar
   icon is dark-on-dark in dark mode (and effectively invisible). The
   themed <DatePicker> in @mash/ui is the preferred replacement, but a
   handful of places (audit "since" filter, scheduled-publish timestamp)
   need true date+time precision which DatePicker doesn't yet support.
   Recolor the picker indicator so those native inputs stay readable in
   dark mode without forking per-page styles. */
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="month"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="week"]::-webkit-calendar-picker-indicator {
  filter: invert(1) opacity(0.7);
  cursor: pointer;
}

.switch {
  width: 30px; height: 17px; background: var(--border-strong);
  border-radius: var(--r-full); position: relative; cursor: pointer;
  transition: background var(--dur-fast);
  flex-shrink: 0;
}
.switch::after {
  content: ""; position: absolute; left: 2px; top: 2px;
  width: 13px; height: 13px; border-radius: 50%;
  background: #fff; transition: left var(--dur-fast) var(--ease-out);
  box-shadow: var(--shadow-sm);
}
.switch.on { background: var(--brand-500); }
.switch.on::after { left: 15px; }

/* ── Badges ──────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px;
  font-size: var(--fs-xs); font-weight: var(--fw-medium);
  border-radius: var(--r-sm);
  background: var(--bg-hover); color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
  line-height: 1.4;
}
.badge-success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-border); }
.badge-warn    { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-border); }
.badge-danger  { background: var(--danger-bg); color: var(--danger-fg); border-color: var(--danger-border); }
.badge-info    { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-border); }
.badge-brand   { background: rgba(79,70,229,0.12); color: var(--brand-300); border-color: rgba(79,70,229,0.30); }
[data-theme="light"] .badge-brand { color: var(--brand-700); }

.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.dot-pulse { position: relative; }
.dot-pulse::after {
  content: ""; position: absolute; inset: -2px;
  border-radius: 50%; border: 1.5px solid currentColor;
  animation: pulse-dot 2s ease-out infinite; opacity: 0.6;
}

/* ── Kbd ─────────────────────────────────────────────── */
.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 18px; padding: 0 4px;
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  font-family: var(--font-mono); font-size: var(--fs-2xs);
  color: var(--text-secondary);
}

/* ── Tables ──────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.tbl thead th {
  text-align: left; padding: var(--s-4) var(--s-5);
  font-size: var(--fs-xs); font-weight: var(--fw-medium);
  color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--bg-inset);
  border-bottom: 1px solid var(--border-default);
  position: sticky; top: 0; z-index: 1;
}
.tbl tbody td {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.tbl tbody tr { transition: background var(--dur-fast); }
.tbl tbody tr:hover { background: var(--bg-hover); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .tbl-num { font-variant-numeric: tabular-nums; text-align: right; }
.tbl .tbl-checkbox { width: 32px; padding-right: 0; }

/* ── Avatar ──────────────────────────────────────────── */
.avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--brand-600); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  flex-shrink: 0; letter-spacing: 0;
  border: 1px solid rgba(255,255,255,0.08);
}
.avatar-xs { width: 16px; height: 16px; font-size: 9px; }
.avatar-sm { width: 20px; height: 20px; font-size: var(--fs-2xs); }
.avatar-md { width: 32px; height: 32px; font-size: var(--fs-sm); }
.avatar-lg { width: 40px; height: 40px; font-size: var(--fs-base); }
.avatar-xl { width: 64px; height: 64px; font-size: var(--fs-xl); }

.avatar-c1 { background: #6B72F5; } .avatar-c2 { background: #8B5CF6; }
.avatar-c3 { background: #06B6D4; } .avatar-c4 { background: #10B981; }
.avatar-c5 { background: #F59E0B; } .avatar-c6 { background: #EC4899; }
.avatar-c7 { background: #64748B; } .avatar-c8 { background: #EF4444; }

/* Named avatar colors (for pages using semantic names) */
.avatar-brand  { background: #6B72F5; }
.avatar-violet { background: #8B5CF6; }
.avatar-teal   { background: #06B6D4; }
.avatar-cyan   { background: #06B6D4; }
.avatar-blue   { background: #3B82F6; }
.avatar-green  { background: #10B981; }
.avatar-amber  { background: #F59E0B; }
.avatar-yellow { background: #EAB308; }
.avatar-pink   { background: #EC4899; }
.avatar-red    { background: #EF4444; }
.avatar-slate  { background: #64748B; }
.avatar-info   { background: #06B6D4; }
.avatar-warn   { background: #F59E0B; }
.avatar-success{ background: #10B981; }
.avatar-danger { background: #EF4444; }

.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { border: 2px solid var(--bg-raised); }
.avatar-stack .avatar + .avatar { margin-left: -8px; }

/* ── Cards ───────────────────────────────────────────── */
.card { background: var(--bg-raised); border: 1px solid var(--border-subtle); border-radius: var(--r-lg); overflow: hidden; }
.card-hd { padding: var(--s-5) var(--s-6); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; gap: var(--s-4); }
.card-hd-title { font-size: var(--fs-base); font-weight: var(--fw-semibold); }
.card-hd-desc { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-tertiary); }
.card-body { padding: var(--s-6); }
.card-body-flush { padding: 0; }
.card-ft { padding: var(--s-4) var(--s-6); border-top: 1px solid var(--border-subtle); background: var(--bg-inset); display: flex; align-items: center; gap: var(--s-4); }

/* ── Stat cards ──────────────────────────────────────── */
.stat-card {
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.card-body .stat-card {
  background: var(--bg-inset);
}
.stat { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-6); }
.stat-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-tertiary); font-weight: var(--fw-medium); }
.stat-value { font-size: var(--fs-3xl); font-weight: var(--fw-semibold); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-delta { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.stat-delta.up { color: var(--success-fg); }
.stat-delta.down { color: var(--danger-fg); }
.metric-tile {
  padding: var(--s-4);
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  min-width: 0;
}

/* ── Progress ────────────────────────────────────────── */
.progress { width: 100%; height: 4px; background: var(--bg-inset); border-radius: var(--r-full); overflow: hidden; }
.progress > div { height: 100%; background: var(--brand-500); border-radius: inherit; transition: width var(--dur-slow) var(--ease-out); }

/* ── Tabs ────────────────────────────────────────────── */
.tabs { display: flex; gap: var(--s-2); border-bottom: 1px solid var(--border-subtle); margin-bottom: var(--s-5); }
.tabs.flush-bottom { margin-bottom: 0; }
.tab {
  padding: var(--s-4) var(--s-5);
  font-size: var(--fs-md); font-weight: var(--fw-medium);
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color var(--dur-fast);
  display: inline-flex; align-items: center; gap: var(--s-3);
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--text-primary); border-bottom-color: var(--brand-500); }
/* Inline count pill rendered after a tab label when `<Tab badge={n} />`
   gets a primitive — keeps "Deals" + "0" visually separate without
   forcing every caller to wrap its count in a <Badge>. */
.tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 18px; padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  font-size: var(--fs-2xs); font-weight: var(--fw-medium);
  line-height: 1;
}
.tab-panel { min-width: 0; }
.tab.active .tab-badge { color: var(--text-secondary); }

/* ── Menu / Dropdown ─────────────────────────────────── */
.menu {
  min-width: 200px;
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: var(--s-2);
  animation: slide-up var(--dur-fast) var(--ease-out);
}
.menu-item {
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-3) var(--s-4);
  font-size: var(--fs-md);
  color: var(--text-primary);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.menu-item:hover { background: var(--bg-hover); }
.menu-item svg { width: 14px; height: 14px; color: var(--text-tertiary); }
.menu-item .kbd { margin-left: auto; }
.menu-separator { height: 1px; background: var(--border-subtle); margin: var(--s-2) calc(var(--s-2) * -1); }
.menu-section { padding: var(--s-3) var(--s-4) var(--s-2); font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-tertiary); font-weight: var(--fw-medium); }

/* ── Tooltip (pure CSS hint) ─────────────────────────── */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated); color: var(--text-primary);
  padding: 4px 8px; font-size: var(--fs-xs); border-radius: var(--r-xs);
  white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity var(--dur-fast);
  border: 1px solid var(--border-default); box-shadow: var(--shadow-md);
  z-index: 100;
}
.tip:hover::after { opacity: 1; }

/* Down-anchored variant — used for tooltips on top-of-page chrome
   (the topbar) where the default upward tooltip would clip out of
   the viewport or sit outside the row. */
.tip.tip-down::after {
  bottom: auto;
  top: calc(100% + 6px);
}

/* ── Toast ───────────────────────────────────────────── */
.toast-region {
  position: fixed; bottom: 20px; right: 20px; z-index: 1000;
  display: flex; flex-direction: column; gap: var(--s-3);
  pointer-events: none;
}
.toast {
  min-width: 320px; max-width: 420px;
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: var(--s-5);
  display: flex; align-items: flex-start; gap: var(--s-4);
  animation: slide-up var(--dur-med) var(--ease-out);
  pointer-events: auto;
}
.toast-ico { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.toast-body { flex: 1; }
.toast-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); margin-bottom: 2px; }
.toast-desc { font-size: var(--fs-sm); color: var(--text-secondary); }
.toast-success .toast-ico { color: var(--success-fg); }
.toast-danger .toast-ico { color: var(--danger-fg); }
.toast-info .toast-ico { color: var(--info-fg); }

/* ── Modal ───────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 900;
  animation: fade-in var(--dur-fast);
  display: flex; align-items: center; justify-content: center;
}
[data-theme="light"] .modal-backdrop { background: rgba(15,19,32,0.4); }
.modal {
  width: 480px; max-width: calc(100vw - 40px); max-height: calc(100vh - 80px);
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  display: flex; flex-direction: column;
  animation: scale-in var(--dur-med) var(--ease-out);
  overflow: hidden;
}
.modal-hd { padding: var(--s-6); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: flex-start; gap: var(--s-4); }
.modal-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.modal-desc { font-size: var(--fs-sm); color: var(--text-secondary); margin-top: var(--s-2); }
.modal-body { padding: var(--s-6); overflow-y: auto; }
.modal-ft { padding: var(--s-5) var(--s-6); border-top: 1px solid var(--border-subtle); display: flex; justify-content: flex-end; gap: var(--s-3); background: var(--bg-inset); }

/* Header intent icon — 36px rounded square shown inside .modal-hd to
   set tone before the user reads the title. Variants map to the same
   semantic palette as .badge and .callout. Mirrors design/ui-dialogs.html. */
.modal-icon {
  width: 36px; height: 36px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.modal-icon svg { width: 18px; height: 18px; }
.modal-icon.brand   { background: rgba(79,70,229,0.12); color: var(--brand-400);  border: 1px solid rgba(79,70,229,0.30); }
.modal-icon.danger  { background: var(--danger-bg);    color: var(--danger-fg);  border: 1px solid var(--danger-border); }
.modal-icon.success { background: var(--success-bg);   color: var(--success-fg); border: 1px solid var(--success-border); }
.modal-icon.warn    { background: var(--warning-bg);   color: var(--warning-fg); border: 1px solid var(--warning-border); }
.modal-icon.info    { background: var(--info-bg);      color: var(--info-fg);    border: 1px solid var(--info-border); }
/* Centered terminal-state variant (e.g. payment-success) — drop into
   .modal-body with .modal-icon-lg to render a 56px hero icon. */
.modal-icon-lg { width: 56px; height: 56px; }
.modal-icon-lg svg { width: 28px; height: 28px; }

/* ── Drawer (right-anchored side sheet) ──────────────── */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 900;
  animation: fade-in var(--dur-fast);
  display: flex; justify-content: flex-end;
}
[data-theme="light"] .drawer-backdrop { background: rgba(15,19,32,0.4); }
.drawer {
  width: 440px; max-width: calc(100vw - 40px); height: 100%;
  background: var(--bg-overlay);
  border-left: 1px solid var(--border-default);
  box-shadow: var(--shadow-xl);
  display: flex; flex-direction: column;
  animation: slide-in-right var(--dur-med) var(--ease-out);
  overflow: hidden;
}
.drawer-sm { width: 360px; }
.drawer-lg { width: 560px; }
.drawer-xl { width: 720px; }
.drawer-hd { padding: var(--s-5) var(--s-6); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; gap: var(--s-4); }
.drawer-title { font-size: var(--fs-base); font-weight: var(--fw-semibold); }
.drawer-eyebrow { font-size: var(--fs-xs); color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; }
.drawer-body { padding: var(--s-6); overflow-y: auto; flex: 1; }
.drawer-ft { padding: var(--s-4) var(--s-6); border-top: 1px solid var(--border-subtle); background: var(--bg-inset); display: flex; align-items: center; gap: var(--s-3); }
@keyframes slide-in-right {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@media (max-width: 768px) {
  .drawer { width: calc(100vw - 24px); border-left: 0; }
}

/* ── Popover ─────────────────────────────────────────── */
.pop {
  position: relative;
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: var(--s-5);
  max-width: 320px;
  z-index: 100;
  animation: slide-up var(--dur-fast) var(--ease-out);
}
.pop-arrow::before {
  content: ""; position: absolute; top: -6px; left: 24px;
  width: 10px; height: 10px;
  background: var(--bg-overlay);
  border-left: 1px solid var(--border-default);
  border-top: 1px solid var(--border-default);
  transform: rotate(45deg);
}
.pop-arrow.pop-arrow-end::before { left: auto; right: 24px; }
.pop-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); margin-bottom: 4px; }
.pop-desc  { font-size: var(--fs-sm); color: var(--text-secondary); }

/* ── Radio card (bordered selectable option) ─────────── */
.radio-card {
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  background: transparent;
  cursor: pointer;
  transition: border-color var(--dur-fast), background var(--dur-fast);
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
}
.radio-card:hover { border-color: var(--border-strong); }
.radio-card.checked,
.radio-card[aria-checked="true"] {
  border-color: var(--brand-500);
  background: rgba(79,70,229,0.06);
}
.radio-card-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.radio-card-title { font-size: var(--fs-md); font-weight: var(--fw-medium); }
.radio-card-hint  { font-size: var(--fs-xs); color: var(--text-tertiary); }
.radio-native {
  accent-color: var(--brand-500);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.preset-tile:hover:not(:disabled) {
  border-color: var(--brand-400) !important;
}

/* ── Toast inline action (the "Reconnect" / "Open project →" link
   the design pairs with title + desc when remediation is one click). ── */
.toast-action {
  margin-top: var(--s-3);
  background: transparent; border: 0; padding: 0;
  font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-medium);
  color: var(--brand-300); cursor: pointer;
}
[data-theme="light"] .toast-action { color: var(--brand-600); }
.toast-action:hover { text-decoration: underline; }
.toast-warn .toast-ico    { color: var(--warning-fg); }

/* ── Section header (small uppercase label) ──────────── */
.section-hd {
  display: flex; align-items: center; gap: var(--s-3);
  margin-bottom: var(--s-3);
}
.section-hd-label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: var(--fw-semibold);
  color: var(--text-tertiary);
  flex: 1;
}
.section-hd-step {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--brand-500);
  color: #fff;
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.section-hd-action { flex-shrink: 0; margin-left: auto; }

/* ── Property list (key/value display) ───────────────── */
.prop-list { display: flex; flex-direction: column; gap: var(--s-3); font-size: var(--fs-sm); }
.prop-list-compact { gap: var(--s-2); }
.prop-row { min-width: 0; }
.prop-list-inline .prop-row {
  display: grid;
  grid-template-columns: minmax(110px, max-content) 1fr;
  column-gap: var(--s-4);
  align-items: baseline;
}
.prop-list-stack .prop-row { display: flex; flex-direction: column; gap: 2px; }
.prop-row-label {
  color: var(--text-tertiary);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: var(--fw-medium);
}
.prop-list-inline .prop-row-label { text-transform: none; letter-spacing: 0; font-size: var(--fs-sm); font-weight: var(--fw-regular); }
.prop-row-value {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ── Code block (mono value with copy) ───────────────── */
.code-block {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-primary);
  min-width: 0;
}
.code-block-value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.code-block-multiline {
  flex-direction: column;
  align-items: stretch;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
}
.code-block-multiline .code-block-pre {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-primary);
}

/* ── Stepper ─────────────────────────────────────────── */
.stepper {
  display: flex; align-items: center; gap: var(--s-3);
  list-style: none; padding: 0; margin: 0;
}
.stepper-item {
  display: inline-flex; align-items: center; gap: var(--s-3);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.stepper-circle {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--bg-inset);
  color: var(--text-tertiary);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 0; padding: 0; font-family: inherit;
  transition: background var(--dur-fast), color var(--dur-fast);
}
button.stepper-circle { cursor: pointer; }
.stepper-item.active .stepper-circle {
  background: var(--brand-500); color: #fff;
}
.stepper-item.done .stepper-circle {
  background: var(--success-strong); color: #fff;
}
.stepper-item.active .stepper-label { color: var(--text-primary); font-weight: var(--fw-medium); }
.stepper-item.todo  .stepper-label { color: var(--text-tertiary); }
.stepper-connector {
  display: inline-block;
  width: 32px; height: 1px;
  background: var(--border-subtle);
  margin: 0 var(--s-2);
}
.stepper-item.done + .stepper-item .stepper-connector,
.stepper-item.done .stepper-connector { background: var(--success-strong); }
@media (max-width: 768px) {
  .stepper { flex-wrap: wrap; }
  .stepper-connector { display: none; }
}

/* ── Callout ─────────────────────────────────────────── */
.callout {
  padding: var(--s-5) var(--s-6);
  border-radius: var(--r-md);
  border: 1px solid var(--border-default);
  background: var(--bg-inset);
  display: flex; align-items: flex-start; gap: var(--s-4);
  font-size: var(--fs-md);
}
.callout-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info-fg); }
.callout-warn { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-fg); }
.callout-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-fg); }
.callout svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }

/* ── Segmented control ───────────────────────────────── */
.segment {
  display: inline-flex;
  max-width: 100%;
  flex-wrap: wrap;
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  padding: 2px;
  gap: 2px;
}
.segment-item { padding: 3px var(--s-4); font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-secondary); border-radius: var(--r-sm); cursor: pointer; transition: all var(--dur-fast); border: 0; background: transparent; font-family: inherit; }
.segment-item:hover { color: var(--text-primary); }
.segment-item.active { background: var(--bg-elevated); color: var(--text-primary); box-shadow: var(--shadow-xs); }
.segment-item:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Table toolbar (selection bar above .tbl) ──────────
   Mirrors design/admin-users.html's "<n> selected · Email
   · Tag · Suspend · Delete · ... matching" row. Lives
   inside the .table-frame, right above the <table>. */
.table-toolbar {
  padding: var(--s-3) var(--s-5);
  display: flex; align-items: center; gap: var(--s-4);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-inset);
}
.table-toolbar-sep { width: 1px; height: 16px; background: var(--border-default); }

/* Selected-row state — subtle brand tint on the whole row. */
.tbl tbody tr.selected { background: color-mix(in oklch, var(--brand-500) 8%, var(--bg-raised)); }
.tbl tbody tr.selected:hover { background: color-mix(in oklch, var(--brand-500) 12%, var(--bg-raised)); }

/* ── Empty / loading state ───────────────────────────── */
.empty-state {
  padding: var(--s-8) var(--s-5);
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2);
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--fs-sm);
}
.empty-state-title { font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--text-primary); }
.empty-state-icon  { color: var(--text-tertiary); margin-bottom: var(--s-2); }
.empty-state-icon svg { width: 28px; height: 28px; }
.empty-state-action { margin-top: var(--s-3); }

/* ── Filter bar (above tables) ───────────────────────────
   Visually fuses with the .table-frame below: shares the
   same border/background, top-rounded only, no bottom border.
   shell.css removes the table's top rounding only when a
   non-standalone .filter-bar sits immediately before it. Use
   .filter-bar-flush when you don't want the merged-frame look. */
.filter-bar {
  display: flex; align-items: center; gap: var(--s-3);
  flex-wrap: wrap;
  padding: var(--s-4) var(--s-5);
  border: 1px solid var(--border-subtle);
  border-bottom: none;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--bg-raised);
}
.filter-bar-flush {
  padding: 0; border: none; border-radius: 0; background: transparent;
  margin-bottom: var(--s-5);
}

/* ── Table section header (flat title above .table-frame) ── */
.table-section-hd {
  display: flex; align-items: center; gap: var(--s-3);
  margin-bottom: var(--s-3);
}
.table-section-hd + .table-section-hd { margin-top: var(--s-6); }
.table-section-hd-title { font-size: var(--fs-base); font-weight: var(--fw-semibold); color: var(--text-primary); }
.table-section-hd-desc  { font-size: var(--fs-sm); color: var(--text-tertiary); }

/* Stacked tables: every table-frame after the first gets top margin so
   sibling DataTables breathe without callers having to wrap each one. */
.table-frame + .table-frame,
.table-frame + .table-section-hd,
.table-section-hd + .table-frame { margin-top: var(--s-6); }
.table-section-hd-title + .table-section-hd { margin-top: var(--s-6); }

/* ── Skeleton ────────────────────────────────────────── */
.skel {
  background: linear-gradient(90deg, var(--bg-hover) 0%, var(--bg-active) 50%, var(--bg-hover) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
  border-radius: var(--r-sm);
}

/* ── Logo mark ───────────────────────────────────────── */
.logo-mark {
  width: 24px; height: 24px; border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--brand-400) 0%, var(--violet-600) 100%);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: var(--fw-bold); font-size: 13px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 2px 8px rgba(79,70,229,0.4);
  flex-shrink: 0;
  position: relative;
}
.logo-mark::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 30% 20%, rgba(255,255,255,0.35), transparent 60%);
  border-radius: inherit; pointer-events: none;
}
.logo-wordmark { font-size: var(--fs-lg); font-weight: var(--fw-semibold); letter-spacing: -0.02em; }

/* ============================================================
   UI library additions — extends the base classes above with
   the variants the React components in components/*.tsx rely on.
   ============================================================ */

/* ── Button variants the design exposes via inline style only ── */
.btn-success { background: var(--success-strong); color: #fff; border-color: var(--success-strong); }
.btn-success:hover { filter: brightness(1.08); }

.btn-warn { background: var(--warning-fg); color: #1a1304; border-color: var(--warning-fg); }
.btn-warn:hover { filter: brightness(1.08); }
.btn-tone-danger { color: var(--danger-fg); }
.btn-tone-danger:hover { color: var(--danger-strong); }
.btn-tone-warn { color: var(--warning-fg); }
.btn-tone-warn:hover { color: var(--warning-strong); }
.btn-tone-success { color: var(--success-fg); }
.btn-tone-success:hover { color: var(--success-strong); }
.btn-block { width: 100%; }
.btn:disabled,
.btn[aria-busy="true"] { opacity: 0.65; cursor: not-allowed; }
.btn-spinner {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* ── Button group — separated cluster used by `<ButtonGroup>` ── */
.btn-group { display: inline-flex; gap: var(--s-3); align-items: center; }

/* ── Pill badge — full-radius variant of `.badge` ── */
.badge-pill { border-radius: var(--r-full); padding: 2px 9px; }

/* ── Callout success — design ships info/warn/danger only ── */
.callout-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-fg); }

/* ── Card with built-in padding (when there's no separate body) ── */
.card-padded { padding: var(--s-6); }

/* Page layout primitives */
.app-page {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: var(--s-7);
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
  min-width: 0;
}
.app-page-wide { max-width: 1440px; }
.app-page-full { max-width: none; margin: 0; }
.app-page-pad-none { padding: 0; }
.app-page-pad-lg { padding: var(--s-8); }

.page-stack {
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
  min-width: 0;
}
.page-stack-sm { gap: var(--s-4); }
.page-stack-lg { gap: var(--s-8); }

.responsive-grid {
  --responsive-grid-min: 260px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--responsive-grid-min)), 1fr));
  gap: var(--s-5);
  min-width: 0;
}
.responsive-grid-sm { --responsive-grid-min: 180px; }
.responsive-grid-lg { --responsive-grid-min: 340px; }
.responsive-grid-gap-sm { gap: var(--s-4); }
.responsive-grid-gap-lg { gap: var(--s-6); }
.auto-grid-5 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--s-4);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s-4);
  align-items: stretch;
  min-width: 0;
}
.kpi-grid[data-columns="1"] { grid-template-columns: minmax(0, 1fr); }
.kpi-grid[data-columns="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi-grid[data-columns="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi-grid[data-columns="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi-grid[data-columns="5"] { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1280px) {
  .kpi-grid[data-columns="5"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .kpi-grid[data-columns="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .kpi-grid[data-columns="3"],
  .kpi-grid[data-columns="5"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .kpi-grid,
  .kpi-grid[data-columns="2"],
  .kpi-grid[data-columns="3"],
  .kpi-grid[data-columns="4"],
  .kpi-grid[data-columns="5"] {
    grid-template-columns: minmax(0, 1fr);
  }
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-5);
  min-width: 0;
}
.toolbar-bordered {
  padding: var(--s-4) var(--s-5);
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
}
.toolbar-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.toolbar-title {
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  line-height: var(--lh-tight);
}
.toolbar-desc {
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  line-height: var(--lh-normal);
}
.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-3);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.action-link {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--brand-300);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: var(--lh-normal);
  text-decoration: none;
  border-radius: var(--r-sm);
  transition: color var(--dur-fast), background var(--dur-fast);
}
[data-theme="light"] .action-link { color: var(--brand-600); }
.action-link:hover { color: var(--brand-200); }
[data-theme="light"] .action-link:hover { color: var(--brand-700); }
.action-link svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}
.action-link-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.action-link-sm { font-size: var(--fs-xs); }
.action-link-muted { color: var(--text-secondary); }
.action-link-muted:hover { color: var(--text-primary); }
.action-link-danger { color: var(--danger-fg); }
.action-link-danger:hover { color: var(--danger-strong); }

.list-stack {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-width: 0;
}
.list-stack-framed {
  gap: 0;
  overflow: hidden;
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
}
.list-row {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  min-width: 0;
  padding: var(--s-4) var(--s-5);
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.list-row-interactive { cursor: pointer; }
.list-row-interactive:hover {
  background: var(--bg-hover);
  border-color: var(--border-default);
}
.list-row-compact,
.list-stack-compact .list-row {
  padding: var(--s-3) var(--s-4);
  gap: var(--s-3);
}
.list-stack-framed .list-row {
  border: 0;
  border-radius: 0;
  background: transparent;
}
.list-stack-framed .list-row + .list-row { border-top: 1px solid var(--border-subtle); }
.list-stack-framed .list-row-interactive:hover { background: var(--bg-hover); }
.list-row-leading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-tertiary);
}
.list-row-leading svg {
  width: 16px;
  height: 16px;
}
.list-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.list-row-head {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  min-width: 0;
}
.list-row-title {
  color: var(--text-primary);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-row-meta {
  flex-shrink: 0;
  color: var(--text-tertiary);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  line-height: var(--lh-normal);
}
.list-row-desc {
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-row-content {
  margin-top: var(--s-2);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  min-width: 0;
}
.list-row-trailing {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-3);
  flex-shrink: 0;
  color: var(--text-tertiary);
}

/* Shared rating display used by marketplace, reviews, and future app pages. */
.rating-stars {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--warning-fg);
  line-height: 1;
}
.rating-star {
  flex-shrink: 0;
  fill: currentColor;
  stroke: currentColor;
}
.rating-star-dim {
  color: var(--border-default);
}

/* Count-driven status tabs for moderation queues and table dashboards. */
.status-metric-tabs {
  display: grid;
  gap: var(--s-4);
}
.status-metric-tabs-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.status-metric-tabs-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.status-metric-tabs-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.status-metric-tab {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-5);
  min-height: 92px;
  text-align: left;
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  background: var(--bg-raised);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.status-metric-tab:hover {
  border-color: var(--border-default);
  background: var(--bg-hover);
}
.status-metric-tab.active {
  border-color: var(--metric-accent);
  background: color-mix(in srgb, var(--bg-raised) 88%, var(--metric-accent) 12%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--metric-accent) 40%, transparent);
}
.status-metric-tab-ic {
  width: 34px;
  height: 34px;
  border-radius: var(--r-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--metric-accent);
  background: var(--bg-inset);
  flex-shrink: 0;
}
.status-metric-tab-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.status-metric-tab-label {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  font-weight: var(--fw-semibold);
}
.status-metric-tab-count {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  line-height: 1;
}
.status-metric-tab-desc {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  line-height: 1.35;
}

@media (max-width: 768px) {
  .app-page { padding: var(--s-6) var(--s-5); }
  .app-page.app-page-pad-none { padding: 0; }
  .app-page.app-page-pad-lg { padding: var(--s-7) var(--s-6); }
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }
  .toolbar-actions { justify-content: flex-start; }
  .list-row { align-items: flex-start; }
  .list-row-head { flex-wrap: wrap; }
  .list-row-desc { white-space: normal; }
  .status-metric-tabs-3,
  .status-metric-tabs-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  .app-page { padding: var(--s-5) var(--s-4); }
  .app-page.app-page-pad-none { padding: 0; }
  .app-page.app-page-pad-lg { padding: var(--s-6) var(--s-5); }
  .toolbar-bordered { padding: var(--s-4); }
  .list-row {
    padding: var(--s-4);
    gap: var(--s-3);
  }
  .list-row-trailing { align-self: center; }
  .status-metric-tabs-2,
  .status-metric-tabs-3,
  .status-metric-tabs-4 { grid-template-columns: 1fr; }
  .status-metric-tab { min-height: 76px; }
}

/* ── Spin keyframe — used by `<Spinner>` and `.btn-spinner` ── */
@keyframes spin { to { transform: rotate(360deg); } }

/* ── LoadingDots bounce ── */
@keyframes dots-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40%           { transform: translateY(-3px); opacity: 1; }
}

/* ── Indeterminate progress sweep ── */
@keyframes progress-indeterminate {
  0%   { margin-left: -40%; }
  100% { margin-left: 100%; }
}

/* ============================================================
   DatePicker — themed alternative to native <input type="date">
   so the calendar respects the dark/light tokens.
   ============================================================ */

.dp-trigger {
  display: inline-flex; align-items: center; justify-content: space-between;
  gap: var(--s-3);
  cursor: pointer; text-align: left;
}
.dp-trigger:disabled { cursor: not-allowed; opacity: 0.5; }
.dp-trigger-active { border-color: var(--brand-500); box-shadow: var(--shadow-focus); }

.dp-pop {
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: var(--s-4);
  width: 280px;
  animation: slide-up var(--dur-fast) var(--ease-out);
}
.dp-pop-range {
  width: auto;
  display: grid;
  grid-template-columns: 140px 280px;
  gap: var(--s-4);
  padding: var(--s-4);
}
.dp-presets {
  display: flex; flex-direction: column; gap: 2px;
  padding-right: var(--s-4);
  border-right: 1px solid var(--border-subtle);
}
.dp-preset {
  background: transparent; border: 0; font: inherit;
  text-align: left; padding: var(--s-3) var(--s-4);
  font-size: var(--fs-sm); color: var(--text-secondary);
  border-radius: var(--r-sm); cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.dp-preset:hover { background: var(--bg-hover); color: var(--text-primary); }

.dp-cal { display: flex; flex-direction: column; gap: var(--s-3); }
.dp-hd  { display: flex; align-items: center; justify-content: space-between; }
.dp-hd-title {
  font-size: var(--fs-md); font-weight: var(--fw-semibold);
  color: var(--text-primary); letter-spacing: -0.01em;
}
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-wkd  {
  text-align: center; padding: 6px 0 4px;
  font-size: var(--fs-2xs); color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.04em;
  font-weight: var(--fw-medium);
}
.dp-day {
  background: transparent; border: 0; font: inherit; padding: 0;
  height: 30px; border-radius: var(--r-sm); cursor: pointer;
  font-size: var(--fs-sm); color: var(--text-primary);
  display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.dp-day:hover:not(:disabled) { background: var(--bg-hover); }
.dp-day.muted          { color: var(--text-disabled); }
.dp-day.today          { box-shadow: inset 0 0 0 1px var(--border-strong); }
.dp-day.in-range       { background: rgba(79, 70, 229, 0.15); border-radius: 0; }
.dp-day.in-range:hover { background: rgba(79, 70, 229, 0.25); }
.dp-day.range-edge     { background: var(--brand-500); color: #fff; font-weight: var(--fw-semibold); border-radius: var(--r-sm); }
.dp-day.selected       { background: var(--brand-500); color: #fff; font-weight: var(--fw-semibold); }
.dp-day.selected:hover { background: var(--brand-600); }
.dp-day:disabled       { opacity: 0.3; cursor: not-allowed; }

.dp-ft {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: var(--s-3); margin-top: var(--s-3);
  border-top: 1px solid var(--border-subtle);
}
.dp-action {
  background: transparent; border: 0; font: inherit;
  padding: 4px 8px; border-radius: var(--r-xs);
  font-size: var(--fs-sm); color: var(--brand-400);
  font-weight: var(--fw-medium); cursor: pointer;
  transition: background var(--dur-fast);
}
.dp-action:hover { background: var(--bg-hover); }

/* ============================================================
   RESPONSIVE — components
   ============================================================ */

@media (max-width: 900px) {
  /* Date picker range — stack the preset rail above the calendar. */
  .dp-pop-range {
    grid-template-columns: 1fr;
    width: min(320px, calc(100vw - 24px));
  }
  .dp-presets {
    flex-direction: row; flex-wrap: wrap;
    padding-right: 0; padding-bottom: var(--s-3);
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }
}

@media (max-width: 768px) {
  /* Tables: shrink padding so more columns fit in a horizontal scroll. */
  .tbl thead th, .tbl tbody td {
    padding: var(--s-3) var(--s-4);
  }
  /* Selection bar wraps onto multiple lines instead of overflowing. */
  .table-toolbar { flex-wrap: wrap; gap: var(--s-3); padding: var(--s-3) var(--s-4); }
  /* Modals fill the screen with a small inset. */
  .modal {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 32px);
    border-radius: var(--r-lg);
  }
  .modal-hd, .modal-body { padding: var(--s-5); }
  .modal-ft {
    padding: var(--s-4) var(--s-5);
    flex-wrap: wrap;
  }
  /* Toasts span the full width of the viewport. */
  .toast-region { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; max-width: none; width: 100%; }
  /* Tabs become horizontally scrollable instead of wrapping. */
  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .tab { flex-shrink: 0; }
  /* Card paddings shrink so phones don't run out of horizontal space. */
  .card-hd, .card-ft { padding: var(--s-4) var(--s-5); }
  .card-body, .card-padded { padding: var(--s-5); }
  /* Stat cards: reduce font + padding for compact stacks. */
  .stat { padding: var(--s-5); gap: var(--s-2); }
  .stat-value { font-size: var(--fs-2xl); }
}

@media (max-width: 480px) {
  /* DatePicker pop fits inside a phone viewport. */
  .dp-pop { width: calc(100vw - 24px); }
  /* Buttons in a row sometimes need to stretch on tiny screens. */
  .btn-block-sm { width: 100%; }
}

/* ── Locale switcher ─────────────────────────────────────
   Drop-in dropdown rendered by partials/locale-switcher.twig.
   Self-contained so it works on every Twig surface (landing
   nav, auth shell, installer wizard, error pages). Native
   <details> for keyboard accessibility + JS-free toggling;
   the partial ships a tiny outside-click + Escape handler. */
.locale-sw {
  position: relative;
  display: inline-flex;
}
.locale-sw > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.locale-sw > summary::-webkit-details-marker { display: none; }
.locale-sw > summary::marker { content: ''; }

.locale-sw-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px 10px;
  border: 1px solid var(--border-default);
  border-radius: var(--r-md, 8px);
  background: var(--bg-elevated, var(--bg-raised));
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: 1.2;
  transition: border-color var(--dur-fast, 120ms), background var(--dur-fast, 120ms), color var(--dur-fast, 120ms);
}
.locale-sw-trigger:hover,
.locale-sw[open] .locale-sw-trigger {
  border-color: var(--brand-400, #6B72F5);
  background: var(--bg-raised);
  color: var(--text-primary);
}
.locale-sw-trigger:focus-visible {
  outline: 2px solid var(--brand-400, #6B72F5);
  outline-offset: 2px;
}
.locale-sw-trigger svg { color: var(--text-tertiary); flex-shrink: 0; }
.locale-sw-trigger:hover svg,
.locale-sw[open] .locale-sw-trigger svg { color: var(--text-secondary); }
.locale-sw-label {
  white-space: nowrap;
}
.locale-sw-chev { transition: transform var(--dur-fast, 120ms); }
.locale-sw[open] .locale-sw-chev { transform: rotate(180deg); }

.locale-sw-menu {
  position: absolute;
  inset-block-start: calc(100% + 6px);
  inset-inline-end: 0;
  inline-size: 220px;
  padding: 4px;
  background: var(--bg-elevated, var(--bg-raised));
  border: 1px solid var(--border-default);
  border-radius: var(--r-md, 10px);
  box-shadow: var(--shadow-lg, 0 12px 32px rgba(0,0,0,0.32));
  z-index: 50;
  animation: locale-sw-pop-in 120ms ease-out;
}
@keyframes locale-sw-pop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.locale-sw-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 8px 10px;
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  text-decoration: none;
  border-radius: var(--r-sm, 6px);
  transition: background var(--dur-fast, 120ms), color var(--dur-fast, 120ms);
}
.locale-sw-item:hover,
.locale-sw-item:focus-visible {
  background: var(--bg-active, rgba(255,255,255,0.04));
  color: var(--text-primary);
  outline: none;
}
.locale-sw-item.is-active {
  color: var(--text-primary);
  background: var(--bg-hover, rgba(255,255,255,0.04));
}
.locale-sw-item.is-active svg {
  color: var(--brand-400, #6B72F5);
  margin-inline-start: auto;
}
.locale-sw-code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold, 600);
  color: var(--text-tertiary);
  letter-spacing: 0.04em;
  min-width: 26px;
}
.locale-sw-item.is-active .locale-sw-code,
.locale-sw-item:hover .locale-sw-code,
.locale-sw-item:focus-visible .locale-sw-code { color: var(--text-secondary); }
.locale-sw-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 540px) {
  .locale-sw-trigger { padding: 4px 8px; }
  .locale-sw-label { display: none; }
  .locale-sw-menu { inline-size: 200px; }
}

/* Floating placement on auth pages (signin / signup / forgot / reset
   / 2fa). Sits in the top-right corner of the form column so guest
   visitors can switch language before they sign in. */
.auth-locale-pin {
  position: absolute;
  inset-block-start: var(--s-5);
  inset-inline-end: var(--s-5);
  z-index: 5;
}

/* Floating placement on the installer wizard top-right. */
.installer-locale-pin {
  position: absolute;
  inset-block-start: var(--s-5);
  inset-inline-end: var(--s-5);
  z-index: 5;
}
