/* =========================================================
   Moonglade Web — internal operations dashboard
   v2 · Reskin · May 2026
   Editorial design system applied as a refinement of the
   existing class names. Drop-in replacement for static/style.css.
   ========================================================= */

/* --- Fonts (Inter + Cormorant Garamond) load via non-render-blocking
   <link> in base.html <head> and login.html <head> — not @import here. --- */

:root {
  /* === Primary === */
  --moon-dark:        #1a3a52;
  --moon-darker:      #142e42;
  --moon-gold:        #c9a961;
  --moon-gold-soft:   #d8be7d;
  --moon-teal:        #2c5f7c;

  /* === Surfaces === */
  --moon-cream:        #f5f1e8;
  --moon-cream-soft:   #faf8f2;
  --moon-bg:           #f5f1e8;   /* cream replaces grey */
  --moon-surface:      #ffffff;

  /* === Lines & text === */
  --moon-divider:      #d8d2c4;   /* Stone-300 */
  --moon-grey-light:   #ece6d5;
  --moon-text:         #0d1f2d;
  --moon-text-soft:    #4a4438;
  --moon-grey:         #8a8170;

  /* === Semantic === */
  --moon-green:        #2d6a4f;
  --moon-amber:        #b08442;
  --moon-red:          #8b2e2e;

  /* === Status (unit availability) — SOLID high-contrast fills, FIXED in light + dark ===
     These encode real-world unit state, not chrome, so they must NOT invert with the theme
     (kept out of the [data-theme="dark"] block deliberately). Consumed by BOTH /block-availability
     (.block-cell--*) and the /inventory Availability Matrix (.matrix-cell.status-*) so a colour
     means the same thing on both surfaces. Tuned to survive WhatsApp/JPEG compression on a phone;
     Available is the loud saturated state, everything else recedes. All hex — html2canvas 1.4.1
     cannot parse oklch()/modern colour functions, and the share PNG capture inherits these. */
  --st-avail-bg:   #1B8A5A;  --st-avail-fg:   #FFFFFF;   /* Available */
  --st-booked-bg:  #D9D4CA;  --st-booked-fg:  #5A554D;   /* Booked — fg darkened from spec #7A756D (3.1:1) to clear 4.5:1 (5.0:1) */
  --st-blocked-bg: #C9A961;  --st-blocked-fg: #4A3B13;   /* Blocked (brand gold) */
  --st-cancel-bg:  #C0392B;  --st-cancel-fg:  #FFFFFF;   /* Cancelled */
  --st-refuge-bg:  #1A3A52;  --st-refuge-fg:  #FFFFFF;   /* Refuge (brand navy)  */

  /* === Type === */
  --serif: "Cormorant Garamond", "Playfair Display", Georgia, serif; /* @kind font */
  --sans:  "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif; /* @kind font */

  /* === Shadows === */
  --shadow-card:     0 2px 16px rgba(26,58,82,0.06);
  --shadow-elevated: 0 12px 48px rgba(26,58,82,0.10);

  /* Measured height of the sticky .page-header (set by JS in base.html).
     0px default → in-content sticky stack behaves exactly as pre-app-shell. */
  --header-h: 0px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--moon-text);
  background: var(--moon-bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11";
}
a { color: var(--moon-dark); text-decoration: none; }
a:hover { color: var(--moon-gold); }

/* =========================================================
   APP SHELL
   ========================================================= */
/* Full-viewport shell: the window no longer scrolls — only the content region
   (.content-scroll) does. Sidebar + slim footer bar stay constant. */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 240px;
  background: var(--moon-darker);
  color: rgba(245,241,232,0.92);
  padding: 28px 0 0;
  flex-shrink: 0;
  display: flex; flex-direction: column;
  position: relative;
  overflow: hidden;          /* internal scroll is owned by <nav>, not the aside */
}
.sidebar-brand {
  padding: 0 24px 24px;
  border-bottom: 1px solid rgba(245,241,232,0.10);
  margin-bottom: 18px;
  text-align: left;
}
.sidebar-brand .logo-link { display: block; padding: 4px 0; margin-bottom: 8px; }
.sidebar-brand .brand-logo {
  max-width: 150px; height: auto; display: block;
  filter: none;             /* WHITE logo file is already light */
  opacity: 0.96;
  margin: 0;
}
.sidebar-brand .tag {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: var(--moon-gold);
  font-weight: 600;
  margin-top: 6px;
}

.sidebar nav {
  padding: 0 0 24px;
  flex: 1 1 auto;            /* grow to fill the column */
  overflow-y: auto;         /* long nav scrolls internally */
  min-height: 0;            /* allow the flex child to shrink below content height */
}
/* Section header — Option C: gold label + gold-hairline divider above each
   group. Horizontal margin (24px) matches the nav items' left padding, so the
   gold label lines up with the link text and the hairline spans the same width. */
.sidebar nav .nav-section {
  font-family: var(--sans);
  color: var(--moon-gold);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin: 18px 24px 6px;
  padding-top: 10px;
  border-top: 1px solid rgba(201,169,97,0.30);
}
/* First section (Overview) sits under the wordmark divider — don't double the rule. */
.sidebar nav .nav-section:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 6px;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  color: rgba(245,241,232,0.78);
  font-size: 13px;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: color .15s, background .15s, border-color .15s;
  text-decoration: none;
}
.sidebar nav a:hover { background: rgba(245,241,232,0.04); color: var(--moon-cream); }
.sidebar nav a.active {
  background: rgba(201,169,97,0.08);
  color: var(--moon-cream);
  border-left-color: var(--moon-gold);
}
.sidebar nav a.active::after {
  content: ""; width: 4px; height: 4px; border-radius: 50%; background: var(--moon-gold);
}

.sidebar-footer {
  flex: 0 0 auto;            /* fixed-size item pinned at the column end */
  padding: 18px 24px 22px;
  font-size: 11px;
  color: rgba(245,241,232,0.5);
  border-top: 1px solid rgba(245,241,232,0.10);
  position: static;          /* (fix from old absolute positioning) */
  width: auto;
}
.sidebar-footer strong { color: var(--moon-cream); font-weight: 600; }
.sidebar-footer a { color: rgba(245,241,232,0.7); text-decoration: underline; text-underline-offset: 2px; }
.sidebar-footer a:hover { color: var(--moon-gold); }

.sidebar-footer .prefs-bar {
  display: flex; flex-direction: column; gap: 10px;
  padding-bottom: 14px; margin-bottom: 14px;
  border-bottom: 1px solid rgba(245,241,232,0.10);
}
.sidebar-footer .density-label,
.sidebar-footer .theme-label {
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  color: rgba(245,241,232,0.45); margin-bottom: 4px; font-weight: 600;
}

/* Density / theme toggle pills */
.density-toggle, .theme-toggle {
  display: inline-flex; padding: 2px; width: fit-content;
  background: rgba(245,241,232,0.06);
  border: 1px solid rgba(245,241,232,0.12);
  border-radius: 999px;
  align-items: center; gap: 2px;
}
.density-toggle-btn, .theme-toggle-btn {
  font-family: var(--sans);
  font-size: 11px; font-weight: 600;
  padding: 4px 12px;
  border: 0; background: transparent;
  color: rgba(245,241,232,0.6);
  border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  transition: background .12s, color .12s;
}
.density-toggle-btn:hover, .theme-toggle-btn:hover { color: var(--moon-cream); }
.density-toggle-btn.active, .theme-toggle-btn.active {
  background: var(--moon-gold); color: var(--moon-darker);
}
.theme-toggle-btn .glyph { font-size: 12px; line-height: 1; }
.theme-toggle-btn .beta-tag {
  font-size: 9px; letter-spacing: 0.04em;
  opacity: 0.55; margin-left: 3px; text-transform: uppercase;
}

/* =========================================================
   MAIN CONTENT
   ========================================================= */
/* Main column: a flex column whose only scrolling child is .content-scroll.
   The slim footer bar (Step 3) sits below the scroll region, always visible. */
.content {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 1400px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* The single page scroller. overflow:auto establishes a BFC so the page-header's
   top margin stays inside (no margin-collapse escape) and existing in-content
   sticky elements (tab strip / table headers) anchor cleanly at its top. */
.content-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
  padding: 0 44px;
}
/* Slim pinned footer bar — always visible below the scroll region. The full
   co-brand panel still lives at the natural bottom of the scrolled content. */
.app-footer-bar {
  flex: 0 0 auto;
  border-top: 1px solid rgba(201,169,97,0.30);
  background: var(--moon-bg);
  text-align: center;
  padding: 10px 16px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--moon-grey);
}

.page-header {
  position: sticky;           /* stays constant at the top of the scroll region */
  top: 0;
  z-index: 30;                /* above tab-strip (20) / matrix-filters (10) / thead (5) */
  background: var(--moon-bg); /* match content-scroll bg so content can't show through */
  padding-top: 36px;          /* top breathing room, INSIDE the bg box (was margin) */
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--moon-divider);
}
.page-header::after {
  content: "";
  position: absolute; bottom: -1px; left: 0;
  width: 48px; height: 2px;
  background: var(--moon-gold);
}
.page-header h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 36px;
  line-height: 1.05;
  letter-spacing: -0.005em;
  color: var(--moon-dark);
  margin: 0;
}
.page-header .breadcrumb {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--moon-grey);
  font-weight: 600;
  margin-bottom: 6px;
  display: block;
}
.page-header .meta {
  font-size: 12px;
  color: var(--moon-grey);
  font-variant-numeric: tabular-nums;
  text-align: right;
  letter-spacing: 0.02em;
}
.page-header .meta .dot {
  display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; vertical-align: middle; margin-right: 4px;
}
.status-success { color: var(--moon-green); font-weight: 600; }
.status-failed  { color: var(--moon-red);   font-weight: 600; }
.status-rolled  { color: var(--moon-amber); font-weight: 600; }
.status-skipped { color: var(--moon-grey); }
.status-running { color: var(--moon-teal);  font-weight: 600; }
.page-header .meta .status-success .dot,
.page-header .meta .status-success::before { background: var(--moon-green); }

/* =========================================================
   KPI CARDS — editorial: serif numbers + gold eyebrow labels
   ========================================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--moon-surface);
  border: 1px solid var(--moon-divider);
  border-left: none;                    /* override prior accent stripe */
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
  transition: box-shadow .2s;
}
.kpi-card:hover { box-shadow: 0 6px 28px rgba(26,58,82,0.10); }
.kpi-card .label, .kpi-card .kpi-label {
  display: block;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--moon-gold);
  margin-bottom: 12px;
}
.kpi-card .value, .kpi-card .kpi-value {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 38px;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--moon-dark);
  font-variant-numeric: tabular-nums;
}
.kpi-card .value .unit, .kpi-card .kpi-value .unit {
  font-size: 18px;
  color: var(--moon-grey);
  margin-left: 2px;
}
.kpi-card .value.gold { color: var(--moon-dark); }
.kpi-card .value.gold::after {
  content: ""; display: block;
  width: 24px; height: 2px;
  background: var(--moon-gold);
  margin-top: 8px;
}
.kpi-card .sub, .kpi-card .kpi-sub {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--moon-grey);
  margin-top: 8px;
  letter-spacing: 0.01em;
}
.kpi-card.kpi-success { box-shadow: var(--shadow-card), inset 3px 0 0 var(--moon-green); }
.kpi-card.kpi-info    { box-shadow: var(--shadow-card), inset 3px 0 0 var(--moon-dark); }
.kpi-card.kpi-warning { box-shadow: var(--shadow-card), inset 3px 0 0 var(--moon-gold); }
.kpi-card.kpi-danger  { box-shadow: var(--shadow-card), inset 3px 0 0 var(--moon-red); }

/* =========================================================
   SECTIONS / CARDS
   ========================================================= */
.section {
  background: var(--moon-surface);
  border: 1px solid var(--moon-divider);
  border-radius: 16px;
  padding: 24px 26px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}
.section h3 {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moon-dark);
  margin: 0 0 18px;
  padding-bottom: 0;
  border-bottom: none;
  display: flex; align-items: center; gap: 12px;
}
.section h3::before {
  content: ""; width: 6px; height: 6px;
  border-radius: 50%; background: var(--moon-gold);
  display: inline-block;
}

/* Detail cards (key-value pairs) */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.detail-card {
  background: var(--moon-surface);
  border: 1px solid var(--moon-divider);
  border-radius: 16px;
  padding: 22px 24px;
  box-shadow: var(--shadow-card);
}
.detail-card h4 {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moon-dark);
  margin: 0 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--moon-gold);
}
.detail-row {
  display: flex; justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px dashed var(--moon-divider);
}
.detail-row:last-child { border-bottom: none; }
.detail-row .label { color: var(--moon-grey); }
.detail-row .value { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* =========================================================
   DATA TABLES — refined hierarchy, keeps density
   ========================================================= */
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
table.data thead th {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moon-dark);
  background: var(--moon-cream);
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--moon-divider);
  position: sticky;
  top: calc(var(--header-h, 0px) + 49px);
  z-index: 5;
}
table.data thead tr:nth-child(2) th { top: calc(var(--header-h, 0px) + 73px); }
.page-without-tabs table.data thead th { top: calc(var(--header-h, 0px) + 0px); }
.page-without-tabs table.data thead tr:nth-child(2) th { top: calc(var(--header-h, 0px) + 28px); }

table.data tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--moon-divider);
  color: var(--moon-text);
  vertical-align: middle;
}
table.data tbody tr:hover td { background: rgba(201,169,97,0.06); }
table.data tbody tr:last-child td { border-bottom: 0; }

table.data tr.total td,
table.data tr.subtotal td {
  background: rgba(201,169,97,0.10);
  font-weight: 600;
  color: var(--moon-dark);
  border-top: 1px solid var(--moon-gold);
  border-bottom: 1px solid var(--moon-gold);
}
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.center, table.data th.center { text-align: center; }

/* Inventory mortgage bands */
table.data thead th.mortgage-band-0,
table.data thead th.mortgage-band-5,
table.data thead th.mortgage-band-10,
table.data thead th.total-band {
  background: var(--moon-dark) !important;
  color: var(--moon-cream) !important;
  border-bottom-color: var(--moon-gold);
}
table.data thead tr:first-child th.mortgage-band-0  { border-top: 2px solid var(--moon-gold); }
table.data thead tr:first-child th.mortgage-band-5  { border-top: 2px solid var(--moon-amber); }
table.data thead tr:first-child th.mortgage-band-10 { border-top: 2px solid var(--moon-teal); }
table.data thead tr:first-child th.total-band       { border-top: 2px solid var(--moon-cream); }
table.data tbody td.mortgage-band-0  { background: rgba(201,169,97,0.05); }
table.data tbody td.mortgage-band-5  { background: rgba(176,132,66,0.06); }
table.data tbody td.mortgage-band-10 { background: rgba(44,95,124,0.06); }
table.data tbody td.total-band {
  background: var(--moon-dark);
  color: var(--moon-cream);
}
table.data tbody td.total-band strong { color: var(--moon-cream); }
table.data tr.subtotal td.total-band { background: var(--moon-darker); }
table.data .pct-good { color: var(--moon-green); font-weight: 600; }
table.data .pct-mid  { color: var(--moon-gold); font-weight: 600; }
table.data .pct-low  { color: var(--moon-red);  font-weight: 600; }

h4.subsection-title {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moon-grey);
  margin: 22px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--moon-divider);
}
h4.subsection-title:first-of-type { margin-top: 4px; }

/* =========================================================
   PILLS / CHIPS — new editorial pill style with dot
   ========================================================= */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
.chip::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor;
}
.chip-green  { color: var(--moon-green); background: rgba(45,106,79,0.12); }
.chip-yellow { color: var(--moon-amber); background: rgba(176,132,66,0.12); }
.chip-amber  { color: var(--moon-amber); background: rgba(176,132,66,0.14); }
.chip-red    { color: var(--moon-red);   background: rgba(139,46,46,0.12); }
.chip-grey   { color: var(--moon-grey);  background: rgba(138,129,112,0.14); }
.chip-blue   { color: var(--moon-teal);  background: rgba(44,95,124,0.12); }
.chip-gold   { color: #8a6f2a;           background: rgba(201,169,97,0.18); }

.status-active  { color: var(--moon-red);   font-weight: 600; }
.status-frozen  { color: var(--moon-green); font-weight: 600; }
.status-tagged  { color: var(--moon-amber); font-weight: 600; }

/* Loan stages */
.loan-stage {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.loan-yes     { background: rgba(45,106,79,0.12);  color: var(--moon-green); }
.loan-no      { background: rgba(138,129,112,0.14);color: var(--moon-grey); }
.loan-pending { background: rgba(201,169,97,0.18); color: #8a6f2a; }

/* =========================================================
   FILTER BAR
   ========================================================= */
.filter-bar {
  background: var(--moon-surface);
  border: 1px solid var(--moon-divider);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex; flex-wrap: wrap; gap: 16px; align-items: end;
  box-shadow: var(--shadow-card);
}
.filter-bar label {
  display: block;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moon-grey);
  margin-bottom: 6px;
}
.filter-bar input, .filter-bar select {
  font-family: var(--sans);
  font-size: 13px;
  padding: 8px 12px;
  background: var(--moon-cream);
  border: 1px solid var(--moon-divider);
  border-radius: 8px;
  color: var(--moon-text);
  min-width: 150px;
}
.filter-bar input:focus, .filter-bar select:focus {
  outline: none;
  border-color: var(--moon-gold);
  box-shadow: 0 0 0 2px rgba(201,169,97,0.30);
}
.filter-bar button {
  font-family: var(--sans);
  background: var(--moon-dark);
  color: var(--moon-cream);
  border: 0;
  padding: 9px 22px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background .15s, box-shadow .15s;
}
.filter-bar button:hover { background: var(--moon-text); box-shadow: inset 0 -2px 0 var(--moon-gold); }
.filter-bar a.clear {
  font-size: 12px; color: var(--moon-grey);
  text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: var(--moon-divider);
}
.filter-bar a.clear:hover { color: var(--moon-red); text-decoration-color: var(--moon-red); }

/* =========================================================
   LOGIN PAGE
   ========================================================= */
.login-wrap {
  display: flex; min-height: 100vh;
  background:
    radial-gradient(circle at 75% 30%, rgba(201,169,97,0.10) 0%, transparent 40%),
    linear-gradient(180deg, var(--moon-darker) 0%, var(--moon-dark) 100%);
  align-items: center; justify-content: center;
  font-family: var(--sans);
  color: var(--moon-cream);
}
.login-card {
  background: var(--moon-cream);
  padding: 48px 48px 40px;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.30);
  width: 380px;
  border-top: 2px solid var(--moon-gold);
}
.login-card h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 32px;
  color: var(--moon-dark);
  margin: 0 0 4px;
  letter-spacing: 0.02em;
}
.login-card .tagline {
  font-size: 10px;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: var(--moon-gold);
  font-weight: 600;
  margin-bottom: 36px;
}
.login-card label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--moon-grey);
  margin: 18px 0 6px;
}
.login-card input {
  width: 100%;
  font-family: var(--sans);
  font-size: 14px;
  padding: 11px 14px;
  background: var(--moon-surface);
  border: 1px solid var(--moon-divider);
  border-radius: 8px;
}
.login-card input:focus {
  outline: none;
  border-color: var(--moon-gold);
  box-shadow: 0 0 0 3px rgba(201,169,97,0.30);
}
.login-card button {
  width: 100%;
  background: var(--moon-dark);
  color: var(--moon-cream);
  border: 0;
  padding: 13px;
  border-radius: 10px;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.04em;
  margin-top: 28px;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
}
.login-card button:hover { background: var(--moon-text); box-shadow: inset 0 -2px 0 var(--moon-gold); }
.login-card .error {
  background: rgba(139,46,46,0.10);
  color: var(--moon-red);
  padding: 10px 14px;
  border-radius: 8px;
  margin-top: 16px;
  font-size: 13px;
  border-left: 3px solid var(--moon-red);
}

/* =========================================================
   FOOTER CO-BRAND STRIP
   ========================================================= */
.copartner-strip {
  margin: 56px -44px 0;
  padding: 36px 44px 28px;
  background: transparent;
  border-top: 1px solid var(--moon-divider);
  text-align: center;
  position: relative;
}
.copartner-strip::before {
  content: "";
  position: absolute;
  top: -1px; left: 50%;
  transform: translateX(-50%);
  width: 48px; height: 2px;
  background: var(--moon-gold);
}
.copartner-label {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--moon-grey);
  margin-bottom: 18px;
}
.copartner-logos {
  display: flex; align-items: center; justify-content: center;
  gap: 36px; margin-bottom: 14px;
}
.copartner-logo {
  height: 34px; width: auto;
  opacity: 0.72; filter: grayscale(0.4);
  transition: opacity .2s, filter .2s;
}
.copartner-logo:hover { opacity: 1; filter: grayscale(0); }
.copartner-logo-einfra { height: 34px; }
.copartner-logo-ira    { height: 34px; }
.copartner-amp { display: none; }       /* replaced by divider rule */
.copartner-divider { width: 1px; height: 24px; background: var(--moon-divider); }

/* Co-brand navy panel — E-Infra's only artwork is a white wordmark (invisible
   on cream) and there's no dark E-Infra variant; so the two-logo lockup sits on
   a navy panel. E-Infra (white + gold, transparent) shows as-is; IRA uses the
   transparent variant whitened via filter (see .copartner-logo-ira below) so
   both logos float clean white on navy. */
.copartner-panel {
  display: inline-flex;
  align-items: center;
  background: var(--moon-dark);
  border-radius: 14px;
  padding: 18px 28px;
  margin: 0 auto 14px;
  box-shadow: inset 0 0 0 1px rgba(201,169,97,0.22);  /* restrained gold hairline */
}
.copartner-panel .copartner-logos { margin-bottom: 0; gap: 26px; }
.copartner-panel .copartner-logo,
.copartner-panel .copartner-logo-einfra,
.copartner-panel .copartner-logo-ira {
  height: auto;
  max-height: 34px;
  width: auto;
  opacity: 1;
  filter: none;                /* white logos on navy — no dimming/grayscale */
}
.copartner-panel .copartner-logo:hover { opacity: 1; filter: none; }
/* IRA: transparent (dark) mark whitened to pure white — ONLY the whitening
   filter, never stacked with the cream-footer grayscale/opacity. E-Infra is
   left untouched (already white + gold on transparent). Covers hover too so it
   doesn't flash back through the panel's filter:none hover rule. */
.copartner-panel .copartner-logo-ira,
.copartner-panel .copartner-logo-ira:hover { filter: brightness(0) invert(1); }
.copartner-panel .copartner-divider {
  width: 1px;
  height: 30px;
  background: rgba(245,241,232,0.25);   /* light divider, visible on navy */
}
.copartner-note {
  font-family: var(--serif);
  font-style: italic;
  font-size: 12px;
  color: var(--moon-grey);
  letter-spacing: 0.02em;
}

/* =========================================================
   TAB STRIP (primary, sticky) — refined
   ========================================================= */
.tab-strip {
  display: flex; gap: 0;
  background: var(--moon-surface);
  border-bottom: 1px solid var(--moon-divider);
  position: sticky; top: var(--header-h, 0px); z-index: 20;
  margin: 0 0 24px 0;
  overflow-x: auto; scrollbar-width: thin;
}
.tab-strip .tab-link {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 14px 22px;
  color: var(--moon-grey);
  text-decoration: none;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s, background .15s;
  white-space: nowrap;
}
.tab-strip .tab-link:hover { color: var(--moon-dark); background: var(--moon-cream); }
.tab-strip .tab-link.active {
  color: var(--moon-dark);
  border-bottom-color: var(--moon-gold);
  font-weight: 600;
}
.tab-strip .tab-count {
  display: inline-block;
  padding: 2px 8px;
  background: var(--moon-cream);
  color: var(--moon-dark);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}
.tab-strip .tab-link.active .tab-count {
  background: var(--moon-gold);
  color: var(--moon-darker);
}

/* Secondary tab strip (sub-tabs) */
.tab-strip-secondary {
  background: var(--moon-cream);
  border: 1px solid var(--moon-divider);
  border-radius: 999px;
  margin: 0 0 20px;
  position: static;
  border-bottom: none;
  padding: 4px;
  gap: 2px;
  width: fit-content;
}
.tab-strip-secondary .tab-link {
  padding: 8px 16px;
  font-size: 12px;
  border-bottom: none;
  border-radius: 999px;
  color: var(--moon-grey);
}
.tab-strip-secondary .tab-link:hover { background: var(--moon-cream-soft); color: var(--moon-dark); }
.tab-strip-secondary .tab-link.active {
  background: var(--moon-dark);
  color: var(--moon-cream);
}
.tab-strip-secondary .tab-link.active .tab-label { color: var(--moon-cream); }
.tab-strip-secondary .tab-count { background: rgba(255,255,255,0.18); color: inherit; }
.tab-strip-secondary .tab-link:not(.active) .tab-count {
  background: var(--moon-surface); color: var(--moon-dark);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* =========================================================
   SEGMENT HEADER + MATRIX CONTAINER
   ========================================================= */
.segment-header {
  margin: 4px 0 16px 0;
  display: flex; align-items: baseline; justify-content: space-between;
}
.segment-header h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  color: var(--moon-dark);
  margin: 0;
}
.segment-header .segment-sub {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--moon-grey);
  letter-spacing: 0.01em;
}

.matrix-container { display: block; }
.matrix-container + .matrix-container { margin-top: 32px; }
.tab-panel .tab-panel .matrix-container .matrix-filters { position: static; }

/* =========================================================
   MATRIX FILTERS / CHIP TOGGLES
   ========================================================= */
.matrix-filters {
  background: var(--moon-surface);
  border: 1px solid var(--moon-divider);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
  position: sticky; top: calc(var(--header-h, 0px) + 49px); z-index: 10;
  box-shadow: var(--shadow-card);
}
.matrix-filters .filter-row {
  display: flex; flex-wrap: wrap; gap: 20px 28px;
  align-items: center; padding: 6px 0;
}
.matrix-filters .filter-row + .filter-row { border-top: 1px dashed var(--moon-divider); }
.matrix-filters .filter-footer {
  justify-content: space-between;
  border-top: 1px solid var(--moon-divider) !important;
  margin-top: 4px; padding-top: 10px;
}
.matrix-filters .filter-group { display: flex; align-items: center; gap: 10px; }
.matrix-filters .filter-label {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moon-grey);
}

.chip-toggles { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.chip-toggle {
  background: var(--moon-surface);
  border: 1px solid var(--moon-divider);
  color: var(--moon-grey);
  padding: 5px 11px;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
  font-variant-numeric: tabular-nums;
}
.chip-toggle:hover { border-color: var(--moon-dark); color: var(--moon-dark); }
.chip-toggle.active {
  background: var(--moon-dark); border-color: var(--moon-dark); color: var(--moon-cream);
}

.matrix-counter {
  font-family: var(--sans);
  font-size: 12px; font-weight: 600;
  color: var(--moon-dark);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.btn-link {
  background: none; border: none;
  color: var(--moon-dark);
  text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: var(--moon-divider);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 12px;
  padding: 4px 0;
}
.btn-link:hover { color: var(--moon-gold); text-decoration-color: var(--moon-gold); }

/* =========================================================
   MATRIX LEGEND + GRID
   ========================================================= */
.matrix-legend {
  display: flex; flex-wrap: wrap; gap: 18px; align-items: center;
  padding: 10px 16px;
  background: var(--moon-cream);
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--moon-grey);
}
.matrix-legend .legend-item { display: inline-flex; align-items: center; gap: 6px; }
.matrix-legend .legend-hint { margin-left: auto; font-style: italic; }

.cell-sample {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 3px;
  vertical-align: middle;
  border: 1px solid rgba(0,0,0,0.08);
}

.matrix-towers { display: flex; flex-direction: column; gap: 24px; }
.matrix-tower {
  background: var(--moon-surface);
  border: 1px solid var(--moon-divider);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
}
.matrix-tower.hidden { display: none; }
.matrix-tower .tower-label {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--moon-dark);
  margin: 0 0 12px;
}

.matrix-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 4px;
}
.matrix-cell {
  position: relative;
  aspect-ratio: 1.6 / 1;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border: 1px solid transparent;
  transition: transform .08s, box-shadow .08s;
  user-select: none;
}
.matrix-cell.hidden { display: none; }
.matrix-cell:hover, .matrix-cell:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(26, 58, 82, 0.20);
  outline: none; z-index: 5;
}
.matrix-cell .cell-label { pointer-events: none; }

/* Status fills from the shared :root tokens (same as /block-availability so a colour means the
   same thing on both pages) + redundant non-colour cues (strike / ▲ / ⊘ / R). Fills theme-fixed. */
.matrix-cell.status-available { background: var(--st-avail-bg);   color: var(--st-avail-fg);   border-color: rgba(0,0,0,0.18); font-weight: 500; }
.matrix-cell.status-booked    { background: var(--st-booked-bg);  color: var(--st-booked-fg);  border-color: var(--moon-divider); font-weight: 400; }
.matrix-cell.status-booked .cell-label { text-decoration: line-through; }
.matrix-cell.status-blocked   { background: var(--st-blocked-bg); color: var(--st-blocked-fg);  border-color: rgba(0,0,0,0.18); }
.matrix-cell.status-blocked::after { content: "▲"; position: absolute; top: 2px; right: 3px; font-size: 8px; line-height: 1; color: var(--st-blocked-fg); pointer-events: none; }
.matrix-cell.status-cancelled { background: var(--st-cancel-bg);  color: var(--st-cancel-fg);  border-color: rgba(0,0,0,0.18); }
.matrix-cell.status-cancelled .cell-label::before { content: "⊘"; margin-right: 2px; }
.matrix-cell.status-refuge    { background: var(--st-refuge-bg);  color: var(--st-refuge-fg); }
.matrix-cell.status-refuge .cell-label::after { content: " R"; font-size: 9px; opacity: 0.7; }

/* Mortgage on an AVAILABLE unit — was a gold/red diagonal hatch, but gold now means Blocked and
   red means Cancelled, so an available-with-mortgage cell would misread. Moved to a neutral ink
   inset ring (edge treatment) that never collides with the status palette: thin=5%, thick=10%. */
/* Mortgage banding on an AVAILABLE unit — WHITE corner wedge (top-right). The v1 ink inset ring
   read poorly for 5% on the solid green fill; a white border-triangle is unmistakable on green and
   survives compression. 5% = single wedge, 10% = larger wedge (more mortgage → bigger wedge), so
   the two read as a consistent pair. Border-triangle only (html2canvas-safe — no clip-path/filter);
   0×0 positioned pseudo-element adds no layout box, so cell height/alignment is unchanged. Cannot
   collide with the Blocked ▲ (also top-right): a cell is never both Available and Blocked. */
.matrix-cell.status-available.mortgage-5::after,
.matrix-cell.status-available.mortgage-10::after {
  content: ""; position: absolute; top: 0; right: 0; width: 0; height: 0; pointer-events: none;
  border-style: solid; border-left-color: transparent; border-top-color: rgba(255,255,255,0.9);
}
.matrix-cell.status-available.mortgage-5::after  { border-width: 11px 0 0 11px; }
.matrix-cell.status-available.mortgage-10::after { border-width: 17px 0 0 17px; }
.matrix-cell.copied {
  background: var(--moon-gold) !important;
  color: var(--moon-darker) !important;
  box-shadow: none !important;
}
.matrix-cell.copied .cell-label::after { content: " ✓"; }

.cell-sample.status-available { background: var(--st-avail-bg);   border-color: rgba(0,0,0,0.18); }
.cell-sample.status-booked    { background: var(--st-booked-bg);  border-color: var(--moon-divider); }
.cell-sample.status-cancelled { background: var(--st-cancel-bg);  border-color: rgba(0,0,0,0.18); }
.cell-sample.status-refuge    { background: var(--st-refuge-bg);  border-color: var(--st-refuge-bg); }
.cell-sample.status-available.mortgage-5,
.cell-sample.status-available.mortgage-10 { position: relative; overflow: hidden; }
.cell-sample.status-available.mortgage-5::after,
.cell-sample.status-available.mortgage-10::after {
  content: ""; position: absolute; top: 0; right: 0; width: 0; height: 0;
  border-style: solid; border-left-color: transparent; border-top-color: rgba(255,255,255,0.92);
}
.cell-sample.status-available.mortgage-5::after  { border-width: 7px 0 0 7px; }
.cell-sample.status-available.mortgage-10::after { border-width: 10px 0 0 10px; }

/* Cell popover */
.matrix-cell .cell-popover {
  position: absolute;
  bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%) scale(0.96);
  min-width: 200px; max-width: 280px;
  background: var(--moon-dark);
  color: var(--moon-cream);
  padding: 10px 12px;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 400;
  opacity: 0; pointer-events: none;
  transition: opacity .12s, transform .12s;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  text-align: left;
}
.matrix-cell:hover .cell-popover, .matrix-cell:focus-visible .cell-popover {
  opacity: 1; transform: translateX(-50%) scale(1);
}
.matrix-cell .cell-popover::after {
  content: ""; position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--moon-dark);
}
.cell-popover .popover-row { margin: 2px 0; line-height: 1.4; }
.cell-popover .popover-row strong { color: var(--moon-gold); font-size: 13px; }
.cell-popover .muted { color: rgba(245,241,232,0.6); }

/* =========================================================
   SAVED VIEWS / FILTER CLEAR / EXPORT BAR / DRILL ROWS
   ========================================================= */
.saved-views-row {
  align-items: center;
  border-bottom: 1px dashed var(--moon-divider);
  margin-bottom: 4px; padding-bottom: 8px;
}
.saved-views-strip {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 6px; flex: 1; min-width: 0;
}
.saved-view-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 4px 3px 10px;
  font-family: var(--sans);
  font-size: 12px; font-weight: 500;
  color: var(--moon-dark);
  background: rgba(201,169,97,0.14);
  border: 1px solid rgba(201,169,97,0.45);
  border-radius: 999px;
  cursor: pointer;
}
.saved-view-chip:hover { background: rgba(201,169,97,0.24); border-color: var(--moon-gold); }
.saved-view-chip.just-applied {
  background: rgba(45,106,79,0.18); border-color: var(--moon-green);
  transform: scale(1.04);
}
.saved-view-label { padding-right: 2px; }
.saved-view-delete {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; font-size: 14px; line-height: 1;
  color: var(--moon-grey); background: transparent;
  border-radius: 50%; cursor: pointer;
}
.saved-view-delete:hover { background: rgba(139,46,46,0.18); color: var(--moon-red); }
.saved-view-save {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  font-family: var(--sans);
  font-size: 12px; font-weight: 600;
  color: var(--moon-dark);
  background: transparent;
  border: 1px dashed var(--moon-divider);
  border-radius: 999px; cursor: pointer;
}
.saved-view-save:hover { background: var(--moon-cream-soft); border-color: var(--moon-gold); color: var(--moon-darker); }
.saved-view-save .glyph { font-weight: 700; font-size: 13px; line-height: 1; }
.saved-view-input {
  padding: 3px 10px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--moon-dark);
  background: var(--moon-surface);
  border: 1px solid var(--moon-gold);
  border-radius: 999px;
  outline: none;
  width: 180px;
}
.saved-view-empty { font-size: 11px; font-style: italic; color: var(--moon-grey); padding: 2px 4px; }

.filter-clear-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px;
  font-family: var(--sans);
  font-size: 12px; font-weight: 600;
  color: var(--moon-red);
  background: rgba(139,46,46,0.08);
  border: 1px solid rgba(139,46,46,0.25);
  border-radius: 999px;
  cursor: pointer; opacity: 0;
  pointer-events: none;
  transform: scale(0.92);
  transition: opacity .18s, transform .18s, background .12s;
}
.filter-clear-pill.is-active { opacity: 1; pointer-events: auto; transform: scale(1); }
.filter-clear-pill:hover { background: rgba(139,46,46,0.16); border-color: var(--moon-red); }
.filter-clear-glyph { font-size: 14px; font-weight: 700; line-height: 1; }

/* Export buttons */
.export-bar { display: inline-flex; gap: 6px; align-items: center; margin-left: auto; }
.export-bar.export-bar-inline { float: right; margin: 0 0 8px 8px; }
.export-link {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  font-family: var(--sans);
  font-size: 12px; font-weight: 500;
  color: var(--moon-dark);
  background: var(--moon-cream-soft);
  border: 1px solid var(--moon-divider);
  border-radius: 999px;
  text-decoration: none;
  transition: all .12s;
}
.export-link:hover { background: var(--moon-cream); border-color: var(--moon-gold); color: var(--moon-darker); }
.export-link .glyph { font-size: 13px; line-height: 1; }
.export-link.is-disabled { opacity: 0.45; pointer-events: none; cursor: not-allowed; }
.page-header .export-bar-page { display: inline-flex; gap: 6px; margin-left: 16px; vertical-align: middle; }

/* Copy affordance */
.copyable {
  position: relative;
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: border-color .12s, background .12s;
}
.copyable:hover { border-bottom-color: var(--moon-gold); }
.copyable.copied { background: rgba(45,106,79,0.12); border-bottom-color: var(--moon-green); }
.copyable .copy-tip {
  position: absolute;
  bottom: 100%; left: 50%;
  transform: translate(-50%, -2px);
  padding: 3px 8px;
  font-family: var(--sans);
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--moon-cream);
  background: var(--moon-green);
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 50;
}
.copyable .copy-tip::after {
  content: ''; position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--moon-green);
}

/* Drill-down rows */
table.data tr.drilldown-row { cursor: pointer; transition: background-color .1s; }
table.data tr.drilldown-row:hover { background: rgba(201,169,97,0.10); }
table.data tr.drilldown-row .drilldown-arrow {
  display: inline-block;
  margin-left: 6px;
  color: var(--moon-gold);
  font-weight: 700;
  opacity: 0;
  transform: translateX(-3px);
  transition: opacity .12s, transform .12s;
}
table.data tr.drilldown-row:hover .drilldown-arrow {
  opacity: 1; transform: translateX(0);
}

/* =========================================================
   STATUS BANNERS
   ========================================================= */
.health-banner {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  border-left: 3px solid transparent;
}
.health-banner.ok    { background: rgba(45,106,79,0.10);  color: var(--moon-green); border-left-color: var(--moon-green); }
.health-banner.stale { background: rgba(176,132,66,0.10); color: var(--moon-amber); border-left-color: var(--moon-amber); }
.health-banner.error { background: rgba(139,46,46,0.10);  color: var(--moon-red);   border-left-color: var(--moon-red); }

/* =========================================================
   UTILITIES
   ========================================================= */
.muted { color: var(--moon-grey); }
.small { font-size: 12px; }
.tiny  { font-size: 11px; }
.right { text-align: right; }
.center{ text-align: center; }
.mb-12 { margin-bottom: 12px; }
.mb-24 { margin-bottom: 24px; }
.no-data { padding: 48px; text-align: center; color: var(--moon-grey); font-style: italic; font-family: var(--serif); font-size: 16px; }

.last-viewed-indicator { font-size: 11px; color: var(--moon-grey); letter-spacing: 0.01em; }
.last-viewed-indicator .last-viewed-label {
  color: var(--moon-grey); text-transform: uppercase;
  font-size: 10px; letter-spacing: 0.14em; font-weight: 600;
}
.last-viewed-indicator strong { color: var(--moon-dark); font-weight: 600; }

/* =========================================================
   COMPACT DENSITY MODE
   ========================================================= */
body[data-density="compact"] table.data tbody td { padding: 6px 10px; font-size: 12.5px; }
body[data-density="compact"] table.data thead th { padding: 8px 10px; }
body[data-density="compact"] .kpi-card { padding: 14px 16px; }
body[data-density="compact"] .kpi-card .value,
body[data-density="compact"] .kpi-card .kpi-value { font-size: 28px; }
body[data-density="compact"] .section { padding: 16px 18px; }
body[data-density="compact"] h4.subsection-title { margin: 14px 0 8px; }

/* =========================================================
   DARK MODE (Beta)
   ========================================================= */
body[data-theme="dark"] {
  --moon-bg:           #0e1a26;
  --moon-cream-soft:   #15263a;
  --moon-cream:        #1a2e44;
  --moon-surface:      #14283e;
  --moon-divider:      rgba(245,241,232,0.10);
  --moon-grey-light:   rgba(245,241,232,0.12);
  --moon-text:         #e8eef5;
  --moon-text-soft:    #b8c2d0;
  --moon-grey:         #8a93a3;
}
body[data-theme="dark"] .tab-strip      { background: var(--moon-cream-soft); }
body[data-theme="dark"] .matrix-filters { background: var(--moon-cream-soft); }
body[data-theme="dark"] .chip-toggle {
  background: var(--moon-cream-soft);
  border-color: var(--moon-divider);
  color: var(--moon-text-soft);
}
body[data-theme="dark"] .chip-toggle:hover { background: var(--moon-cream); color: var(--moon-text); }

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 720px) {
  .content-scroll { padding: 0 20px; }
  .page-header { padding-top: 24px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .matrix-grid { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); }
  .matrix-cell { font-size: 10px; }
  .matrix-filters { position: static; }
}

/* ===== Ported component families — editorial retint (Stage 1 correction) =====
   Families used in live templates that the editorial rewrite dropped or
   renamed. Geometry preserved from the prior stylesheet; color + type
   restyled into the editorial system (cream/white surfaces, stone dividers,
   serif tabular numbers, gold-as-punctuation). Targets the REAL class names. */

/* --- KPI cards (BEM: kpi-card-* co-applied with .kpi-card) ------------------
   Mirrors the editorial .kpi-card .value/.label/.sub treatment, retargeted to
   the BEM class names the kpi_card macro + leads dashboards actually emit. */
.kpi-card-title {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--moon-gold);
  margin-bottom: 12px;
}
.kpi-card-value {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 38px;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--moon-dark);
  font-variant-numeric: tabular-nums;
}
.kpi-card-sub {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--moon-grey);
  margin-top: 8px;
  letter-spacing: 0.01em;
}
.kpi-card-trend {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  margin-top: 8px;
  letter-spacing: 0.02em;
}
.trend-up   { color: var(--moon-green); }
.trend-down { color: var(--moon-red); }
.trend-flat { color: var(--moon-grey); }
.kpi-card.kpi-card-active { box-shadow: var(--shadow-card), inset 3px 0 0 var(--moon-gold); }
.kpi-card.kpi-card-stub {
  position: relative;            /* anchor for the stub badge */
  opacity: 0.7;
  border-style: dashed;
  background: var(--moon-cream-soft);
}
.kpi-card-stub-badge {
  position: absolute;
  top: 12px; right: 12px;
  font-family: var(--sans);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--moon-grey);
  background: transparent;
  border: 1px solid var(--moon-divider);
  padding: 2px 7px;
  border-radius: 999px;
}

/* --- Manager performance heatmap (table also carries .data) -----------------
   Cells use double-class so the tint/text-color beats `table.data tbody td`. */
table.heatmap { width: 100%; border-collapse: collapse; }
.heatmap-cell { font-variant-numeric: tabular-nums; font-weight: 600; }
.heatmap-cell.heatmap-cell--green  { background: rgba(45,106,79,0.12);  color: var(--moon-green); }
.heatmap-cell.heatmap-cell--yellow { background: rgba(176,132,66,0.14); color: var(--moon-amber); }
.heatmap-cell.heatmap-cell--red    { background: rgba(139,46,46,0.12);  color: var(--moon-red); }

/* --- Table total / subtotal rows (real class names: *-row, in tfoot) -------- */
table.data tr.total-row td {
  padding: 12px 14px;
  background: rgba(201,169,97,0.10);
  font-weight: 600;
  color: var(--moon-dark);
  border-top: 1px solid var(--moon-gold);
  border-bottom: 1px solid var(--moon-gold);
}
table.data tr.total-row td strong { color: var(--moon-dark); }
table.data tr.subtotal-row td {
  padding: 12px 14px;
  background: rgba(138,129,112,0.08);
  font-weight: 600;
  color: var(--moon-dark);
  border-top: 1px solid var(--moon-divider);
}

/* --- Segment / pay-mode filter pills ---------------------------------------- */
.segment-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 16px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--moon-divider);
}
.segment-bar.pay-mode-bar { margin-top: 8px; }
.segment-label {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--moon-grey);
  margin-right: 6px;
}
.seg-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--moon-divider);
  background: var(--moon-surface);
  color: var(--moon-grey);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: background .12s, border-color .12s, color .12s;
}
.seg-pill:hover { border-color: var(--moon-dark); color: var(--moon-dark); }
.seg-pill .seg-dot { font-size: 8px; line-height: 1; color: var(--moon-gold); }
.seg-pill .seg-count { font-size: 11px; opacity: 0.7; font-variant-numeric: tabular-nums; }
.seg-pill.active {
  background: var(--moon-dark);
  border-color: var(--moon-dark);
  color: var(--moon-cream);
  font-weight: 600;
}
.seg-pill.active .seg-dot { color: var(--moon-gold); }
.seg-pill.active .seg-count { opacity: 0.85; }

/* --- Inventory unit-type filter pills (mirrors the segment bar) ------------- */
.unit-type-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 6px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--moon-divider);
}
.unit-type-label {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--moon-grey);
  margin-right: 6px;
}
.ut-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--moon-divider);
  background: var(--moon-surface);
  color: var(--moon-grey);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: background .12s, border-color .12s, color .12s;
}
.ut-pill:hover { border-color: var(--moon-dark); color: var(--moon-dark); }
.ut-pill .ut-dot { font-size: 8px; line-height: 1; color: var(--moon-gold); }
.ut-pill .ut-count { font-size: 11px; opacity: 0.7; font-variant-numeric: tabular-nums; }
.ut-pill.active {
  background: var(--moon-dark);
  border-color: var(--moon-dark);
  color: var(--moon-cream);
  font-weight: 600;
}
.ut-pill.active .ut-dot { color: var(--moon-gold); }
.ut-pill.active .ut-count { opacity: 0.85; }
.ut-note {
  margin: 4px 0 16px;
  font-size: 11px;
  color: var(--moon-grey);
}

/* --- View / Family rollup toggle (segmented control, navy active) ----------- */
.view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  align-self: flex-start;
  padding: 3px;
  background: var(--moon-cream);
  border: 1px solid var(--moon-divider);
  border-radius: 999px;
}
.view-toggle-label {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moon-grey);
  padding: 0 8px 0 6px;
}
.view-toggle .pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  border-radius: 999px;
  border: 0;
  color: var(--moon-grey);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s, color .12s;
}
.view-toggle .pill:hover { color: var(--moon-dark); }
.view-toggle .pill.active {
  background: var(--moon-dark);
  color: var(--moon-cream);
  font-weight: 600;
}
.view-toggle .pill .count { font-size: 11px; opacity: 0.65; font-variant-numeric: tabular-nums; }
.view-toggle .pill.active .count { opacity: 0.85; }

/* --- RRL org drill-down (expandable sub-rows) ------------------------------- */
.drill-chevron {
  display: inline-block;
  width: 12px;
  margin-left: 6px;
  cursor: pointer;
  user-select: none;
  color: var(--moon-gold);
  font-weight: 700;
  transition: transform .15s ease, color .15s;
}
.drill-chevron:hover { color: var(--moon-gold-soft); }
.drill-chevron.expanded { transform: rotate(90deg); }
.org-subrow.hidden { display: none; }
table.data tr.org-subrow td {
  background: var(--moon-cream-soft);
  font-size: 12.5px;
  color: var(--moon-text-soft);
}
.org-subrow-label { padding-left: 32px !important; font-style: italic; }
.org-subrow-rank { color: var(--moon-grey); }

/* --- CRM aging buckets ------------------------------------------------------ */
.aging-bucket-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.aging-bucket {
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--moon-divider);
  border-left: 3px solid var(--moon-divider);
  background: var(--moon-surface);
}
.aging-bucket-label {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--moon-gold);
  margin-bottom: 8px;
}
.aging-bucket-count {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 500;
  line-height: 1;
  color: var(--moon-dark);
  font-variant-numeric: tabular-nums;
}
.aging-bucket-balance {
  margin-top: 4px;
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  color: var(--moon-text-soft);
}
.aging-bucket--green    { border-left-color: var(--moon-green); background: rgba(45,106,79,0.06); }
.aging-bucket--yellow   { border-left-color: var(--moon-gold);  background: rgba(201,169,97,0.08); }
.aging-bucket--orange   { border-left-color: var(--moon-amber); background: rgba(176,132,66,0.08); }
.aging-bucket--red      { border-left-color: var(--moon-red);   background: rgba(139,46,46,0.06); }
.aging-bucket--critical { border-left-color: #6e1820;           background: rgba(110,24,32,0.08); }
.aging-bucket--unknown  { border-left: 3px dashed var(--moon-grey); background: rgba(138,129,112,0.06); }

/* --- Inventory empty-state panel -------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--moon-text-soft);
}
.empty-state-glyph {
  font-size: 38px;
  line-height: 1;
  opacity: 0.3;
  margin-bottom: 12px;
  color: var(--moon-grey);
}
.empty-state-msg {
  margin: 0;
  font-family: var(--serif);
  font-size: 16px;
  font-style: italic;
  color: var(--moon-grey);
}

/* --- Dashboard audit-activity widget ---------------------------------------- */
.widget { margin-bottom: 0; }
.widget.widget-audit { border-left: 3px solid var(--moon-gold); padding-left: 18px; }
.widget-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
.widget-header h3 { margin: 0; }
.widget-link {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--moon-dark);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color .12s, color .12s;
}
.widget-link:hover { color: var(--moon-gold); border-bottom-color: var(--moon-gold); }
.mini-kpis {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--moon-grey);
}
.mini-kpis strong {
  color: var(--moon-dark);
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  margin-right: 4px;
  font-variant-numeric: tabular-nums;
}
.mini-kpis .warn strong { color: var(--moon-amber); }
.mini-kpis .red strong  { color: var(--moon-red); }
.activity-feed {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 280px;
  overflow-y: auto;
}
.activity-feed li {
  display: grid;
  grid-template-columns: 70px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--moon-divider);
  font-size: 13px;
}
.activity-feed li:last-child { border-bottom: none; }
.activity-feed .time {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--moon-grey);
  font-size: 12px;
}
.activity-feed .user { font-weight: 600; color: var(--moon-dark); }
.activity-feed .target {
  text-align: right;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Audit-log controls: quick filters / filter strip / pagination ---------- */
.quick-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.filter-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
}
.filter-strip label {
  display: flex;
  flex-direction: column;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moon-grey);
}
.filter-strip select,
.filter-strip input[type="date"] {
  margin-top: 4px;
  padding: 8px 12px;
  background: var(--moon-cream);
  border: 1px solid var(--moon-divider);
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--moon-text);
  min-width: 150px;
}
.filter-strip select:focus,
.filter-strip input[type="date"]:focus {
  outline: none;
  border-color: var(--moon-gold);
  box-shadow: 0 0 0 2px rgba(201,169,97,0.30);
}
.filter-strip button {
  padding: 9px 18px;
  background: var(--moon-dark);
  color: var(--moon-cream);
  border: 0;
  border-radius: 10px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
}
.filter-strip button:hover { background: var(--moon-text); box-shadow: inset 0 -2px 0 var(--moon-gold); }
.filter-strip-spacer { flex: 1; }
.pagination {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-top: 14px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--moon-grey);
  font-variant-numeric: tabular-nums;
}
.pagination a {
  padding: 6px 14px;
  border: 1px solid var(--moon-divider);
  border-radius: 12px;
  background: var(--moon-cream-soft);
  color: var(--moon-dark);
  text-decoration: none;
  font-weight: 500;
  transition: background .12s, border-color .12s, color .12s;
}
.pagination a:hover { background: var(--moon-cream); border-color: var(--moon-gold); color: var(--moon-darker); }

/* --- Export buttons (ride alongside .export-link, already styled) ------------
   .export-link supplies the editorial secondary-button look; these add a
   subtle per-format tint so the class names resolve and read distinctly. */
.export-link.export-pdf  .glyph { color: var(--moon-red); }
.export-link.export-xlsx .glyph { color: var(--moon-green); }

/* --- Generic count chip in toggles (view pill etc.) ------------------------- */
.count { font-variant-numeric: tabular-nums; }

/* --- unit_type chips in Open Units lists (dynamic .chip-unit-{type}) -------- */
.chip-unit-residential { color: var(--moon-teal);  background: rgba(44,95,124,0.12); }
.chip-unit-commercial  { color: var(--moon-amber); background: rgba(176,132,66,0.14); }
.chip-unit-refuge      { color: var(--moon-grey);  background: rgba(138,129,112,0.14); }

/* --- Buttons — centralized editorial button system (Stage 2) ----------------
   Previously defined inline in admin_operations + reconciliation only, leaving
   ~14 other consumers (leads dashboards, admin user pages, milestones, etc.)
   unstyled. Centralized here so the class names resolve everywhere. */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, box-shadow .15s, color .15s;
}
.btn-primary { background: var(--moon-dark); color: var(--moon-cream); }
.btn-primary:hover { background: var(--moon-text); box-shadow: inset 0 -2px 0 var(--moon-gold); }
.btn-warn { background: var(--moon-amber); color: var(--moon-cream); }
.btn-warn:hover { background: #9a7038; box-shadow: inset 0 -2px 0 var(--moon-gold); }
.btn-disabled { background: var(--moon-grey-light); color: var(--moon-grey); cursor: not-allowed; }
.btn-disabled:hover { box-shadow: none; }

/* --- Notice / callout — editorial info banner (Stage 2 polish) --------------
   Base structure + default (gold) accent; per-use semantic color (error /
   success / warn) is set inline on the element and overrides bg + border. */
.notice {
  background: var(--moon-cream-soft);
  border-left: 3px solid var(--moon-gold);
  color: var(--moon-text);
  padding: 10px 14px;
  border-radius: 8px;
  margin: 12px 0;
  font-size: 13px;
}

/* --- Admin form container — editorial inputs (Stage 2 polish) --------------- */
.admin-form label {
  display: block;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--moon-grey);
  margin-bottom: 6px;
}
.admin-form input,
.admin-form select,
.admin-form textarea {
  width: 100%;
  font-family: var(--sans);
  font-size: 14px;
  padding: 8px 12px;
  background: var(--moon-cream);
  border: 1px solid var(--moon-divider);
  border-radius: 8px;
  color: var(--moon-text);
}
.admin-form input:focus,
.admin-form select:focus,
.admin-form textarea:focus {
  outline: none;
  border-color: var(--moon-gold);
  box-shadow: 0 0 0 2px rgba(201,169,97,0.30);
}
.admin-form textarea { resize: vertical; }

/* --- navy-total tfoot — documented manifest_table pattern (editorial navy
   total). No live consumer today (Grand-Total rows use tr.total-row /
   tr.subtotal-row); styled for the documented pattern + token hygiene. */
table.data tfoot.navy-total td {
  background: var(--moon-dark);
  color: var(--moon-cream);
  font-weight: 600;
  border-top: 2px solid var(--moon-gold);
}
table.data tfoot.navy-total td strong { color: var(--moon-cream); }

/* =========================================================
   MOBILE SHELL (≤768px) — 19 Oct 2026
   Everything here is inside the 768px block except the two display:none lines
   below, so desktop (>768px) renders exactly as before. The older 720px rule
   (RESPONSIVE, above) is left as is; where both apply, these come later and win.
   - The window scrolls again (no fixed 100vh shell); the sidebar becomes an
     off-canvas drawer driven by static/js/nav.js; a sticky top bar holds ☰.
   - --header-h (measured in base.html) includes the top bar here, so the tab
     strip / matrix filters still stack under the sticky page header.
   - .table-scroll (every table.data, rv-data via .rv-tblwrap) becomes its own
     scroller; its header row sticks at top:0 inside the box, never the page
     offset (see tests/test_sticky_headers_in_scroll_wrappers.py for why).
   ========================================================= */
.m-topbar, .nav-overlay { display: none; }
.dt-short { display: none; }               /* compact date twin, shown ≤768px only */

@media (max-width: 768px) {
  :root { --topbar-h: 52px; }

  /* --- shell: document scroll ------------------------------------------- */
  .app-shell      { display: block; height: auto; min-height: 100dvh; overflow: visible; }
  .content        { display: block; max-width: none; overflow: visible; }
  .content-scroll { overflow: visible; padding: 0 16px; overflow-wrap: break-word; }
  .app-footer-bar { font-size: 10px; letter-spacing: 0.08em; }

  /* --- top bar ---------------------------------------------------------- */
  .m-topbar {
    display: flex; align-items: center; gap: 8px;
    position: sticky; top: 0; z-index: 60;
    height: var(--topbar-h);
    padding: 0 14px 0 4px;
    background: var(--moon-darker);
    border-bottom: 1px solid rgba(201,169,97,0.30);
  }
  .m-menu-btn {
    flex: 0 0 auto;
    width: 44px; height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 0; border-radius: 8px; background: transparent;
    color: var(--moon-cream); font-size: 22px; line-height: 1; cursor: pointer;
  }
  .m-menu-btn:focus-visible { outline: 2px solid var(--moon-gold); outline-offset: -2px; }
  .m-brand { flex: 0 0 auto; display: inline-flex; align-items: center; height: 44px; }
  .m-brand img { height: 28px; width: auto; display: block; }
  .m-title {
    flex: 1 1 auto; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-family: var(--serif); font-size: 19px; font-weight: 500;
    color: var(--moon-cream);
  }

  /* --- drawer ----------------------------------------------------------- */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(84vw, 300px); height: 100dvh;
    z-index: 80;
    transform: translateX(-100%);
    visibility: hidden;                        /* closed drawer is out of the tab order */
    transition: transform .22s ease, visibility 0s linear .22s;
  }
  body.nav-open .sidebar {
    transform: none; visibility: visible;
    transition: transform .22s ease;
    box-shadow: 12px 0 48px rgba(0,0,0,0.35);
  }
  .nav-overlay {
    display: block;
    position: fixed; inset: 0; z-index: 70;
    background: rgba(13,31,45,0.55);
    opacity: 0; pointer-events: none;
    transition: opacity .22s ease;
  }
  body.nav-open .nav-overlay { opacity: 1; pointer-events: auto; }
  body.nav-open { position: fixed; left: 0; right: 0; overflow: hidden; }   /* top: set by nav.js */
  .sidebar nav a { min-height: 44px; font-size: 14px; }
  .sidebar-footer .density-toggle-btn,
  .sidebar-footer .theme-toggle-btn { min-height: 44px; padding: 6px 16px; font-size: 12px; }
  .sidebar-footer a { display: inline-block; padding: 12px 0; }

  /* --- page header: clamp title, actions wrap below ---------------------- */
  .page-header {
    top: var(--topbar-h);
    padding-top: 16px; margin-bottom: 20px;
    flex-direction: column; align-items: stretch; gap: 10px;
  }
  .page-header > * { min-width: 0; max-width: 100%; }
  .page-header h2 { font-size: clamp(24px, 7vw, 32px); overflow-wrap: anywhere; }
  .page-header .meta { text-align: left; }

  .section { padding: 18px 14px; border-radius: 12px; }
  .section h3 { flex-wrap: wrap; row-gap: 6px; }             /* a chip after the title drops to a new line */

  /* --- grids: KPI tiles 2-up, card/detail grids single column ------------- */
  .kpi-grid, .kpi-strip, .aging-bucket-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }      /* minmax: a wide table can't stretch the track */
  .copartner-strip { margin: 40px -16px 0; padding: 28px 16px 22px; }   /* bleed matches the 16px gutter */
  .copartner-panel { max-width: 100%; padding: 14px 18px; }
  .kpi-card .value, .kpi-card .kpi-value, .kpi-card-value { font-size: clamp(22px, 6.5vw, 30px); overflow-wrap: anywhere; }

  /* --- dashboard Team Activity: time | name | chip, target on its own line - */
  .widget-header { flex-wrap: wrap; gap: 4px 12px; }
  .mini-kpis { gap: 8px 16px; }
  .activity-feed li { grid-template-columns: 58px minmax(0, 1fr) auto; gap: 2px 8px; }
  .activity-feed .user { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .activity-feed .target { grid-column: 2 / -1; text-align: left; max-width: 100%; }

  /* --- layouts set in inline styles: the class is added only where the phone needs it, and the
     desktop keeps its inline style, so !important is the only way past it ------------------- */
  .m-stack { grid-template-columns: minmax(0, 1fr) !important; }              /* inline 1fr 1fr grids */
  .m-full  { flex: 1 1 100% !important; min-width: 0 !important; max-width: 100% !important; }   /* min-width panels */

  /* --- tables ----------------------------------------------------------- */
  .table-scroll { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-scroll:not(.rv-tblwrap) {
    overflow-y: auto;
    max-height: calc(100dvh - var(--header-h, 0px) - 16px);
  }
  /* at least ~84px per column (nav.js sets --mg-cols): the box scrolls instead of squeezing
     a long-text column to one word per line or breaking "A-1109" at its hyphen */
  .table-scroll > table.data, .table-scroll > table.rv-data { min-width: max(100%, calc(var(--mg-cols, 0) * 84px)); }
  .table-scroll table.data thead th { top: 0; }
  .table-scroll table.data thead tr:nth-child(2) th { position: static; }
  /* first column (row label) stays put while the rest scrolls sideways */
  .table-scroll table.data tbody td:first-child,
  .table-scroll table.data tbody th:first-child,
  .table-scroll table.data tfoot td:first-child {
    position: sticky; left: 0; z-index: 3;
    min-width: 88px;                                   /* a flat id ("A-1109") stays on one line */
    background-color: var(--moon-surface);
    box-shadow: 1px 0 0 var(--moon-divider);
  }
  .table-scroll table.data thead tr:first-child th:first-child { left: 0; z-index: 6; }
  table.data thead th, table.data tbody td, table.data tfoot td { padding-left: 10px; padding-right: 10px; }
  /* date cells stay on one line; .dt-full/.dt-short pairs swap to the compact form */
  td.dt, th.dt { white-space: nowrap; }
  .dt-full { display: none; }
  .dt-short { display: inline; }

  /* --- forms, buttons, chips -------------------------------------------- */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
  select, textarea { font-size: 16px; }                      /* no iOS zoom on focus */
  input, select, textarea { max-width: 100%; min-width: 0; }  /* size="40", long options or a flex row can't push the page wide */
  button, .btn, select,
  input[type="submit"], input[type="button"],
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]) { min-height: 44px; }
  .tab-strip .tab-link { min-height: 44px; padding: 12px 16px; }
  .filter-bar { padding: 14px 16px; gap: 12px; }
  .filter-bar > * { max-width: 100%; }
  .chip { font-size: 10px; padding: 2px 8px; letter-spacing: 0.06em; }

  /* --- long text / code ------------------------------------------------- */
  /* pre keeps its lines and scrolls inside its own box (!important beats the inline pre-wrap on the
     stderr blocks in the callback-test / digest pages) */
  pre { white-space: pre !important; overflow-wrap: normal; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  code, kbd, samp { overflow-wrap: anywhere; word-break: break-word; }
  .table-scroll code { overflow-wrap: normal; word-break: normal; white-space: nowrap; }   /* ids in a scrolling table stay whole */
  .content-scroll img, .content-scroll video, .content-scroll canvas { max-width: 100%; height: auto; }

  /* --- login / password card -------------------------------------------- */
  .login-wrap { min-height: 100dvh; padding: 16px; }
}

@media (max-width: 480px) {
  .login-card { width: 100%; padding: 36px 24px 28px; border-radius: 12px; }
}

@media print {
  .m-topbar, .nav-overlay { display: none !important; }
}

/* =========================================================
   PRINT — undo the fixed-viewport shell so PDF/print exports
   (Investor Digest, Inventory) render full-page, not clipped to
   one viewport. The full co-brand panel still prints; the slim
   pinned bar is suppressed.
   ========================================================= */
@media print {
  :root          { --header-h: 0px; }   /* collapse the sticky-stack offset */
  .app-shell    { height: auto; overflow: visible; display: block; }
  .content      { max-width: none; overflow: visible; display: block; }
  .content-scroll { overflow: visible; }
  .page-header  { position: static; }
  .app-footer-bar { display: none; }
}
