/*
 * TTS Outside Market — the one stylesheet (internal UI and the sign-in pages).
 *
 * STABLE CONTRACT (templates rely on these; rename nothing, add new tokens instead):
 *   - Blocks in base.html: title, extra_head, nav, content.
 *   - Tokens (--color-*, --space-*, --radius, --font-*, --tap) keep their names.
 *   - Components: .btn (.btn--primary/.btn--ghost/.btn--danger/.btn--sm/.btn--block),
 *     .pill (.pill--urgent/.pill--risk/.pill--action/.pill--ok/.pill--muted), .card,
 *     .field, .table-wrap, .flash, .empty, .stack, .cluster.
 *
 * Direction (ui-ux-pro-max: style "Liquid Glass", Apple platform material, density 8):
 * Apple-native look — system font (SF Pro on Apple devices), Apple system colours, capsule
 * controls and translucent "glass" for the chrome (top bar, tabs, buttons, pills, panels)
 * floating over a softly tinted backdrop. Content keeps a near-opaque layer so dense
 * tables and text stay sharp. Light and dark follow the OS.
 *
 * Accessibility: text tokens are >= 4.5:1 on the glass surfaces of each scheme (the glass
 * is >= 72% opaque over a light/dark base, so contrast is computed on the blended colour);
 * pill and flash text >= 4.5:1 on their tint; control borders and the focus ring >= 3:1.
 * prefers-reduced-transparency (and browsers without backdrop-filter) get opaque
 * surfaces; prefers-reduced-motion removes movement; forced-colors keeps borders.
 * No font CDN: CSP is default-src 'self'.
 */

:root {
  color-scheme: light dark;

  /* Apple system palette (light) */
  --color-bg: #f2f2f7;               /* systemGroupedBackground */
  --color-surface: #ffffff;
  --color-surface-2: #f5f5f7;
  --color-text: #1d1d1f;             /* 16:1 on surface */
  --color-text-2: #3a3a3c;           /* 11:1 */
  --color-muted: #5f5f64;            /* 6.2:1 on surface, 5.6:1 on bg */
  --color-border: rgb(60 60 67 / 0.14);   /* hairlines (decorative) */
  --color-border-strong: #86868b;    /* input outlines: 3.6:1 */
  --color-primary: #0071e3;          /* filled buttons, white text 4.6:1 */
  --color-primary-hover: #0062c4;
  --color-on-primary: #ffffff;
  --color-link: #0066cc;             /* 5.6:1 */
  --color-accent: #0071e3;           /* focus ring: 4.3:1 on bg */
  --color-danger: #c4271c;           /* 5.5:1 */
  --color-accent-strong: #d70015;    /* badge, white text 5.4:1 */

  --color-urgent-bg: #ffe3e1;  --color-urgent-fg: #a1150f;  --color-urgent-line: #ff3b30;
  --color-risk-bg: #ffefd6;    --color-risk-fg: #8a4500;    --color-risk-line: #ff9500;
  --color-action-bg: #e0eeff;  --color-action-fg: #0047a8;  --color-action-line: #007aff;
  --color-ok-bg: #ddf6e4;      --color-ok-fg: #17602c;      --color-ok-line: #34c759;
  --color-muted-bg: #e9e9ee;   --color-muted-fg: #3a3a3c;

  /* Liquid Glass material */
  --glass: rgb(255 255 255 / 0.66);          /* chrome: bar, tabs, ghost buttons */
  --glass-strong: rgb(255 255 255 / 0.84);   /* content panels, tables */
  --glass-fill: rgb(118 118 128 / 0.12);     /* iOS field / segmented fill */
  --glass-edge: rgb(255 255 255 / 0.75);     /* the bright rim */
  --glass-hairline: rgb(0 0 0 / 0.07);
  --glass-blur: blur(28px) saturate(180%);
  --glass-shadow: 0 1px 1px rgb(0 0 0 / 0.04), 0 8px 28px rgb(0 0 0 / 0.08);
  --glass-shadow-lift: 0 2px 4px rgb(0 0 0 / 0.06), 0 16px 40px rgb(0 0 0 / 0.14);
  --glass-rim: inset 0 1px 0 var(--glass-edge), inset 0 0 0 1px var(--glass-hairline);
  --backdrop:
    radial-gradient(60rem 40rem at 0% -10%, rgb(0 122 255 / 0.14), transparent 60%),
    radial-gradient(50rem 36rem at 105% 0%, rgb(175 82 222 / 0.10), transparent 60%),
    radial-gradient(56rem 40rem at 50% 115%, rgb(52 199 89 / 0.08), transparent 60%);

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.875rem;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --radius: 12px;            /* fields, small surfaces */
  --radius-lg: 20px;         /* panels and cards */
  --radius-pill: 999px;      /* buttons, pills, nav items */
  --tap: 44px;               /* minimum touch target */
  --shadow: var(--glass-shadow);
  --duration: 200ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);   /* Apple-like spring-out */
  --page-max: 1440px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #000000;
    --color-surface: #1c1c1e;
    --color-surface-2: #2c2c2e;
    --color-text: #f5f5f7;           /* 16:1 on surface */
    --color-text-2: #d1d1d6;         /* 11:1 */
    --color-muted: #a1a1a6;          /* 6.9:1 on surface */
    --color-border: rgb(235 235 245 / 0.14);
    --color-border-strong: #8e8e93;  /* 4.9:1 on surface */
    --color-primary: #0071e3;        /* white text 4.6:1, as in light */
    --color-primary-hover: #0062c4;
    --color-on-primary: #ffffff;
    --color-link: #5eb0ff;           /* 7.7:1 */
    --color-accent: #4da3ff;
    --color-danger: #ff6961;
    --color-accent-strong: #d70015;

    --color-urgent-bg: #4a1513;  --color-urgent-fg: #ffb4ab;  --color-urgent-line: #ff453a;
    --color-risk-bg: #4a2d06;    --color-risk-fg: #ffcf87;    --color-risk-line: #ff9f0a;
    --color-action-bg: #0c2c55;  --color-action-fg: #a9d1ff;  --color-action-line: #0a84ff;
    --color-ok-bg: #0f3a1c;      --color-ok-fg: #9be7b0;      --color-ok-line: #30d158;
    --color-muted-bg: #3a3a3c;   --color-muted-fg: #e5e5ea;

    --glass: rgb(44 44 46 / 0.62);
    --glass-strong: rgb(28 28 30 / 0.86);
    --glass-fill: rgb(118 118 128 / 0.24);
    --glass-edge: rgb(255 255 255 / 0.14);
    --glass-hairline: rgb(255 255 255 / 0.08);
    --glass-shadow: 0 1px 1px rgb(0 0 0 / 0.3), 0 10px 32px rgb(0 0 0 / 0.45);
    --glass-shadow-lift: 0 2px 6px rgb(0 0 0 / 0.4), 0 18px 44px rgb(0 0 0 / 0.6);
    --backdrop:
      radial-gradient(60rem 40rem at 0% -10%, rgb(10 132 255 / 0.22), transparent 60%),
      radial-gradient(50rem 36rem at 105% 0%, rgb(191 90 242 / 0.16), transparent 60%),
      radial-gradient(56rem 40rem at 50% 115%, rgb(48 209 88 / 0.10), transparent 60%);
  }
}

/* ---- base ---------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: var(--text-base)/1.47 var(--font-sans);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  color: var(--color-text);
  background: var(--color-bg);
  overflow-wrap: anywhere;
}
/* The tinted "wallpaper" the glass refracts; fixed so it does not scroll with content. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: var(--backdrop), var(--color-bg);
}
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; margin: 0 0 var(--space-3);
  letter-spacing: -0.022em; }
h1 { font-size: var(--text-2xl); font-weight: 700; }
h2 { font-size: var(--text-xl); font-weight: 650; }
h3 { font-size: var(--text-lg); font-weight: 600; }
p { margin: 0 0 var(--space-3); }
a { color: var(--color-link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: var(--space-2); top: -100px; z-index: 50;
  background: var(--color-surface); padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill); box-shadow: var(--glass-shadow-lift); }
.skip-link:focus { top: var(--space-2); }
.num, time, .date { font-variant-numeric: tabular-nums; }
.muted { color: var(--color-muted); }
.small { font-size: var(--text-sm); }

/* Shared glass recipe (chrome) and the near-opaque content layer. */
.topbar, .tabs, .btn, .pill, .nav__count, .toast, dialog.modal, .skip-link {
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}
.card, .section, .keydate, .day, .table-wrap, .page--auth, .flash, .empty,
dialog.modal--inline, fieldset.group {
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}

/* ---- layout -------------------------------------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--glass); color: var(--color-text);
  box-shadow: inset 0 -1px 0 var(--glass-hairline), 0 1px 12px rgb(0 0 0 / 0.04);
  padding-top: env(safe-area-inset-top); }
.topbar__inner { max-width: var(--page-max); margin: 0 auto;
  padding: var(--space-2) max(var(--space-4), env(safe-area-inset-right)) var(--space-2)
    max(var(--space-4), env(safe-area-inset-left));
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); }
.brand { color: inherit; font: 700 var(--text-lg)/1 var(--font-display); letter-spacing: -0.02em;
  text-decoration: none; min-height: var(--tap); display: inline-flex; align-items: center;
  gap: var(--space-2); }
.brand:hover { text-decoration: none; }
.brand span { font-weight: 500; color: var(--color-muted); }
/* Navigation: a floating capsule of items, the current one raised like a selected tab. */
.nav { display: flex; gap: 2px; flex: 1 1 auto; padding: 3px; border-radius: var(--radius-pill);
  background: var(--glass-fill); overflow-x: auto; scrollbar-width: none; min-width: 0; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: var(--color-text-2); text-decoration: none; padding: 0 var(--space-3); white-space: nowrap;
  min-height: 38px; display: inline-flex; align-items: center; border-radius: var(--radius-pill);
  font-size: var(--text-sm); font-weight: 500;
  transition: background-color var(--duration) var(--ease), color var(--duration) var(--ease); }
.nav a:hover { background: var(--glass); color: var(--color-text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--color-surface); color: var(--color-text); font-weight: 600;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 2px 8px rgb(0 0 0 / 0.06), inset 0 0 0 1px var(--glass-hairline); }
.signout { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }
.signout__who { font-size: var(--text-sm); color: var(--color-muted); }
.page { max-width: var(--page-max); margin: 0 auto;
  padding: var(--space-5) max(var(--space-4), env(safe-area-inset-right)) var(--space-6)
    max(var(--space-4), env(safe-area-inset-left)); }
.page:focus { outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: var(--space-3); margin-bottom: var(--space-4); }
.page-head h1 { margin: 0; }
/* Tabs as an Apple segmented control. */
.tabs { display: flex; width: fit-content; flex-wrap: wrap; gap: 2px; margin-bottom: var(--space-3);
  padding: 3px; border-radius: var(--radius); background: var(--glass-fill); max-width: 100%; }
.tabs + .tabs { margin-top: calc(-1 * var(--space-1)); }
.tabs a { min-height: 36px; display: inline-flex; align-items: center; padding: 0 var(--space-4);
  text-decoration: none; color: var(--color-text-2); font-size: var(--text-sm); font-weight: 500;
  border-radius: 9px; transition: background-color var(--duration) var(--ease); }
.tabs a:hover { background: var(--glass); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--color-text); font-weight: 600; background: var(--color-surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.1), 0 2px 6px rgb(0 0 0 / 0.06); }
.stack > * + * { margin-top: var(--space-4); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.grid-3 { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
.grid-2 { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 768px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .topbar__inner { gap: var(--space-2); }
  .nav { order: 3; flex-basis: 100%; }          /* its own scrollable row under the brand */
  .signout__who { display: none; }
  .page { padding-top: var(--space-4); }
  h1 { font-size: 1.625rem; }
}

/* ---- surfaces ------------------------------------------------------------------------ */
.card, .section { background: var(--glass-strong); border-radius: var(--radius-lg);
  box-shadow: var(--glass-rim), var(--glass-shadow); padding: var(--space-4) var(--space-5); min-width: 0; }
.section { margin-bottom: var(--space-4); }
.card > h2:first-child, .card > header:first-child { margin-top: 0; }
.section__head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: var(--space-2); margin-bottom: var(--space-3); }
.section__head h2 { margin: 0; }
.empty { color: var(--color-muted); padding: var(--space-5) var(--space-4); text-align: center; margin: 0;
  background: var(--glass); border-radius: var(--radius-lg);
  box-shadow: inset 0 0 0 1px var(--color-border); }
@media (max-width: 600px) { .card, .section { padding: var(--space-4); border-radius: 18px; } }

/* ---- buttons (capsules) -------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap); padding: 0 var(--space-5); border-radius: var(--radius-pill); border: 0;
  background: var(--glass); color: var(--color-link);
  box-shadow: var(--glass-rim), 0 1px 3px rgb(0 0 0 / 0.08);
  font: inherit; font-weight: 600; letter-spacing: -0.01em; text-decoration: none; cursor: pointer;
  transition: background-color var(--duration) var(--ease), transform 120ms var(--ease),
    box-shadow var(--duration) var(--ease); }
.btn:hover { background: var(--glass-strong); text-decoration: none;
  box-shadow: var(--glass-rim), 0 4px 14px rgb(0 0 0 / 0.1); }
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--color-primary); color: var(--color-on-primary);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.25), 0 4px 14px rgb(0 113 227 / 0.3); }
.btn--primary:hover { background: var(--color-primary-hover);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.25), 0 6px 18px rgb(0 113 227 / 0.36); }
.btn--danger { color: var(--color-danger); }
.btn--danger:hover { background: var(--color-urgent-bg); }
.btn--ghost { color: var(--color-text); }
.btn--sm { min-height: 34px; padding: 0 var(--space-4); font-size: var(--text-sm); }
.btn--block { width: 100%; }
.btn[disabled], .htmx-request .btn[type="submit"], .btn[aria-disabled="true"] {
  opacity: 0.5; cursor: progress; transform: none; }
@media (pointer: coarse) { .btn--sm { min-height: var(--tap); } }

/* ---- pills (always text + colour, never colour alone) -------------------------------- */
.pill { display: inline-flex; align-items: center; gap: var(--space-1); padding: 3px 10px;
  border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 650; line-height: 1.35;
  letter-spacing: 0; white-space: nowrap; border: 1px solid transparent; }
.pill--urgent { background: var(--color-urgent-bg); color: var(--color-urgent-fg);
  border-color: color-mix(in srgb, var(--color-urgent-line) 45%, transparent); }
.pill--risk { background: var(--color-risk-bg); color: var(--color-risk-fg);
  border-color: color-mix(in srgb, var(--color-risk-line) 45%, transparent); }
.pill--action { background: var(--color-action-bg); color: var(--color-action-fg);
  border-color: color-mix(in srgb, var(--color-action-line) 40%, transparent); }
.pill--ok { background: var(--color-ok-bg); color: var(--color-ok-fg);
  border-color: color-mix(in srgb, var(--color-ok-line) 45%, transparent); }
.pill--muted { background: var(--color-muted-bg); color: var(--color-muted-fg); }

/* ---- forms (iOS-style filled fields with a visible outline) -------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-weight: 600; font-size: var(--text-sm); color: var(--color-text-2); }
.field .helptext, .field [id$="_helptext"] { color: var(--color-muted); font-size: var(--text-sm); }
input, select, textarea { font: inherit; color: var(--color-text); background: var(--color-surface);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius); min-height: var(--tap);
  padding: var(--space-2) var(--space-3); width: 100%; max-width: 100%;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-accent) 30%, transparent); }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--color-primary);
  box-shadow: none; }
input[type="file"] { padding: var(--space-2); }
textarea { min-height: 88px; }
[aria-invalid="true"] { border-color: var(--color-danger); border-width: 2px; }
.errorlist { list-style: none; margin: 0; padding: 0; color: var(--color-danger);
  font-size: var(--text-sm); font-weight: 600; }
.errorlist.nonfield { padding: var(--space-2) var(--space-3); background: var(--color-urgent-bg);
  color: var(--color-urgent-fg); border-radius: var(--radius); margin-bottom: var(--space-3); }
.form-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
  align-items: end; }
.form-grid--wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.check-field { flex-direction: row; align-items: center; gap: var(--space-2); min-height: var(--tap); }
.filters { margin-bottom: var(--space-4); }
.thumbs { list-style: none; margin: 0 0 var(--space-3); padding: 0; display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 130px), 1fr)); }
.thumbs li { min-width: 0; }
.thumbs img { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover;
  border-radius: var(--radius); box-shadow: inset 0 0 0 1px var(--color-border), var(--glass-shadow);
  background: var(--color-surface-2); }
.thumbs__meta { display: block; margin-top: var(--space-1); }
.input--confirm { width: 8rem; }  /* "type the rule name" before going live */

/* ---- tables -------------------------------------------------------------------------- */
.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg); background: var(--glass-strong);
  box-shadow: var(--glass-rim), var(--glass-shadow); }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); overflow-wrap: normal; }
th, td { text-align: left; padding: 10px var(--space-3); border-bottom: 1px solid var(--color-border);
  vertical-align: top; }
th { background: color-mix(in srgb, var(--color-surface) 70%, transparent); font-size: var(--text-xs);
  font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-muted);
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); }
tbody tr { transition: background-color var(--duration) var(--ease); }
tbody tr:hover { background: color-mix(in srgb, var(--color-action-line) 7%, transparent); }
tbody tr:last-child td { border-bottom: 0; }
td.date, th.date { white-space: nowrap; }
caption { text-align: left; padding: var(--space-2) var(--space-3); color: var(--color-muted); }

/* ---- flash / toast ------------------------------------------------------------------- */
.flashes { margin-bottom: var(--space-4); display: grid; gap: var(--space-2); }
.flash { padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); margin: 0 0 var(--space-2);
  background: var(--glass-strong); box-shadow: var(--glass-rim), var(--glass-shadow);
  border-left: 0; position: relative; padding-left: calc(var(--space-4) + 6px); }
.flashes .flash { margin: 0; }
.flash::before { content: ""; position: absolute; left: 8px; top: 10px; bottom: 10px; width: 4px;
  border-radius: 4px; background: var(--color-border-strong); }
.flash--success, .flash--info { background: var(--color-ok-bg); color: var(--color-ok-fg); }
.flash--success::before, .flash--info::before { background: var(--color-ok-line); }
.flash--warning { background: var(--color-risk-bg); color: var(--color-risk-fg); }
.flash--warning::before { background: var(--color-risk-line); }
.flash--error { background: var(--color-urgent-bg); color: var(--color-urgent-fg); }
.flash--error::before { background: var(--color-urgent-line); }
.flash a { color: inherit; text-decoration: underline; }
.toast { position: fixed; left: var(--space-4); right: var(--space-4);
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom)); z-index: 40;
  margin: 0 auto; max-width: 480px; padding: var(--space-3) var(--space-5); border-radius: var(--radius-pill);
  background: rgb(29 29 31 / 0.88); color: #fff; box-shadow: var(--glass-shadow-lift); text-align: center; }

/* ---- dashboard ----------------------------------------------------------------------- */
.bucket { position: relative; overflow: hidden; }
.bucket::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px;
  background: var(--color-border-strong); }
.bucket--urgent::before { background: var(--color-urgent-line); }
.bucket--risk::before { background: var(--color-risk-line); }
.bucket--action::before { background: var(--color-action-line); }
.bucket__head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2);
  margin-bottom: var(--space-3); }
.bucket__head h2 { margin: 0; }
.bucket__hint { color: var(--color-muted); font-size: var(--text-sm); margin-top: calc(-1 * var(--space-2)); }
.job-list { list-style: none; margin: 0; padding: 0; }
.job-list > li { border-top: 1px solid var(--color-border); padding: var(--space-3) 0; }
.job-list > li:first-child { border-top: 0; padding-top: 0; }
.job-line__addr { font-weight: 650; letter-spacing: -0.01em; }
.job-line__meta { color: var(--color-muted); font-size: var(--text-sm); }
.reasons { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-1); }

/* key dates: the most prominent thing on a job */
.dates { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-top: var(--space-1); }
.dates__item { display: flex; flex-direction: column; }
.dates__label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--color-muted); font-weight: 600; }
.dates__value { font-weight: 700; font-variant-numeric: tabular-nums; }
.dates__value--past { color: var(--color-danger); }
.dates__value--none { color: var(--color-muted); font-weight: 400; }
.keydates { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
.keydate { background: var(--glass-strong); border-radius: var(--radius-lg);
  box-shadow: var(--glass-rim), var(--glass-shadow); padding: var(--space-3) var(--space-4); }
.keydate .dates__value { font: 700 var(--text-xl)/1.2 var(--font-display); letter-spacing: -0.02em; display: block; }
.keydate .btn { margin-top: var(--space-2); }

/* job facts */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: var(--space-3) var(--space-4); margin: 0; }
.facts dt { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--color-muted); font-weight: 600; }
.facts dd { margin: 2px 0 0; white-space: pre-line; }

/* inline editing via <details> */
details.edit > summary { cursor: pointer; color: var(--color-link); min-height: var(--tap);
  display: inline-flex; align-items: center; font-weight: 600; }
details.edit[open] { background: var(--glass-fill); padding: var(--space-3); border-radius: var(--radius); }

/* ---- calendar ------------------------------------------------------------------------ */
.week { display: grid; gap: var(--space-2); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1024px) { .week { grid-template-columns: repeat(7, minmax(0, 1fr)); } }
.day { background: var(--glass-strong); border-radius: var(--radius-lg);
  box-shadow: var(--glass-rim), var(--glass-shadow); padding: var(--space-3); min-width: 0; }
.day--today { box-shadow: inset 0 0 0 2px var(--color-primary), var(--glass-shadow); }
.day--weekend { background: var(--glass); }
.day h2 { font-size: var(--text-base); display: flex; justify-content: space-between; gap: var(--space-2); }
.day h3 { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-muted);
  margin: var(--space-3) 0 var(--space-1); }
.day ul { list-style: none; margin: 0; padding: 0; font-size: var(--text-sm); }
.day li { padding: var(--space-1) 0; border-top: 1px solid var(--color-border); }
.day li:first-child { border-top: 0; }

/* ---- pagination ---------------------------------------------------------------------- */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--space-2); margin-top: var(--space-3); }

/* ---- modal (native <dialog>) as a glass sheet ---------------------------------------- */
dialog.modal { border: 0; border-radius: 24px; padding: 0; width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); overflow: auto; color: var(--color-text);
  background: var(--glass-strong); box-shadow: var(--glass-rim), var(--glass-shadow-lift); }
dialog.modal::backdrop { background: rgb(0 0 0 / 0.32);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.modal__head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-5) var(--space-5) 0; }
.modal__head h2 { margin: 0; }
.modal__body { padding: var(--space-4) var(--space-5) var(--space-5); }
.modal__body .field + .field { margin-top: var(--space-3); }

@media print {
  .topbar, .signout, .btn, form { display: none !important; }
  body { background: #fff; }
  body::before { display: none; }
}
.page-sub { margin: 0; }
dialog.modal--inline { position: static; margin: 0 auto; width: 100%; max-width: 560px; max-height: none;
  box-shadow: var(--glass-rim), var(--glass-shadow); }
.reasons .pill { white-space: normal; border-radius: var(--radius); }
.pill a { color: inherit; }

/* ---- sign-in pages (templates/accounts/*) -------------------------------------------- */
.page--auth { max-width: 26rem; margin: 12vh auto var(--space-6); padding: var(--space-6) var(--space-5);
  background: var(--glass-strong); border-radius: 28px; box-shadow: var(--glass-rim), var(--glass-shadow-lift); }
@media (max-width: 480px) { .page--auth { margin: var(--space-5) var(--space-4); } }
.page--auth h1 { font-size: var(--text-2xl); text-align: center; }
.page--auth label { display: block; font-weight: 600; margin-bottom: var(--space-1); color: var(--color-text-2); }
.page--auth button, .page--auth .button { display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 50px; margin-top: var(--space-4); border-radius: var(--radius-pill); border: 0;
  background: var(--color-primary); color: var(--color-on-primary); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; box-shadow: 0 4px 14px rgb(0 113 227 / 0.3);
  transition: background-color var(--duration) var(--ease), transform 120ms var(--ease); }
.page--auth button:hover, .page--auth .button:hover { background: var(--color-primary-hover); text-decoration: none; }
.page--auth button:active, .page--auth .button:active { transform: scale(0.98); }
.page--auth .button.secondary { background: var(--glass); color: var(--color-link);
  box-shadow: var(--glass-rim); }
.page--auth .error { color: var(--color-danger); font-weight: 600; margin: var(--space-2) 0 0; }
.page--auth .note { color: var(--color-text-2); }

/* ---- suggestion inbox (templates/internal/suggestion*.html) -------------------------- */
.nav__count { display: inline-flex; align-items: center; justify-content: center; min-width: 1.25rem;
  height: 1.25rem; margin-left: 6px; padding: 0 6px; border-radius: var(--radius-pill); font-size: var(--text-xs);
  font-weight: 700; background: var(--color-accent-strong); color: #fff; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list > li + li { margin-top: var(--space-1); }
.mailbox-checks { padding: var(--space-3) var(--space-4); }
.review__sub { font-size: var(--text-base); margin: var(--space-4) 0 var(--space-2); }
.mail-body { margin: 0; padding: var(--space-3) var(--space-4); max-height: 32rem; overflow: auto; white-space: pre-wrap;
  overflow-wrap: anywhere; font: var(--text-sm)/1.5 var(--font-mono); background: var(--glass-fill);
  border-radius: var(--radius); }
.quote { margin: 0 0 var(--space-2); padding-left: var(--space-3); border-left: 3px solid var(--color-border-strong);
  color: var(--color-text-2); }
fieldset.group { margin: var(--space-4) 0 0; padding: var(--space-3) var(--space-4) var(--space-4); min-width: 0;
  border: 0; border-radius: var(--radius-lg); background: var(--glass); box-shadow: inset 0 0 0 1px var(--color-border); }
fieldset.group > legend { font-weight: 700; padding: 0 var(--space-1); }
fieldset.group--nested { margin-top: var(--space-3); background: var(--glass-fill); }
fieldset.group--nested > legend { font-weight: 600; font-size: var(--text-sm); }
.choices fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.choices legend { font-weight: 600; font-size: var(--text-sm); padding: 0; margin-bottom: var(--space-1); }
.choices label { display: flex; align-items: flex-start; gap: var(--space-2); min-height: var(--tap);
  padding: var(--space-2) 0; font-weight: 400; font-size: var(--text-base); cursor: pointer; }
input[type="radio"] { width: 22px; height: 22px; min-height: 0; flex: none; margin: 1px 0 0;
  accent-color: var(--color-primary); box-shadow: none; }
.doc-review > li { padding: var(--space-3) 0; border-top: 1px solid var(--color-border); }
.doc-review > li:first-child { border-top: 0; padding-top: 0; }
.doc-review__name { margin-bottom: var(--space-2); }
.review__form + details.edit { margin-top: var(--space-4); }

/* ---- mailbox (templates/internal/mailbox*.html) -------------------------------------- */
.bulk-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--space-2) var(--space-4); margin-bottom: var(--space-2); }
.bulk-bar label { font-weight: 600; cursor: pointer; }
.timeline { margin: 0; padding-left: var(--space-5); }
.timeline > li + li { margin-top: var(--space-2); }

/* Work order lines: grouped rows (countertops, sinks, labor) with an edit sheet per line. */
.line-group + .line-group { margin-top: var(--space-5); }
.line-group__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2);
  margin-bottom: var(--space-1); }
.line-group__head h3 { margin: 0; font-size: var(--text-base); }
.line-list { list-style: none; margin: 0 0 var(--space-2); padding: 0; }
.line-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 7.5rem; align-items: center;
  gap: var(--space-3); padding: var(--space-2) 0; border-top: 1px solid var(--color-border); }
.line-list > .line-row:first-child { border-top: 0; }
.line-row__main { display: grid; gap: 2px; min-height: var(--tap); padding: 6px 10px; margin: 0 -10px;
  border: 0; border-radius: var(--radius); background: transparent; color: inherit; font: inherit;
  text-align: left; cursor: pointer; transition: background-color var(--duration) var(--ease); }
.line-row__main:hover { background: var(--glass-fill); }
.line-row__title { font-weight: 650; letter-spacing: -0.01em; display: flex; flex-wrap: wrap;
  align-items: center; gap: 6px; }
.line-row__sub { color: var(--color-muted); font-size: var(--text-sm); }
.line-row--error .line-row__main { box-shadow: inset 3px 0 0 var(--color-urgent-line); }
.line-row__qty { display: grid; grid-template-columns: 6.5rem auto; align-items: center; column-gap: 6px; }
.line-row__qty input { text-align: right; font-variant-numeric: tabular-nums; }
.line-row__unit { color: var(--color-muted); font-size: var(--text-sm); min-width: 1.5rem; }
.line-row__hint { grid-column: 1 / -1; color: var(--color-muted); font-size: var(--text-xs); text-align: right;
  padding-right: calc(1.5rem + 6px); }
.line-row__qty .errorlist, .line-row__qty .pill { grid-column: 1 / -1; justify-self: end; }
.line-row__check { justify-self: end; }
.line-empty { color: var(--color-muted); font-size: var(--text-sm); padding: var(--space-2) 0; }
.line-group__add { margin-top: var(--space-1); }
/* The "checked" toggle: a capsule that fills green once ticked. */
.toggle-check { position: relative; display: inline-flex; }
.toggle-check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-check span { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 14px;
  border-radius: var(--radius-pill); background: var(--glass); color: var(--color-link); font-size: var(--text-sm);
  font-weight: 600; cursor: pointer; box-shadow: var(--glass-rim);
  transition: background-color var(--duration) var(--ease), color var(--duration) var(--ease); }
.toggle-check span::before { content: ""; width: 14px; height: 14px; border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px currentColor; }
.toggle-check input:checked + span { background: var(--color-ok-bg); color: var(--color-ok-fg); }
.toggle-check input:checked + span::before { background: currentColor;
  box-shadow: inset 0 0 0 3px var(--color-ok-bg); }
.toggle-check input:focus-visible + span { outline: 3px solid var(--color-accent); outline-offset: 2px; }
dialog.line-sheet { width: min(640px, calc(100vw - 32px)); }
@media (max-width: 640px) {
  .line-row { grid-template-columns: minmax(0, 1fr) auto; }
  .line-row__main { grid-column: 1 / -1; }
  .line-row__check { align-self: center; }
}
.notes-preview { white-space: pre-wrap; margin: 0; font: inherit; color: var(--color-text-2); }

/* ---- accessibility fallbacks --------------------------------------------------------- */
/* Reduced transparency, or no backdrop-filter support: solid surfaces, same contrast. */
@media (prefers-reduced-transparency: reduce) {
  :root { --glass: var(--color-surface); --glass-strong: var(--color-surface); --backdrop: none; }
  *, *::before, *::after { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root { --glass: var(--color-surface); --glass-strong: var(--color-surface); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .btn:active, .page--auth button:active { transform: none; }
}
@media (forced-colors: active) {
  .card, .section, .table-wrap, .keydate, .day, .btn, .pill, .flash, dialog.modal, .nav a[aria-current="page"],
  .tabs a[aria-current="page"], .page--auth { border: 1px solid CanvasText; }
}
