/* ============================================================
 * CF/Thrive Dashboards — Design System Stylesheet
 *
 * Canonical reference: docs/design_system.md
 * Loaded on every authenticated page via base.html.
 *
 * Sections:
 *   1. Tokens (CSS custom properties)
 *   2. Reset + base
 *   3. Typography utilities
 *   4. Page chrome (topbar, sidebar, content area)
 *   5. Mobile sidebar drawer
 *   6. Page patterns (masthead, section labels, ornaments)
 *   7. Components (cells, stat cards, tables, filters, pagination)
 *   8. Status, semantic, helpers
 *   9. Index page (dashboard launcher)
 * ============================================================ */


/* ----- 1. Tokens ----- */

:root {
  --ink: #1a1a1a;
  --ink-2: #2a2a2a;
  --paper: #faf8f3;
  --paper-warm: #f3efe6;
  --rule: #d8d3c5;
  --rule-soft: #e8e3d4;
  --accent: #c2410c;
  --accent-soft: #fbeae0;
  --muted: #6b6862;
  --paper-on-dark: #faf8f3;
  --muted-on-dark: #9b9690;
  --good: #16785f;
  --good-soft: #dcefe6;
  --warn: #b87a00;
  --warn-soft: #f5e9cf;
  --bad: #a52a2a;
  --bad-soft: #f5dcdc;

  --topbar-h: 56px;
  --topbar-h-mobile: 52px;
  --sidebar-w: 240px;

  --font-display: 'Bricolage Grotesque', 'Helvetica Neue', sans-serif;
  --font-body: 'Newsreader', Georgia, serif;
  --font-mono: 'DM Mono', 'SFMono-Regular', Menlo, monospace;
}


/* ----- 2. Reset + base ----- */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }


/* ----- 3. Typography utilities ----- */

.type-display {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 52px;
  line-height: 0.95;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 96;
}

.type-h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 38px;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 96;
}

.type-stat {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 38px;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 96;
  font-variant-numeric: tabular-nums;
}

.type-h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 24px;
  letter-spacing: -0.015em;
}

.type-h4 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.type-h5 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0;
}

.type-body { font-size: 14px; }
.type-body-sm { font-size: 13px; }
.type-caption { font-size: 12px; color: var(--muted); }

.type-kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.type-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 500;
}

.type-num,
.numeric {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}


/* ----- 4. Page chrome ----- */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--ink);
  border-bottom: 1px solid var(--ink-2);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 100;
}

.topbar__menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--paper-on-dark);
  font-size: 22px;
  padding: 0 12px 0 0;
  cursor: pointer;
}

.topbar__brand {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 8px 0;
}

.topbar__brand img {
  height: 28px;
  width: auto;
  display: block;
}

.topbar__spacer { flex: 1; }

.topbar__user {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--paper-on-dark);
}

.topbar__user-name {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--muted-on-dark);
}

.topbar__signout {
  background: transparent;
  border: 1px solid var(--ink-2);
  color: var(--paper-on-dark);
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 7px 14px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.topbar__signout:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--paper);
  border-right: 1px solid var(--rule);
  overflow-y: auto;
  padding: 24px 0;
  z-index: 50;
}

.sidebar__category { margin-bottom: 4px; }

.sidebar__category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  padding: 10px 20px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  text-align: left;
  transition: background 0.15s ease;
}

.sidebar__category-header:hover { background: var(--paper-warm); }

.sidebar__category-caret {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.sidebar__category.is-collapsed .sidebar__category-caret {
  transform: rotate(-90deg);
}

.sidebar__category-list {
  list-style: none;
  margin: 0; padding: 0;
  overflow: hidden;
  max-height: 1000px;
  transition: max-height 0.25s ease;
}

.sidebar__category.is-collapsed .sidebar__category-list {
  max-height: 0;
}

.sidebar__link {
  display: block;
  padding: 8px 20px 8px 32px;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink);
  border-left: 2px solid transparent;
  transition: background 0.15s ease, border-left-color 0.15s ease;
}

.sidebar__link:hover { background: var(--paper-warm); }

.sidebar__link.is-active {
  background: var(--paper-warm);
  border-left-color: var(--accent);
  font-weight: 500;
}

.sidebar__empty {
  padding: 8px 20px 8px 32px;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

.app-main {
  margin-top: var(--topbar-h);
  margin-left: var(--sidebar-w);
  padding: 48px 56px 96px;
  min-height: calc(100vh - var(--topbar-h));
}

/* While a fetch is in flight, keep the data on screen but dim it so it's clear
   a refresh is underway (paired with the top progress bar). Toggled by the
   global fetch wrapper in dashboard.js. */
.app-main.cf-refreshing {
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

/* ----- Global loading bar -----
   A thin indeterminate bar pinned to the very top of the viewport, shown
   whenever any fetch() is in flight. Wired once in dashboard.js so every
   dashboard — current and future — gets it for free. */
.cf-progress {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: 3px;
  z-index: 200;            /* above the topbar (z-index 100) */
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.cf-progress.is-active { opacity: 1; }
.cf-progress.is-active::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: 30%;
  background: var(--accent);
  animation: cf-indeterminate 1.15s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
@keyframes cf-indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(333%); }
}
@media (prefers-reduced-motion: reduce) {
  .cf-progress.is-active::before { animation-duration: 2.4s; }
}


/* ----- 5. Mobile sidebar drawer ----- */

.sidebar-backdrop {
  display: none;
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0; bottom: 0;
  background: rgba(26, 26, 26, 0.35);
  z-index: 40;
}

@media (max-width: 900px) {
  .app-main { padding: 32px 32px 64px; }
}

@media (max-width: 768px) {
  .topbar {
    height: var(--topbar-h-mobile);
    padding: 0 16px;
  }
  .topbar__menu-toggle { display: block; }
  .topbar__brand img { height: 24px; }

  .sidebar {
    top: var(--topbar-h-mobile);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.05);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop { top: var(--topbar-h-mobile); }
  .sidebar-backdrop.is-visible { display: block; }

  .app-main {
    margin-top: var(--topbar-h-mobile);
    margin-left: 0;
    padding: 20px 16px 64px;
  }
}


/* ----- 6. Page patterns ----- */

.masthead {
  border-bottom: 2px solid var(--ink);
  padding-bottom: 18px;
  margin-bottom: 36px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 32px;
}

.masthead-left .kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  margin-bottom: 8px;
}

.masthead-left h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 52px;
  line-height: 0.95;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 96;
}

.masthead-right {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  line-height: 1.7;
}

.masthead-right strong { color: var(--ink); font-weight: 600; }

@media (max-width: 768px) {
  .masthead {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }
  .masthead-left h1 { font-size: 36px; }
  .masthead-right { text-align: left; }
}

.section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.section-label::before {
  content: '';
  width: 24px;
  height: 1px;
  background: var(--ink);
}

.ornament {
  text-align: center;
  font-family: var(--font-mono);
  color: var(--rule);
  margin: 56px 0;
  letter-spacing: 6px;
  font-size: 12px;
}


/* ----- 7. Components ----- */

.cell {
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 22px 24px;
}

.stat-card .stat-card__label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
}
.stat-card .stat-card__value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 38px;
  margin-top: 6px;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-card .stat-card__sub {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--rule-soft);
}
.stat-card .stat-card__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 0;
  font-size: 12px;
}
.stat-card .stat-card__row-name { color: var(--muted); }
.stat-card .stat-card__row-value {
  color: var(--ink);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.cell-grid {
  display: grid;
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
}
.cell-grid--3 { grid-template-columns: repeat(3, 1fr); }
.cell-grid--4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
  .cell-grid--4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .cell-grid--3,
  .cell-grid--4 { grid-template-columns: 1fr; }
}

/* KPI strip — the de-facto dashboard summary tiles (used by 7+ dashboards under the
   .kpi-* names). Structurally the same skeleton as .cell / .cell-grid above, kept
   under the .kpi-* names dashboards already use to avoid markup churn. Each page sets
   its own column count — `.kpi-grid { grid-template-columns: repeat(N, 1fr) }` — and
   may add page-specific modifiers (.feature, .kpi-risk, .is-gold, …) or overrides
   (e.g. a compact 26px .num for a dense 6-up grid) in its own <style>. */
.kpi-grid {
  display: grid;
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
}
.kpi-cell { background: var(--paper); padding: 22px 24px; }
.kpi-cell .label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}
/* Number + inline tag (e.g. a pct or WoW arrow) on one baseline-aligned row. When a
   page puts .num directly under .label instead, it adds its own margin-top to .num. */
.kpi-cell .num-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 8px;
}
.kpi-cell .num {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 30px;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.kpi-cell .pct-tag {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}
.kpi-cell .sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 500;
  padding: 10px 12px 10px 0;
  border-bottom: 1px solid var(--ink);
}
table.data-table th.num { text-align: right; padding-right: 0; }
table.data-table td {
  padding: 12px 12px 12px 0;
  border-bottom: 1px solid var(--rule-soft);
  font-variant-numeric: tabular-nums;
}
table.data-table td.num {
  text-align: right;
  padding-right: 0;
  font-family: var(--font-mono);
  font-weight: 500;
}
table.data-table td.identity {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 15px;
}
table.data-table tbody tr:hover { background: var(--paper-warm); }

/* De-tabled "row" system — CSS-grid rows that read like a table but flex per page.
   Used by membership_eft, membership_l10, nmi, revenue_mtd (and daily_huddle, which
   keeps its own inline copy and is intentionally NOT consolidated here). The skeleton
   below is the eft/nmi canonical: header strip, row separators, hover, the right-
   aligned numeric cell, and the standard name/sub/value cells. Pages set their own
   grid-template-columns (.club-grid, .weekly-grid, etc.) and may override gap/padding,
   .r-name size, and the value-cell (.r-val / .r-num) styling to their row density —
   notably .r-num is a bare right-aligned cell here; pages that use .r-num AS the value
   cell (revenue_mtd, l10) restyle it locally. Per-page modifiers (.muted/.neg/.hot/
   .cnt/.total/.subline/.r-band) stay in each page's <style>. */
.rows-head, .row-line {
  display: grid;
  align-items: center;
  gap: 16px;
  padding: 13px 4px;
}
.rows-head {
  border-bottom: 2px solid var(--ink);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.row-line { border-bottom: 1px solid var(--rule-soft); }
.row-line:hover { background: var(--paper-warm); }
.rows-head .r-num, .row-line .r-num { text-align: right; }
.r-name { font-family: var(--font-display); font-weight: 500; font-size: 15px; }
.r-sub  { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.r-val {
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* Date-preset / toggle buttons — the de-facto control used by 6 dashboards for
   period presets and segmented toggles. Pages keep their own wrapper (.presets /
   .preset-row) with page-specific margins; the button itself is canonical here. */
.preset-btn {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 7px 13px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--muted);
  cursor: pointer;
}
.preset-btn:hover { border-color: var(--ink); color: var(--ink); }
.preset-btn.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.filter-pill,
.filter-pill select {
  background: transparent;
  border: 1px solid var(--rule);
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.filter-pill.is-active {
  background: var(--ink);
  color: var(--paper-on-dark);
  border-color: var(--ink);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 24px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}
.pagination__controls { display: flex; gap: 8px; }
.pagination__btn {
  background: transparent;
  border: 1px solid var(--rule);
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.pagination__btn:hover:not(:disabled) { background: var(--paper-warm); }
.pagination__btn:disabled { opacity: 0.4; cursor: default; }


/* ----- 8. Status, semantic, helpers ----- */

.badge {
  display: inline-block;
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}
.badge--good    { background: var(--good-soft); color: var(--good); }
.badge--warn    { background: var(--warn-soft); color: var(--warn); }
.badge--bad     { background: var(--bad-soft);  color: var(--bad); }
.badge--neutral { background: var(--rule-soft); color: var(--ink); }

.text-muted  { color: var(--muted); }
.text-accent { color: var(--accent); }
.text-good   { color: var(--good); }
.text-warn   { color: var(--warn); }
.text-bad    { color: var(--bad); }

/* Pace / status dot — a small colored circle preceding a metric. Color names map to
   the semantic tokens (green=good, yellow=warn, red=bad, none=no signal). Pages may
   tune the dot's size/margin to their row density in their own <style>. (This is the
   dot; the separate `.band-good/warn/bad` number-color modifiers some pages put on
   .kpi-num / .cat-num are page-local and unrelated to this.) */
.band {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: -1px;
}
.band-green  { background: var(--good); }
.band-yellow { background: var(--warn); }
.band-red    { background: var(--bad); }
.band-none   { background: transparent; }


/* ----- 9. Index page (dashboard launcher) ----- */

.launcher-section { margin-bottom: 48px; }
.launcher-section:last-child { margin-bottom: 0; }

.launcher-section__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 28px;
  letter-spacing: -0.015em;
  margin-bottom: 4px;
}

.launcher-section__sub {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  margin-bottom: 20px;
}

.launcher-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
}

.launcher-card {
  background: var(--paper);
  padding: 24px;
  display: block;
  transition: background 0.15s ease, border-left-color 0.15s ease;
  border-left: 2px solid transparent;
}
.launcher-card:hover {
  background: var(--paper-warm);
  border-left-color: var(--accent);
}

.launcher-card__title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}

.launcher-card__desc {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.launcher-empty {
  background: var(--paper);
  padding: 24px;
  font-style: italic;
  color: var(--muted);
  font-size: 13px;
}


/* ----- 10. Login page ----- */

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.login-hero {
  background: var(--ink);
  color: var(--paper-on-dark);
  padding: 64px 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.login-hero__logo img {
  height: 56px;
  width: auto;
  display: block;
}

.login-hero__statement {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 44px;
  line-height: 1.05;
  letter-spacing: -0.02em;
  max-width: 520px;
}

.login-hero__statement em {
  font-style: italic;
  color: var(--accent);
  font-weight: 500;
}

.login-hero__footer {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted-on-dark);
}

.login-panel {
  background: var(--paper);
  padding: 64px 56px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-panel__inner {
  max-width: 380px;
  width: 100%;
}

.login-panel__kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
  margin-bottom: 16px;
}

.login-panel__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 36px;
  line-height: 1;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}

.login-panel__body {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 32px;
  line-height: 1.55;
}

.login-panel__signin {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-panel__notice {
  background: var(--bad-soft);
  border-left: 2px solid var(--bad);
  padding: 12px 16px;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--bad);
  margin-bottom: 24px;
}

.login-panel__notice--info {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--accent);
}

@media (max-width: 900px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-hero {
    padding: 32px 24px;
    min-height: 240px;
  }
  .login-hero__logo img { height: 40px; }
  .login-hero__statement { font-size: 28px; }
  .login-panel { padding: 40px 24px; }
  .login-panel__title { font-size: 28px; }
}
