/* ============================================================
   Hamilton Madden CRM — application styles
   Single stylesheet, no external dependencies (CSP-friendly).

   Everything is built on the token scale below. Rules of thumb:
   - spacing        -> var(--sp-*)          (4px base scale)
   - panel radius   -> var(--r-2)           (cards, tables, forms, board cols)
   - control radius -> var(--r-1)           (buttons, inputs, chips)
   - panel padding  -> var(--pad)
   - control height -> var(--ctl-h)         (buttons + inputs align on rows)
   ============================================================ */

:root {
  /* brand */
  --brand: #ff6900;
  --bg: #fbf8f3;
  --surface: #ffffff;
  --surface-2: #f4efe8;
  --surface-3: #ede6db;
  --border: #e8dfd2;
  --border-strong: #d6c9b6;
  --text: #241d1b;
  --text-muted: #857873;
  --text-subtle: #a89c93;
  --primary: #e05e00;
  --primary-hover: #c25200;
  --primary-contrast: #ffffff;
  --primary-tint: #fdeede;
  --link: #b5560c;
  --accent: #e95095;
  --danger: #b42318;   --danger-bg: #fef3f2;
  --warn: #b54708;     --warn-bg: #fffaeb;
  --success: #067647;  --success-bg: #ecfdf3;
  --info-bg: #fff4ea;
  --focus-ring: color-mix(in srgb, var(--primary) 32%, transparent);

  /* spacing scale (4px base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  /* radii */
  --r-1: 7px;
  --r-2: 12px;
  --r-3: 16px;
  --r-pill: 999px;

  /* type scale */
  --fs-xs: 0.75rem;    /* 12 */
  --fs-sm: 0.8125rem;  /* 13 */
  --fs-base: 0.875rem; /* 14 */
  --fs-md: 1rem;       /* 16 */
  --fs-lg: 1.1875rem;  /* 19 */
  --fs-xl: 1.5rem;     /* 24 */
  --fs-2xl: 1.75rem;   /* 28 */

  /* sizing */
  --ctl-h: 38px;
  --ctl-h-sm: 30px;
  --pad: 20px;
  --pad-sm: 14px;
  --header-h: 56px;
  --maxw: 1180px;
  --aside-w: 340px;
  --edge: 24px;        /* page side padding */
  --stack: var(--sp-6);

  --shadow-xs: 0 1px 2px rgba(60, 40, 20, .05);
  --shadow-sm: 0 1px 3px rgba(60, 40, 20, .08), 0 1px 2px rgba(60, 40, 20, .04);
  --shadow-md: 0 6px 20px rgba(60, 40, 20, .12);
  --shadow-lg: 0 16px 40px rgba(40, 26, 12, .18);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #ff7a1a;
    --bg: #16110d;
    --surface: #1e1813;
    --surface-2: #271f18;
    --surface-3: #322820;
    --border: #362c22;
    --border-strong: #4a3c2e;
    --text: #efe7dd;
    --text-muted: #a89a8c;
    --text-subtle: #8a7d6f;
    --primary: #ff7a1a;
    --primary-hover: #ff9042;
    --primary-contrast: #1c0f04;
    --primary-tint: #33220f;
    --link: #ff9a4d;
    --accent: #f272a8;
    --danger: #f97066;  --danger-bg: #2b1615;
    --warn: #f5a524;    --warn-bg: #2a2213;
    --success: #47c78a; --success-bg: #12251d;
    --info-bg: #2a1e12;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .5);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .55);
    --shadow-lg: 0 18px 44px rgba(0, 0, 0, .6);
  }
}

/* ============================================================
   base
   ============================================================ */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

h1, h2, h3 { line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: var(--fs-xl); margin: 0; }
h2 { font-size: var(--fs-lg); margin: 0; }
h3 { font-size: var(--fs-md); margin: 0; }

p { margin: 0 0 var(--sp-3); }

.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
strong { font-weight: 600; }

::selection { background: var(--primary-tint); }

/* ============================================================
   layout shell
   ============================================================ */
main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--sp-6) var(--edge) var(--sp-7);
}

/* consistent vertical rhythm */
main > * + * { margin-top: var(--sp-5); }
main > section { margin-top: var(--stack); }
main h1 + * { margin-top: var(--sp-4); }
main h2 + *, main h3 + * { margin-top: var(--sp-3); }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}
.page-head > div { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

/* ============================================================
   app shell — slim topbar + left sidebar
   ============================================================ */
:root { --sidebar-w: 216px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  height: var(--header-h);
  padding: 0 var(--sp-4);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  padding-bottom: 2px;
  border-bottom: 2px solid var(--brand);
}
.topbar .brand:hover { text-decoration: none; }
.topbar .spacer { flex: 1; }

.nav-burger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-1);
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 1rem;
}

.header-search { margin: 0; }
.header-search input {
  width: 200px;
  height: 32px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border-color: var(--border);
}
@media (max-width: 560px) { .header-search { display: none; } }

.user-menu { display: flex; align-items: center; gap: var(--sp-3); white-space: nowrap; }
.user-menu span { color: var(--text-muted); font-size: var(--fs-sm); }
.user-menu form { margin: 0; }

/* layout row: sidebar + content — a fixed shell below the header.
   The row fills the viewport under the topbar; the sidebar and the
   content each scroll on their own, so the nav never moves with the page. */
.layout {
  display: flex;
  align-items: flex-start;
  height: calc(100dvh - var(--header-h));
}

.sidebar {
  flex: 0 0 var(--sidebar-w);
  height: 100%;
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-3) var(--sp-6);
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-1);
  color: var(--text-muted);
  font-weight: 500;
  font-size: var(--fs-sm);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--primary-tint); color: var(--primary); }

.nav-group { margin-top: var(--sp-3); }
.nav-group > .nav-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: var(--sp-1);
}

/* collapsible group header */
summary.nav-label {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-subtle);
  cursor: pointer;
  border-radius: var(--r-1);
  list-style: none;
  user-select: none;
}
summary.nav-label::-webkit-details-marker { display: none; }
summary.nav-label:hover { background: var(--surface-2); color: var(--text-muted); }
summary.nav-label:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}
summary.nav-label::after {
  content: "";
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .15s ease;
}
.nav-group[open] > summary.nav-label::after { transform: rotate(45deg); }

.content { flex: 1; min-width: 0; height: 100%; overflow-y: auto; }

/* off-canvas sidebar on narrow screens */
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
@media (max-width: 900px) {
  .nav-burger { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: var(--header-h);
    bottom: 0;
    height: auto;
    width: 244px;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 60;
    box-shadow: var(--shadow-lg);
  }
  .nav-toggle:checked ~ .layout .sidebar { transform: none; }
}

/* ============================================================
   buttons  (share --ctl-h with inputs so rows align)
   ============================================================ */
button,
.btn,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: var(--ctl-h);
  padding: 0 var(--sp-4);
  font: inherit;
  font-weight: 550;
  line-height: 1;
  white-space: nowrap;
  color: var(--primary-contrast);
  background: var(--primary);
  border: 1px solid transparent;
  border-radius: var(--r-1);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease;
}
button:hover,
.btn:hover { background: var(--primary-hover); text-decoration: none; }
button:focus-visible,
.btn:focus-visible,
.btn-secondary:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
button:disabled { opacity: .55; cursor: not-allowed; }

.btn-secondary,
button.secondary,
button[type="button"].btn-secondary {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border-strong);
}
.btn-secondary:hover,
button.secondary:hover { background: var(--surface-2); text-decoration: none; }

.btn-sm { height: var(--ctl-h-sm); padding: 0 var(--sp-3); font-size: var(--fs-sm); }

/* compact buttons inside dense contexts */
table.data td button,
.task-list button,
form.inline button,
nav.pagination a {
  height: var(--ctl-h-sm);
  padding: 0 var(--sp-3);
  font-size: var(--fs-sm);
}
table.data td button,
.task-list button,
form.inline button {
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
}
table.data td button:hover,
.task-list button:hover,
form.inline button:hover { background: var(--surface-3); }

/* row-action cell: Edit link + Delete submit rendered as one identical
   button (.row-btn), kept on a single line with an even gutter */
table.data td.actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  white-space: nowrap;
}
.actions .row-btn,
table.data td.actions form.inline button.row-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--ctl-h-sm);
  padding: 0 var(--sp-3);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 550;
  line-height: 1;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-1);
  text-decoration: none;
  cursor: pointer;
}
.actions .row-btn:hover,
table.data td.actions form.inline button.row-btn:hover {
  background: var(--surface-3);
  text-decoration: none;
}
.actions .row-btn::-moz-focus-inner { border: 0; padding: 0; }

/* a page-head action row is not a dense context: its inline-form submit
   buttons match the sibling <a class="btn-secondary"> links exactly */
.page-head form.inline button {
  height: var(--ctl-h);
  padding: 0 var(--sp-4);
  font-size: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
}
.page-head form.inline button:hover { background: var(--surface-2); }

/* square icon-only button — a bare glyph action that sits inline with text
   (e.g. edit / remove next to a list item). Works as <a> or <button>. */
.icon-btn,
form.inline button.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  height: var(--ctl-h-sm);
  width: var(--ctl-h-sm);
  min-width: 0;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-1);
  cursor: pointer;
}
.icon-btn:hover,
form.inline button.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
  text-decoration: none;
}
.icon-btn.danger:hover,
form.inline button.icon-btn.danger:hover {
  color: var(--danger);
  background: var(--danger-bg);
}
.icon-btn:focus-visible,
form.inline button.icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.icon-btn svg { width: 15px; height: 15px; display: block; pointer-events: none; }

/* ============================================================
   form controls
   ============================================================ */
input, select, textarea {
  width: 100%;
  height: var(--ctl-h);
  padding: 0 var(--sp-3);
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-1);
}
textarea { height: auto; min-height: 76px; padding: var(--sp-2) var(--sp-3); resize: vertical; line-height: 1.5; }

/* custom checkbox / radio — larger hit area, brand fill, drawn tick */
input[type="checkbox"],
input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  min-width: 0;
  padding: 0;
  margin: 0;
  display: inline-grid;
  place-content: center;
  vertical-align: -3px;
  color: var(--primary-contrast);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-1);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
input[type="radio"] { border-radius: var(--r-pill); }
input[type="checkbox"]::before,
input[type="radio"]::before {
  content: "";
  width: 10px;
  height: 10px;
  transform: scale(0);
  transition: transform .12s ease;
  box-shadow: inset 1em 1em currentColor;
}
input[type="checkbox"]::before {
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0, 43% 62%);
}
input[type="radio"]::before { width: 8px; height: 8px; border-radius: 50%; }
input[type="checkbox"]:checked,
input[type="radio"]:checked { background: var(--primary); border-color: var(--primary); }
input[type="checkbox"]:checked::before,
input[type="radio"]:checked::before { transform: scale(1); }
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
input[type="checkbox"]:disabled,
input[type="radio"]:disabled { opacity: .55; cursor: not-allowed; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
input::placeholder, textarea::placeholder { color: var(--text-subtle); }
label { font-weight: 500; }

/* no spinner buttons on number fields — we validate server-side */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* file input — field chrome shared with other inputs; the native picker
   button restyled to read like a secondary button */
input[type="file"] {
  display: inline-flex;
  align-items: center;
  padding: 0;
  overflow: hidden;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  cursor: pointer;
}
input[type="file"]::file-selector-button {
  height: 100%;
  margin-right: var(--sp-3);
  padding: 0 var(--sp-4);
  font: inherit;
  font-weight: 550;
  color: var(--text);
  background: var(--surface-2);
  border: 0;
  border-right: 1px solid var(--border-strong);
  cursor: pointer;
  transition: background .12s ease;
}
input[type="file"]::file-selector-button:hover { background: var(--surface-3); }

/* ============================================================
   panel  — the single card treatment, reused everywhere
   ============================================================ */
.panel,
.card,
dl.kv,
form.inline-form,
.timeline,
.inline-section,
table.data,
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-xs);
}
.panel, .card, dl.kv, form.inline-form, .timeline, .inline-section { padding: var(--pad); }
.panel--narrow { max-width: 760px; }

/* vertical rhythm between stacked blocks inside a panel */
.panel > * + * { margin-top: var(--sp-4); }

/* a kv/list block already sitting inside a panel drops its own chrome */
.panel dl.kv, .inline-section dl.kv,
.panel .timeline, .inline-section .timeline {
  border: 0;
  padding: 0;
  box-shadow: none;
  background: none;
}

/* ============================================================
   stat tiles
   ============================================================ */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: var(--sp-4);
}
.card { display: flex; flex-direction: column; gap: var(--sp-1); }
.card-number { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.card-label { color: var(--text-muted); font-size: var(--fs-sm); }
.card-label a { color: inherit; }
.card-label a:hover { color: var(--primary); }

/* a stat tile that drills through to the records behind the number */
a.card { color: inherit; text-decoration: none; transition: box-shadow .1s, border-color .1s; }
a.card:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }

/* ============================================================
   key / value blocks (multi-column)
   ============================================================ */
dl.kv {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: var(--sp-4) var(--sp-5);
  margin: 0;
}
dl.kv .kv-row { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
dl.kv .kv-row.wide { grid-column: 1 / -1; }
dl.kv dt {
  color: var(--text-subtle);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ============================================================
   forms
   ============================================================ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 var(--sp-5);
  max-width: 720px;
  margin-top: var(--sp-4);
}
.form-grid .field { display: flex; flex-direction: column; gap: var(--sp-1); margin-bottom: var(--sp-4); min-width: 0; }
.form-grid .field label { font-size: var(--fs-sm); font-weight: 500; }
.form-grid .field .helptext { color: var(--text-muted); font-size: var(--fs-xs); }
.form-grid .field ul.errorlist { margin: 2px 0 0; padding-left: var(--sp-4); color: var(--danger); font-size: var(--fs-xs); list-style: none; }
.form-grid .field:has(textarea),
.form-grid .field.wide { grid-column: 1 / -1; }

.form-actions { display: flex; gap: var(--sp-3); align-items: center; margin-top: var(--sp-4); }
.form-actions a { color: var(--text-muted); }

.form-fieldset { border: 0; padding: 0; margin: 0 0 var(--sp-5); min-width: 0; }
.form-fieldset legend {
  padding: 0;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-subtle);
  margin-bottom: var(--sp-2);
}
.form-fieldset .form-grid { margin-top: 0; }
.form-fieldset > .helptext { color: var(--text-muted); font-size: var(--fs-xs); margin: 0; }

/* form grid sitting directly in a panel: panel padding already spaces it */
.panel > form > .form-grid,
.inline-section form.inline-editable > .form-grid { margin-top: 0; }
.inline-section .section-head + .form-grid { margin-top: var(--sp-3); }

form.stacked { max-width: 460px; margin-top: var(--sp-4); }
form.stacked p { margin: 0 0 var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-1); }
form.stacked p label { font-size: var(--fs-sm); }
form.stacked .helptext { color: var(--text-muted); font-size: var(--fs-xs); }
form.stacked ul.errorlist { margin: 2px 0 0; padding-left: var(--sp-4); color: var(--danger); font-size: var(--fs-xs); list-style: none; }
form.stacked .form-actions { margin-top: 0; }

/* filter bars */
form.filters {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: var(--sp-4);
}
form.filters > input,
form.filters > select,
form.filters > button { width: auto; }
form.filters input:not([type="search"]),
form.filters select { min-width: 180px; }
form.filters input[type="search"] { min-width: 280px; }
form.filters label {
  display: flex; flex-direction: column; gap: var(--sp-1);
  font-size: var(--fs-xs); color: var(--text-muted);
}
form.filters label input { min-width: 120px; }

/* checkbox / radio filter: inline, natural-size control aligned with the row */
form.filters label:has(> input[type="checkbox"]),
form.filters label:has(> input[type="radio"]) {
  flex-direction: row;
  align-items: center;
  gap: var(--sp-2);
  height: var(--ctl-h);
  font-size: var(--fs-sm);
  color: var(--text);
}
form.filters label > input[type="checkbox"],
form.filters label > input[type="radio"] { min-width: 0; }

/* inline action forms (status change, move stage) */
form.inline-form {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  flex-wrap: wrap;
}
form.inline-form p,
form.inline-form label { margin: 0; }
form.inline-form label { display: flex; flex-direction: column; gap: var(--sp-1); font-size: var(--fs-xs); color: var(--text-muted); }
form.inline-form :is(input, select) { width: auto; min-width: 160px; }
form.inline .helptext { display: none; }
form.inline { display: inline; }

/* ============================================================
   detail layout: main + sticky aside
   ============================================================ */
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--aside-w);
  gap: var(--sp-6);
  align-items: start;
}
.detail-grid > div > * + *,
.detail-grid > aside > * + * { margin-top: var(--sp-5); }
.detail-grid > aside { position: sticky; top: var(--sp-4); }
@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; gap: var(--sp-5); }
  .detail-grid > aside { position: static; }
}

/* ============================================================
   tables
   ============================================================ */
.table-scroll { overflow-x: auto; border-radius: var(--r-2); }
table.data {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
table.data thead th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-subtle);
  background: var(--surface-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tfoot th {
  text-align: left;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);

}

table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data td .small { color: var(--text-muted); }

/* ============================================================
   messages / notices
   ============================================================ */
.messages {
  list-style: none;
  margin: var(--sp-4) auto 0;
  padding: 0 var(--edge);
  max-width: var(--maxw);
}
.messages li {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--r-1);
  margin-bottom: var(--sp-2);
  background: var(--surface);
}
.messages li.success { background: var(--success-bg); border-left-color: var(--success); }
.messages li.error   { background: var(--danger-bg);  border-left-color: var(--danger); }
.messages li.warning { background: var(--warn-bg);    border-left-color: var(--warn); }
.messages li.info    { background: var(--info-bg);    border-left-color: var(--brand); }

.notice {
  padding: var(--sp-3) var(--sp-4);
  background: var(--info-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: var(--r-1);
}

/* ============================================================
   timeline
   ============================================================ */
.timeline .section-head { margin-bottom: var(--sp-3); }
.timeline-list { list-style: none; margin: 0; padding: 0; }
.timeline-list > li {
  padding: var(--sp-3) 0 var(--sp-3) var(--sp-3);
  border-left: 2px solid var(--border-strong);
}
.timeline-list > li + li { border-top: 1px solid var(--border); }
.timeline-list > li.overdue { border-left-color: var(--danger); }
.timeline-list .tl-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.timeline-list .tl-head form.inline { margin-left: auto; }

/* grouped icon actions on a document row, pinned to the right of the head */
.timeline-list .tl-head .doc-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}
.timeline-list .tl-head .doc-actions form.inline { margin-left: 0; }
.timeline-list p { margin: var(--sp-2) 0 0; }
.timeline-list .tl-meta { display: block; margin-top: var(--sp-1); color: var(--text-subtle); }

.tag {
  display: inline-block;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .03em;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 1px var(--sp-2);
  margin-right: var(--sp-2);
}

.task-list { list-style: none; padding: 0; margin: 0; }
.task-list li {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}
.task-list li:last-child { border-bottom: 0; }
.task-list li.overdue { color: var(--danger); }
.task-list form.inline { margin-left: auto; }
.task-list .row-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}
.task-list .row-actions form.inline { margin-left: 0; }

/* attention queue — issues listed inside a panel */
.issue-list { list-style: none; padding: 0; margin: 0; }
.issue-list li {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}
.issue-list li:last-child { border-bottom: 0; }
.issue-list li .tag { align-self: center; }
.issue-list li.sev-high .tag {
  color: var(--danger); background: var(--danger-bg); border-color: var(--danger);
}
.issue-list li.sev-medium .tag {
  color: var(--warn); background: var(--warn-bg); border-color: var(--warn);
}

/* ============================================================
   pipeline board
   ============================================================ */
.board { display: flex; gap: var(--sp-4); overflow-x: auto; padding-bottom: var(--sp-2); }
.board-col {
  flex: 0 0 264px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.board-col h3 { font-size: var(--fs-sm); }
.board-col > .small { color: var(--text-muted); }
.board-col.drop-target { outline: 2px dashed var(--primary); outline-offset: -4px; }
.board-cards { min-height: 32px; display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-2); }
.board-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-1);
  padding: var(--sp-3);
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.board-card a { font-weight: 600; }
.board-card .small { color: var(--text-muted); }
.board-card.draggable { cursor: grab; }
.board-card.sortable-ghost { opacity: .35; }
.board-card.sortable-chosen { box-shadow: var(--shadow-md); }
.board-hint { color: var(--text-muted); font-size: var(--fs-sm); margin-bottom: var(--sp-4); }

/* ============================================================
   pagination
   ============================================================ */
nav.pagination {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  justify-content: center;
  margin-top: var(--sp-5);
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
nav.pagination a {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-1);
  color: var(--text);
  background: var(--surface);
}
nav.pagination a:hover { background: var(--surface-2); text-decoration: none; }

/* ============================================================
   plain lists inside content
   ============================================================ */
main :is(.detail-grid, section) ul:not(.timeline-list):not(.task-list):not(.messages):not(.main-nav) {
  margin: 0;
  padding-left: var(--sp-5);
}
main ul:not(.timeline-list):not(.task-list):not(.messages):not(.main-nav) li { margin: var(--sp-1) 0; }

/* ============================================================
   change history
   ============================================================ */
ol.history { list-style: none; margin: 0; padding: 0; }
ol.history > li + li {
  margin-top: var(--sp-5);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border);
}
ol.history .history-head {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-3);
}
ol.history table.data { margin-top: var(--sp-2); }

/* ============================================================
   htmx
   ============================================================ */
.htmx-indicator { opacity: 0; transition: opacity .15s; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }
[hx-get], [hx-post] { cursor: pointer; }
.inline-editable.htmx-swapping { opacity: .4; }
.inline-section.htmx-request { opacity: .6; transition: opacity .1s; }

/* ============================================================
   auth pages
   ============================================================ */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6) var(--sp-4);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: var(--sp-6);
  box-shadow: var(--shadow-md);
}
.auth-card .brand {
  display: inline-block;
  font-weight: 700;
  color: var(--text);
  border-bottom: 2px solid var(--brand);
  padding-bottom: 2px;
  margin-bottom: var(--sp-5);
}
.auth-card .messages { max-width: none; margin: 0 0 var(--sp-4); padding: 0; }
.auth-card h1 { font-size: var(--fs-lg); margin-bottom: var(--sp-3); }
.auth-card form > * + * { margin-top: var(--sp-3); }
.auth-card form :is(p, div) { display: flex; flex-direction: column; gap: var(--sp-1); }
.auth-card button { width: 100%; }
.auth-card a { font-size: var(--fs-sm); }
.auth-card ul { padding-left: var(--sp-5); }
.auth-card .auth-aside {
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
}

/* ============================================================
   modal  (native <dialog>, loaded by HTMX into #modal-root)
   ============================================================ */
.modal {
  width: min(680px, calc(100vw - var(--sp-6)));
  max-width: none;
  max-height: calc(100vh - var(--sp-7));
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.modal::backdrop { background: rgba(36, 29, 27, .45); }
.confirm-modal { width: min(420px, calc(100vw - var(--sp-6))); }
.confirm-modal .modal-actions [data-confirm-ok] { font-weight: 600; }
.modal .compose-form { display: flex; flex-direction: column; max-height: calc(100vh - var(--sp-7)); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: var(--fs-lg); margin: 0; }
.modal-x {
  height: var(--ctl-h-sm);
  width: var(--ctl-h-sm);
  padding: 0;
  font-size: var(--fs-lg);
  color: var(--text-muted);
  background: transparent;
  border-color: transparent;
}
.modal-x:hover { background: var(--surface-2); color: var(--text); }

.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-body > * + * { margin-top: var(--sp-4); }
.modal-body .field { display: flex; flex-direction: column; gap: var(--sp-1); }
.modal-body .field > label,
.modal-body .field > .label { font-size: var(--fs-sm); font-weight: 500; }
.modal-body textarea { min-height: 180px; }
.modal-body ul.errorlist { margin: 2px 0 0; padding-left: var(--sp-4); color: var(--danger); font-size: var(--fs-xs); list-style: none; }

.modal-body fieldset.recipients { border: 0; padding: 0; margin: 0; min-width: 0; }
.modal-body fieldset.recipients legend {
  padding: 0;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-subtle);
  margin-bottom: var(--sp-3);
}
.modal-body fieldset.recipients .field + .field { margin-top: var(--sp-4); }
.modal-body ul#id_contacts,
.modal-body ul#id_distribution_lists {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.modal-body ul#id_contacts li label,
.modal-body ul#id_distribution_lists li label {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 400;
}
.modal-body ul#id_contacts input,
.modal-body ul#id_distribution_lists input { width: auto; }

.modal-actions {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
}

/* ============================================================
   footer
   ============================================================ */
.app-footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--sp-5) var(--edge) var(--sp-6);
  color: var(--text-subtle);
  font-size: var(--fs-sm);
}

/* ============================================================
   responsive
   ============================================================ */
@media (max-width: 640px) {
  :root { --edge: 16px; --pad: 16px; }
  .topbar { gap: var(--sp-3); padding: 0 var(--sp-3); }
  .user-menu span { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}

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