/* Refiner V3 - design system
   Dense, calm admin UI: one accent (blue), neutral zinc greys, 1px dividers,
   monospace tabular numbers. Yellow is reserved for refined numbers. */

@font-face {
  font-family: 'Geist';
  src: url('fonts/Geist-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('fonts/GeistMono-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --font: 'Geist', 'Segoe UI Variable Text', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Geist Mono', 'Cascadia Mono', Consolas, ui-monospace, monospace;

  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #e9e9ec;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --grid-line: #e7e7ea;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #6b6b74;

  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: #eef2ff;
  --accent-text: #1d4ed8;
  --on-accent: #ffffff;
  --focus: #2563eb;

  --ok: #15803d;        --ok-soft: #dcfce7;
  --warn: #a16207;      --warn-soft: #fef3c7;
  --danger: #b91c1c;    --danger-soft: #fee2e2;
  --info: #1d4ed8;      --info-soft: #dbeafe;

  /* Refined numbers: yellow rows everywhere (sheets, agent sheets, admin). */
  --row-refined: #fff3a3;
  --row-refined-hover: #ffec80;
  --row-refined-edge: #eab308;
  --chip-refined-bg: #fde047;
  --chip-refined-text: #5b3d00;
  /* Agent sheets: a number the agent selected, pointed at or copied ("Used"). */
  --row-used: #ede9fe;
  --row-used-edge: #7c3aed;
  --chip-used-bg: #ddd6fe;
  --chip-used-text: #4c1d95;
  --row-failed: #fdf0f0;
  --row-failed-edge: #ef4444;
  --row-refining-edge: #3b82f6;

  --sel: rgba(37, 99, 235, 0.14);
  --row-hover: rgba(15, 23, 42, 0.04);
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.10), 0 1px 3px rgba(0, 0, 0, 0.06);
  --radius: 6px;
  --radius-lg: 10px;
  --topbar-h: 56px;
  --sidebar-w: 236px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e10; --surface: #151518; --surface-2: #1c1c20; --surface-3: #26262b;
    --border: #2a2a30; --border-strong: #3a3a42; --grid-line: #26262c;
    --text: #f4f4f5; --text-2: #b4b4bc; --text-3: #92929c;
    --accent: #2b5fd9; --accent-hover: #3a6ee6; --accent-soft: rgba(59, 118, 246, 0.16); --accent-text: #93b4ff;
    --on-accent: #ffffff; --focus: #6d9bff;
    --ok: #4ade80; --ok-soft: rgba(34, 197, 94, 0.16);
    --warn: #fbbf24; --warn-soft: rgba(245, 158, 11, 0.16);
    --danger: #f87171; --danger-soft: rgba(239, 68, 68, 0.16);
    --info: #93b4ff; --info-soft: rgba(59, 130, 246, 0.18);
    --row-refined: #3d3710; --row-refined-hover: #48410f; --row-refined-edge: #facc15;
    --chip-refined-bg: #facc15; --chip-refined-text: #3a2a00;
    --row-used: #2e2650; --row-used-edge: #a78bfa; --chip-used-bg: #6d28d9; --chip-used-text: #f5f3ff;
    --row-failed: rgba(239, 68, 68, 0.10); --row-failed-edge: #f87171; --row-refining-edge: #6d9bff;
    --sel: rgba(109, 155, 255, 0.2);
    --row-hover: rgba(255, 255, 255, 0.05);
    --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0e10; --surface: #151518; --surface-2: #1c1c20; --surface-3: #26262b;
  --border: #2a2a30; --border-strong: #3a3a42; --grid-line: #26262c;
  --text: #f4f4f5; --text-2: #b4b4bc; --text-3: #92929c;
  --accent: #2b5fd9; --accent-hover: #3a6ee6; --accent-soft: rgba(59, 118, 246, 0.16); --accent-text: #93b4ff;
  --on-accent: #ffffff; --focus: #6d9bff;
  --ok: #4ade80; --ok-soft: rgba(34, 197, 94, 0.16);
  --warn: #fbbf24; --warn-soft: rgba(245, 158, 11, 0.16);
  --danger: #f87171; --danger-soft: rgba(239, 68, 68, 0.16);
  --info: #93b4ff; --info-soft: rgba(59, 130, 246, 0.18);
  --row-refined: #3d3710; --row-refined-hover: #48410f; --row-refined-edge: #facc15;
  --chip-refined-bg: #facc15; --chip-refined-text: #3a2a00;
  --row-used: #2e2650; --row-used-edge: #a78bfa; --chip-used-bg: #6d28d9; --chip-used-text: #f5f3ff;
  --row-failed: rgba(239, 68, 68, 0.10); --row-failed-edge: #f87171; --row-refining-edge: #6d9bff;
  --sel: rgba(109, 155, 255, 0.2);
  --row-hover: rgba(255, 255, 255, 0.05);
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-size: 13px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ic { width: 16px; height: 16px; flex: none; }
.ic-lg { width: 20px; height: 20px; flex: none; }

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  padding: 8px 12px; border-radius: var(--radius); background: var(--accent); color: var(--on-accent);
}
.skip-link:focus { top: 12px; }

/* ------------------------------------------------------------------ shell */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; height: var(--topbar-h); padding: 0 16px; border-bottom: 1px solid var(--border); }
.brand-mark {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: var(--on-accent);
}
.brand-mark .ic { width: 16px; height: 16px; }
.brand-name { font-weight: 650; letter-spacing: -0.01em; }
.brand-env {
  margin-left: auto; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 500;
  color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border);
}
.sidebar nav { padding: 8px 8px 16px; flex: 1; }
.nav-group + .nav-group { margin-top: 14px; }
.nav-title { padding: 8px 10px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
.nav-link {
  display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; border-radius: var(--radius);
  color: var(--text-2); font-weight: 500;
  transition: background-color 120ms ease, color 120ms ease;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent-text); }
.nav-badge {
  margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px; text-align: center;
  font-size: 11px; font-weight: 600; line-height: 18px; background: var(--danger); color: #fff;
}
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: var(--surface-3); color: var(--text-2); font-weight: 600; font-size: 13px;
}
.who-text { display: flex; flex-direction: column; min-width: 0; }
.who-name, .who-role { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-name { font-weight: 550; font-size: 13px; }
.who-role { font-size: 12px; color: var(--text-3); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; height: var(--topbar-h); padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
/* .icon-btn sets display later in this file, so these carry its class too: the drawer button
   on narrow screens only, the collapse button on wide screens only. */
.icon-btn.nav-toggle { display: none; }
.content { padding: 20px 24px 48px; min-width: 0; outline: none; }
.content:focus { outline: none; }

.engine-pill {
  display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: 12.5px; font-weight: 550;
  white-space: nowrap;
}
.engine-pill:hover { text-decoration: none; border-color: var(--border-strong); color: var(--text); }
.engine-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.engine-pill.is-on .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.engine-pill.is-busy .dot { background: var(--info); box-shadow: 0 0 0 3px var(--info-soft); animation: pulse 1.4s ease-in-out infinite; }
.engine-pill .mini { width: 44px; height: 4px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.engine-pill .mini > span { display: block; height: 100%; background: var(--info); width: 0; transition: width 300ms ease; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 13px; font-weight: 550; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, transform 80ms ease;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-danger-solid { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-danger-solid:hover { background: #991b1b; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; height: 38px; }
.btn .count { font-family: var(--mono); font-size: 12px; opacity: 0.85; }
.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius);
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .ic { width: 18px; height: 18px; }
.icon-btn-sm { width: 28px; height: 28px; }
.icon-btn-sm .ic { width: 15px; height: 15px; }
.badge-count {
  position: absolute; top: 2px; right: 1px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 650; line-height: 17px; text-align: center;
  border: 2px solid var(--bg);
}

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar .spacer { flex: 1; }
.toolbar-sep { width: 1px; height: 22px; background: var(--border); margin: 0 2px; }

/* ------------------------------------------------------------------ forms */
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: 12.5px; font-weight: 550; color: var(--text-2); }
.field .help { font-size: 12px; color: var(--text-3); }
.field .error { font-size: 12px; color: var(--danger); }
.input, .field input[type="text"], .field input[type="password"], .field input[type="number"], .field input[type="search"], select.input, .field select, textarea.input {
  height: 34px; width: 100%; padding: 0 10px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
select.input, .field select { padding-right: 28px; background-color: var(--surface); color: var(--text); }
textarea.input { height: auto; padding: 8px 10px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, textarea.input:focus {
  outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent);
}
.input-sm { height: 30px; font-size: 13px; }
.search { position: relative; }
.search .ic { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 30px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.field-invalid input, .field-invalid select { border-color: var(--danger); }

/* toggle switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative; width: 40px; height: 22px; border-radius: 999px; background: var(--surface-3);
  border: 1px solid var(--border-strong); transition: background-color 150ms ease, border-color 150ms ease;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 150ms ease;
}
.switch input:checked + .track { background: var(--ok); border-color: var(--ok); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .track { opacity: 0.5; }
.switch-lg .track { width: 52px; height: 28px; }
.switch-lg .track::after { width: 22px; height: 22px; }
.switch-lg input:checked + .track::after { transform: translateX(24px); }

/* segmented control (status filters) */
.seg { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); flex-wrap: wrap; }
.seg button {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text-2); font-size: 12.5px; font-weight: 550; cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.seg .n { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); }

/* ------------------------------------------------------------------ status chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 21px; padding: 0 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
  background: var(--surface-2); color: var(--text-2);
}
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.chip-pending { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.chip-refining { background: var(--info-soft); color: var(--info); }
.chip-refining::before { animation: pulse 1.2s ease-in-out infinite; }
.chip-refined { background: var(--chip-refined-bg); color: var(--chip-refined-text); }
.chip-assigned { background: var(--ok-soft); color: var(--ok); }
.chip-failed { background: var(--danger-soft); color: var(--danger); }
.chip-duplicate { background: transparent; color: var(--text-3); border: 1px dashed var(--border-strong); }
.chip-plain::before { display: none; }
.chip-new { background: var(--accent); color: var(--on-accent); }
.chip-new::before { display: none; }
.chip-role { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.chip-role::before { display: none; }
.chip-off { background: var(--surface-2); color: var(--text-3); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.9s linear infinite; }

/* ------------------------------------------------------------------ sections, KPIs, tables */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; margin-bottom: 16px; }
.page-head .sub { color: var(--text-3); margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.section { margin-top: 24px; }
.section:first-child { margin-top: 0; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 10px; }
.section-head h2 { font-size: 15px; }
.section-head .sub { color: var(--text-3); font-size: 12.5px; }
.section-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.panel { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.panel-pad { padding: 16px; }
.cols-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; }
.cols-2-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }

.kpis {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden;
}
.kpi { padding: 14px 16px; border-left: 1px solid var(--border); min-width: 0; }
.kpi:first-child { border-left: 0; }
.kpi .label { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 550; color: var(--text-3); }
.kpi .value { margin-top: 4px; font-family: var(--mono); font-size: 24px; font-weight: 550; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .foot { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.kpi .swatch { width: 8px; height: 8px; border-radius: 2px; }
.sw-pending { background: var(--border-strong); }
.sw-refining { background: var(--row-refining-edge); }
.sw-refined { background: var(--row-refined-edge); }
.sw-assigned { background: var(--ok); }
.sw-failed { background: var(--row-failed-edge); }
.sw-duplicate { background: transparent; border: 1px dashed var(--text-3); }
.kpis.kpis-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.table th {
  position: sticky; top: 0; z-index: 1; text-align: left; font-weight: 600; font-size: 12px; color: var(--text-3);
  background: var(--surface-2); padding: 0 12px; height: 34px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 0 12px; height: 40px; border-bottom: 1px solid var(--grid-line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.table .r { text-align: right; }
.table .c { text-align: center; }
.table .w1 { width: 1%; white-space: nowrap; }
.table .trunc { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table tr.is-off td { color: var(--text-3); }
.table tr.st-refined td, .table tr.st-assigned td { background: var(--row-refined); }
.table tr.st-refined:hover td, .table tr.st-assigned:hover td { background: var(--row-refined-hover); }
.table tr.st-failed td { background: var(--row-failed); }
.table-foot { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-3); }
.table-foot .pager { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.row-actions { display: flex; justify-content: flex-end; gap: 2px; }

.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-item { display: grid; grid-template-columns: 110px minmax(0, 1fr) 76px; align-items: center; gap: 10px; font-size: 13px; }
.bar-item .val { white-space: nowrap; }
.bar-item .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-track > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; width: 0; }
.bar-item .val { text-align: right; font-family: var(--mono); font-size: 12.5px; }

.progress { height: 8px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 300ms ease; }
.progress.is-done > span { background: var(--ok); }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius); font-size: 13px; border: 1px solid transparent; }
.alert .ic { margin-top: 2px; }
.alert-info { background: var(--info-soft); color: var(--text); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.alert-warn { background: var(--warn-soft); color: var(--text); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.alert-error { background: var(--danger-soft); color: var(--text); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.alert-ok { background: var(--ok-soft); color: var(--text); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.alert .ic { color: currentColor; }
.alert-info .ic { color: var(--info); } .alert-warn .ic { color: var(--warn); } .alert-error .ic { color: var(--danger); } .alert-ok .ic { color: var(--ok); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 40px 16px; text-align: center; color: var(--text-3); }
.empty .ic-lg { width: 28px; height: 28px; color: var(--text-3); }
.empty strong { color: var(--text); font-weight: 600; }
.skeleton { border-radius: var(--radius); background: var(--surface-2); min-height: 16px; animation: pulse 1.6s ease-in-out infinite; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-3); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 10px; border-radius: 2px; display: inline-block; border: 1px solid var(--border-strong); }
.legend .lg-refined { background: var(--row-refined); border-color: var(--row-refined-edge); }
.legend .lg-failed { background: var(--row-failed); border-color: var(--row-failed-edge); }
.legend .lg-pending { background: var(--surface); }
.legend .lg-refining { background: var(--surface); box-shadow: inset 3px 0 0 var(--row-refining-edge); }
.legend .lg-duplicate { background: var(--surface-2); border-style: dashed; }
.legend .lg-assigned { background: var(--ok); border-color: var(--ok); }
.legend .lg-note { background: color-mix(in srgb, var(--accent) 5%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 55%, transparent); }

/* ------------------------------------------------------------------ spreadsheet grid */
.sheet-shell { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; }
.sheet-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--surface); }
.sheet-bar .search { flex: 0 1 220px; min-width: 150px; }
.sheet-bar .search.search-wide { flex: 0 1 340px; }
.sheet-bar select.input { width: auto; max-width: 220px; }

/* Automatic refine bar: schedule, countdown, last run. */
.refine-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 12px; padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--info) 30%, transparent); border-radius: var(--radius-lg); background: var(--info-soft);
}
.refine-bar > .ic { color: var(--info); width: 18px; height: 18px; }
.refine-bar.is-off { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.refine-bar.is-off > .ic { color: var(--warn); }
.refine-bar .rb-text { flex: 1; min-width: 260px; font-size: 13px; }
.refine-bar .rb-sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.refine-bar .rb-clock { display: grid; grid-template-columns: auto auto; align-items: baseline; gap: 2px 10px; }
.refine-bar .rb-label { font-size: 12px; color: var(--text-2); }
.refine-bar .rb-time { font-family: var(--mono); font-size: 24px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.refine-bar .rb-progress { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: color-mix(in srgb, var(--info) 18%, transparent); overflow: hidden; }
.refine-bar .rb-progress > span { display: block; height: 100%; background: var(--info); width: 0; transition: width 900ms linear; }
.refine-bar .rb-actions { display: flex; gap: 8px; }
/* A user's two sheets: Vehicle Numbers Sheet / Boat Numbers Sheet. */
.book-tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.book-tabs[hidden] { display: none; }
.book-tab {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 14px; margin-bottom: -1px;
  border: 1px solid transparent; border-bottom: 2px solid transparent; border-radius: var(--radius) var(--radius) 0 0;
  background: none; color: var(--text-2); font: inherit; font-size: 13.5px; font-weight: 550; cursor: pointer;
}
.book-tab .ic { width: 16px; height: 16px; }
.book-tab:hover { color: var(--text); background: var(--surface-2); }
.book-tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); background: var(--surface); }
/* The Boat Sheet's bar: Manual Refine only, its own refiner database. */
.refine-bar.boat-bar { background: color-mix(in srgb, #0d9488 9%, var(--surface)); border-color: color-mix(in srgb, #0d9488 35%, transparent); }
.refine-bar.boat-bar > .ic { color: #0d9488; }
.sheet-shell.is-boat { border-top: 3px solid #0d9488; }
a.btn.is-disabled { opacity: 0.5; pointer-events: none; }
.engine-pill .pill-count { font-family: var(--mono); font-size: 12px; color: var(--text); }
.next-run { font-weight: 500; font-size: 13px; color: var(--text-2); margin-left: 6px; }

/* Autosave state in the sheet toolbar. */
.save-state { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); min-width: 220px; }
.save-state.is-saved .ic { color: var(--ok); }
.save-state.is-saving .ic, .save-state.is-dirty .ic { color: var(--info); }
.save-state.is-error { color: var(--danger); }
table.sheet tr.row-error > td.col-rn { box-shadow: inset 3px 0 0 var(--danger); color: var(--danger); }

/* Manual Refiner upload. */
.mr-intro { color: var(--text-2); font-size: 13px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 12px; padding: 22px 16px; text-align: center;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg); background: var(--surface-2); cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .ic-lg { color: var(--text-3); }
.dropzone:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.dz-file { font-family: var(--mono); }
.mr-result { margin-top: 12px; }
.mr-table { max-height: 360px; }

/* Day picker: Today / Yesterday / Date Range / All Dates (Denver days). */
.daterange { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.daterange .field-label { display: inline-flex; align-items: center; gap: 6px; }
.daterange .range-inputs { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.daterange input[type="date"].input { width: auto; }
.daterange .day-label { font-size: 12.5px; color: var(--text-3); }
.names-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 16px; }
.grid-wrap {
  position: relative; overflow: auto; max-height: calc(100vh - 290px); min-height: 280px;
  outline: none; overscroll-behavior: contain; background: var(--surface);
}
.grid-wrap:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
table.sheet { border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 100%; table-layout: fixed; }
/* Row and cell colours below use background-COLOR only: the hover tint and the
   selection are drawn as a background-IMAGE on top, so they show on every row,
   yellow, red or plain (a "background" shorthand would wipe them out). */
table.sheet th, table.sheet td {
  height: 32px; padding: 0 8px; border-right: 1px solid var(--grid-line); border-bottom: 1px solid var(--grid-line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background-color: var(--surface);
}
table.sheet thead th {
  position: sticky; top: 0; z-index: 3; height: 34px; background: var(--surface-2); color: var(--text-2);
  font-size: 12px; font-weight: 600; text-align: left; user-select: none;
}
table.sheet thead th .col-key { color: var(--text-3); font-family: var(--mono); font-weight: 500; margin-right: 6px; }
table.sheet .col-rn, table.sheet .col-sel { position: sticky; z-index: 2; text-align: center; padding: 0; color: var(--text-3); }
table.sheet .col-rn { left: 0; width: 52px; font-family: var(--mono); font-size: 11.5px; background-color: var(--surface-2); }
table.sheet .col-sel { left: 52px; width: 34px; }
table.sheet thead .col-rn, table.sheet thead .col-sel { z-index: 4; }
table.sheet .col-sel input { width: 15px; height: 15px; margin: 0; vertical-align: middle; accent-color: var(--accent); cursor: pointer; }
table.sheet td.cell { cursor: cell; position: relative; }
table.sheet td.cell.is-locked { cursor: default; }
table.sheet td.num-cell { font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.sheet td.meta { color: var(--text-2); font-size: 12.5px; }
table.sheet td.meta .chip { vertical-align: middle; }

/* state of the row: left edge in the row-number column + background */
table.sheet tr > .col-rn { box-shadow: inset 3px 0 0 transparent; }
table.sheet tr.st-refining > .col-rn { box-shadow: inset 3px 0 0 var(--row-refining-edge); }
table.sheet tr.st-failed > .col-rn { box-shadow: inset 3px 0 0 var(--row-failed-edge); }
table.sheet tr.st-refined > .col-rn, table.sheet tr.st-assigned > .col-rn { box-shadow: inset 3px 0 0 var(--row-refined-edge); }
table.sheet tr.st-refined > td, table.sheet tr.st-assigned > td { background-color: var(--row-refined); }
table.sheet tr.st-refined > td.col-rn, table.sheet tr.st-assigned > td.col-rn { background-color: color-mix(in srgb, var(--row-refined) 70%, var(--surface-2)); }
table.sheet tr.st-failed > td { background-color: var(--row-failed); }
/* Duplicates are removed from distribution: shown muted, the number struck through. */
table.sheet tr.st-duplicate > td { color: var(--text-3); }
table.sheet tr.st-duplicate > td.num-cell { text-decoration: line-through; text-decoration-color: var(--border-strong); }
table.sheet tr.st-duplicate > .col-rn { box-shadow: inset 3px 0 0 var(--border-strong); }
/* One divider row per day on the daily sheets. */
table.sheet tr.group-row > td {
  height: 30px; padding: 0 12px; background-color: var(--surface-2); color: var(--text-2); font-size: 12px;
  border-bottom: 1px solid var(--border); border-top: 1px solid var(--border);
}
table.sheet tr.group-row strong { color: var(--text); font-weight: 600; }
/* Agent sheets: the ID column and the blank gap column before the number. */
table.sheet td.id-cell { font-weight: 550; color: var(--text); }
table.sheet .gap-col { padding: 0; }
table.sheet td.gap-col {
  background-image: repeating-linear-gradient(135deg, transparent 0 5px, color-mix(in srgb, var(--border) 70%, transparent) 5px 6px);
}
/* Agent sheets: rows stay plain; a number turns violet ("Used") once the agent selects it,
   points at it to copy it, or copies it (the Main Admin sees the same). */
table.sheet.agent-sheet tr.st-assigned > td { background-color: var(--surface); }
table.sheet.agent-sheet tr.st-assigned > td.col-rn { background-color: var(--surface-2); }
table.sheet.agent-sheet tr.st-assigned > .col-rn { box-shadow: inset 3px 0 0 transparent; }
table.sheet.agent-sheet td.num-cell { cursor: copy; transition: background-color 160ms ease; }
table.sheet.agent-sheet tr.is-accessed > td.num-cell { background-color: var(--row-used); color: var(--chip-used-text); }
table.sheet.agent-sheet tr.is-accessed > .col-rn { box-shadow: inset 3px 0 0 var(--row-used-edge); }
table.sheet.agent-sheet tr.is-copied > td.num-cell { font-weight: 650; box-shadow: inset -3px 0 0 var(--row-used-edge); }
/* The small box above an agent sheet: which agents' sheets received numbers in today's runs. */
.dist-box {
  display: flex; align-items: flex-start; gap: 10px; min-height: 56px; padding: 8px 12px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 4%, var(--surface)); font-size: 12.5px; line-height: 1.5;
  /* two lines are reserved, so the sheet below never jumps when the box fills or refreshes */
}
.dist-box > .ic { flex: none; width: 16px; height: 16px; margin-top: 3px; color: var(--accent-text); }
.dist-body { display: flex; flex: 1; flex-direction: column; gap: 4px; min-width: 0; }
.dist-run { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.dist-head { font-weight: 600; }
.dist-head .muted { font-weight: 400; }
.dist-agents { display: flex; flex-wrap: wrap; gap: 6px; }
.dist-agent {
  display: inline-flex; align-items: center; gap: 5px; padding: 0 9px; border-radius: 999px; line-height: 22px;
  border: 1px solid var(--border-strong); background: var(--surface); font-weight: 550; white-space: nowrap;
}
.dist-agent b { font-weight: 650; color: var(--accent-text); }
.dist-agent .you { font-size: 11px; font-weight: 500; color: var(--text-3); }
.dist-agent.is-me { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.dist-agent.is-me .you { color: var(--accent-text); }
.dist-earlier summary { cursor: pointer; color: var(--text-3); font-size: 12px; user-select: none; }
.dist-earlier .dist-run { margin-top: 4px; }
/* Two blank lines between deliveries: newly added numbers sit below the existing ones. */
table.sheet tr.gap-row > td { background-color: var(--surface); border-right-color: transparent; }
.copy-tip {
  position: absolute; z-index: 5; display: inline-grid; place-items: center; width: 26px; height: 24px; padding: 0;
  border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}
.copy-tip .ic { width: 14px; height: 14px; }
.copy-tip:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip-copied { background: var(--chip-used-bg); color: var(--chip-used-text); }
.chip-accessed { background: transparent; border-color: var(--row-used-edge); box-shadow: inset 0 0 0 1px var(--row-used-edge); }
.legend .lg-used { background: var(--row-used); border-color: var(--row-used-edge); }
.sound-btn.is-off { color: var(--text-3); }
/* Agent sheets: the writable row above each run (ID / name the numbers were run under) and the spare rows. */
table.sheet.agent-sheet tr.note-row > td { background-color: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
table.sheet.agent-sheet tr.note-row > td.cell { color: var(--text); font-weight: 550; cursor: text; }
table.sheet.agent-sheet tr.note-row > td.cell[data-c="0"]:empty::before,
table.sheet.agent-sheet tr.note-row > td.cell[data-c="1"]:empty::before {
  content: 'ID'; color: var(--text-3); font-weight: 400; font-style: italic; font-family: var(--font);
}
table.sheet.agent-sheet tr.note-row > td.cell[data-c="1"]:empty::before { content: 'Name'; }
table.sheet.agent-sheet tr.note-row > td.note-label { color: var(--text-3); font-size: 11.5px; font-weight: 500; }
table.sheet.agent-sheet tr.note-row > .col-rn { box-shadow: inset 3px 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }

/* Mouse selection: whole rows / columns, the Copy bar and the right-click menu. */
.grid-box { position: relative; }
table.sheet td.col-rn, table.sheet td.meta { cursor: pointer; }
table.sheet thead th.col-head, table.sheet thead th.col-rn { cursor: pointer; }
table.sheet thead th.col-head:hover, table.sheet thead th.col-rn:hover { color: var(--text); background-color: color-mix(in srgb, var(--accent) 8%, var(--surface-2)); }
/* Hover (like a spreadsheet): a light tint on the row under the pointer, a thin frame on the cell.
   :where() keeps these weaker than the selection rules below, so a selection always shows. */
table.sheet :where(tbody tr:not(.group-row, .gap-row):hover) > td { background-image: linear-gradient(var(--row-hover), var(--row-hover)); }
table.sheet :where(tbody tr:not(.group-row, .gap-row):hover) > td.col-rn { color: var(--text); }
table.sheet :where(td.cell:hover) { box-shadow: inset 0 0 0 1px var(--border-strong); }
/* Pinned to the bottom of the window, so it is in view however long the sheet is. */
.sel-bar {
  position: fixed; left: 16px; bottom: 18px; z-index: 50;   /* bottom left: the toasts use the bottom right */
  display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 14px; max-width: calc(100vw - 32px);
  border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); box-shadow: var(--shadow-pop);
  font-size: 12.5px; white-space: nowrap; animation: sel-in 140ms ease-out;
}
@keyframes sel-in { from { opacity: 0; } to { opacity: 1; } }
@media (min-width: 1025px) { .sel-bar { left: calc(var(--sidebar-w, 236px) + 16px); } }
.sel-bar[hidden] { display: none; }
.sel-bar .sel-what { color: var(--text-2); margin-right: 4px; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.sel-bar .btn { border-radius: 999px; }
.ctx-menu {
  position: fixed; z-index: 80; min-width: 230px; padding: 5px; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); box-shadow: var(--shadow-pop); font-size: 13px;
}
.ctx-item {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; height: 32px; padding: 0 10px;
  border: 0; border-radius: var(--radius); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.ctx-item:hover, .ctx-item:focus-visible { background: var(--surface-2); outline: none; }
.ctx-item kbd { font-size: 10.5px; color: var(--text-3); }
.ctx-sep { height: 1px; margin: 4px 6px; background: var(--border); }
@media (max-width: 600px) { .sel-bar .sel-what { display: none; } }
table.sheet tr.is-deleted > td.cell { text-decoration: line-through; color: var(--text-3); }
table.sheet tr.is-flash > td { animation: flash 1.2s ease-out 1; }
@keyframes flash { 0% { filter: brightness(0.92); } 100% { filter: none; } }

/* Selection, like Excel / Google Sheets: a blue tint over the selected cells, a blue frame
   around the selected block, a bold frame on the active cell, and the row numbers and column
   headers of the selection highlighted. !important: a selection must show over any row
   colour (yellow, red, the agent's copied numbers) and any state edge. */
table.sheet td.in-range, table.sheet tr.is-row-sel > td, table.sheet tr.is-checked > td {
  background-image: linear-gradient(var(--sel), var(--sel)) !important;
}
table.sheet td.in-range {
  --st: 0px; --sb: 0px; --sl: 0px; --sr: 0px;
  box-shadow: inset 0 var(--st) 0 0 var(--accent), inset 0 calc(-1 * var(--sb)) 0 0 var(--accent),
              inset var(--sl) 0 0 0 var(--accent), inset calc(-1 * var(--sr)) 0 0 0 var(--accent) !important;
}
table.sheet td.sel-t { --st: 2px; }
table.sheet td.sel-b { --sb: 2px; }
table.sheet td.sel-l { --sl: 2px; }
table.sheet td.sel-r { --sr: 2px; }
table.sheet td.is-active { box-shadow: inset 0 0 0 2px var(--accent) !important; }
table.sheet td.col-rn.rn-in {
  background-color: color-mix(in srgb, var(--accent) 16%, var(--surface-2)) !important; color: var(--accent); font-weight: 650;
  box-shadow: inset -2px 0 0 var(--accent) !important;
}
table.sheet thead th.is-col-in { color: var(--text); background-color: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); box-shadow: inset 0 -2px 0 var(--accent); }
table.sheet thead th.is-col-sel { color: var(--accent); background-color: color-mix(in srgb, var(--accent) 18%, var(--surface-2)); box-shadow: inset 0 -2px 0 var(--accent); }
table.sheet td.is-dirty::after {
  content: ''; position: absolute; top: 0; right: 0; border-style: solid; border-width: 0 7px 7px 0;
  border-color: transparent var(--warn) transparent transparent;
}
table.sheet td.hint-bad { color: var(--danger); text-decoration: underline dotted; text-underline-offset: 3px; }
table.sheet td.hint-dup { color: var(--warn); text-decoration: underline dotted; text-underline-offset: 3px; }
table.sheet .cell-input {
  position: absolute; inset: 0; width: 100%; height: 100%; padding: 0 6px; border: 2px solid var(--accent); border-radius: 0;
  background: var(--surface); color: var(--text); font: inherit; outline: none; z-index: 1;
}
table.sheet td.num-cell .cell-input { font-family: var(--mono); }
table.sheet .row-new > .col-rn { color: var(--warn); font-weight: 600; }
table.sheet tbody tr:hover > td.col-rn { color: var(--text); }
.sheet-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 7px 12px;
  border-top: 1px solid var(--border); background: var(--surface-2); font-size: 12px; color: var(--text-3);
}
.sheet-foot .dirty { color: var(--warn); font-weight: 600; }
.sheet-foot .kbd-hints { margin-left: auto; }
kbd {
  font-family: var(--mono); font-size: 11px; padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
}
.link-btn { border: 0; background: none; padding: 0; color: var(--accent-text); cursor: pointer; font: inherit; }
.link-btn:hover { text-decoration: underline; }
.hist-btn { opacity: 0.55; }
tr:hover .hist-btn, .hist-btn:focus-visible { opacity: 1; }

/* ------------------------------------------------------------------ popovers, modal, drawer, toasts */
.popover-wrap { position: relative; }
.popover {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; width: 360px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
  overscroll-behavior: contain;
}
.menu-pop { width: 240px; padding: 6px; }
.menu-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-head span { font-size: 12px; color: var(--text-3); }
.menu-item.is-disabled { color: var(--text-3); cursor: default; }
.menu-item.is-disabled:hover { background: none; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px; border: 0; border-radius: var(--radius);
  background: none; color: var(--text); font-size: 13px; text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); text-decoration: none; }
.notif-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.notif-list { max-height: 420px; overflow-y: auto; overscroll-behavior: contain; }
.notif {
  display: grid; grid-template-columns: 8px minmax(0, 1fr); gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--grid-line);
  color: var(--text); text-decoration: none;
}
.notif:hover { background: var(--surface-2); text-decoration: none; }
.notif .unread-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: transparent; }
.notif.is-unread .unread-dot { background: var(--accent); }
.notif .t { font-weight: 550; font-size: 13px; }
.notif .b { font-size: 12.5px; color: var(--text-2); margin-top: 1px; }
.notif .when { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.notif-foot { padding: 8px 14px; text-align: center; font-size: 12.5px; }

dialog.modal {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--border);
  border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-pop); overscroll-behavior: contain;
}
dialog.modal.modal-lg { width: min(820px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(9, 9, 11, 0.45); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 12px; }
.modal-head h2 { font-size: 16px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 4px 18px 16px; overflow-y: auto; max-height: calc(100vh - 200px); }
.modal-body p + p { margin-top: 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.modal-foot .left { margin-right: auto; display: flex; align-items: center; gap: 8px; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 60; width: min(420px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column; transform: translateX(100%); transition: transform 180ms ease; overscroll-behavior: contain;
}
.drawer.is-open { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 15px; }
.drawer-head .icon-btn { margin-left: auto; }
.drawer-body { padding: 16px; overflow-y: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 16px 0 0; padding: 0; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 14px 16px; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border-strong); }
.timeline li.ev-refined::before, .timeline li.ev-assigned::before { border-color: var(--row-refined-edge); background: var(--row-refined); }
.timeline li.ev-failed::before { border-color: var(--row-failed-edge); }
.timeline li.ev-queued::before, .timeline li.ev-refining::before { border-color: var(--row-refining-edge); }
.timeline .ev { font-weight: 600; font-size: 13px; text-transform: capitalize; }
.timeline .d { font-size: 12.5px; color: var(--text-2); }
.timeline .w { font-size: 11.5px; color: var(--text-3); }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast {
  display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 11px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-pop); font-size: 13px;
  animation: toast-in 180ms ease-out;
}
.toast .ic { width: 18px; height: 18px; }
.toast-ok .ic { color: var(--ok); } .toast-error .ic { color: var(--danger); } .toast-info .ic { color: var(--info); } .toast-warn .ic { color: var(--warn); }
.toast .t { font-weight: 600; }
.toast .b { color: var(--text-2); margin-top: 1px; }
.toast button { border: 0; background: none; color: var(--text-3); cursor: pointer; padding: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ admin specifics */
/* The Vehicle Refiner's control (.refine-control) and the Boat Refiner's card (.boat-control) share a layout. */
.refine-control, .boat-control {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: center; padding: 16px;
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface);
}
:is(.refine-control, .boat-control) .state { display: flex; align-items: center; gap: 14px; }
:is(.refine-control, .boat-control) .state-text strong { display: block; font-size: 15px; }
:is(.refine-control, .boat-control) .state-text span { font-size: 12.5px; color: var(--text-3); }
:is(.refine-control, .boat-control) .state-text .small strong { display: inline; font-size: inherit; color: var(--text-2); }
:is(.refine-control, .boat-control) .ctrl { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-start; padding-left: 66px; }
@media (max-width: 960px) { :is(.refine-control, .boat-control) .ctrl { padding-left: 0; } }
.state-badge { font-family: var(--mono); font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; }
.state-badge.on { background: var(--ok-soft); color: var(--ok); }
.state-badge.off { background: var(--surface-2); color: var(--text-2); }
.state-badge.manual { background: color-mix(in srgb, #0d9488 14%, var(--surface)); color: #0d9488; }
/* The Boat Refiner next to the Vehicle Refiner on the dashboard: its own database, Manual Refine only. */
.boat-control { border-color: color-mix(in srgb, #0d9488 35%, var(--border)); }
.boat-mark { display: inline-grid; place-items: center; width: 52px; height: 30px; border-radius: 999px; color: #0d9488;
  background: color-mix(in srgb, #0d9488 12%, var(--surface)); }
.boat-mark .ic { width: 18px; height: 18px; }
/* The Boat Refiner page's button on the dashboard card, and its table of the users' Boat Numbers Sheets. */
.btn.btn-boat { background: #0d9488; border-color: #0d9488; color: #fff; }
.btn.btn-boat:hover { background: #0f766e; border-color: #0f766e; }
.boat-sheets td { vertical-align: middle; }
.boat-sheets td.has-failed { color: var(--danger); font-weight: 600; }
.boat-sheets .row-actions { gap: 6px; flex-wrap: wrap; }
span.btn.is-disabled { opacity: 0.5; cursor: default; }
.refiner-db .ic { width: 13px; height: 13px; vertical-align: -2px; }
.refiner-db code { font-family: var(--mono); font-size: 11.5px; padding: 0 4px; border-radius: 4px; background: var(--surface-2); }
.batch-line { display: grid; grid-template-columns: minmax(0, 1fr) 160px; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--grid-line); }
.batch-line:first-child { border-top: 0; }
.batch-line .t { font-weight: 550; font-size: 13px; }
.batch-line .s { font-size: 12px; color: var(--text-3); }

.agent-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.agent-pick {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; transition: border-color 120ms ease, background-color 120ms ease;
}
.agent-pick:hover { border-color: var(--border-strong); }
.agent-pick.is-on { border-color: var(--accent); background: var(--accent-soft); }
.agent-pick.is-inactive { opacity: 0.55; cursor: not-allowed; }
.agent-pick input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.agent-pick .nm { font-weight: 550; font-size: 13px; }
.agent-pick .st { font-size: 11.5px; color: var(--text-3); }
.agent-pick .txt { display: flex; flex-direction: column; min-width: 0; }
.agent-pick .txt > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; height: 100%; justify-content: flex-end; }
.chart .stack { width: 100%; max-width: 28px; display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; min-height: 2px; background: var(--surface-2); }
.chart .stack > span { display: block; width: 100%; }
.chart .seg-assigned { background: var(--ok); }
.chart .seg-refined { background: var(--row-refined-edge); }
.chart .seg-failed { background: var(--row-failed-edge); }
.chart .seg-duplicate { background: var(--border-strong); }
.chart .lbl { font-size: 10.5px; color: var(--text-3); font-family: var(--mono); white-space: nowrap; }

.tabs-inline { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs-inline button {
  height: 36px; padding: 0 12px; border: 0; background: none; color: var(--text-2); font-weight: 550; font-size: 13px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs-inline button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px 12px; max-height: 180px; overflow: auto; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); }
.stat-row { display: flex; flex-wrap: wrap; gap: 24px; }
.stat-row .stat .v { font-family: var(--mono); font-size: 20px; font-weight: 550; }
.stat-row .stat .l { font-size: 12px; color: var(--text-3); }
.pre { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; color: var(--text-2); max-width: 420px; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ auth page */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: 100%; max-width: 380px; }
.auth-card { padding: 28px 24px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.brand-lg { height: auto; padding: 0 0 20px; border: 0; }
.auth-title { font-size: 22px; }
.auth-sub { color: var(--text-3); margin: 4px 0 18px; }
.auth-card .alert { margin-bottom: 14px; }
.auth-foot { margin-top: 18px; font-size: 12px; color: var(--text-3); text-align: center; }
.narrow { max-width: 460px; }

/* ------------------------------------------------------------------ spreadsheet-first layout */
/* Sheet pages (Numbers Sheets, Number Entry, Agent Sheets) fill the window like Google
   Sheets: the controls take what they need and the grid takes the rest of the height. */
body.sheet-layout .content { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h)); padding: 12px 16px 10px; }
body.sheet-layout .content > * { flex: none; }
body.sheet-layout .content > .sheet-shell, body.sheet-layout .content > .sheet-main { flex: 1 1 0; min-height: 340px; display: flex; flex-direction: column; }
body.sheet-layout .sheet-main > .sheet-shell { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; margin-top: 0 !important; }
body.sheet-layout .sheet-shell > * { flex: none; }
body.sheet-layout .sheet-shell > .grid-box { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
body.sheet-layout .grid-box > .grid-wrap { flex: 1 1 0; max-height: none; min-height: 160px; }
body.sheet-layout .page-head { margin-bottom: 10px; }
body.sheet-layout .refine-bar { margin-bottom: 10px; padding: 8px 12px; }
body.sheet-layout .book-tabs { margin-bottom: 10px; }
/* Phones and short windows: the page scrolls as usual and the grid is nearly a screen tall. */
@media (max-width: 960px), (max-height: 600px) {
  body.sheet-layout .content { display: block; height: auto; }
  body.sheet-layout .content > .sheet-shell, body.sheet-layout .content > .sheet-main,
  body.sheet-layout .sheet-shell > .grid-box { display: block; min-height: 0; }
  body.sheet-layout .grid-box > .grid-wrap { max-height: calc(100vh - 110px); min-height: 320px; }
}
.grid-box { position: relative; }

/* Hide controls: the title, refine bar, tabs and the day / status filters fold away. */
.controls-toggle .lbl { font-weight: 550; }
body.controls-hidden .collapsible { display: none !important; }
body.controls-hidden .content { padding-top: 8px; }
.mini-clock { display: none; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 12px; color: var(--text-2); white-space: nowrap; }
.mini-clock .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--text); }
body.controls-hidden .mini-clock { display: inline-flex; }
/* With the controls hidden the toolbar stays on one line (it scrolls sideways on a narrow screen). */
body.controls-hidden .sheet-shell > .sheet-bar:first-child { flex-wrap: nowrap; overflow-x: auto; }
body.controls-hidden .sheet-shell > .sheet-bar:first-child > * { flex-shrink: 0; }
body.controls-hidden .sheet-shell > .sheet-bar:first-child > .search { flex: 0 1 200px; min-width: 140px; flex-shrink: 1; }
body.controls-hidden .save-state { min-width: 0; }
.mini-title { display: none; font-weight: 650; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
body.controls-hidden .mini-title { display: inline; }

/* The menu collapsed to icons (button in the top bar, remembered on this PC). */
.nav-collapse { display: inline-grid; }
@media (min-width: 961px) {
  body.nav-mini { --sidebar-w: 60px; }
  body.nav-mini .brand-name, body.nav-mini .brand-env, body.nav-mini .nav-title, body.nav-mini .nav-link > span:not(.nav-badge),
  body.nav-mini .who-text { display: none; }
  body.nav-mini .brand { padding: 0; justify-content: center; }
  body.nav-mini .nav-link { justify-content: center; padding: 0; position: relative; }
  body.nav-mini .nav-badge { position: absolute; top: 2px; right: 4px; min-width: 16px; padding: 0 4px; font-size: 10px; line-height: 15px; }
  body.nav-mini .sidebar nav { padding: 8px 6px 16px; }
  body.nav-mini .nav-group + .nav-group { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
  body.nav-mini .who { justify-content: center; }
}
@media (max-width: 960px) { .icon-btn.nav-collapse { display: none; } }

/* Daily security key: the lock page, the lock screen and the dialog. */
.key-card { max-width: 480px; margin: 48px auto; padding: 28px 26px; text-align: center; border: 1px solid var(--border);
  border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-pop); }
.key-card h2 { font-size: 19px; margin: 12px 0 6px; }
.key-card > p { color: var(--text-2); }
.key-mark { display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); }
.key-mark .ic { width: 24px; height: 24px; }
.key-form { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; text-align: left; }
.key-form label { font-weight: 550; font-size: 13px; }
.key-row { display: flex; gap: 8px; }
.key-input { font-family: var(--mono); font-size: 16px; letter-spacing: 0.06em; flex: 1; min-width: 0; }
.pw-table td { vertical-align: middle; }
.pw-table .pw-user { white-space: nowrap; }
.pw-table .key-value code { font-size: 15px; padding: 2px 8px; white-space: nowrap; }
.pw-table .key-meta { margin-top: 4px; }
.pw-table .row-actions { flex-wrap: nowrap; }
.key-error { color: var(--danger); font-size: 13px; }
body.is-key-locked .sel-bar, body.is-key-locked .copy-tip { display: none !important; }

/* Security & Access tab. */
.key-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.key-box { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); display: flex; flex-direction: column; gap: 10px; }
.key-box.is-missing { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); background: color-mix(in srgb, var(--warn) 5%, var(--surface)); }
.key-box .kb-head { display: flex; align-items: center; gap: 10px; }
.key-box .kb-head strong { font-size: 15px; }
.key-box .kb-head .switch { margin-left: auto; }
.key-value { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.key-value code { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: 0.08em; padding: 4px 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); }
.key-meta { font-size: 12.5px; color: var(--text-3); }
.key-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.role-list { display: flex; flex-wrap: wrap; gap: 6px 14px; }
@media (max-width: 960px) { .key-cards { grid-template-columns: minmax(0, 1fr); } }

/* Find a number on any agent sheet. */
.num-search-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.num-search-row .search { flex: 0 1 520px; min-width: 220px; }
.num-results { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.sheet-shell > .num-results { margin: 8px 10px; background: color-mix(in srgb, var(--accent) 4%, var(--surface)); }
.num-results .num-note { padding: 2px 0; }
.num-head { font-size: 13px; margin-bottom: 6px; }
.num-head code { font-family: var(--mono); padding: 0 4px; border-radius: 4px; background: var(--surface-2); }
.num-table { max-height: 320px; }
.num-table tr.is-mine td { background: var(--row-refined); }
.num-table mark { background: var(--row-refined); color: inherit; font-weight: 650; padding: 0; }
#number-finder .section-head h2 { font-size: 15px; }

.menu-sep { height: 1px; margin: 6px 0; background: var(--border); }
#text-file-btn + .menu-pop { width: 300px; }

/* Printing the sheets is turned off for everyone but the Main Admin (Security & Access). */
@media print {
  body.no-print .shell, body.no-print .toasts { display: none !important; }
  body.no-print::before { content: attr(data-print-note); display: block; padding: 40px; font: 16px sans-serif; }
}

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi:nth-child(4) { border-left: 0; }
  .kpi:nth-child(n + 4) { border-top: 1px solid var(--border); }
  .kpis.kpis-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpis-4 .kpi:nth-child(4) { border-left: 1px solid var(--border); }
  .kpis-4 .kpi:nth-child(n + 4) { border-top: 0; }
  .cols-2, .cols-2-even { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; width: var(--sidebar-w);
    transform: translateX(-100%); transition: transform 180ms ease;
  }
  .sidebar.is-open { transform: none; box-shadow: var(--shadow-pop); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 45; background: rgba(9, 9, 11, 0.4); }
  .icon-btn.nav-toggle { display: inline-grid; }
  .topbar { padding: 0 12px; }
  .content { padding: 16px 16px 40px; }
  .engine-pill .engine-text { display: none; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .refine-control { grid-template-columns: minmax(0, 1fr); }
  .refine-control .ctrl { justify-content: flex-start; }
  .grid-wrap { max-height: calc(100vh - 250px); }
  .sheet-foot .kbd-hints { display: none; }
}
@media (max-width: 600px) {
  .kpis, .kpis.kpis-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis-4 .kpi:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .kpi:nth-child(odd) { border-left: 0; }
  .kpi:nth-child(4) { border-left: 1px solid var(--border); }
  .kpi:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .page-head .actions { margin-left: 0; }
  .batch-line { grid-template-columns: minmax(0, 1fr); }
  .bar-item { grid-template-columns: 80px minmax(0, 1fr) 44px; }
  .kv { grid-template-columns: 100px minmax(0, 1fr); }
}

/* ------------------------------------------------------------------ chat (Main Admin <-> each user) */
.chat-panel {
  position: fixed; right: 16px; bottom: 16px; z-index: 70; display: flex; flex-direction: column;
  width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100vh - 90px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); overflow: hidden;
}
.chat-panel[hidden] { display: none; }
.chat-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--border); }
.chat-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .sub { display: block; font-size: 11.5px; font-weight: 400; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; }
.chat-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.chat-list[hidden], .chat-msgs[hidden], .chat-compose[hidden], .chat-note[hidden] { display: none; }
.chat-thread {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center; width: 100%; padding: 10px 14px;
  border: 0; border-bottom: 1px solid var(--grid-line); background: none; color: var(--text); text-align: left; cursor: pointer; font: inherit;
}
.chat-thread:hover { background: var(--surface-2); }
.chat-thread .avatar { width: 34px; height: 34px; }
.chat-thread .name { font-weight: 600; font-size: 13px; }
.chat-thread .last { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-thread.has-unread .last { color: var(--text); font-weight: 550; }
.chat-thread .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 11px; color: var(--text-3); white-space: nowrap; }
.chat-unread { min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 650; line-height: 18px; text-align: center; }
.chat-msgs { flex: 1; display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; overflow-y: auto; overscroll-behavior: contain; background: var(--bg); }
.chat-day { align-self: center; margin: 6px 0 2px; font-size: 11px; font-weight: 550; color: var(--text-3); }
.chat-msg {
  align-self: flex-start; max-width: 84%; padding: 7px 10px; border-radius: 12px; border-bottom-left-radius: 4px;
  background: var(--surface); border: 1px solid var(--border); font-size: 13px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat-msg.is-mine { align-self: flex-end; background: var(--accent); border-color: var(--accent); color: var(--on-accent); border-bottom-left-radius: 12px; border-bottom-right-radius: 4px; }
.chat-msg .when { display: block; margin-top: 3px; font-size: 10.5px; opacity: 0.7; text-align: right; white-space: nowrap; }
.chat-compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px; border-top: 1px solid var(--border); background: var(--surface); }
.chat-compose textarea {
  flex: 1; min-height: 36px; max-height: 120px; padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; line-height: 1.4; resize: none;
}
.chat-compose textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.chat-compose .btn { height: 36px; }
.chat-empty { margin: auto; padding: 24px 20px; text-align: center; color: var(--text-3); font-size: 13px; }
.chat-note { padding: 7px 14px; font-size: 11.5px; color: var(--text-3); border-top: 1px solid var(--grid-line); background: var(--surface); }
.chat-btn.has-unread { color: var(--accent-text); }
body.chat-open .toasts { right: calc(28px + min(380px, calc(100vw - 32px))); }
@media (max-width: 640px) {
  .chat-panel:not(.chat-docked) { right: 8px; left: 8px; bottom: 8px; width: auto; height: min(70vh, 560px); }
  body.chat-open .toasts { right: 16px; bottom: calc(min(70vh, 560px) + 20px); }
}
/* The chat beside a Numbers Sheet (the user's own, or the one the Main Admin opened): the sheet and the
   chat share the row; hiding the chat gives the sheet the whole width again. */
.sheet-row { display: flex; gap: 12px; min-width: 0; }
.sheet-row > .sheet-shell { flex: 1 1 0; min-width: 0; }
.chat-dock { flex: none; display: flex; flex-direction: column; width: 340px; min-height: 0; }
.chat-dock[hidden] { display: none; }
.chat-dock > .chat-panel.chat-docked { position: static; flex: 1 1 0; width: auto; height: auto; min-height: 420px; box-shadow: none; }
body.sheet-layout .content > .sheet-row { flex: 1 1 0; min-height: 340px; }
body.sheet-layout .sheet-row > .sheet-shell { min-height: 0; display: flex; flex-direction: column; margin-top: 0 !important; }
body.sheet-layout .chat-dock > .chat-panel.chat-docked { min-height: 0; }
@media (max-width: 960px), (max-height: 600px) {
  .sheet-row, body.sheet-layout .content > .sheet-row { display: block; }
  body.sheet-layout .sheet-row > .sheet-shell { display: block; min-height: 0; }
  .chat-dock { width: auto; height: 440px; margin-top: 12px; }
}
/* the notification sound (Settings) */
.sound-card { display: flex; flex-direction: column; gap: 12px; }
.sound-now { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sound-now .ic { width: 18px; height: 18px; color: var(--text-3); }
.sound-now .name { font-weight: 600; }
.sound-card input[type="file"] { font-size: 13px; max-width: 100%; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
