/* ==========================================================================
   Healing Touch — Package Expiry Notifier
   Operator UI.

   Every colour in this file comes from a token, so the light and dark themes
   stay in step. If you need a new colour, add a token in all three theme
   states below rather than writing a hex value into a component rule.
   ========================================================================== */

/* --- tokens ---------------------------------------------------------------
   Three theme states have to resolve correctly:

     bare :root                    light — and the default nobody chose
     prefers-color-scheme: dark    dark, unless the operator stamped light
     [data-theme="dark"|"light"]   the operator's explicit choice, wins both ways

   Two colour jobs are kept deliberately separate:

     the milestone ramp (--ms-*)   ordinal: how close the expiry is. One hue,
                                   light to dark. A 7-day reminder is not an
                                   error, so it never borrows the status red.
     status (--ok/warn/crit/info)  reserved for problems: no email on file, a
                                   record needing a human, missing config,
                                   a failed send.

   The ramp was checked with the palette validator: worst adjacent pair
   ΔE 16.4 (protanopia) / 17.8 (normal vision), both above the gate. Its two
   palest steps fall under 3:1 against the surface, so every segment that uses
   them carries a visible label — see .meter and .ms-chip.
   ------------------------------------------------------------------------ */

:root {
  color-scheme: light;

  --ground: #f2eeee;
  --paper: #ffffff;
  --paper-2: #faf7f7;
  --paper-sunken: #ece7e7;

  --line: #e7dedd;
  --line-control: #a08e8f;

  --ink: #241c1d;
  --ink-2: #5a4c4d;
  --ink-3: #756364;

  --accent: #4a1f22;
  --accent-lift: #6b3034;
  --accent-tint: #f4e9e8;
  --on-accent: #fffaf9;

  --ok: #16704a;
  --ok-tint: #e6f2ec;
  --warn: #91600d;
  --warn-tint: #fbf1de;
  --crit: #a83226;
  --crit-tint: #fbe9e7;
  --info: #2a5a75;
  --info-tint: #e8f1f6;

  /* Milestone ramp: --ms-1 is the furthest from expiry, --ms-4 the closest. */
  --ms-1: #e5cdc9;
  --ms-2: #b8827e;
  --ms-3: #8a4643;
  --ms-4: #4a1f22;
  --ms-1-ink: #241c1d;
  --ms-2-ink: #241c1d;
  --ms-3-ink: #fffaf9;
  --ms-4-ink: #fffaf9;

  --shadow-sm: 0 1px 2px rgba(36, 28, 29, 0.06);
  --shadow-md: 0 1px 2px rgba(36, 28, 29, 0.05), 0 10px 24px -14px rgba(36, 28, 29, 0.22);
  --shadow-lg: 0 24px 60px -20px rgba(36, 28, 29, 0.38);

  /* A modal scrim and a toast must stay dark in BOTH themes, so neither can be
     mixed from --ink — that token inverts and would wash the page pale. */
  --scrim: rgba(36, 28, 29, 0.62);
  --toast-bg: #241c1d;
  --toast-ink: #f6f1f1;

  /* Type roles. Georgia carries the brand across from the reminder email;
     the mono face is for identifiers staff retype into the POS, where
     0/O and 1/l need to stay distinct. */
  --font-display: Georgia, "Times New Roman", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-data: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --t-xs: 11.5px;
  --t-sm: 13px;
  --t-base: 14.5px;
  --t-md: 16px;
  --t-lg: 19px;
  --t-xl: 24px;
  --t-hero: clamp(38px, 6vw, 52px);

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --speed: 0.16s;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --ground: #171213;
    --paper: #201819;
    --paper-2: #291f21;
    --paper-sunken: #130f10;

    --line: #362a2c;
    --line-control: #826d70;

    --ink: #f2e9e9;
    --ink-2: #c3b2b3;
    --ink-3: #9a8788;

    /* Plum is too dark to carry the accent on a dark ground, so it lifts to a
       dusty rose off the same hue — the brand reads, the text stays legible. */
    --accent: #e6a8a4;
    --accent-lift: #f2c0bc;
    --accent-tint: #352426;
    --on-accent: #2a1416;

    --ok: #6fc79c;
    --ok-tint: #16302a;
    --warn: #e0ad5a;
    --warn-tint: #33270f;
    --crit: #f09287;
    --crit-tint: #3a1c19;
    --info: #86bcd8;
    --info-tint: #14262f;

    /* Sequential ramps flip their anchor in dark: closest to expiry is now
       the lightest step, so "more urgent" still means "more presence". */
    --ms-1: #4a2225;
    --ms-2: #8f524d;
    --ms-3: #c58a80;
    --ms-4: #f2cac1;
    --ms-1-ink: #f2e9e9;
    --ms-2-ink: #f2e9e9;
    --ms-3-ink: #241416;
    --ms-4-ink: #241416;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.45), 0 10px 24px -14px rgba(0, 0, 0, 0.75);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.85);

    --scrim: rgba(8, 5, 6, 0.74);
    --toast-bg: #3a2d2f;
    --toast-ink: #f6efef;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --ground: #171213;
  --paper: #201819;
  --paper-2: #291f21;
  --paper-sunken: #130f10;

  --line: #362a2c;
  --line-control: #826d70;

  --ink: #f2e9e9;
  --ink-2: #c3b2b3;
  --ink-3: #9a8788;

  --accent: #e6a8a4;
  --accent-lift: #f2c0bc;
  --accent-tint: #352426;
  --on-accent: #2a1416;

  --ok: #6fc79c;
  --ok-tint: #16302a;
  --warn: #e0ad5a;
  --warn-tint: #33270f;
  --crit: #f09287;
  --crit-tint: #3a1c19;
  --info: #86bcd8;
  --info-tint: #14262f;

  --ms-1: #4a2225;
  --ms-2: #8f524d;
  --ms-3: #c58a80;
  --ms-4: #f2cac1;
  --ms-1-ink: #f2e9e9;
  --ms-2-ink: #f2e9e9;
  --ms-3-ink: #241416;
  --ms-4-ink: #241416;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.45), 0 10px 24px -14px rgba(0, 0, 0, 0.75);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.85);

  --scrim: rgba(8, 5, 6, 0.74);
  --toast-bg: #3a2d2f;
  --toast-ink: #f6efef;
}

/* --- base ---------------------------------------------------------------- */

* { box-sizing: border-box; }

/* A class that sets `display` outbids the user-agent rule for [hidden], which
   would leave modals stuck on screen. Keep this ahead of every layout rule. */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--t-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 400;
  text-wrap: balance;
  margin: 0;
}

p { margin: 0; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

code, .mono { font-family: var(--font-data); font-size: 0.92em; }

code {
  background: var(--paper-sunken);
  padding: 1px 5px;
  border-radius: var(--r-xs);
}

.muted { color: var(--ink-3); }
.small { font-size: var(--t-sm); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Digits that stack in a column must not shift width as they change. */
.num, .metric-value, .hero-value, td.num, .meter-count { font-variant-numeric: tabular-nums; }

/* One focus treatment, applied once, so nothing can quietly opt out. */
:where(a, button, input, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- topbar -------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
  padding: var(--s3) var(--s5);
  background: var(--accent);
  color: var(--on-accent);
}

.brand { display: flex; flex-direction: column; gap: 1px; }
.brand-mark {
  font-family: var(--font-display);
  font-size: var(--t-md);
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.brand-sub {
  font-size: var(--t-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.72;
}

.topbar-side { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }

/* Config state reads at a glance instead of hiding in a run of grey text —
   a missing Brevo key disables sending, so it can't be a footnote. */
.status-chips { display: flex; gap: var(--s2); flex-wrap: wrap; }
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--on-accent) 12%, transparent);
  font-size: var(--t-xs);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.status-chip::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.status-chip.is-bad {
  background: var(--crit-tint);
  color: var(--crit);
  font-weight: 600;
}
.status-chip.is-warn { background: var(--warn-tint); color: var(--warn); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border: 1px solid color-mix(in srgb, var(--on-accent) 34%, transparent);
  border-radius: 999px;
  background: none;
  color: inherit;
  font-size: var(--t-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--speed), border-color var(--speed);
}
.theme-toggle:hover { background: color-mix(in srgb, var(--on-accent) 14%, transparent); }
.theme-toggle:focus-visible { outline-color: var(--on-accent); }

/* --- layout -------------------------------------------------------------- */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--s5) var(--s4) var(--s7);
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

/* Steps 2 and 3 appear together once an export is loaded, so they share the
   same rhythm as step 1 above them. */
#results {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  min-width: 0;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s5);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  min-width: 0;
}

.card-head { display: flex; flex-direction: column; gap: var(--s1); }

.card h2 {
  font-size: var(--t-lg);
  display: flex;
  align-items: center;
  gap: var(--s3);
  color: var(--ink);
}

/* The steps are numbered because the work genuinely is a sequence: you cannot
   review before loading, or send before reviewing. */
.step {
  display: inline-grid;
  place-items: center;
  width: 26px; height: 26px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-ui);
  font-size: var(--t-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.lede { color: var(--ink-2); max-width: 68ch; }

/* --- controls ------------------------------------------------------------ */

.row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}

button, input, select { font: inherit; color: inherit; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field-grow { flex: 1 1 240px; }
.field-label {
  font-size: var(--t-xs);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 600;
}

input[type="search"],
input[type="email"],
input[type="date"],
select {
  padding: 8px 11px;
  border: 1px solid var(--line-control);
  border-radius: var(--r-sm);
  background: var(--paper);
  color: var(--ink);
  min-width: 190px;
  transition: border-color var(--speed), box-shadow var(--speed);
}
input[type="search"]:hover, input[type="email"]:hover, select:hover { border-color: var(--ink-3); }
/* Search boxes sit inside a column-flex .field, so growth belongs to the field
   (see .field-grow) — a `flex` shorthand here would set the input's HEIGHT. */
input[type="search"] { width: 100%; }
input::placeholder { color: var(--ink-3); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: 9px 17px;
  border: 1px solid var(--line-control);
  border-radius: var(--r-sm);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-weight: 500;
  transition: background var(--speed), border-color var(--speed), color var(--speed);
}
.btn:hover:not(:disabled) { background: var(--paper-2); border-color: var(--ink-3); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-lift); border-color: var(--accent-lift); }

.btn-lg { padding: 12px 22px; font-size: var(--t-md); }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  font: inherit;
}
.link:hover { color: var(--accent-lift); }

/* --- step 1: dropzone ---------------------------------------------------- */

.dropzone {
  display: grid;
  place-items: center;
  gap: var(--s2);
  padding: var(--s6) var(--s5);
  border: 1.5px dashed var(--line-control);
  border-radius: var(--r-md);
  background: var(--paper-2);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--speed), background var(--speed);
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.is-over {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-tint);
}
.dropzone-icon { color: var(--ink-3); }
.dropzone.is-over .dropzone-icon { color: var(--accent); }
.dropzone-title { font-size: var(--t-md); }

/* Loaded-file state, so it's never ambiguous which export is on screen. */
.file-state {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
  padding: 10px var(--s3);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ok);
  border-radius: var(--r-sm);
  background: var(--ok-tint);
  font-size: var(--t-sm);
}
.file-state .file-name { font-family: var(--font-data); font-weight: 600; }
.file-state.is-error { border-left-color: var(--crit); background: var(--crit-tint); color: var(--crit); }
.file-state.is-busy { border-left-color: var(--info); background: var(--info-tint); color: var(--info); }

/* --- scope bar ----------------------------------------------------------- */

/* Sending targets the *filtered* list, so the count that Send would actually
   act on follows you down a 900-row table rather than sitting out of sight. */
.scopebar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
  padding: 10px var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
}
.scopebar-main { display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; }
.scopebar-count {
  font-family: var(--font-display);
  font-size: var(--t-xl);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.scopebar-label { color: var(--ink-2); font-size: var(--t-sm); }
.scopebar.is-filtered { border-color: var(--warn); }

.filter-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--warn-tint);
  color: var(--warn);
  font-size: var(--t-xs);
  font-weight: 600;
}

/* --- step 2: figures ----------------------------------------------------- */

.review-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.85fr) 2fr;
  gap: var(--s4);
  align-items: stretch;
}
@media (max-width: 780px) {
  .review-grid { grid-template-columns: 1fr; }
}

/* The one number the tool exists to produce gets hero treatment; everything
   else is context and stays quiet. */
.hero {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--s1);
  padding: var(--s4) var(--s5);
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--on-accent);
}
.hero-value {
  font-family: var(--font-display);
  font-size: var(--t-hero);
  line-height: 1;
}
.hero-label {
  font-size: var(--t-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.8;
}
.hero-note { font-size: var(--t-sm); opacity: 0.85; }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--s2);
  margin: 0;
}
/* A description list is the honest markup for label/value pairs, and it puts
   dt before dd — column-reverse lets the value still read first. */
.metrics dt, .metrics dd { margin: 0; }
.metric {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
  gap: 1px;
  padding: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper);
}
.metric-value { font-size: var(--t-xl); line-height: 1.15; font-weight: 600; }
.metric-label {
  font-size: var(--t-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 600;
}
/* A metric that is only interesting when it isn't zero says so in its colour. */
.metric.is-flagged { border-color: var(--warn); background: var(--warn-tint); }
.metric.is-flagged .metric-value, .metric.is-flagged .metric-label { color: var(--warn); }

/* --- milestone meter ----------------------------------------------------- */

/* Part-to-whole across an ordered scale: a stacked bar on the plum ramp, so
   the shape of today's batch (mostly gentle 6-month notices? mostly 7-day
   scrambles?) reads before any number does. Every segment is labelled — the
   two palest ramp steps sit below 3:1 on the surface, so colour alone would
   not be enough to identify them. */
.meter-block { display: flex; flex-direction: column; justify-content: center; gap: var(--s2); }
.meter-title {
  font-size: var(--t-xs);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 600;
}
.meter {
  display: flex;
  gap: 2px; /* surface gap between segments, per the mark spec */
  height: 30px;
  border-radius: var(--r-xs);
  overflow: hidden;
}
.meter-seg {
  display: grid;
  place-items: center;
  min-width: 2px;
  font-size: var(--t-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  border-radius: 2px;
}
.meter-empty {
  height: 30px;
  border: 1px dashed var(--line-control);
  border-radius: var(--r-xs);
  display: grid;
  place-items: center;
  color: var(--ink-3);
  font-size: var(--t-sm);
}
.meter-legend {
  display: flex;
  gap: var(--s3);
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--t-sm);
}
.meter-legend li { display: flex; align-items: center; gap: 6px; }
/* The ring has to be strong enough that the ramp's darkest step still reads as
   a swatch against a dark surface, where fill and ground nearly coincide. */
.meter-swatch {
  width: 11px; height: 11px;
  border-radius: 2px;
  flex: none;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--ink) 38%, transparent);
}
.meter-count { font-weight: 600; }
.meter-legend .muted { color: var(--ink-3); }

/* Ramp slots. Referenced by data-ms so JS never writes a colour.
   Scoped to the three things that take a ramp *fill* — a bare [data-ms]
   selector would also match the <tr data-ms> rows, which only want the
   3px stripe set further down. */
:is(.meter-seg, .meter-swatch, .ms-chip)[data-ms="1"] { background: var(--ms-1); color: var(--ms-1-ink); }
:is(.meter-seg, .meter-swatch, .ms-chip)[data-ms="2"] { background: var(--ms-2); color: var(--ms-2-ink); }
:is(.meter-seg, .meter-swatch, .ms-chip)[data-ms="3"] { background: var(--ms-3); color: var(--ms-3-ink); }
:is(.meter-seg, .meter-swatch, .ms-chip)[data-ms="4"] { background: var(--ms-4); color: var(--ms-4-ink); }

/* --- notices ------------------------------------------------------------- */

.notices { display: flex; flex-direction: column; gap: var(--s2); }

.notice {
  display: flex;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--r-sm);
  font-size: var(--t-base);
}
.notice-icon { flex: none; font-weight: 700; line-height: 1.45; }
.notice-body { display: flex; flex-direction: column; gap: var(--s1); }
.notice-title { font-weight: 600; }

.notice.is-warn { background: var(--warn-tint); border-left-color: var(--warn); }
.notice.is-warn .notice-icon, .notice.is-warn .notice-title { color: var(--warn); }
.notice.is-crit { background: var(--crit-tint); border-left-color: var(--crit); }
.notice.is-crit .notice-icon, .notice.is-crit .notice-title { color: var(--crit); }
.notice.is-info { background: var(--info-tint); border-left-color: var(--info); }
.notice.is-info .notice-icon, .notice.is-info .notice-title { color: var(--info); }
.notice.is-ok { background: var(--ok-tint); border-left-color: var(--ok); }
.notice.is-ok .notice-icon, .notice.is-ok .notice-title { color: var(--ok); }

/* --- tabs ---------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: var(--s1);
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: 10px var(--s3);
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
  font-weight: 500;
  transition: color var(--speed), border-color var(--speed);
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tab-count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--paper-sunken);
  color: var(--ink-2);
  font-size: var(--t-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.tab[aria-selected="true"] .tab-count { background: var(--accent-tint); color: var(--accent); }
/* A count that means "someone has to deal with this" is not neutral. */
.tab-count.is-flagged { background: var(--warn-tint); color: var(--warn); }

/* min-width: 0 keeps the table's 720px minimum inside .table-wrap's own
   scroller instead of widening the card and the page body. */
.panel { display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }
.panel:focus-visible { outline-offset: 4px; }

.panel-note { color: var(--ink-2); max-width: 84ch; font-size: var(--t-sm); }

.toolbar {
  display: flex;
  align-items: flex-end;
  gap: var(--s2);
  flex-wrap: wrap;
}
.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--s3); }
.toolbar-right.is-leading { margin-left: 0; }
.result-count { font-size: var(--t-sm); color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* --- tables -------------------------------------------------------------- */

.table-wrap {
  overflow: auto;
  max-height: 60vh;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper);
}
/* min-width makes a narrow viewport scroll the table rather than crush every
   column into two-line wraps. */
table {
  width: 100%;
  min-width: 720px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--t-base);
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--paper-2);
  text-align: left;
  padding: 9px var(--s3);
  border-bottom: 1px solid var(--line);
  font-size: var(--t-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
  font-weight: 700;
  white-space: nowrap;
}
th.num { text-align: right; }

/* Sortable headers look interactive, and say which way they're pointing. */
th.sortable { padding: 0; }
th.sortable button {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 9px var(--s3);
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
th.num.sortable button { justify-content: flex-end; }
th.sortable button:hover { color: var(--accent); }
th.sortable .arrow { opacity: 0; font-size: 9px; }
th[aria-sort="ascending"] .arrow, th[aria-sort="descending"] .arrow { opacity: 1; }
th[aria-sort] button { color: var(--accent); }

td {
  padding: 9px var(--s3);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--paper-2); }
/* `width: 1%` on an auto-layout table collapses a column to its content, so the
   numeric, date and action columns stay tight and the email column — the only
   one that benefits from slack — absorbs whatever is left. */
td.num, th.num, td.nowrap, td.actions, th:last-child { width: 1%; }
td.num { text-align: right; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }

.cell-stack { display: flex; flex-direction: column; gap: 1px; }
/* An email address has no natural break opportunity, so a long one sets the
   column's minimum width and forces the whole table into horizontal scroll. */
.cell-email { overflow-wrap: anywhere; }
.cell-sub { font-size: var(--t-sm); color: var(--ink-3); }
/* A customer code is one token staff read out and retype — never break it. */
.cell-code {
  font-family: var(--font-data);
  font-size: var(--t-sm);
  color: var(--ink-3);
  white-space: nowrap;
}

/* The reason column can push a 7-column table past the viewport, so the row's
   action stays pinned to the right edge instead of scrolling out of reach. */
td.actions, th:last-child {
  position: sticky;
  right: 0;
  background: var(--paper);
  border-left: 1px solid var(--line);
  /* Reads as pinned when a wide table does scroll underneath it. */
  box-shadow: -6px 0 8px -6px color-mix(in srgb, var(--ink) 22%, transparent);
}
th:last-child { background: var(--paper-2); z-index: 2; }
tbody tr:hover td.actions { background: var(--paper-2); }

/* The urgency stripe restates the milestone chip at the row edge, so a long
   table can be scanned down the left margin alone. */
tbody tr[data-ms] td:first-child { box-shadow: inset 3px 0 0 var(--stripe, transparent); }
tbody tr[data-ms="1"] { --stripe: var(--ms-1); }
tbody tr[data-ms="2"] { --stripe: var(--ms-2); }
tbody tr[data-ms="3"] { --stripe: var(--ms-3); }
tbody tr[data-ms="4"] { --stripe: var(--ms-4); }

.ms-chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: var(--r-xs);
  font-size: var(--t-xs);
  font-weight: 700;
  white-space: nowrap;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--r-xs);
  background: var(--paper-sunken);
  color: var(--ink-2);
  font-size: var(--t-xs);
  font-weight: 600;
  white-space: nowrap;
}
.tag.is-crit { background: var(--crit-tint); color: var(--crit); }
.tag.is-warn { background: var(--warn-tint); color: var(--warn); }

.none { color: var(--ink-3); font-style: italic; }

.empty {
  padding: var(--s6) var(--s4);
  text-align: center;
  color: var(--ink-2);
}
.empty-title { font-family: var(--font-display); font-size: var(--t-md); color: var(--ink); }

/* --- step 3: send -------------------------------------------------------- */

/* Scope is restated in full next to the button, because the button is
   irreversible and the count depends on filters set far up the page. */
.send-scope {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  background: var(--paper-2);
}
.send-scope-count {
  font-family: var(--font-display);
  font-size: var(--t-xl);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.send-scope.is-blocked { border-left-color: var(--crit); background: var(--crit-tint); }

.send-actions { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }

.test-block {
  border-top: 1px solid var(--line);
  padding-top: var(--s3);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}
.test-block > summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
  width: fit-content;
}
.test-block[open] > summary { margin-bottom: var(--s1); }

.progress { display: flex; flex-direction: column; gap: var(--s2); }
.progress-track {
  height: 10px;
  background: var(--paper-sunken);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease-out;
}
.progress.is-done .progress-fill { background: var(--ok); }
.progress-text { font-size: var(--t-sm); color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* The run report is a panel, not a toast: the counts are the record of what
   just happened and must stay on screen. */
.report {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s4);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ok);
  border-radius: var(--r-sm);
  background: var(--ok-tint);
}
.report.has-failures { border-left-color: var(--crit); background: var(--crit-tint); }
.report-title { font-family: var(--font-display); font-size: var(--t-md); }
.report-figures { display: flex; gap: var(--s5); flex-wrap: wrap; }
.report-figure { display: flex; flex-direction: column; }
.report-figure-value { font-size: var(--t-lg); font-weight: 600; font-variant-numeric: tabular-nums; }
.report-figure-label {
  font-size: var(--t-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
  font-weight: 600;
}

/* --- overlays ------------------------------------------------------------ */

.overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: grid;
  place-items: center;
  padding: var(--s5);
  z-index: 40;
  animation: fade var(--speed) ease-out;
}
@keyframes fade { from { opacity: 0; } }

.preview-panel {
  background: var(--paper);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: min(780px, 100%);
  height: min(88vh, 920px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s4);
  border-bottom: 1px solid var(--line);
}
.preview-head-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.preview-name { font-family: var(--font-display); font-size: var(--t-md); }
.preview-meta { font-size: var(--t-sm); color: var(--ink-2); word-break: break-word; }
/* Sunken ground behind the iframe so the email reads as an email. */
.preview-stage { flex: 1; background: var(--paper-sunken); padding: var(--s3); min-height: 0; }
#previewFrame {
  width: 100%; height: 100%;
  border: 0;
  border-radius: var(--r-sm);
  /* Deliberately not themed: the email renders on white wherever it lands, so
     the preview has to show white even when the app around it is dark. */
  background: #fff;
}

.confirm-panel {
  background: var(--paper);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--s5);
  width: min(500px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}
.confirm-panel h2 { font-size: var(--t-lg); }
.confirm-body { color: var(--ink-2); }
.confirm-figure {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-sm);
  background: var(--paper-2);
  border-left: 3px solid var(--accent);
}
.confirm-figure-value {
  font-family: var(--font-display);
  font-size: var(--t-xl);
  font-variant-numeric: tabular-nums;
}
.confirm-panel .row { justify-content: flex-end; margin-top: var(--s1); }

/* --- toasts -------------------------------------------------------------- */

/* A stack, not a single slot: the old single node meant a second message
   silently destroyed the first. */
.toasts {
  position: fixed;
  bottom: var(--s5);
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--s2);
  width: min(520px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  padding: 11px var(--s4);
  border-radius: var(--r-sm);
  background: var(--toast-bg);
  color: var(--toast-ink);
  box-shadow: var(--shadow-lg);
  font-size: var(--t-base);
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}
/* Status toasts keep the dark surface and carry their state in a stripe. Tinting
   the whole toast would put light text on --crit/--ok, which lighten in dark
   mode — white on the dark-mode salmon is about 1.9:1. */
.toast.is-error { border-left: 3px solid var(--crit); }
.toast.is-ok { border-left: 3px solid var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- narrow screens ------------------------------------------------------ */

@media (max-width: 620px) {
  .topbar { padding: var(--s3) var(--s4); }
  .card { padding: var(--s4); }
  main { padding: var(--s4) var(--s3) var(--s6); }
  .scopebar { padding: var(--s2) var(--s3); }
  .toolbar-right { margin-left: 0; width: 100%; }
}

/* --- signed-in user ------------------------------------------------------ */

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding-left: var(--s3);
  border-left: 1px solid rgba(255, 255, 255, 0.18);
  font-size: var(--t-sm);
}
.user-name { font-weight: 600; }
.user-role {
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  opacity: 0.7;
}
.user-chip .link { color: inherit; opacity: 0.85; }
