/* Notive Sheets components, built on tokens.css.
 * Rules taken from the Notive Design System: Nova Blue base, Sky Blue accents/focus,
 * Leaf Green only for the single primary action, navy-tinted shadows, Lucide line icons, no emoji.
 * App adaptation: denser type (14px) and small radii (sm/md) for a data-heavy tool UI.
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-body);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: var(--heading-tracking);
  color: var(--text-strong);
  margin: 0;
  line-height: 1.2;
}
h1 { font-size: 26px; }
h2 { font-size: var(--h4); }
h3 { font-size: var(--text-lg); }

a {
  color: var(--link);
  text-decoration-color: var(--sky-300);
  text-underline-offset: 2px;
  transition: color var(--dur-fast) var(--ease);
}
a:hover { color: var(--link-hover); }

:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-xs);
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon--sm { width: 16px; height: 16px; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- App shell */

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: minmax(0, 1fr); /* keep wide tables inside their own scroll box */
}

.topnav {
  background: var(--nova-300);
  color: var(--neutral-0);
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: 0 var(--space-6);
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topnav__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--neutral-0);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: var(--heading-tracking);
  white-space: nowrap;
}
.topnav__brand:hover { color: var(--neutral-0); }
/* Square bullet borrowed from the eyebrow device; the official logo SVG replaces the wordmark
   once it is exported from the design system (logo only in white on Nova). */
.topnav__mark {
  width: 10px;
  height: 10px;
  background: var(--sky-300);
  border-radius: 2px;
}
.topnav__links {
  display: flex;
  gap: var(--space-1);
  flex: 1;
}
.topnav__link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--sky-100);
  text-decoration: none;
  font-weight: 600;
}
.topnav__link:hover { color: var(--neutral-0); background: rgb(255 255 255 / 0.06); }
.topnav__link[aria-current="page"] {
  color: var(--neutral-0);
  background: rgb(66 162 226 / 0.18);
}
.topnav__user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.topnav__user form { margin: 0; }

.page {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-12);
}
.page--wide { max-width: none; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sky-600);
  margin-bottom: var(--space-1);
}
.eyebrow::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--sky-300);
  border-radius: 1px;
}
.muted { color: var(--text-muted); }

/* ---------------------------------------------------------------- Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 0 var(--space-4);
  border: 1.5px solid transparent;
  border-radius: var(--radius-pill);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Primary = Leaf Green. Nova text: white on Leaf 300 is only 2.3:1. */
.btn--primary { background: var(--leaf-300); color: var(--nova-300); }
.btn--primary:hover { background: var(--leaf-400); color: var(--nova-300); }
.btn--secondary { background: var(--nova-300); color: var(--neutral-0); }
.btn--secondary:hover { background: var(--nova-100); color: var(--neutral-0); }
.btn--ghost { background: transparent; color: var(--nova-300); border-color: var(--border-default); }
.btn--ghost:hover { border-color: var(--nova-300); background: var(--surface-muted); }
.btn--on-dark { background: transparent; color: var(--neutral-0); border-color: rgb(255 255 255 / 0.3); }
.btn--on-dark:hover { border-color: var(--neutral-0); color: var(--neutral-0); }
.btn--danger { background: var(--error-400); color: var(--neutral-0); }
.btn--sm { min-height: 30px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn--block { width: 100%; }

/* ---------------------------------------------------------------- Forms */

.field { display: grid; gap: 6px; margin-bottom: var(--space-4); }
.field__label { font-weight: 700; color: var(--text-strong); }
.field__help { color: var(--text-muted); font-size: var(--text-xs); }
.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  font: inherit;
  font-size: var(--text-md);
  color: var(--text-strong);
  background: var(--neutral-0);
  border: 1.5px solid var(--border-default);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast) var(--ease);
}
.input:hover,
.select:hover,
.textarea:hover { border-color: var(--neutral-500); }
.input:focus,
.select:focus,
.textarea:focus { border-color: var(--sky-300); box-shadow: var(--shadow-focus); outline: none; }
.input--code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.3em;
  font-size: 20px;
  text-align: center;
}
.field--error .input { border-color: var(--error-400); }

/* ---------------------------------------------------------------- Cards & alerts */

.card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.card__body { padding: var(--space-6); }

.alert {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-4);
  color: var(--nova-300);
  background: var(--ice-400);
}
.alert--error { background: rgb(214 40 57 / 0.1); }
.alert--error .icon { color: var(--error-400); }

.empty {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  text-align: center;
  padding: var(--space-12) var(--space-6);
}
.empty__icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--ice-400);
  color: var(--nova-300);
}

/* ---------------------------------------------------------------- Auth screens */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background:
    radial-gradient(1200px 600px at 100% 0%, rgb(66 162 226 / 0.18), transparent 60%),
    var(--nova-300);
}
.auth__card { width: 100%; max-width: 400px; }
.auth__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--neutral-0);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  margin-bottom: var(--space-6);
  justify-content: center;
}
.auth h1 { font-size: var(--h4); margin-bottom: var(--space-2); }
.auth p { margin: 0 0 var(--space-4); }
.qr {
  display: block;
  margin: 0 auto var(--space-3);
  width: 200px;
  height: 200px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}
.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--text-xs);
  background: var(--surface-muted);
  border-radius: var(--radius-xs);
  padding: var(--space-2);
  text-align: center;
  word-break: break-all;
  margin-bottom: var(--space-4);
}

/* ---------------------------------------------------------------- Pills, avatars, progress */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.pill--neutral { background: var(--neutral-100); color: var(--neutral-700); }
.pill--nova { background: var(--ice-400); color: var(--nova-300); }
.pill--sky { background: var(--sky-100); color: var(--sky-600); }
.pill--leaf { background: var(--leaf-100); color: var(--leaf-600); }
.pill--warning { background: rgb(253 167 105 / 0.3); color: var(--nova-300); }
.pill--warning::before { background: var(--warning-ui); }
/* Error 400 text on its tint is 4.25:1, so the label stays Nova and the dot carries the colour. */
.pill--error { background: rgb(214 40 57 / 0.1); color: var(--nova-300); }
.pill--error::before { background: var(--error-400); }

.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  background: var(--sky-100);
  color: var(--nova-300);
  flex: none;
}
.avatar--on-dark { background: var(--sky-300); color: var(--nova-300); }

.progress {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 140px;
}
.progress__track {
  flex: 1;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--ice-400);
  overflow: hidden;
}
.progress__bar { height: 100%; background: var(--leaf-300); border-radius: inherit; }
.progress__label { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.5em; text-align: right; }

/* ---------------------------------------------------------------- Toast */

.toast-region {
  position: fixed;
  right: var(--space-6);
  bottom: var(--space-6);
  display: grid;
  gap: var(--space-2);
  z-index: 50;
}
.toast {
  background: var(--nova-300);
  color: var(--neutral-0);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-width: 420px;
}
.toast--error { border-left: 0; background: var(--nova-400); }
.toast--error .icon { color: var(--warning-layer); }
.auth__footer { margin-top: var(--space-4); margin-bottom: 0; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------------------------------------------------------------- Grid */

.grid-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.grid-toolbar__search,
.grid-toolbar__filter {
  position: relative;
  display: flex;
  align-items: center;
}
.grid-toolbar__search .icon,
.grid-toolbar__filter .icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}
.grid-toolbar .input,
.grid-toolbar .select {
  min-height: 34px;
  padding-left: 32px;
  font-size: var(--text-sm);
}
.grid-toolbar__search .input { width: 240px; }
.grid-toolbar__spacer { flex: 1; }
.grid-toolbar__hint { font-size: var(--text-xs); }

.grid-region {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.grid-scroll {
  overflow: auto;
  max-height: calc(100vh - 260px);
}
.grid {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  width: max-content;
  min-width: 100%;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.grid__col-num { width: 52px; }
.grid th,
.grid td {
  height: 36px;
  padding: 0 var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface-muted);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--neutral-600);
  border-bottom: 1px solid var(--ice-500);
}
.grid__sort {
  all: unset;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  width: 100%;
}
.grid__sort:focus-visible { box-shadow: var(--shadow-focus); border-radius: var(--radius-xs); }
.grid th[aria-sort="ascending"],
.grid th[aria-sort="descending"] { color: var(--nova-300); }
.grid__rownum {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface-muted);
  color: var(--neutral-500);
  font-size: var(--text-xs);
  text-align: right !important;
}
.grid thead .grid__rownum { z-index: 4; }
.grid tbody tr:hover td { background: var(--ice-200); }
.grid__cell { cursor: cell; outline: none; position: relative; }
.grid__cell.is-active {
  box-shadow: inset 0 0 0 2px var(--sky-300);
  background: var(--neutral-0) !important;
}
.grid__cell.is-editing { padding: 0; overflow: visible; box-shadow: inset 0 0 0 2px var(--sky-400); }
.grid__cell.is-saving { color: var(--neutral-500); }
.grid__cell.has-conflict { box-shadow: inset 0 0 0 2px var(--warning-ui); }
.grid__cell.has-error { box-shadow: inset 0 0 0 2px var(--error-400); }
.grid__cell.has-remote-change::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warning-ui);
}
.grid tr.is-flash td { animation: grid-flash 1.6s var(--ease); }
@keyframes grid-flash {
  from { background: var(--sky-100); }
  to { background: transparent; }
}
.grid__clip { overflow: hidden; text-overflow: ellipsis; }
.grid__user { display: inline-flex; align-items: center; gap: var(--space-2); }
.grid__none { text-align: center !important; color: var(--text-muted); height: 96px !important; }

.grid-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-muted);
}
.pager { display: flex; align-items: center; gap: var(--space-2); }

@media (prefers-reduced-motion: reduce) {
  .grid tr.is-flash td { animation: none; }
}
/* First data column stays visible while scrolling sideways (next to the row numbers). */
.grid tbody td:nth-child(2),
.grid thead th:nth-child(2) {
  position: sticky;
  left: 52px;
  z-index: 2;
  background: var(--surface-card);
  box-shadow: 1px 0 0 var(--ice-500);
}
.grid thead th:nth-child(2) { z-index: 4; background: var(--surface-muted); }
.grid tbody tr:hover td:nth-child(2) { background: var(--ice-200); }

/* ---------------------------------------------------------------- Forms & detail layout */

.split {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: var(--space-6);
  align-items: start;
}
@media (max-width: 960px) { .split { grid-template-columns: minmax(0, 1fr); } }
.stack { display: grid; gap: var(--space-6); }
.card h2 { font-size: var(--text-md); margin-bottom: var(--space-3); }
.form-row { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: var(--space-4); }
.form-actions { display: flex; gap: var(--space-3); margin-top: var(--space-6); }
.field__optional { font-weight: 400; font-size: var(--text-xs); }
.field__error {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--nova-300);
  font-size: var(--text-xs);
  font-weight: 700;
}
.field__error .icon { color: var(--error-400); }
.input--mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; }
.textarea { min-height: 80px; resize: vertical; line-height: 1.5; }

.meta {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-1) var(--space-3);
  margin: var(--space-4) 0 0;
  font-size: var(--text-xs);
}
.meta dt { color: var(--text-muted); }
.meta dd { margin: 0; }
.meta__mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-4); }
.history__head { display: flex; align-items: center; gap: var(--space-2); }
.history__changes { margin: var(--space-1) 0 0 32px; padding: 0; list-style: none; font-size: var(--text-xs); }
.history__changes li { overflow-wrap: anywhere; }
.history__time { display: block; margin-left: 32px; font-size: var(--text-xs); }

/* ---------------------------------------------------------------- Simple table */

.table { width: 100%; border-collapse: collapse; }
.table th,
.table td {
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
  vertical-align: middle;
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-muted);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--neutral-600);
}
.table tbody tr:hover td { background: var(--ice-200); }
.table__code a { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; }
.table__link { text-decoration: none; font-weight: 700; }
.table__clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast { display: flex; gap: var(--space-2); align-items: center; }
.eyebrow a { color: inherit; text-decoration: none; }

/* ---------------------------------------------------------------- Sheets */

.page-header__actions { display: flex; gap: var(--space-3); align-items: center; }
.page-header__actions form { margin: 0; }
.page-header__lead { margin: var(--space-2) 0 0; max-width: 72ch; }
.narrow { max-width: 640px; }
.card__head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: var(--space-3); }
.card__head h2 { margin: 0; }
.table--compact th,
.table--compact td { padding: 8px var(--space-3); vertical-align: top; }
.table__sub { font-size: var(--text-xs); margin-top: 2px; }
.table code,
.table__sub code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.type-tag { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.type-tag .icon { color: var(--sky-500); }
.pill-row { display: flex; flex-wrap: wrap; gap: 4px; }
.pill--deprecated { opacity: 0.5; text-decoration: line-through; }
.empty--inline { padding: var(--space-6); }
.progress--lg .progress__track { height: 10px; }
.progress--lg { margin-bottom: var(--space-3); }
.category-counts { list-style: none; padding: 0; margin: 0 0 var(--space-3); display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); font-size: var(--text-xs); }
.grid-scroll--preview { max-height: 520px; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); }
.table--cells td { white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.pager--end { justify-content: flex-end; margin-top: var(--space-3); }
.cell-customer strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.alert code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.split > *,
.stack > * { min-width: 0; }

/* --- Badges, tabs, code blocks (M4) ------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--warning-ui);
  color: var(--neutral-1000);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1;
}
.badge--muted { background: var(--neutral-100); color: var(--neutral-700); }
.tabs {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.tabs__tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-muted);
  font-weight: 600;
  text-decoration: none;
}
.tabs__tab:hover { color: var(--text-strong); }
.tabs__tab[aria-current="page"] { color: var(--nova-300); border-bottom-color: var(--nova-300); }
.code-block {
  margin: var(--space-2) 0 0;
  padding: var(--space-3);
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--text-xs);
  white-space: pre-wrap;
  word-break: break-word;
}
.quote {
  margin: var(--space-2) 0 0;
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--border-default);
  color: var(--text-body);
}

/* --- Grid (M5): editors, picker, conflict, filters, drawer --------------------------------- */
.grid__open {
  all: unset;
  display: block;
  width: 100%;
  cursor: pointer;
  text-align: right;
}
.grid__open:hover { color: var(--nova-300); text-decoration: underline; }
.grid__open:focus-visible { box-shadow: var(--shadow-focus); border-radius: var(--radius-xs); }
.grid__required { color: var(--error-400); margin-left: 2px; }
.grid tr.is-deleted td { color: var(--neutral-500); text-decoration: line-through; }
.grid tr.is-deleted .pill { opacity: 0.6; }
.grid__cell[aria-readonly="true"] { cursor: default; }
.grid__cell--number { text-align: right !important; }
.cell-editor { position: absolute; inset: 0; z-index: 5; background: var(--neutral-0); }
.cell-editor .input {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: 0 var(--space-3);
  box-shadow: inset 0 0 0 2px var(--sky-400);
  font-size: var(--text-sm);
}
.cell-editor.is-saving .input,
.popover.is-saving { opacity: 0.6; }
.has-error .cell-editor .input { box-shadow: inset 0 0 0 2px var(--error-400); }
.cell-editor .editor-error {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  margin-top: 2px;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-xs);
  background: var(--error-400);
  color: var(--neutral-0);
  font-size: var(--text-xs);
  white-space: normal;
  box-shadow: var(--shadow-md);
}
.popover {
  position: absolute;
  z-index: 40;
  padding: var(--space-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--surface-card);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
}
.popover .textarea { width: 100%; max-height: 50vh; resize: vertical; }
.popover .editor-error {
  margin-top: var(--space-2);
  color: var(--error-400);
  font-size: var(--text-xs);
}
.cell-editor__hint { margin-top: var(--space-1); font-size: var(--text-xs); }
.picker .input { width: 100%; }
.picker__list {
  list-style: none;
  margin: var(--space-2) 0 0;
  padding: 0;
  max-height: 280px;
  overflow: auto;
}
.picker__list li[role="option"] {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 6px var(--space-2);
  border-radius: var(--radius-xs);
  cursor: pointer;
}
.picker__list li.is-highlighted { background: var(--ice-300); }
.picker__list li[aria-selected="true"] { font-weight: 700; }
.picker__list li[aria-selected="true"]::after { content: "✓"; color: var(--nova-300); }
.picker__hint { font-size: var(--text-xs); }
.picker__empty { padding: 6px var(--space-2); }
.conflict { max-width: 360px; }
.conflict p { margin: var(--space-1) 0; }
.conflict__value { margin-bottom: var(--space-2); }
.grid-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  background: var(--ice-200);
  color: var(--text-body);
  font-size: var(--text-xs);
  text-decoration: none;
}
.chip:hover { border-color: var(--nova-300); }
.chip--toggle { background: transparent; color: var(--text-muted); }
.chip--toggle.is-on { background: var(--ice-300); color: var(--nova-300); }
.filter-builder { display: flex; align-items: center; gap: var(--space-2); }
.filter-form { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.filter-form[hidden] { display: none; }
.grid-toolbar .filter-form .select,
.grid-toolbar .filter-form .input { padding-left: var(--space-2); }
.filter-form select[multiple] { min-height: 34px; height: 72px; }
.filter-form__dates { display: inline-flex; gap: var(--space-1); }
.drawer:empty { display: none; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  width: min(480px, 100vw);
  background: var(--surface-card);
  border-left: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
}
.drawer__panel, .drawer__form { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.drawer__form { flex: 1; }
.drawer__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}
.drawer__head h2 { margin: 0; font-size: var(--h4); }
.drawer__body { flex: 1; overflow: auto; padding: var(--space-4) var(--space-6); }
.drawer__foot {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-muted);
}
.fields {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: var(--space-2) var(--space-4);
  margin: 0 0 var(--space-6);
}
.fields dt { color: var(--text-muted); font-size: var(--text-sm); }
.fields dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.fields__long { white-space: normal; }
.checks { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }
.checks label { display: inline-flex; align-items: center; gap: 6px; }
[hidden] { display: none !important; }
.drawer__section { margin: var(--space-6) 0 var(--space-3); }
.drawer__body.stack { gap: var(--space-4); align-content: start; }
.drawer__body .field { margin: 0; }

/* --- Settings pages (M6) ------------------------------------------------------------------ */
.card__head { gap: var(--space-3); align-items: center; }
.card__head > .muted { margin-left: auto; }
.card__subhead { margin: var(--space-6) 0 var(--space-1); font-size: var(--text-md); }
.table__actions { white-space: nowrap; text-align: right; }
.table__actions,
.table__actions form { display: inline-flex; gap: var(--space-1); align-items: center; }
.table__actions { display: table-cell; }
.btn--icon { padding: 0 6px; }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.plain-list { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: grid; gap: var(--space-2); }
.plain-list li { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.plain-list form { margin: 0; }
.check { display: inline-flex; align-items: center; gap: var(--space-2); margin: var(--space-2) 0; }
.form-row--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-row--tight { display: grid; grid-template-columns: minmax(0, 1fr) 180px; gap: var(--space-2); align-items: center; margin: 4px 0; }
.input--sm, .select--sm { min-height: 30px; padding: 2px 8px; font-size: var(--text-sm); }
.options-table td { vertical-align: middle; }
.options-table tr.is-retired td { color: var(--text-muted); }
.inline-form { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-top: var(--space-3); }
.inline-form .input { max-width: 220px; }
.inline-form .select { width: auto; }
.retire { position: relative; display: inline-block; }
.retire summary { list-style: none; }
.retire summary::-webkit-details-marker { display: none; }
.retire__form {
  position: absolute;
  right: 0;
  z-index: 20;
  display: grid;
  gap: var(--space-2);
  width: 260px;
  padding: var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--surface-card);
  box-shadow: var(--shadow-lg);
  text-align: left;
  white-space: normal;
}
.convert-preview { margin: var(--space-3) 0; }
.radio-card {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.radio-card > span { display: grid; gap: 2px; }
.radio-card:has(input:checked) { border-color: var(--sky-400); background: var(--ice-200); }
.radio-card:has(input:disabled) { opacity: 0.5; cursor: not-allowed; }
fieldset.field { border: 0; padding: 0; margin: 0 0 var(--space-4); display: grid; gap: var(--space-2); }
.form-row--2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.token-reveal { border: 2px solid var(--leaf-300, var(--success)); margin-bottom: var(--space-6); }
.token-reveal h2 { display: flex; align-items: center; gap: var(--space-2); }
.token-reveal__row { display: flex; gap: var(--space-2); }
.token-reveal__row .input { flex: 1; }
.stack--tight { gap: var(--space-2); }
.stack--tight form { margin: 0; }
tr.is-retired td { color: var(--text-muted); }
.activity-filters .select { width: auto; max-width: 220px; padding-left: var(--space-2); }
.activity-filters__date { display: inline-flex; align-items: center; gap: var(--space-2); }
.activity-filters__date .input { padding-left: var(--space-2); width: auto; }
.history__head .pill .icon { margin-right: 2px; }
.link-button { all: unset; cursor: pointer; color: inherit; }
.link-button:hover, .link-button:focus-visible { color: var(--link); text-decoration: underline; }
.drawer__section .link-button { font-size: var(--text-sm); font-weight: 400; color: var(--link); }
.meta--wide { grid-template-columns: 200px minmax(0, 1fr); }
.diff-table__old { color: var(--text-muted); text-decoration: line-through; }
.diff-table__new { font-weight: 600; }
.plain-list--bullets { list-style: disc; padding-left: var(--space-6); display: block; }
.plain-list--bullets li { display: list-item; }
.raw { margin-top: var(--space-4); }
.raw summary { cursor: pointer; }
.pill--icon::before { display: none; }
.input--monospace { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--text-sm); }
.card .stack--tight { margin-top: var(--space-4); }
