/* ===========================================================================
   ABI Wellness portal — visual system.

   Four surfaces, one accent, and depth used to say what a thing is for.

   The portal is read all day by people doing finance and operations work, so
   the hierarchy is: where am I, what is the state, what is the number, what
   can I do, what am I working on. Everything below exists to make that order
   legible without reading.

   Depth is functional, not decorative. There are exactly four levels --
   canvas, surface, raised, overlay -- and a page usually has one to three
   raised surfaces: its summary, its controls and its data. Rows, badges and
   buttons never get their own shadow.

   Colour is mostly absent. Roughly nine tenths of a page is neutral; navy
   marks what is interactive and the semantic colours are used only where
   they carry meaning (a status, a warning, money that went backwards). The
   brand green appears once, on the mark in the sidebar.
   =========================================================================== */

:root {
  /* --- surfaces, in the order they stack ------------------------------- */
  --canvas: #f4f6f9;
  --surface: #ffffff;
  --surface-subtle: #f7f9fc;
  --surface-hover: #f1f5fa;
  --surface-sunken: #eef2f7;

  /* Older names, kept so every rule written against them re-skins with the
     rest of the file rather than being hunted down one at a time. */
  --bg: var(--canvas);

  --line: #e1e6ed;
  --line-strong: #c9d2dd;

  --ink: #172033;
  --muted: #68738a;
  --faint: #8b95a8;

  /* Navy is the interactive colour: primary buttons, the active nav row,
     emphasis bars. Links are the one blue, so a link inside a table still
     reads as a link and a navy button still reads as the primary action. */
  --accent: #1b2a44;
  --accent-hover: #26385a;
  --accent-ink: #ffffff;
  --accent-soft: #eaeff7;
  --link: #175cd3;
  --link-hover: #11408f;
  --brand: #14746a;

  --sidebar: #16213a;
  --sidebar-ink: #b9c4d6;
  --sidebar-ink-strong: #ffffff;
  --sidebar-active: rgba(255, 255, 255, 0.10);
  --sidebar-line: rgba(255, 255, 255, 0.08);

  --ok-bg: #e9f6ee;
  --ok-ink: #116434;
  --warn-bg: #fff6e0;
  --warn-ink: #8a5a00;
  --error: #b42318;
  --error-bg: #fdefee;
  --info-bg: #eef4ff;
  --info-ink: #1849a9;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 12px;

  /* Two shadows, each with a job. Raised: a work surface lifted off the
     canvas. Overlay: something floating over the page. */
  --shadow-raised:
    0 1px 2px rgba(16, 24, 40, 0.05),
    0 3px 8px rgba(16, 24, 40, 0.05);
  --shadow-overlay: 0 10px 30px rgba(16, 24, 40, 0.16);
  --shadow: var(--shadow-raised);

  --focus-ring: 0 0 0 3px rgba(23, 92, 211, 0.22);

  --sidebar-w: 232px;
  --header-h: 56px;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--canvas);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

h1, h2, h3 { margin: 0 0 0.4rem; line-height: 1.25; }
h1 { font-size: 1.625rem; line-height: 2.125rem; font-weight: 680; letter-spacing: -0.018em; }
h2 { font-size: 0.9375rem; font-weight: 650; }
h3 { font-size: 0.9375rem; font-weight: 650; }
p { margin: 0 0 0.7rem; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 0.8125rem; }
.error { color: var(--error); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

/* Money, counts, identifiers and periods line up column to column. */
.num, .kpi-value, .figure, .tab-count, td.num, th.num,
.summary-value, .stat-value { font-variant-numeric: tabular-nums; }

/* 16px inline icons. Hand-written paths in the templates; no icon font, no
   build step, no coloured bubbles. */
.icon {
  width: 16px;
  height: 16px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 14px; height: 14px; }

/* ----- Auth (login) ------------------------------------------------------ */
/* A plain canvas. The diagonal navy wedge read as a marketing landing
   page; this is an internal portal, and the only thing on the screen that
   should draw the eye is the one card you have to fill in. */
.auth-body {
  background: var(--canvas);
  min-height: 100vh;
}
.auth-main {
  min-height: 100vh;
  display: flex;
  /* One column, not a row. base.html puts the message list and the page's
     own content side by side inside this element, so as a row a "your
     session expired" banner lands beside the sign-in card instead of above
     it. With a single child -- every page here before now -- the two lay
     out identically. */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
/* Only the banner is sized here. The sign-in shell and the error panels
   keep the widths they already had, so those pages do not move. */
.auth-main > .messages {
  width: 100%;
  max-width: 420px;
}
/* The session-expired banner spans the same measure as the composition. */
.auth-main > .messages { max-width: 420px; }
@media (min-width: 880px) {
  .auth-main > .messages { max-width: 840px; }
}
/* ----- Sign-in entry screen ---------------------------------------------
   Rendered at `/` and at `/login/`. Two areas on a desktop -- who this is,
   and the one thing to do -- and one column on a phone.

   The identity panel is LIGHT. accessbio-logo.png has an opaque white
   background, so a dark panel would show a white rectangle floating on
   navy. The colours below are sampled from the logo itself: #34354A is its
   wordmark ink and #91C94E its mark. Nothing here is an invented brand
   palette, and the logo is never recoloured or cropped.
   ------------------------------------------------------------------------ */
.signin {
  width: 100%;
  max-width: 420px;
  display: grid;
  gap: 1rem;
}
@media (min-width: 880px) {
  .signin {
    /* ~45% identity / ~55% form. */
    max-width: 880px;
    grid-template-columns: 45fr 55fr;
    gap: 0;
    align-items: stretch;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-raised);
    overflow: hidden;
    background: var(--surface);
  }
}

/* --- identity ----------------------------------------------------------- */
.signin-identity {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1.1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  /* A quiet strip of the logo's own green, so the panel belongs to the mark
     rather than to a palette somebody invented for it. */
  border-top: 3px solid #91c94e;
}
@media (min-width: 880px) {
  .signin-identity {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 1.5rem;
    padding: 2.5rem;
    border: none;
    border-right: 1px solid var(--line);
    border-top: none;
    border-left: 3px solid #91c94e;
    border-radius: 0;
    /* WHITE, not the subtle grey, because the logo's own background is
       opaque white -- on anything else it reads as a pale rectangle pasted
       onto the panel. The divider and the green edge do the separating. */
    background: var(--surface);
  }
}
/* Its own aspect ratio, never stretched. Capped by width so the intrinsic
   720x155 scales down intact. */
.signin-logo {
  display: block;
  width: 150px;
  height: auto;
  flex: none;
}
@media (min-width: 880px) {
  .signin-logo { width: 232px; }
}
.signin-identity-text h1 {
  margin: 0;
  font-size: 1.125rem;
  line-height: 1.3;
  letter-spacing: -0.005em;
  color: #34354a;
}
.signin-identity-text p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
}
@media (min-width: 880px) {
  .signin-identity-text h1 { font-size: 1.5rem; }
  .signin-identity-text p { font-size: 0.875rem; }
}

/* --- the form ----------------------------------------------------------- */
.signin-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-raised);
  padding: 1.5rem 1.6rem 1.65rem;
}
@media (min-width: 880px) {
  .signin-panel {
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
/* 360-420px of form, centred in the right-hand region. */
.signin-form {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
}
.signin-form h2 {
  margin: 0 0 1rem;
  font-size: 1.0625rem;
}
.signin-submit { margin-top: 1.1rem; }
.signin-note {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
}
.signin-note:first-of-type { margin-top: 1rem; }
.signin-footer {
  margin: 1.5rem 0 0;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 0.75rem;
}

/* A short screen, or a phone with the keyboard open, scrolls rather than
   clipping the form. .auth-main centres with justify-content, which on an
   overflowing flex column would otherwise cut off the top. */
.signin-body .auth-main {
  justify-content: flex-start;
  padding-top: clamp(1.25rem, 6vh, 4rem);
  padding-bottom: clamp(1.25rem, 6vh, 4rem);
}
@media (min-height: 720px) {
  .signin-body .auth-main { justify-content: center; }
}
/* The sign-in screen's own measure. Scoped to .signin-body and placed after
   the shared rules above, so it overrides them HERE and nowhere else -- the
   error pages keep their 840px. */
.signin-body .auth-main > .messages { max-width: 420px; }
@media (min-width: 880px) {
  .signin-body .auth-main > .messages { max-width: 880px; }
}

.form-error-box {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid #f2c4c0;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  margin: 0.8rem 0;
  font-size: 0.875rem;
  font-weight: 500;
}

/* ----- App shell --------------------------------------------------------- */
.app-body { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  z-index: 40;
}
.sidebar a { color: inherit; text-decoration: none; }
.sidebar-brand {
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid var(--sidebar-line);
}
.sidebar-brand a {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  border-radius: 8px;
}
.sidebar-brand a:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
}
.brand-text strong {
  font-size: 0.875rem;
  font-weight: 650;
  color: var(--sidebar-ink-strong);
}
.brand-text small {
  color: rgba(185,196,214,0.72);
  font-size: 0.6875rem;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0.6rem 0.5rem 1.25rem;
  gap: 1px;
  overflow-y: auto;
}
.sidebar-nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 38px;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  color: var(--sidebar-ink);
  font-size: 0.875rem;
  transition: background-color 120ms ease, color 120ms ease;
}
.sidebar-nav a .icon { opacity: 0.72; }
.sidebar-nav a:hover {
  background: rgba(255,255,255,0.06);
  color: var(--sidebar-ink-strong);
  text-decoration: none;
}
.sidebar-nav a:hover .icon { opacity: 1; }
/* A soft fill AND a left indicator: on a flat dark panel one alone is easy
   to miss when several rows are the same length. */
.sidebar-nav a.is-active {
  background: var(--sidebar-active);
  color: var(--sidebar-ink-strong);
  font-weight: 600;
}
.sidebar-nav a.is-active .icon { opacity: 1; }
.sidebar-nav a.is-active::before {
  content: "";
  position: absolute;
  left: -0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: #7fb3ff;
}
.sidebar-nav a:focus-visible {
  outline: 2px solid #7fb3ff;
  outline-offset: -2px;
}
.nav-section {
  margin: 0.9rem 0.6rem 0.3rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: rgba(185,196,214,0.55);
}

.shell {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
/* A product shell, not a website navbar: solid, bordered, no glass. */
.top-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
/* The brand stands in for the sidebar where the sidebar is hidden. It is
   shown by the narrow breakpoint, not here. */
.header-brand {
  display: none;
  font-size: 0.875rem;
  font-weight: 650;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.header-user {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.25;
}
.user-meta strong { font-size: 0.8125rem; font-weight: 600; }
.user-meta span { font-size: 0.75rem; color: var(--muted); }
.menu-btn {
  display: none;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  font-size: 0.8125rem;
  font-weight: 600;
}
.menu-btn:hover { background: var(--surface-hover); }
.nav-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.nav-toggle:focus-visible ~ .shell .menu-btn { box-shadow: var(--focus-ring); }
.nav-backdrop { display: none; }

.content {
  padding: 1.25rem 1.5rem 3rem;
  /* Centred on a wide screen so a table does not run to a 2500px line
     length, and fluid below that. This is the only width cap on the page
     path; forms narrow themselves with .form-panel / .form-layout. */
  max-width: 1480px;
  width: 100%;
  margin: 0 auto;
}

/* ----- Forms ------------------------------------------------------------- */
label {
  display: block;
  margin: 0.65rem 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink);
}
input[type="text"],
input[type="password"],
input[type="search"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="month"],
input[type="file"],
select,
textarea {
  font: inherit;
  font-size: 0.875rem;
  width: 100%;
  min-height: 36px;
  margin-top: 0.25rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
select {
  /* Room for the native arrow, which otherwise sits on the last character. */
  padding-right: 1.6rem;
}
textarea { min-height: 88px; padding: 0.5rem 0.6rem; resize: vertical; }
::placeholder { color: var(--faint); opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: #b4c0ce; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: var(--focus-ring);
}
input[type="checkbox"], input[type="radio"] {
  width: auto;
  min-height: 0;
  margin: 0;
  accent-color: var(--accent);
}
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* ----- Buttons ----------------------------------------------------------- */
.btn,
button,
a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 0.4rem 0.85rem;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  text-decoration: none !important;
  white-space: nowrap;
  transition: background-color 130ms ease, border-color 130ms ease,
              box-shadow 130ms ease, transform 130ms ease;
}
.btn:hover,
button:hover,
a.button:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
.btn:active,
button:active,
a.button:active { transform: translateY(1px); }
.btn:focus-visible,
button:focus-visible,
a.button:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled,
button:disabled,
.btn[disabled] {
  background: var(--surface-sunken);
  border-color: var(--line);
  color: var(--faint);
  cursor: not-allowed;
  transform: none;
}

/* Secondary: a real control, visibly clickable, but never competing with
   the one primary action on the page. */
.btn-ghost,
button.btn-ghost,
a.button.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
.btn-ghost:hover,
button.btn-ghost:hover,
a.button.btn-ghost:hover {
  background: var(--surface-hover);
  border-color: #b4c0ce;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}
.btn-secondary { background: #2d3f5c; border-color: #2d3f5c; color: #fff; }
.btn-secondary:hover { background: #3a4f72; border-color: #3a4f72; }
.btn-danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn-danger:hover { background: #8f1c14; border-color: #8f1c14; }
.btn-small { min-height: 30px; padding: 0.2rem 0.6rem; font-size: 0.8125rem; }
.btn-block { width: 100%; }

.inline { display: inline; margin: 0; }
.inline button { width: auto; }
.checkbox {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  font-weight: 400;
}
.checkbox input { width: auto; margin: 0; }

/* ----- Page header ------------------------------------------------------- */
/* One compact row: who/what/when on the left, at most one dominant action
   on the right. Never a card. */
/* The page says what it is once, here, so this is where the hierarchy
   starts: a heavier title, a quiet line of context, and the one action that
   matters opposite it. */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem 1.25rem;
  flex-wrap: wrap;
  margin: 0 0 1.5rem;
}
.page-head > div:first-child { min-width: 0; }
.page-head h1 { margin-bottom: 0.15rem; }
.page-head > div:first-child > p {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
}
.page-head > div:first-child > p + p { margin-top: 0.1rem; }
/* The way back, above the title, where a browser back button would be. */
.page-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0 0 0.3rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
}
.page-eyebrow:hover { color: var(--link); text-decoration: none; }
.page-head .actions-row { align-items: center; }

.data-banner {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border: 1px solid #f0dcb0;
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.65rem;
  font-size: 0.8125rem;
  font-weight: 600;
  margin: 0.3rem 0 0.8rem;
}

/* ----- Summary surfaces -------------------------------------------------- */
/* One raised surface divided into cells, not four floating cards. The first
   cell is the figure the page is about; the rest are context. */
.summary-surface {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin: 0 0 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-raised);
  overflow: hidden;
}
.summary-item {
  padding: 0.9rem 1.1rem;
  border-left: 1px solid var(--line);
  min-width: 0;
}
.summary-item:first-child { border-left: none; }
.summary-item h2,
.summary-item .summary-label {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.summary-value {
  margin: 0.3rem 0 0.1rem;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.summary-item.is-lead .summary-value { font-size: 1.75rem; line-height: 2.25rem; }
.summary-item p.muted { margin: 0; font-size: 0.75rem; }
.summary-item.is-warning { background: var(--warn-bg); }
.summary-item.is-warning .summary-value { color: var(--warn-ink); }
.summary-value.is-negative { color: var(--error); }

/* KPI tiles stay for the pages that genuinely show unrelated figures, but
   they are quiet surfaces now, not raised ones: a page's depth belongs to
   its work, not to its statistics. */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin: 0 0 1.25rem;
}
/* Wide screens: each KPI group is one row of equal tiles, so a group can
   never wrap and leave a single orphan tile on a second line. minmax(0, 1fr)
   lets a tile shrink below its content width, so the row never widens the
   page. Groups are kept to five tiles or fewer. Narrower screens keep the
   wrapping grid above. */
@media (min-width: 1200px) {
  .kpi-grid {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
  }
  .kpi-value { overflow-wrap: anywhere; }
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 0.95rem;
  min-width: 0;
}
a.kpi {
  color: inherit;
  text-decoration: none;
  transition: border-color 130ms ease, box-shadow 130ms ease;
}
a.kpi:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-raised);
  text-decoration: none;
}
.kpi h2 {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kpi-value {
  margin: 0.3rem 0 0.1rem;
  font-size: 1.5rem;
  line-height: 1.9rem;
  font-weight: 650;
  letter-spacing: -0.012em;
}
.kpi .muted { margin: 0; font-size: 0.75rem; }

/* ----- Panels ------------------------------------------------------------ */
/* A panel is a normal surface: bordered, not lifted. Raising belongs to the
   data table, the command bar and the summary -- the things being worked. */
.card, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 0 0 1rem;
}
.panel h2, .card h2 { font-size: 0.9375rem; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { letter-spacing: -0.005em; }
.panel-head h2 { margin: 0; }
.panel-head > a, .panel-head > span { font-size: 0.8125rem; }
.grid-2 {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

/* ----- Data panel (tables) ---------------------------------------------- */
/* The table is the work surface, so this is the one thing on most pages
   that is lifted off the canvas. */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  /* A positioning context for anything absolute inside a wide table -- a
     visually hidden column label, for instance. Without one it resolves
     against the page and drags the whole document sideways by the table's
     width, which is how the product list came to scroll horizontally on a
     phone while every element in it measured as fitting. */
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-raised);
}
/* A small table inside a panel is not a second work surface. */
.panel .table-wrap, .card .table-wrap {
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}
/* A count, a filter or a bulk action belonging to the table below it. */
.panel-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.55rem 0.85rem;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}
.panel-toolbar + .table-wrap { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.panel-toolbar strong { color: var(--ink); }

table {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
  border: none;
  border-radius: 0;
}
th, td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.8125rem;
  vertical-align: top;
}
td { line-height: 1.45; }
th {
  background: var(--surface-subtle);
  color: #46536a;
  font-weight: 650;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  border-bottom: 1px solid var(--line-strong);
}
tbody tr { transition: background-color 120ms ease; }
tbody tr:hover { background: var(--surface-hover); }
tr:last-child td { border-bottom: none; }
/* The first cell names the row, so it is the one that reads as the subject. */
.table-wrap tbody td:first-child { color: var(--ink); }
.table-wrap tbody td:first-child > a,
.table-wrap tbody td:first-child > strong > a { font-weight: 600; color: var(--ink); }
.table-wrap tbody td:first-child > a:hover,
.table-wrap tbody td:first-child > strong > a:hover { color: var(--link); }

.empty-state {
  padding: 2rem 1.25rem;
  color: var(--muted);
  text-align: center;
  font-size: 0.875rem;
}
.empty-state strong { display: block; color: var(--ink); margin-bottom: 0.2rem; }

/* ----- Status pills ------------------------------------------------------ */
/* Soft background, coloured text, never shaped like a button. Pills are for
   states only; a filter, a nav item or a tag is not a pill. */
/* A badge is a state. It is deliberately NOT button-shaped: fully round,
   no border, no shadow, small caps-ish weight -- so nothing on the page
   invites a click that does not exist. Ordinary values (a brand, a
   category, a rule name) are plain text; see .cell-note below. */
.pill {
  display: inline-block;
  padding: 0.08rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  line-height: 1.6;
  font-weight: 650;
  letter-spacing: 0.01em;
  background: var(--surface-sunken);
  color: #44506a;
  white-space: nowrap;
  border: none;
  box-shadow: none;
}
/* A badge that IS a link says so on hover; it never looks like a button. */
a.pill:hover { text-decoration: underline; }
.status-open { background: var(--info-bg); color: var(--info-ink); }

/* Sample request statuses. Same muted palette as the ticket pills: the
   emphasis on this screen belongs to the actions, not to seven colours
   competing in a status column. */
.sample-draft { background: #f1f3f6; color: #5c6779; }
.sample-submitted { background: var(--warn-bg); color: var(--warn-ink); }
.sample-approved { background: var(--info-bg); color: var(--info-ink); }
.sample-fulfilled { background: #e9ecf8; color: #33409c; }
.sample-delivered { background: var(--ok-bg); color: var(--ok-ink); }
.sample-rejected { background: #fde0dd; color: #a32218; }
.sample-cancelled { background: #eceff3; color: #51607a; }
.status-in_progress { background: var(--warn-bg); color: var(--warn-ink); }
.status-resolved { background: var(--ok-bg); color: var(--ok-ink); }
.status-closed { background: #eceff3; color: #51607a; }
.priority-low { background: #f1f3f6; color: #5c6779; }
.priority-normal { background: var(--info-bg); color: var(--info-ink); }
.priority-high { background: #ffeacc; color: #9a4f00; }
.priority-urgent { background: #fde0dd; color: #a32218; }
.pill-muted { background: #f1f3f6; color: var(--muted); }

/* ---------------------------------------------------------------------------
   Sample approval: part of a request can be granted and part declined.

   A reduced decision must not read as a full one, and a declined product has
   to stay visible -- the rep asked for it, so removing it from the table
   would hide what was refused.
   -------------------------------------------------------------------------- */
/* A cancelled sample's ticket still shows the instruction it was raised
   with -- it is the record of what was asked for and must not be rewritten.
   So the instruction is visibly stood down instead: the notice sits above it
   and the original is dimmed, which is the difference between "ignore this"
   and "this never happened". */
.stand-down { margin-bottom: 10px; }
.comment.opening.is-superseded {
  opacity: 0.66;
}
.comment.opening.is-superseded p {
  text-decoration: line-through;
  text-decoration-color: rgba(0, 0, 0, 0.35);
}

.pill.is-partial {
  background: var(--warn-bg);
  color: var(--warn-ink);
}
/* Still legible, clearly not part of what is shipping. Not display:none --
   the row is the record of what was asked for. */
tr.is-declined > td { opacity: 0.62; }
tr.is-declined > td:first-child { text-decoration: line-through; }

/* The box the message belongs to, so the eye lands on the field and not just
   on the sentence. */
.approval-form tr.has-error > td { background: var(--error-bg); }
.approval-form input.is-invalid {
  border-color: var(--error);
  outline: 2px solid var(--error-bg);
}
.approval-form .message-error {
  margin: 4px 0 0;
  padding: 4px 6px;
  font-size: 0.78rem;
  text-align: left;
  white-space: normal;
}
.approval-form .qty-input { width: 86px; }
.approval-form textarea { width: 100%; max-width: 46em; }

@media (max-width: 560px) {
  /* Four columns in 390px: the approver has to reach the quantity box, so
     the table is tightened until it fits rather than left to scroll with the
     box half off the screen. The product name wraps; the SKU never does. */
  .approval-form table { font-size: 0.82rem; }
  .approval-form th, .approval-form td { padding: 6px 4px; }
  .approval-form .qty-input { width: 56px; padding: 6px 4px; }
  .approval-form .field-help { font-size: 0.68rem; }
  .approval-form .message-error { font-size: 0.72rem; }
  .approval-form td:nth-child(2) { overflow-wrap: anywhere; }
}
.badge {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 0.6875rem;
  font-weight: 600;
}

/* ----- Command bar ------------------------------------------------------- */
/* Filters read as one control bar rather than scattered boxes: search first,
   the frequent filters next, the actions at the end. */
.filter-bar, .command-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin: 0 0 1rem;
  align-items: flex-end;
  padding: 0.75rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-raised);
}
.filter-bar label, .command-bar label {
  margin: 0;
  min-width: 0;
  /* A select is as wide as its longest option needs; only the search box
     grows. 190px clipped "Handled and unhandled" to "Handled and unhand". */
  flex: 0 1 220px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}
.filter-bar select,
.filter-bar input,
.command-bar select,
.command-bar input {
  width: 100%;
  margin-top: 0.2rem;
}
/* The search box leads, so it gets the room -- up to a readable line. */
.filter-bar label:first-of-type,
.command-bar label.is-search { flex: 1 1 260px; max-width: 420px; }
.filter-bar .filter-actions, .command-bar .filter-actions {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  margin-left: auto;
}
.filter-bar button, .command-bar button { width: auto; margin: 0; }
.filter-bar .filter-actions > a, .command-bar .filter-actions > a {
  font-size: 0.8125rem;
  color: var(--muted);
  padding: 0 0.2rem;
}
.filter-bar .filter-actions > a:hover { color: var(--link); }

.trend-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.trend-list li {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.8125rem;
}
.trend-list li:last-child { border-bottom: none; }
.trend-bar {
  height: 7px;
  background: var(--surface-sunken);
  border-radius: 999px;
  overflow: hidden;
}
.trend-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

/* ----- Fact grids and the detail rail ------------------------------------ */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.6rem;
}
/* A fact, not a card. These sit inside a panel that is already a surface,
   so boxing each one gave seven nested cards on the customer profile and
   the same again on a ticket. A label, a value and the grid's own spacing
   is enough to read them as a list. */
.meta-item {
  padding: 0.4rem 0 0.45rem;
  border-top: 1px solid var(--line);
  font-size: 0.8125rem;
  min-width: 0;
  overflow-wrap: anywhere;
}
.meta-item strong { font-weight: 600; }
.meta-item .label, .meta-item > .muted:first-child {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

/* The facts block inside the ticket rail. The frame lives on .ticket-rail
   now; what used to be a .rail card here is gone, along with the later rule
   that only existed to cancel its margin. */
.rail-section {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--line);
}
.rail-section:first-child { border-top: none; }
.rail-section h2 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.rail-facts { display: grid; gap: 0.6rem; margin: 0; }
.rail-fact .label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}
.rail-fact strong { font-size: 0.875rem; font-weight: 600; }
.rail-fact > div { font-size: 0.8125rem; }

/* A list of what can be done, each with its own button on the right. */
.action-panel { margin: 0 0 1rem; }
.action-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--line);
}
.action-item:first-of-type { border-top: none; padding-top: 0.25rem; }
.action-item > div:first-child { min-width: 0; }
.action-item strong { font-size: 0.875rem; font-weight: 600; }
.action-item p { margin: 0.15rem 0 0; font-size: 0.8125rem; color: var(--muted); }
.action-item form { margin: 0; }

.ticket-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1.25rem;
  align-items: start;
}
/* Form pages (New Ticket, New user, user edit, Change password) stay at a
   readable width however wide the content column gets. The user edit page
   stacks its panels in one column at that width rather than squeezing two.

   The measure itself is set once, with the rest of the form composition
   further down; it used to be declared here at 760px as well and the later
   value simply won. */
.ticket-layout.form-layout {
  max-width: 900px;
  grid-template-columns: minmax(0, 1fr);
}
.comment {
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.6rem;
}
.comment header {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.comment p { margin: 0; font-size: 0.875rem; }
.comment.internal {
  border-left: 3px solid var(--warn-ink);
  background: #fffaf0;
}

.ticket-form label { margin-bottom: 0.85rem; }
.ticket-form button { width: auto; margin-top: 0.5rem; }
.search-results { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.search-results li:hover { background: var(--surface-hover); }
.search-results li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: baseline;
}
button.linkish, .btn-tiny {
  width: auto;
  min-height: 28px;
  margin: 0;
  padding: 0.15rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  font-size: 0.8125rem;
}
button.linkish:hover, .btn-tiny:hover {
  background: var(--surface-hover);
  border-color: #b4c0ce;
  color: var(--ink);
}
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.message {
  background: var(--ok-bg);
  color: var(--ok-ink);
  border: 1px solid #b7dfc4;
  border-left: 3px solid var(--ok-ink);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
}
.stack-gap > * + * { margin-top: 1rem; }
.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.rep-switch { min-width: 220px; }
.rep-switch label { margin: 0; }

/* ----- Responsive ----- */
@media (max-width: 1080px) {
  .grid-2, .ticket-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}
/* A grid item's minimum width defaults to its content's, so a panel holding a
   wide table (the Overview's Team snapshot) or the trend list used to stretch
   its column past the viewport on a phone and make the whole page scroll
   sideways. Letting the columns shrink keeps that scroll inside the panel's
   own .table-wrap. */
.grid-2 > *, .ticket-layout > * { min-width: 0; }
@media (max-width: 860px) {
  .menu-btn { display: inline-flex; }
  .sidebar {
    transform: translateX(-105%);
    transition: transform 0.18s ease;
  }
  .nav-toggle:checked ~ .sidebar {
    transform: translateX(0);
  }
  .nav-toggle:checked ~ .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 24, 34, 0.45);
    z-index: 35;
  }
  .shell { margin-left: 0; }
  .content { padding: 1rem 1rem 2.5rem; }
  .user-meta { display: none; }
  .kpi-value, .summary-item.is-lead .summary-value { font-size: 1.375rem; line-height: 1.75rem; }
  .summary-item { border-left: none; border-top: 1px solid var(--line); }
  .summary-item:first-child { border-top: none; }
  .trend-list li {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
}
@media (max-width: 520px) {
  .top-header { padding: 0.5rem 1rem; }
  .filter-bar label, .command-bar label { min-width: 100%; flex: 1 1 100%; }
  .filter-bar .filter-actions, .command-bar .filter-actions { margin-left: 0; width: 100%; }
  .page-head .actions-row { width: 100%; }
}

/* Ticket list: sortable headers, pagination, error messages (M1) */
.message-error {
  background: var(--error-bg);
  color: var(--error);
  border-color: #f3b7b2;
}
th a {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
th a:hover { color: var(--link); }
th a:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 3px; }
th.is-sorted { background: var(--surface-sunken); }
th.is-sorted a { color: var(--ink); }
.sort-indicator { font-size: 0.6875rem; color: var(--link); }
.pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.85rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

/* Ticket timeline (M1) */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 0 1.1rem;
  border-left: 2px solid var(--line);
}
.timeline-item {
  position: relative;
  padding: 0 0 0.9rem 0.9rem;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-mark {
  position: absolute;
  left: -1.55rem;
  top: 0.3rem;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--line-strong);
  border: 2px solid var(--surface);
}
.timeline-item.event-created .timeline-mark,
.timeline-item.event-resolved .timeline-mark { background: var(--accent); }
.timeline-item.event-closed .timeline-mark { background: var(--accent); }
.timeline-item.event-reopened .timeline-mark { background: var(--error); }
.timeline-summary { margin: 0; font-weight: 600; font-size: 0.875rem; }
.timeline-meta { margin: 0.1rem 0 0; color: var(--muted); font-size: 0.75rem; }

/* Inline notice inside a panel (e.g. ticket pre-filled from an inquiry) */
.note-box {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border: 1px solid #f0dcb0;
  border-left: 3px solid var(--warn-ink);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  margin: 0 0 1rem;
  font-size: 0.8125rem;
}
.note-box ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }
.note-box a { color: inherit; }

/* Dashboard "Needs attention" row (M6.6) */
.attention {
  border: 1px solid var(--line);
  box-shadow: var(--shadow-raised);
  padding: 0.85rem 0.95rem;
}
.attention .actions-row { gap: 0.5rem; }
.attention-item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.8125rem;
  transition: border-color 130ms ease, box-shadow 130ms ease;
}
.attention-item:hover {
  border-color: #b4c0ce;
  color: var(--ink);
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}
.attention-item:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.attention-item strong { font-size: 1.05rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* Global search box in the portal header (M6.2) */
/* Search leads the strip and the account controls close it, so the bar
   reads left to right instead of leaving half of itself empty. */
.header-search { margin: 0 auto 0 0.25rem; flex: 0 1 340px; max-width: 340px; }
.header-search input {
  width: 100%;
  min-height: 34px;
  margin: 0;
  padding: 0.3rem 0.65rem;
  font-size: 0.8125rem;
  background: var(--surface-subtle);
}
.header-search input:focus { background: var(--surface); }
@media (max-width: 720px) {
  .header-search { display: none; }
}

/* Clickable table rows (Phase 1)
   The link itself stays in the first cell — the row only signals that it opens.
   No nested anchors, so keyboard and screen-reader behaviour is unchanged. */
.table-wrap tbody tr.is-linked { cursor: default; }
.table-wrap tbody tr.is-linked:hover {
  background: var(--surface-hover);
  box-shadow: inset 2px 0 0 var(--accent);
}
.table-wrap tbody tr.is-linked:hover td:first-child a {
  color: var(--link);
  text-decoration: underline;
}
.table-wrap tbody tr.is-linked:focus-within {
  background: var(--surface-hover);
  box-shadow: inset 2px 0 0 var(--accent);
}
/* A trailing chevron on the row action, so "this opens" is visible without
   hovering. The markup stays one link in one cell. */
.row-open {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
}
tr:hover .row-open { color: var(--link); }

/* Manager queue state and ticket conversation (Phase 2) */
.waiting-manager { background: #ffeacc; color: #9a4f00; }
.waiting-rep { background: var(--surface-sunken); color: #51607a; }

/* Conversation thread. The team's side is tinted so a manager can see whose
   turn it is at a glance; the markup is the same for both. */
.comment.from-team {
  border-left: 3px solid var(--link);
  background: var(--info-bg);
  border-color: #cfdcf7;
}
.comment.opening {
  border-left: 3px solid var(--line);
}
.comment-author { font-weight: 650; color: var(--ink); }
.ticket-context {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1.1rem;
  margin: 0.35rem 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}
.ticket-context strong { color: var(--ink); font-weight: 600; }
/* Numeric table cells read better right-aligned. */
td.num, th.num { text-align: right; }
td.nowrap, th.nowrap { white-space: nowrap; }

/* Overview section headings (Phase 2) — they group the page without adding
   another panel border around every block. */
.section-label {
  margin: 1.5rem 0 0.6rem;
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
.section-label:first-of-type { margin-top: 0.25rem; }

/* Admin account actions and the one-time generated password (Phase 3) */
.account-action {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}
.account-action:last-child { border-bottom: none; padding-bottom: 0; }
.account-action p { margin: 0.15rem 0 0; font-size: 0.8125rem; color: var(--muted); }
.account-action strong { font-size: 0.875rem; font-weight: 600; }
.generated-password {
  border-left: 3px solid var(--warn-ink);
  background: var(--warn-bg);
}
.generated-password-value {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: var(--info-bg);
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  margin: 0.4rem 0;
  user-select: all;
  word-break: break-all;
}

/* Narrow screens: let a wide table scroll instead of collapsing (Phase 4)
   .table-wrap already scrolls, but `table { width: 100% }` meant the table
   could never be wider than the viewport, so a nine-column ticket list
   squashed every cell to a few characters rather than scrolling. A minimum
   width restores the intended behaviour: the table scrolls inside its own
   container and the page itself never overflows sideways.

   Scoped to the full-width data tables, which are direct children of
   .content. The small tables inside .panel (age buckets, team snapshot,
   recent orders, search results) stay fluid and need no scrolling. */
@media (max-width: 860px) {
  .content > .table-wrap table { min-width: 700px; }
}

/* Admin account actions stack rather than squeezing the button (Phase 4) */
@media (max-width: 520px) {
  .account-action {
    flex-direction: column;
    align-items: stretch;
  }
  .account-action form,
  .account-action button { width: 100%; }
  /* A stacked filter bar does not need the label-height offset. */
  .filter-bar .filter-actions { margin-top: 0.5rem; }
}

/* Long values (emails, clinic names) wrap inside a cell instead of forcing
   the table wider than its own minimum. */
td, th { overflow-wrap: anywhere; }
td.nowrap, th.nowrap, .pill { overflow-wrap: normal; }

/* ----- Phone-width table readability -------------------------------------
   Scoped to the narrow breakpoint: the desktop rendering above is unchanged.

   The rule immediately above sets `overflow-wrap: anywhere` on every cell.
   On a wide screen that is harmless, but in a 390-440px viewport it lets a
   column's minimum width fall to a single character, and the auto layout
   duly collapses it: "Felix Martinez" came out as five vertical fragments,
   "1099 contractor" as six, "$44,859.00" split across two lines and the
   ticket queue's subject became a 92px, six-line strip.

   `break-word` keeps the longest word as the column's floor, so a name
   column can no longer collapse. A table that then exceeds the viewport
   scrolls inside its own .table-wrap, which already has overflow-x: auto;
   the page itself still does not scroll sideways.

   This block must stay after the rule it overrides: the two selectors have
   the same specificity, and a media query adds none. */
@media (max-width: 860px) {
  td, th { overflow-wrap: break-word; }

  /* An amount, a count or a quantity is read as one thing. */
  td.num, th.num { white-space: nowrap; }

  /* The ticket queue's table sits inside its bulk-action form, so the
     min-width floor further up never reached it. */
  .content > form > .table-wrap table { min-width: 700px; }

  /* A ticket number is an identifier and was breaking at its hyphen
     ("TKT-" / "00006"). The subject is what the row is about, and without a
     floor the auto layout gave it less room than "Submitted by". */
  .ticket-table td.ticket-id-cell { white-space: nowrap; }
  .ticket-table td.subject-cell { min-width: 190px; }

  /* The product name, same reasoning. The tick column is always first in
     this table, so the second cell is always the product. */
  .product-table td:nth-child(2) { min-width: 165px; }
  /* A SKU is one code. Every .mono value in this table is a single SKU --
     the comma-joined lists live in .rule-table, which is left free to wrap. */
  .product-table .mono { white-space: nowrap; }

  /* The rule tables sit inside a section, so the floor never reached them
     either and their columns collapsed to ~53px. A rule's name and code
     ("5 + 1", "RH-5+1") are identifiers and stay whole. */
  .rule-table { min-width: 700px; }
  .rule-table td:first-child { white-space: nowrap; }
}

/* ----- Idle sign-out warning -----
   Shown by the inline script in base.html two minutes before the session
   expires. `hidden` must win over the display rule below. */
.idle-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(19, 37, 54, 0.45);
}
.idle-overlay[hidden] { display: none; }
.idle-dialog {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
  padding: 1.25rem 1.3rem 1.1rem;
}
.idle-dialog h2 { margin: 0 0 0.4rem; font-size: 1.0625rem; }
.idle-dialog p { margin: 0 0 1rem; color: var(--muted); }
.idle-dialog strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.idle-dialog .actions-row { justify-content: flex-end; }

/* ---------------------------------------------------------------------------
   Commission setup screens.

   Interaction, not decoration: a selection bar that appears when rows are
   ticked, a row that opens in place to be edited, a rule form that shows only
   the fields its kind needs, and a preview panel. Everything reuses the
   portal's existing colours and spacing.
   --------------------------------------------------------------------------- */

/* A class that sets `display` beats the browser's [hidden] rule, so every
   element this file gives a display to has to opt back in. Conditional form
   sections depend on it: without this the spend-bracket fields stay visible
   on a buy-X-get-Y rule. */
.bulk-bar[hidden],
.field-row[hidden],
.try-result[hidden],
.picker-item[hidden],
.editor-review[hidden],
.field[hidden],
fieldset[hidden] { display: none; }
.bulk-bar {
  position: sticky;
  top: calc(var(--header-h) + 8px);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 0.5rem 0.85rem;
  flex-wrap: wrap;
  margin: 0 0 0.75rem;
  padding: 0.6rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-overlay);
  font-size: 0.8125rem;
}
.bulk-bar label { margin: 0; }
.bulk-bar select, .bulk-bar input { margin: 0; width: auto; min-width: 170px; }

.product-table th.tick,
.product-table td.tick { width: 34px; text-align: center; }
.product-table tr.is-free-row td:first-child + td { padding-left: 22px; }

.inline-menu { position: relative; display: inline-block; }
.inline-menu > summary { list-style: none; cursor: pointer; }
.inline-menu > summary::-webkit-details-marker { display: none; }
.inline-menu .menu-body {
  position: absolute;
  right: 0;
  z-index: 30;
  min-width: 210px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-overlay);
}
.inline-menu .menu-body a {
  display: flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 0.8125rem;
}
.inline-menu .menu-body a:hover { background: var(--surface-hover); text-decoration: none; }

.inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline-form label { margin: 0; }

.field-row { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-end; }
.field-row label { margin: 0 0 10px; }
.field-row label.checkbox { display: flex; align-items: center; gap: 6px; }

.rule-form fieldset {
  margin: 14px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.rule-form legend { padding: 0 6px; color: var(--muted); font-size: 0.85rem; }

.product-picker { margin: 8px 0 14px; }
.product-picker input[type="search"] { width: 260px; margin-bottom: 8px; }
.picker-list {
  max-height: 210px;
  overflow-y: auto;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-subtle);
}
.picker-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; }

.try-box {
  margin-top: 1.25rem;
  padding: 0.9rem 1rem;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.try-box h4 { margin: 0 0 6px; }
.try-result { margin-top: 12px; }
.try-result table { width: 100%; }

.advanced > summary { cursor: pointer; color: var(--muted); margin: 22px 0 10px; }
tr.muted-row td { opacity: 0.55; }

/* Invoice review */
.invoice-row > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
  background: var(--surface);
  font-size: 0.8125rem;
  display: grid;
  grid-template-columns: 92px 88px 1fr 130px 130px 120px;
  gap: 12px;
  align-items: center;
}
.invoice-row > summary::-webkit-details-marker { display: none; }
.invoice-row[open] > summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.invoice-row .invoice-body {
  padding: 14px;
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 6px 6px;
  background: var(--surface-subtle);
}
.alloc-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 8px; }
.alloc-row select, .alloc-row input { margin: 0; }
.preview-line { margin: 10px 0; font-weight: 600; }
@media (max-width: 900px) {
  .invoice-row > summary { grid-template-columns: 1fr 1fr; }
}

/* Tabs on a brand's workspace: its rules and its products, without scrolling
   past one to reach the other. */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin: 0 0 1rem;
  border-bottom: 1px solid var(--line);
}
.tabs .tab {
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  transition: color 120ms ease, border-color 120ms ease, background-color 120ms ease;
}
.tabs .tab:hover {
  background: var(--surface-hover);
  color: var(--ink);
  text-decoration: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.tabs .tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

/* A percentage input with its suffix attached to the box rather than floating
   after it, so "17.5 %" does not read as two separate things. */
.pct-field { display: inline-flex; align-items: center; }
.pct-field input { margin: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.pct-suffix {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 0.55rem;
  border: 1px solid var(--line-strong);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 0.8125rem;
}
.link-button {
  cursor: pointer;
  color: var(--link);
  text-decoration: underline;
  list-style: none;
  font-size: 0.8125rem;
}
.link-button::-webkit-details-marker { display: none; }

/* Statement: a figure and its label on one baseline, and the arithmetic
   available without being in the way. */
.calc-detail > summary { cursor: pointer; color: var(--muted); font-size: 0.88rem; }
.calc-detail .calc-body { margin-top: 6px; color: var(--muted); font-size: 0.88rem; }
.kpi .kpi-value.is-negative { color: var(--error); }

/* "Try this rule" reads as a sentence, so its inputs sit on the line with the
   words rather than wrapping away from them. */
.try-box .field-row { align-items: center; gap: 12px; }
.try-box .field-row label { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.try-box .field-row input { margin: 0; }

/* A line nobody has classified yet, in the reclassification form. */
.alloc-row.is-undecided { border-left: 3px solid #c8734b; padding-left: 10px; }

/* ---------------------------------------------------------------------------
   Commission configuration, second pass.

   Denser tables, one editor panel instead of a form inside a table cell, and
   states that read as states: what is configured now, what is scheduled, what
   is missing. Every selector here belongs to markup only the commission
   screens use, so Sales, Customers, Tickets and Team are untouched.
   --------------------------------------------------------------------------- */

/* Facts about the thing the page is about, one per line, aligned. */
.head-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 22px;
  margin: 6px 0 0;
  font-size: 0.9rem;
}
.head-meta dt { color: var(--muted); font-weight: 400; }
.head-meta dd { margin: 0 0 0 4px; font-variant-numeric: tabular-nums; }

/* Where a list came from, said once, instead of a badge on every row. */
.source-status {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.product-table,
.rule-table { font-size: 0.8125rem; }
.product-table td,
.rule-table td { vertical-align: top; }
.product-table tr.is-child-row td { background: var(--surface-subtle); border-top: none; }
.product-table td.child-cell { padding-left: 26px; }
.product-table .child-mark { color: var(--muted); margin-right: 6px; }
.product-table tr.is-editing td { background: var(--info-bg); box-shadow: inset 2px 0 0 var(--link); }
.rule-table .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: center;
  font-size: 0.88rem;
}

.pill-warn {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border: 1px solid #f0dcb0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 20px 0 8px;
}
.rule-section { margin: 20px 0; }
.rule-section h3 { margin-bottom: 6px; font-size: 0.98rem; }
.rule-section h3 .muted { font-weight: 400; font-size: 0.85rem; }

.quiet-details > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
  margin: 10px 0;
}
.plain-list { margin: 4px 0; padding-left: 18px; }
.plain-list li { margin: 2px 0; }

.rule-section h3 + .muted { font-size: 0.8125rem; }

/* One editor, in a panel. A form inside a narrow table cell had nowhere to put
   a field error, a history, or a summary of what the change would do. */
.editor-panel {
  margin: 1.25rem 0;
  padding: 1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-raised);
  scroll-margin-top: calc(var(--header-h) + 12px);
}
.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.editor-head h2 { margin: 0; font-size: 0.9375rem; }
.editor-head p { margin: 2px 0 0; font-size: 0.8125rem; }

.editor-now {
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.editor-now h3 { margin: 0 0 6px; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 2px 12px; margin: 0; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.editor-panel .field,
.rule-form .field,
.stacked-form { margin-bottom: 12px; }
.editor-panel .field > label,
.rule-form .field > label,
.stacked-form > label {
  display: block;
  margin-bottom: 3px;
  font-size: 0.88rem;
  font-weight: 600;
}
.rule-form .field.grow { flex: 1 1 220px; }
.rule-form .field > label.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
}
.editor-panel .field input[type="text"],
.editor-panel .field input[type="date"],
.editor-panel .field select { width: 100%; max-width: 340px; }
.stacked-form input[type="text"],
.stacked-form input[type="date"] { width: 100%; }

.field-help { margin: 3px 0 0; color: var(--muted); font-size: 0.82rem; max-width: 46em; }
.field-error { margin: 3px 0 0; color: var(--error); font-size: 0.85rem; font-weight: 600; }
[aria-invalid="true"] { border-color: var(--error); }

.editor-review {
  margin: 14px 0;
  padding: 10px 12px;
  background: var(--warn-bg);
  border: 1px solid #f0dcb0;
  border-radius: 6px;
}
.editor-review h3 { margin: 0 0 4px; font-size: 0.85rem; color: var(--warn-ink); }
.editor-review li { font-size: 0.88rem; }
.editor-actions { margin-top: 14px; }
.editor-history > summary { cursor: pointer; color: var(--muted); font-size: 0.88rem; margin-top: 12px; }
.editor-history .menu-body { padding: 8px 0 0; font-size: 0.88rem; }
.editor-history p { margin: 2px 0; }

/* The product picker: a filter that hides rows, a running count, and two
   buttons that act only on what is shown. */
.picker-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 8px;
}
.picker-tools input[type="search"] { width: 240px; margin: 0; }
.picker-count { color: var(--muted); font-size: 0.88rem; }
.picker-list { max-height: 260px; }
.picker-item { justify-content: flex-start; }
.picker-item .picker-name { flex: 1 1 auto; min-width: 0; }
.picker-item:hover { background: var(--surface-hover); }

.bulk-detail { margin-left: auto; }
.bulk-detail > summary { cursor: pointer; color: var(--link); font-size: 0.88rem; }
.bulk-detail .menu-body {
  position: absolute;
  z-index: 10;
  right: 14px;
  max-width: 420px;
  max-height: 260px;
  overflow-y: auto;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(31, 42, 51, 0.12);
}

.try-box h3 { margin: 0 0 6px; font-size: 0.98rem; }
.try-box .pill { font-weight: 400; }
.try-box .field-row .field { margin-bottom: 0; }

@media (max-width: 900px) {
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 6px; }
  .editor-panel .field input[type="text"],
  .editor-panel .field input[type="date"],
  .editor-panel .field select { max-width: none; }
  .picker-tools input[type="search"] { width: 100%; }
  .section-head { flex-direction: column; align-items: flex-start; }
}


/* ---------------------------------------------------------------------------
   The statement a rep reads.

   One figure, one status, one compact breakdown, then the invoices. The invoice
   list is a grid rather than a table so each row can open in place and keep its
   numeric columns aligned with the header above it.
   --------------------------------------------------------------------------- */

.month-picker { display: flex; align-items: center; gap: 6px; margin: 0; }
.month-picker label { margin: 0; color: var(--muted); font-size: 0.88rem; }
.month-picker select { margin: 0; }

.statement-headline {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(280px, 0.9fr);
  gap: 0;
  margin: 0 0 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-raised);
  overflow: hidden;
}
.headline-figure { padding: 1.1rem 1.25rem; }
.headline-figure h2 {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.headline-figure .figure {
  margin: 2px 0 4px;
  font-size: 2rem;
  line-height: 2.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.headline-figure .figure.is-negative { color: var(--error); }
.headline-figure p.muted { margin: 0; font-size: 0.8125rem; max-width: 34em; }

.breakdown {
  display: grid;
  grid-template-columns: 1fr auto;
  align-content: start;
  gap: 0 18px;
  margin: 0;
  padding: 1.1rem 1.25rem;
  background: var(--surface-subtle);
  border-left: 1px solid var(--line);
  font-size: 0.8125rem;
}
.breakdown dt { color: var(--muted); padding: 3px 0; }
.breakdown dd { margin: 0; padding: 3px 0; text-align: right; font-variant-numeric: tabular-nums; }
.breakdown dt.is-total,
.breakdown dd.is-total {
  margin-top: 4px;
  padding-top: 7px;
  border-top: 1px solid var(--line-strong);
  font-weight: 700;
  color: var(--ink);
}

/* Said once, where it matters, instead of a box that repeats the header. */
.inline-notice {
  margin: 0 0 1rem;
  padding: 0.55rem 0.75rem;
  background: var(--warn-bg);
  border: 1px solid #f0dcb0;
  border-left: 3px solid var(--warn-ink);
  border-radius: var(--radius-sm);
  color: var(--warn-ink);
  font-size: 0.8125rem;
}

.invoice-head,
.statement-invoice > summary {
  display: grid;
  grid-template-columns: 62px 82px minmax(120px, 1fr) 132px 128px 150px;
  gap: 12px;
  align-items: baseline;
}
.invoice-head {
  padding: 0.5rem 0.8rem;
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line-strong);
}
.invoice-head .num,
.statement-invoice > summary .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
#invoice-list {
  border: 1px solid var(--line);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-raised);
  overflow: hidden;
}
.invoice-head {
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  margin-top: 0;
}
.statement-invoice { border-bottom: 1px solid var(--line); background: var(--surface); }
.statement-invoice:last-child { border-bottom: none; }
.statement-invoice[hidden] { display: none; }
.statement-invoice > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.6rem 0.8rem;
  font-size: 0.8125rem;
  transition: background-color 120ms ease;
}
.statement-invoice > summary::-webkit-details-marker { display: none; }
.statement-invoice > summary:hover { background: var(--surface-hover); }
.statement-invoice > summary:focus-visible { outline: 2px solid var(--link); outline-offset: -2px; }
.statement-invoice[open] > summary { background: var(--surface-sunken); font-weight: 600; }
.statement-invoice .invoice-body {
  padding: 10px 12px 14px 12px;
  background: var(--surface-subtle);
  border-top: 1px solid var(--line);
}
.detail-table { width: 100%; font-size: 0.88rem; }
.detail-table th { white-space: nowrap; }
.detail-table tr.is-refund td { color: var(--error); }
.detail-table tfoot td { border-top: 1px solid var(--line-strong); }
.invoice-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  margin-top: 8px;
  font-size: 0.88rem;
}

.reconcile-details { margin: 20px 0; }
.reconcile-details > summary {
  cursor: pointer;
  padding: 8px 0;
  font-weight: 600;
  color: var(--ink);
  border-top: 1px solid var(--line);
}
.reconcile-details > summary .pill { font-weight: 400; margin-left: 8px; }
.reconcile-details .menu-body { padding: 4px 0 0; }

@media (max-width: 900px) {
  .statement-headline { grid-template-columns: 1fr; }
  .breakdown { border-left: none; border-top: 1px solid var(--line); }
  .invoice-head { display: none; }
  .statement-invoice > summary { grid-template-columns: 1fr 1fr; }
}

/* Measured in the browser at phone width, not guessed at: the tab strip above
   was the element making the whole page scroll sideways, and these are the
   others the same measurement found. */
.head-meta dt::after { content: ":"; }
.rule-table .row-actions a,
.rule-table .row-actions .link-button {
  text-decoration: none;
  white-space: nowrap;
}
.rule-table .row-actions a:hover,
.rule-table .row-actions .link-button:hover { text-decoration: underline; }
.product-table td:last-child { white-space: nowrap; }
.product-table .chip-row { display: flex; flex-wrap: wrap; gap: 3px; }
.picker-empty { padding: 8px 2px; color: var(--muted); font-size: 0.88rem; }

/* Keyboard focus on the controls these screens added. Scoped to them: the
   portal's form fields already have a focus style, and links and summaries
   elsewhere are left as they are. */
.tabs .tab:focus-visible,
.row-actions a:focus-visible,
.row-actions .link-button:focus-visible,
.quiet-details > summary:focus-visible,
.reconcile-details > summary:focus-visible,
.editor-history > summary:focus-visible,
.bulk-detail > summary:focus-visible,
.inline-menu > summary:focus-visible,
.editor-panel a:focus-visible,
.rule-form a:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 3px;
}
.picker-item:focus-within { background: var(--surface-sunken); }

/* An amount is read as one thing. Where a neighbouring column is wide enough
   to squeeze it, the figure must not break across two lines. */
.money-table td.num,
.money-table th.num,
.detail-table td.num,
.preview-out td.num,
.statement-invoice > summary .num { white-space: nowrap; }

/* ---------------------------------------------------------------------------
   Invoice review.

   The invoice list reuses the statement's grid. Inside an invoice: the amounts
   that add up, the products once each, and one product opened at a time.
   --------------------------------------------------------------------------- */
.invoice-amounts {
  max-width: 460px;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.invoice-amounts dt.is-open,
.invoice-amounts dd.is-open { color: var(--warn-ink); }

.review-products tr.is-open-row td { background: var(--warn-bg); }
.review-products td:last-child { white-space: nowrap; }
/* On a narrow screen this table scrolls inside its wrapper rather than
   squeezing a product name down to one letter per line. */
.review-products { min-width: 760px; }
.review-products td:first-child { min-width: 170px; }

.product-editor {
  margin: 8px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.product-editor > summary {
  cursor: pointer;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 0.92rem;
}
.product-editor[open] > summary { border-bottom: 1px solid var(--line); }
.product-editor > summary:focus-visible { outline: 2px solid var(--link); outline-offset: -2px; }
.product-editor .editor-body { padding: 10px 12px 12px; }
.product-editor .alloc-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: flex-start;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.product-editor .alloc-row:first-child { border-top: none; }
.product-editor .field { margin-bottom: 0; }
.product-editor .field > label {
  display: block;
  margin-bottom: 3px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}
.product-editor select { min-width: 280px; max-width: 520px; }
.product-editor input[type="number"] { width: 90px; }
.product-editor .field-help { max-width: 34em; }
.alloc-row[hidden] { display: none; }

.preview-out { margin: 10px 0; }
.preview-out table { width: 100%; font-size: 0.9rem; }
.preview-stale { color: var(--warn-ink); }

/* The preview says two different kinds of thing and they must not read as
   one: what the invoice pays TODAY, and what a proposal would do to it. A
   refused proposal has no figure of its own at all, so its block leads with
   the refusal and the headings below separate the workings from the result. */
.preview-out h4 {
  margin: 14px 0 4px;
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}
.preview-out > h4:first-child { margin-top: 0; }
.preview-out .table-wrap { margin-bottom: 6px; }
.save-blocked { color: var(--warn-ink); }
.product-editor .field-help.error { color: var(--error); }


/* Something the save would leave behind for somebody to look at. Not a
   refusal, so not red; not finished, so not green. */
.message-followup {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-color: #f0dcb0;
}


/* ---------------------------------------------------------------------------
   Product names.

   A statement's product column is a NAME, so it wraps -- product names run to
   fifty characters and a code does not. The SKU beside it on a manager's
   screen stays a code: monospaced, quiet, and never the thing being read.
   Where no name is set, the gap is said in words rather than filled with the
   SKU.
   -------------------------------------------------------------------------- */
.detail-table td .product-name,
.product-table td .product-name {
  display: block;
  overflow-wrap: anywhere;
}
.detail-table td .product-name + .muted { margin-top: 1px; }
.is-unnamed { color: var(--warn-ink); font-style: italic; }
.detail-table td:first-child,
.preview-out td:first-child { overflow-wrap: anywhere; }


/* ---------------------------------------------------------------------------
   Ticket queue: tabs, compact filters, and the selection toolbar.

   The tabs are three filters over the statuses that already exist, so they
   read as one control rather than three pages. Everything here is sized for
   a list somebody scans all day: no cards, no charts, no paragraphs.
   -------------------------------------------------------------------------- */
.lifecycle-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin: 0 0 1rem;
}
.lifecycle-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  transition: color 120ms ease, border-color 120ms ease, background-color 120ms ease;
}
.lifecycle-tab:hover {
  color: var(--ink);
  background: var(--surface-hover);
  text-decoration: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.lifecycle-tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}
.lifecycle-tab:focus-visible { outline: 2px solid var(--link); outline-offset: -2px; border-radius: 3px; }
.lifecycle-tab .tab-count {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--surface-sunken);
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 650;
  text-align: center;
}
.lifecycle-tab.is-active .tab-count { background: var(--accent); color: #fff; }

.ticket-filters {
  margin: 0 0 1rem;
  padding: 0.75rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-raised);
}
.filter-primary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: end;
}
.filter-primary label { font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.filter-primary select, .filter-primary input[type="search"] { display: block; }
.filter-search { flex: 1 1 260px; min-width: 200px; }
.filter-search input[type="search"] { width: 100%; }
.filter-primary label.checkbox { display: flex; align-items: center; gap: 5px; }
.more-filters { margin-top: 8px; }
.more-filters > summary {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  width: max-content;
  padding: 0.2rem 0;
}
.more-filters > summary:hover { color: var(--ink); }
.more-filters > summary:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 3px; }
.more-filters[open] > summary { color: var(--ink); }
.filter-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: end;
  padding: 10px 0 2px;
}
.filter-secondary label { font-size: 0.75rem; font-weight: 600; color: var(--muted); }

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin: -0.5rem 0 1rem;
  font-size: 0.75rem;
}
.filter-chips .muted { font-weight: 600; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
}
.chip:hover { background: var(--surface-hover); color: var(--ink); text-decoration: none; }
.chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.chip-reset { border-style: dashed; color: var(--muted); }

/* Appears only once something is ticked, so it never takes space it has not
   earned. */
.bulk-bar[hidden] { display: none; }
.bulk-bar #bulk-count { font-weight: 650; color: var(--ink); }

.ticket-table th.tick-col, .ticket-table td.tick-col { width: 34px; padding-right: 0; text-align: center; }
.ticket-table td.row-action { white-space: nowrap; text-align: right; }
/* The subject is what the row is about. */
.ticket-table td.subject-cell { font-weight: 600; color: var(--ink); }
.ticket-table td.ticket-id-cell { font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .lifecycle-tabs { overflow-x: auto; }
  .filter-primary, .filter-secondary { flex-direction: column; align-items: stretch; }
  .filter-search { flex: 1 1 auto; }
  .bulk-bar { position: sticky; bottom: 0; z-index: 5; }
}


/* ---------------------------------------------------------------------------
   Interaction affordances.

   Everything here exists so a control looks like a control: a disclosure
   that turns, a menu that floats, a tap target a thumb can hit, and one
   focus ring used everywhere rather than four.
   --------------------------------------------------------------------------- */

/* A disclosure says which way it is facing. The marker is replaced rather
   than hidden, so the triangle does not double up with the chevron. */
.quiet-details > summary,
.calc-detail > summary,
.more-filters > summary,
.reconcile-details > summary,
.editor-history > summary,
.bulk-detail > summary,
.advanced > summary {
  list-style: none;
}
.quiet-details > summary::-webkit-details-marker,
.calc-detail > summary::-webkit-details-marker,
.more-filters > summary::-webkit-details-marker,
.reconcile-details > summary::-webkit-details-marker,
.editor-history > summary::-webkit-details-marker,
.bulk-detail > summary::-webkit-details-marker,
.advanced > summary::-webkit-details-marker { display: none; }
.quiet-details > summary::before,
.calc-detail > summary::before,
.more-filters > summary::before,
.reconcile-details > summary::before,
.editor-history > summary::before,
.bulk-detail > summary::before,
.advanced > summary::before {
  content: "";
  display: inline-block;
  width: 0.4em;
  height: 0.4em;
  margin-right: 0.45em;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg) translate(-0.1em, -0.1em);
  transition: transform 140ms ease;
}
.quiet-details[open] > summary::before,
.calc-detail[open] > summary::before,
.more-filters[open] > summary::before,
.reconcile-details[open] > summary::before,
.editor-history[open] > summary::before,
.bulk-detail[open] > summary::before,
.advanced[open] > summary::before {
  transform: rotate(45deg) translate(-0.05em, -0.15em);
}

/* The statement's invoice rows and the review's product rows open in place,
   so they carry the same chevron on the left of the row.

   Those two summaries are grid containers: a ::before on them would become a
   grid ITEM and push every column along by one, which is exactly what it did
   -- the customer landed under "Product net sales" and the status wrapped. So
   the mark is taken out of flow and the row is padded to make room for it. */
.statement-invoice > summary,
.invoice-row > summary { position: relative; padding-left: 1.6rem; }
.invoice-head { padding-left: 1.6rem; }
.statement-invoice > summary::before,
.invoice-row > summary::before {
  content: "";
  position: absolute;
  left: 0.75rem;
  top: 50%;
  width: 0.38em;
  height: 0.38em;
  border-right: 1.5px solid var(--faint);
  border-bottom: 1.5px solid var(--faint);
  transform: translateY(-50%) rotate(-45deg);
  transition: transform 140ms ease;
}
.statement-invoice[open] > summary::before,
.invoice-row[open] > summary::before { transform: translateY(-60%) rotate(45deg); }
/* The product editor's summary is ordinary flow, so its mark can be inline. */
.product-editor > summary::before {
  content: "";
  display: inline-block;
  width: 0.38em;
  height: 0.38em;
  margin-right: 0.5em;
  border-right: 1.5px solid var(--faint);
  border-bottom: 1.5px solid var(--faint);
  transform: rotate(-45deg);
  transition: transform 140ms ease;
}
.product-editor[open] > summary::before { transform: rotate(45deg); }

/* A disclosure used as a button keeps the button's shape. */
summary.btn, summary.btn-ghost { list-style: none; }
summary.btn::-webkit-details-marker { display: none; }

.rule-form fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}
.rule-form legend {
  padding: 0 0.4rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.picker-list {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}
.picker-item { border-radius: 4px; padding: 0.2rem 0.3rem; }

.head-meta { font-size: 0.8125rem; }
.head-meta dt { font-weight: 500; }
.source-status { font-size: 0.8125rem; }
.field-help { font-size: 0.75rem; }
.field-error { font-size: 0.8125rem; }
.plain-list li { font-size: 0.8125rem; }
.kv { font-size: 0.8125rem; }
.section-head h2 { margin: 0; }
.rule-section h3 { font-size: 0.9375rem; }
.row-actions { font-size: 0.8125rem; }
.actions-row > a:not(.btn):not(.button) { font-size: 0.8125rem; }
.month-picker label { font-size: 0.75rem; font-weight: 600; }
.month-picker select { min-width: 160px; }

/* Links sitting among buttons in a page header read as the quiet option. */
.page-head .actions-row > a:not(.btn):not(.button) {
  color: var(--muted);
  font-weight: 500;
  padding: 0 0.15rem;
}
.page-head .actions-row > a:not(.btn):not(.button):hover { color: var(--link); }

/* Two levels of feedback the portal already emits, told apart by colour
   rather than by reading them. */
.message-info { background: var(--info-bg); color: var(--info-ink); border-color: #c7d7f8; border-left-color: var(--info-ink); }
.message-warning { background: var(--warn-bg); color: var(--warn-ink); border-color: #f0dcb0; border-left-color: var(--warn-ink); }
.message-error { border-left: 3px solid var(--error); }
.message-followup { border-left: 3px solid var(--warn-ink); }

/* ----- Phone ------------------------------------------------------------- */
@media (max-width: 860px) {
  /* A thumb needs something to hit. */
  .btn, button, a.button, .lifecycle-tab, .tabs .tab, .chip, .menu-btn { min-height: 38px; }
  .btn-small { min-height: 34px; }
  .lifecycle-tab, .tabs .tab { display: inline-flex; align-items: center; }
  .lifecycle-tabs, .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: thin; }
  .lifecycle-tab, .tabs .tab { white-space: nowrap; }

  /* The page header stacks, and its action keeps the full width rather than
     shrinking to a corner of the screen. */
  .page-head { gap: 0.75rem; }
  .page-head .actions-row { width: 100%; }

  .summary-surface { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .ticket-layout { gap: 1rem; }
  .rail-section { padding: 0.75rem 0.9rem; }
  .action-item { flex-direction: column; align-items: stretch; gap: 0.5rem; }
  .action-item form, .action-item .btn { width: 100%; }
  .panel, .card { padding: 0.85rem 0.9rem; }
  .meta-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

/* The header search carries its own icon inside the field, so the control
   reads as a search box rather than as an unlabelled text input. */
.search-field {
  position: relative;
  display: block;
  margin: 0;
}
.search-field > .icon {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--faint);
  pointer-events: none;
}
.search-field input[type="search"] { padding-left: 2rem; }
.search-field:focus-within > .icon { color: var(--link); }

/* A field that lives in a table's toolbar: label beside the control, not
   above it, so the toolbar stays one line deep. */
.panel-toolbar .toolbar-field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  flex: 0 1 auto;
  min-width: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}
.panel-toolbar .toolbar-field select,
.panel-toolbar .toolbar-field input {
  margin: 0;
  width: auto;
  min-width: 190px;
  min-height: 32px;
  font-size: 0.8125rem;
}
.panel-toolbar .toolbar-field.is-wide { flex: 1 1 240px; }
.panel-toolbar .toolbar-field.is-wide input { width: 100%; min-width: 0; }
.panel-toolbar .toolbar-hint { margin-left: auto; }
@media (max-width: 860px) {
  .panel-toolbar .toolbar-field { flex: 1 1 100%; }
  .panel-toolbar .toolbar-field select,
  .panel-toolbar .toolbar-field input { flex: 1 1 auto; min-width: 0; width: 100%; }
  .panel-toolbar .toolbar-hint { margin-left: 0; }
}

/* An identifier is one thing at any width. */
.ticket-table td.ticket-id-cell { white-space: nowrap; }

/* A run bar: one operation that writes, with its own explanation, kept
   visibly apart from the read-only filters above it. */
.run-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin: 0 0 1.25rem;
  padding: 0.75rem 0.95rem;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.run-bar strong { font-size: 0.875rem; font-weight: 600; }
.run-bar p { margin: 0.1rem 0 0; font-size: 0.8125rem; }
.run-bar select { margin: 0; width: auto; min-width: 170px; }

/* An action whose form needs a reason opens in place rather than firing
   from the list. */
.action-item.is-stacked { display: block; }
.action-form > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  margin-top: 0.6rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.action-form > summary::-webkit-details-marker { display: none; }
.action-form > summary:hover { background: var(--surface-hover); border-color: #b4c0ce; }
.action-form > summary:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.action-form[open] > summary { background: var(--surface-sunken); }
.action-form[open] > form {
  margin-top: 0.75rem;
  padding: 0.85rem 0.95rem;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: 560px;
}
.action-form form textarea { min-height: 64px; }
@media (max-width: 860px) {
  .run-bar { flex-direction: column; align-items: stretch; }
  .run-bar .actions-row select { flex: 1 1 auto; }
}

/* A summary cell holding a name, a date or a status rather than a figure:
   the same slot, but read as words. */
.summary-value.is-text {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

/* The rep switch is a scope control; where it still sits beside a heading
   it reads as one labelled control rather than a stray form. */
.rep-switch {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  margin: 0;
}
.rep-switch label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.rep-switch select { margin: 0; width: auto; min-width: 170px; }

/* Panels that are each a small table or list, laid out so three of them do
   not leave half a row empty. */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: start;
}
.panel-grid > * { min-width: 0; margin-bottom: 0; }

/* A row of counts that open filtered queues. Controls, not a surface. */
.attention-row { margin: 0 0 1.25rem; }
.attention-item > .icon { color: var(--faint); margin-left: 0.1rem; }
.attention-item:hover > .icon { color: var(--link); }

/* A month waiting on somebody is not the same as a month nobody has
   started, and neither is a month that is finished. */
.status-in_review, .status-in { background: var(--warn-bg); color: var(--warn-ink); }

.rail-actions .actions-row { margin-bottom: 0.25rem; }

/* A disclosure inside a table cell sits on the line with its neighbours.
   Three of them stacked made every rep's row three buttons tall. */
td > .action-form { display: inline-block; vertical-align: top; margin: 0 0.35rem 0 0; }
td > .action-form > summary { margin-top: 0.5rem; min-height: 32px; font-size: 0.8125rem; }
td > .action-form[open] { display: block; margin-right: 0; }
td > .action-form[open] > form { max-width: 420px; }
td > .quiet-details > summary { margin: 0.6rem 0 0; }

/* The table a form sits inside should not force the form wider than it is
   readable, and a bare .form-panel inside a flex/grid parent still needs a
   minimum of nothing to shrink against. */
form.form-panel { min-width: 0; }

/* An amount, a count or a quantity is one thing at every width. The rule
   that lets long words break inside a cell applied to the numeric columns
   too, so "$128,128.00" came out as "$128,128.0" and a lone "0" beneath it.
   A table that no longer fits scrolls inside its own .table-wrap. */
td.num, th.num {
  white-space: nowrap;
  overflow-wrap: normal;
}

/* Below 900px the invoice summary becomes two columns over two rows, so a
   vertically centred chevron lands on the second line, beside the customer
   instead of beside the date. Pin it to the first line. */
@media (max-width: 900px) {
  .statement-invoice > summary::before,
  .invoice-row > summary::before {
    top: 0.85rem;
    transform: rotate(-45deg);
  }
  .statement-invoice[open] > summary::before,
  .invoice-row[open] > summary::before { transform: rotate(45deg); }
}

/* A disclosure sharing a row with buttons: closed it is one of them; opened
   it takes the whole line so its form is not squeezed into a button's
   width. */
.actions-row > .action-form > summary { margin-top: 0; }
.actions-row > .action-form[open] { flex: 1 1 100%; }
.actions-row > .action-form[open] > form { max-width: 480px; }

/* A panel is as tall as what is in it. Stretching every panel in a row to
   match the tallest one left the short ones with a dead half-page under
   their content. */
.grid-2 { align-items: start; }
.grid-2 > *, .panel-grid > * { margin-bottom: 0; }

/* With the boxes gone the grid's gap is doing the separating, so it tightens
   up and the first row in each column loses its rule. */
.meta-grid { gap: 0 1.25rem; }
.meta-grid > .meta-item:first-child { border-top: none; }
@media (min-width: 861px) {
  /* Only the first item of each column can lose its rule, and only when the
     grid actually has more than one column to speak of. */
  .meta-grid { row-gap: 0; }
}

/* "There is nothing to do" is not a warning. It was wearing the amber of
   one, which made an empty attention list read as a problem. */
.note-quiet {
  margin: 0 0 1.25rem;
  padding: 0.6rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.8125rem;
}

/* A grouped sub-section of a form. The browser's own legend colour and
   border read as an error at a glance. */
fieldset {
  margin: 1rem 0;
  padding: 0.85rem 1rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}
legend {
  padding: 0 0.4rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* An input that states its own size keeps it. The blanket `width: 100%`
   above stretched the commission rate box across the page and pushed its
   "%" onto the next line -- the same break a `size="6"` was added to fix
   once before. */
input[size] { width: auto; }
.inline-form { align-items: center; }
.inline-form label { display: inline-flex; align-items: center; gap: 0.4rem; }
.inline-form label input { margin: 0; }

/* A page's one-line context is prose, so it stops at a readable measure.
   Left to run the full width it pushed the page's action onto a second row
   and left it sitting under the title instead of opposite it. */
/* Prose keeps a reading measure; a row of short facts (a brand's counts and
   rate, a ticket's state) does not, and was wrapping its last value onto a
   line of its own. */
.page-head > div:first-child { max-width: 96ch; }
.page-head > div:first-child > p { max-width: 68ch; }
.page-head .head-meta { max-width: none; }

/* A tickbox and its words are one control, so the control bar sizes it to
   its text instead of giving it a column and wrapping the label into it. */
.filter-bar label.checkbox,
.command-bar label.checkbox,
.filter-primary label.checkbox,
.filter-secondary label.checkbox {
  flex: 0 0 auto;
  gap: 0.4rem;
  align-self: center;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
}

/* The signed-out error pages (400/403/404/500) sit on the same canvas as the
   sign-in card and are read the same way: one short surface, centred. */
.error-panel {
  width: 100%;
  max-width: 520px;
  margin: 3rem auto;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
  padding: 1.4rem 1.5rem 1.5rem;
}
.error-panel h1 { font-size: 1.25rem; }
.error-panel p { font-size: 0.875rem; }

/* A figure that does not exist yet, in the slot where a figure goes. */
.summary-none {
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
}

/* The three ticket forms collapse behind their own headings. The heading is
   kept as an h2 inside the summary -- its presence and its order are the
   contract that stops a close form appearing above Start and Resolve -- so
   it has to read as the disclosure's label rather than as a page heading. */
.action-form > summary > h2 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: inherit;
}

/* A two-word label fits a summary cell; "Customers to follow up" needs the
   second line rather than a narrower column. */
.summary-item h2, .summary-item .summary-label { text-wrap: balance; }


/* ===========================================================================
   V5 — hierarchy, not more cards.

   The V4 pass gave the portal depth. What it did not give it was RANK: a
   filter bar, a summary, a table and a reference panel all arrived as white
   bordered surfaces of equal weight, so a page had to be read rather than
   seen. Everything below exists to rank what is already there --
   typography, spacing and a quieter background for the things that are not
   the work -- without introducing a single new card.
   =========================================================================== */

/* ----- Quiet surfaces ----------------------------------------------------
   Reference material, help text and "nothing is happening" states sit on the
   canvas tint rather than on white. White is for the work. */
.panel-quiet {
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin: 0 0 1rem;
}
.panel-quiet > h2, .panel-quiet > h3 {
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.5rem;
}
.panel-quiet p { font-size: 0.8125rem; color: var(--muted); }
.panel-quiet p:last-child { margin-bottom: 0; }

/* A metric reading zero is not news. It keeps its place in the row so the
   set stays comparable, but it stops competing with the ones that are not. */
.kpi.is-quiet {
  background: transparent;
  border-color: #e8ecf2;
}
.kpi.is-quiet .kpi-value { color: var(--faint); font-weight: 600; }
.kpi.is-quiet h2 { color: var(--faint); }

/* ----- The attention surface --------------------------------------------
   What is waiting for somebody is the most actionable thing on a dashboard,
   so it reads as one operational block of things to open rather than a row
   of loose chips sitting on the canvas. */
.attention-surface {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0 0 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
  overflow: hidden;
}
.attention-surface .attention-item {
  flex: 1 1 190px;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  padding: 0.8rem 1rem;
  border: none;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: 0.8125rem;
}
.attention-surface .attention-item:first-child { border-left: none; }
.attention-surface .attention-item:hover {
  background: var(--surface-hover);
  box-shadow: none;
}
.attention-surface .attention-item:focus-visible {
  outline: none;
  box-shadow: inset var(--focus-ring);
}
.attention-surface .attention-item strong {
  font-size: 1.375rem;
  font-weight: 680;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.attention-surface .attention-item .icon { margin-left: auto; color: var(--faint); }
.attention-surface .attention-item:hover .icon { color: var(--link); }

/* ----- The ticket rail ---------------------------------------------------
   One surface on the right of a ticket, divided into sections. The forms
   inside stay exactly as they are in the DOM -- separate forms, in the order
   the lifecycle tests lock -- and only the frames around them are removed,
   so what looked like a stack of admin cards reads as one rail. */
.ticket-rail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-raised);
  overflow: hidden;
}
.ticket-rail > * {
  margin: 0;
  border: none;
  border-top: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  padding: 0.95rem 1.05rem;
}
.ticket-rail > *:first-child { border-top: none; }
/* .stack-gap is what spaced these out as separate cards. */
.ticket-rail.stack-gap > * + * { margin-top: 0; }
.ticket-rail .rail-section { padding: 0; border-top: none; }
.ticket-rail > * > h2 {
  margin: 0 0 0.6rem;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.ticket-rail .rail-facts { gap: 0.65rem; }
.ticket-rail .action-form { display: block; margin: 0.4rem 0 0; }
.ticket-rail .action-form > summary { width: 100%; }
.ticket-rail p.muted { font-size: 0.75rem; }

/* ----- The queue's resolution tool ---------------------------------------
   It is not a second filter bar. It is the tool the table's Resolve buttons
   read from, so it is attached to the top of the table, tinted rather than
   white, and labelled with what it is for. */
.panel-toolbar.is-tool {
  background: var(--surface-sunken);
  border-color: var(--line);
  color: var(--ink);
}
.panel-toolbar .toolbar-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.panel-toolbar .toolbar-label .icon { color: var(--faint); }

/* ----- Table cells that are values, not states ---------------------------
   A brand, a category, a rule name: ordinary data, so ordinary text. The
   secondary line under a cell subject is quieter than the subject. */
.cell-note {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.cell-note + .cell-note { margin-top: 0.1rem; }
.cell-value { font-size: 0.8125rem; color: var(--ink); }
.cell-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.75rem;
  color: var(--muted);
}
.cell-list li { overflow-wrap: anywhere; }
.cell-list .cell-more { color: var(--faint); }

/* ----- Form composition --------------------------------------------------
   A form is read one field at a time, so it keeps a readable measure instead
   of stretching to a 1480px canvas. Short related fields may share a row;
   anything someone writes prose into keeps the full width. */
/* One authoritative measure for every form page. */
.form-panel { max-width: 680px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0 1rem;
}
.form-grid > .field-wide { grid-column: 1 / -1; }
.form-section {
  margin: 0 0 1.25rem;
  padding: 0 0 1.25rem;
  border-bottom: 1px solid var(--line);
}
.form-section:last-of-type { border-bottom: none; padding-bottom: 0; }
.form-section > h2 {
  margin: 0 0 0.15rem;
  font-size: 0.875rem;
  font-weight: 650;
}
.form-section > p.muted { margin: 0 0 0.75rem; font-size: 0.8125rem; }

/* A form page with its explanatory material beside it rather than above it. */
.form-with-aside {
  display: grid;
  grid-template-columns: minmax(0, 680px) minmax(240px, 300px);
  gap: 1.5rem;
  align-items: start;
}
.form-with-aside > * { min-width: 0; }
@media (max-width: 1080px) {
  .form-with-aside { grid-template-columns: minmax(0, 1fr); max-width: 680px; }
}

/* ----- Interaction -------------------------------------------------------
   Every actionable thing already had hover and focus. These are the states
   that were missing: pressed, expanded, and a row that is genuinely
   selected rather than merely hovered. */
tbody tr.is-selected { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
tbody tr:has(.ticket-tick:checked),
tbody tr:has(.tick-one:checked) {
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}
details[open] > summary.btn-ghost { background: var(--surface-sunken); }
.btn:disabled:hover, button:disabled:hover {
  background: var(--surface-sunken);
  border-color: var(--line);
}
/* Something that destroys or reverses work does not look like navigation. */
.btn-danger:focus-visible { box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.22); }

/* ----- The narrow breakpoint --------------------------------------------- */
@media (max-width: 860px) {
  /* The sidebar is behind the toggle here, so the strip carries the brand. */
  .header-brand { display: inline-block; }
  .header-search { flex: 0 1 auto; margin-left: auto; }
  .attention-surface .attention-item {
    flex: 1 1 100%;
    border-left: none;
    border-top: 1px solid var(--line);
  }
  .attention-surface .attention-item:first-child { border-top: none; }
  .ticket-rail > * { padding: 0.85rem 0.9rem; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
}

/* The subject is what a queue row is about, so on a wide screen it gets the
   room rather than being squeezed to two lines by the metadata beside it. */
@media (min-width: 1100px) {
  .ticket-table td.subject-cell, .ticket-table th:nth-child(3) { min-width: 240px; }
}

/* The figure a finance row exists for. Heavier than the cells around it so a
   column of payouts can be scanned without reading the labels. */
.figure-strong {
  font-size: 0.9375rem;
  font-weight: 680;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
/* Reference prose set as a quiet block rather than a loose grey paragraph. */
p.panel-quiet { font-size: 0.8125rem; color: var(--muted); }

/* A statements table is read a month at a time, so the row where the month
   changes carries the division. One rule, not a heading row: the table stays
   sortable and the markup stays a table. */
tbody tr.is-group-start td { border-top: 1px solid var(--line-strong); }
tbody tr.is-group-start:first-child td { border-top: none; }

/* Stacked controls all start at the same edge; only the desktop row centres
   its tickbox against the inputs beside it. */
@media (max-width: 760px) {
  .filter-primary label.checkbox,
  .filter-secondary label.checkbox { align-self: start; }
}


/* ===========================================================================
   V6 — the remaining polish.

   Four ranks of action, one connected stat strip instead of free-floating
   KPI cards, a phone queue that reaches its table sooner, and the classes
   that replaced the last fixed inline styles.
   =========================================================================== */

/* ----- Danger -----------------------------------------------------------
   Reserved for what deactivates access, terminates work, rejects an
   approved path, or removes a configured entity. Reactivate, restore and
   "offer again" are the undo of those things and stay neutral on purpose.

   Two weights: solid where it is the page's terminating action, quiet where
   it sits in a row of ordinary ghost controls and would otherwise shout. */
.btn-danger,
button.btn-danger,
a.button.btn-danger {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}
.btn-danger:hover,
button.btn-danger:hover,
a.button.btn-danger:hover { background: #8f1c14; border-color: #8f1c14; color: #fff; }

.btn-danger-ghost,
button.btn-danger-ghost {
  background: var(--surface);
  border-color: #e6bdb9;
  color: var(--error);
}
.btn-danger-ghost:hover,
button.btn-danger-ghost:hover {
  background: var(--error-bg);
  border-color: #d89a95;
  color: #8f1c14;
}
.btn-danger-ghost:focus-visible,
button.btn-danger-ghost:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.22);
}
.btn-danger:disabled, .btn-danger-ghost:disabled {
  background: var(--surface-sunken);
  border-color: var(--line);
  color: var(--faint);
}

/* ----- The stat strip ---------------------------------------------------
   Four readings of one queue are one thing, so they share a surface with
   rules between them. This is the summary surface's quieter sibling: no
   shadow, because the queue it describes is not the work on this page. */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin: 0 0 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.stat {
  padding: 0.8rem 1rem;
  border-left: 1px solid var(--line);
  min-width: 0;
}
.stat:first-child { border-left: none; }
.stat h2 {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value {
  margin: 0.25rem 0 0.1rem;
  font-size: 1.375rem;
  line-height: 1.75rem;
  font-weight: 680;
  letter-spacing: -0.012em;
  font-variant-numeric: tabular-nums;
}
.stat p.muted { margin: 0; font-size: 0.75rem; }
/* A reading of nothing keeps its place so the set stays comparable, and
   stops competing with the readings that are not nothing. */
.stat.is-quiet .stat-value { color: var(--faint); font-weight: 600; }
.stat.is-quiet h2, .stat.is-quiet p.muted { color: var(--faint); }

/* A panel whose table has no rows says so in a line, rather than framing an
   empty grid at full height. */
.empty-inline {
  margin: 0;
  padding: 0.35rem 0 0.1rem;
  color: var(--muted);
  font-size: 0.8125rem;
}

/* ----- Classes that replaced fixed inline styles ------------------------- */
/* A form that follows content it acts on, rather than opening a panel. */
.form-after { margin-top: 0.75rem; }
/* A quantity cell: wide enough for four digits and a stepper, no wider. */
.qty-input { width: 5.5rem; }
/* A history line in a disclosure: a list item, not a message banner. */
.plain-entry {
  background: none;
  border: 0;
  padding: 0.25rem 0;
  margin: 0;
  color: inherit;
  font-weight: 400;
  font-size: 0.8125rem;
}

/* ----- The phone queue --------------------------------------------------
   Search and Status stay in the bar; Priority, Assignment and Needs
   response fold into the More filters disclosure that already exists, so
   the table starts higher up the page. There is ONE of each input in the
   document -- nothing is duplicated and no GET name changes.

   Gated on :has() support. Without it every control stays visible, which is
   exactly today's behaviour, so the fallback can never hide a control it
   has no way to reveal. The disclosure's own open state is extended in the
   template, so a filter in force is never behind a closed one. */
@supports selector(:has(*)) {
  @media (max-width: 760px) {
    /* label.checkbox already carries display:flex at (0,2,1), so these have
       to match it or the tickbox alone would stay visible. */
    .filter-primary > label.is-extra,
    .filter-primary > label.checkbox.is-extra { display: none; }
    .ticket-filters:has(.more-filters[open]) .filter-primary > label.is-extra,
    .ticket-filters:has(.more-filters[open]) .filter-primary > label.checkbox.is-extra {
      display: flex;
    }
  }
}

/* ----- Low-density forms ------------------------------------------------
   The form and its aside start on the same line, so a short form does not
   look like it stopped early next to a tall rail. */
.form-with-aside > .panel-quiet { margin-top: 0; }
.form-with-aside .panel-quiet ul { margin: 0; padding-left: 1.1rem; }
.form-with-aside .panel-quiet li { font-size: 0.8125rem; margin: 0.15rem 0; }

@media (max-width: 860px) {
  .stat { border-left: none; border-top: 1px solid var(--line); }
  .stat:first-child { border-top: none; }
}
