/* ============================================================
   CORE Design System — shared token + component layer
   ============================================================
   The site-wide design language (docs/design-system.md), extracted
   from revenue/index.php ("rh" = the Robinhood-style actuals page
   Matt approved 2026-07-15). Pages OPT IN:

     <link rel="preconnect" href="https://fonts.googleapis.com">
     <link href="https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600;700&family=Geist+Mono:wght@400;500;600&display=swap" rel="stylesheet">
     <link rel="stylesheet" type="text/css" href="/style/core-design.css">
     <body class="rh-page ...">

   All component rules are scoped under .rh-page, so this file is
   safe to load anywhere and inert until the body class is added.
   The dark top nav and logo are NOT part of this system — never
   restyle them. Row-action icons keep the global .action-btn
   standard from style.css.

   Pages that predate this file with their own copy of these tokens
   (revenue/index.php, revenue/bridge.php, reports/at-risk-health.php)
   keep working; migrate them to this file opportunistically.
   ============================================================ */

:root {
    --bg:          #FFFFFF;
    --bg-subtle:   #F7F8FA;
    --surface:     #FFFFFF;
    --surface-alt: #F5F6F8;
    --hover:       #F0F1F4;
    --border:      #E8EAED;
    --border-soft: #F0F2F5;

    --text:        #0D0E12;
    --text-sub:    #5E636E;
    --text-mute:   #9CA0AA;

    --green:       #00B67A;
    --green-soft:  #E6F7F0;
    --red:         #E94D3E;
    --red-soft:    #FCE9E7;
    --amber:       #E89132;
    --amber-soft:  #FCEFDE;
    --gray:        #6A6D78;
    --gray-soft:   #EEF0F3;
    /* blue exists for rare informational needs; NOT for buttons/links */
    --blue:        #2B6BF0;
    --blue-soft:   #E6EEFE;

    --sans: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

    --shadow-sm: 0 1px 2px rgba(13, 14, 18, 0.04);
    --shadow-md: 0 2px 8px rgba(13, 14, 18, 0.06);
    --shadow-lg: 0 10px 30px rgba(13, 14, 18, 0.08);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-pill: 999px;

    /* ── Chart palette (approved 2026-07-17) ──────────────────
       Two rules. Rule 1, directional charts (sparklines, single-
       metric trends): --green up, --red down, dashed --text-mute
       for projections. Rule 2, categorical series: the five slots
       below, assigned in FIXED order, never cycled. When a chart
       also encodes up/down, green/red belong to direction and
       series start at --chart-2. Validated for CVD separation and
       lightness band on white; green/amber sit <3:1 contrast so
       every chart pairs with direct labels or its data table
       (the relief rule). Spec: docs/design-system.md § Charts. */
    --chart-1: #00B67A;   /* green — the system green leads */
    --chart-2: #6E56CF;   /* violet */
    --chart-3: #E89132;   /* amber — the system amber */
    --chart-4: #1F9BC4;   /* cyan */
    --chart-5: #D4577E;   /* rose */
}

/* ── Base ─────────────────────────────────────────────────── */
body.rh-page {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-feature-settings: "cv11" 1, "ss01" 1;
    font-weight: 400;
    line-height: 1.5;
    margin: 0;
    -webkit-font-smoothing: antialiased;
}
.rh-page * { box-sizing: border-box; }
/* neutralize the destructive global button defaults (CLAUDE.md note 7) */
.rh-page .btn, .rh-page button {
    height: auto;
    line-height: normal;
    box-sizing: border-box;
    margin: 0;
    font-family: var(--sans);
    background-image: none;
    box-shadow: none;
}
.rh-page :focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.rh-page input[type="radio"], .rh-page input[type="checkbox"] { accent-color: var(--text); }
@media (prefers-reduced-motion: reduce) {
    .rh-page * { transition: none !important; animation: none !important; }
}

.rh-page .rh-wrap { max-width: 1360px; margin: 0 auto; padding: 30px 36px 80px; }

/* ── Page header ──────────────────────────────────────────── */
.rh-page .page-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    gap: 20px;
    flex-wrap: wrap;
}
.rh-page .page-head h1 {
    margin: 0 0 4px 0;
    font-family: var(--sans);
    font-weight: 600;
    font-size: 24px;
    letter-spacing: -0.015em;
    color: var(--text);
}
.rh-page .page-head .sub { font-size: 13px; color: var(--text-sub); }
.rh-page .page-head .sub b { color: var(--text-sub); font-weight: 500; }
.rh-page .page-head .sub .dot {
    display: inline-block; width: 4px; height: 4px; background: var(--text-mute);
    border-radius: 50%; margin: 0 8px 2px; vertical-align: middle;
}

/* header actions: quiet text links + ONE pill CTA */
.rh-page .top-links { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.rh-page .top-link {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-sub);
    padding: 7px 12px;
    border-radius: var(--radius-pill);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    background: transparent;
    border: none;
    cursor: pointer;
}
.rh-page .top-link:hover { background: var(--hover); color: var(--text); }
.rh-page .top-link.on { color: var(--text); background: var(--gray-soft); }

.rh-page .btn-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--text);
    color: #fff;
    border: 1px solid var(--text);
    border-radius: var(--radius-pill);
    padding: 8px 16px;
    font-size: 13.5px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    margin-left: 8px;
}
.rh-page .btn-pill:hover { background: #26282E; }
.rh-page .btn-pill.outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.rh-page .btn-pill.outline:hover { background: var(--hover); }
.rh-page .btn-pill.danger { background: var(--red); border-color: var(--red); }

/* ── Metric cards ─────────────────────────────────────────── */
.rh-page .rh-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 0 0 24px; }
.rh-page .rh-mcard {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 18px 12px;
    box-shadow: var(--shadow-sm);
}
.rh-page .rh-mcard .lab { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-sub); font-weight: 500; }
.rh-page .rh-mcard .lab i { width: 7px; height: 7px; border-radius: 50%; background: var(--gray); flex: none; }
.rh-page .rh-mcard .lab i.pos { background: var(--green); }
.rh-page .rh-mcard .lab i.neg { background: var(--red); }
.rh-page .rh-mcard .lab i.warn { background: var(--amber); }
.rh-page .rh-mcard .val { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; color: var(--text); }
.rh-page .rh-mcard .val.pos { color: var(--green); }
.rh-page .rh-mcard .val.neg { color: var(--red); }
.rh-page .rh-mcard .sub { font-size: 12px; color: var(--text-mute); margin-top: 1px; }
.rh-page .rh-mcard .sub b { color: var(--text-sub); font-weight: 500; font-family: var(--mono); }
@media (max-width: 1000px) { .rh-page .rh-metrics { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px)  { .rh-page .rh-metrics { grid-template-columns: 1fr; } }

/* ── Hero number (dashboard pages) ────────────────────────── */
.rh-page .hero-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 36px 28px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}
.rh-page .hero-number {
    font-family: var(--sans);
    font-weight: 500;
    font-size: clamp(36px, 4.6vw, 56px);
    letter-spacing: -0.03em;
    line-height: 1.05;
    color: var(--text);
    font-feature-settings: "tnum" 1, "lnum" 1;
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin: 0;
}
.rh-page .hero-number .dollar { color: var(--text-sub); font-size: 0.55em; font-weight: 400; }
.rh-page .delta-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
    font-size: 13px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-feature-settings: "tnum" 1;
}
.rh-page .delta-pill.pos  { color: var(--green); background: var(--green-soft); }
.rh-page .delta-pill.neg  { color: var(--red);   background: var(--red-soft); }
.rh-page .delta-pill.zero { color: var(--gray);  background: var(--gray-soft); }

/* ── Filters row ──────────────────────────────────────────── */
.rh-page .rh-filters { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 13px; color: var(--text-sub); flex-wrap: wrap; }
.rh-page .rh-filters select,
.rh-page select.rh-select {
    font-family: var(--sans);
    font-size: 13px;
    color: var(--text);
    border: 1px solid var(--border);
    background-color: var(--surface);
    border-radius: var(--radius-pill);
    padding: 6px 12px;
}

/* ── Select affordance ────────────────────────────────────────
   Every dropdown on an rh page shows the system chevron — a
   select must never render identical to a text input (spec
   change 2026-07-16). Universal on purpose, and the chevron
   trio is !important so page-level `background:` shorthands
   (the bug that hid it) can't erase it. Widget internals
   (jQuery UI datepicker) and multi-selects opt back out below. */
.rh-page select:not([multiple]) {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235E636E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 10px center !important;
    padding-right: 32px !important;
    cursor: pointer;
}
.rh-page .ui-datepicker select {
    appearance: auto;
    -webkit-appearance: menulist;
    background-image: none !important;
    padding-right: 2px !important;
}

/* ── Sheet + table ────────────────────────────────────────── */
.rh-page .rh-sheet {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.rh-page .rh-sheet .sheet-scroll { overflow-x: auto; }
.rh-page table.rh-table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 14px; }
.rh-page table.rh-table thead th {
    text-align: left;
    padding: 12px 14px 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.rh-page table.rh-table thead th.num-col { text-align: right; }
.rh-page table.rh-table thead th.sorting { cursor: pointer; }
.rh-page table.rh-table thead th.sorting:hover { color: var(--text); }
.rh-page table.rh-table thead th.sorting_asc:after  { content: ' ↑'; color: var(--text); }
.rh-page table.rh-table thead th.sorting_desc:after { content: ' ↓'; color: var(--text); }
.rh-page table.rh-table tbody td {
    padding: 14px;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: top;
    font-size: 13.5px;
    color: var(--text);
}
.rh-page table.rh-table tbody tr:last-child td { border-bottom: none; }
.rh-page table.rh-table tbody tr:hover td { background: var(--surface-alt); }
.rh-page table.rh-table tbody td.num {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
    font-weight: 500;
}
.rh-page table.rh-table tbody td.num.zero { color: var(--text-mute); font-weight: 400; }
.rh-page table.rh-table tbody tr.dead-row td { color: var(--text-mute); }

/* primary entity link in a row */
.rh-page .cli-name { color: var(--text); text-decoration: none; font-weight: 600; }
.rh-page .cli-name:hover { text-decoration: underline; }
/* muted second line under any cell's main value */
.rh-page .cell-sub { display: block; font-family: var(--mono); font-size: 11px; color: var(--text-mute); margin-top: 2px; letter-spacing: 0.02em; }

/* ── State: dot + word (replaces pastel status pills) ─────── */
.rh-page .rh-state { font-weight: 500; white-space: nowrap; }
.rh-page .rh-state .hstate { display: inline-flex; align-items: center; gap: 7px; }
.rh-page .rh-state .hstate i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.rh-page .rh-state.ok .hstate i   { background: var(--green); }
.rh-page .rh-state.warn .hstate i { background: var(--amber); }
.rh-page .rh-state.risk .hstate i { background: var(--red); }
.rh-page .rh-state.dead { color: var(--text-mute); font-weight: 400; }
.rh-page .rh-state.dead .hstate i { background: transparent; border: 1.5px solid var(--text-mute); width: 6px; height: 6px; }
/* attention sub-line (e.g. "1 open issue") */
.rh-page .rh-state .issues { display: block; font-family: var(--mono); font-size: 11px; font-weight: 500; color: var(--red); margin-top: 3px; }

/* ── Micro tag (agency chips, service keys) ───────────────── */
.rh-page .rh-tag {
    display: inline-block;
    font-family: var(--mono);
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-sub);
    background: var(--gray-soft);
    border-radius: 5px;
    padding: 2px 7px;
    letter-spacing: 0.02em;
}
.rh-page .rh-tag.pos  { color: var(--green); background: var(--green-soft); }
.rh-page .rh-tag.neg  { color: var(--red);   background: var(--red-soft); }
.rh-page .rh-tag.warn { color: var(--amber); background: var(--amber-soft); }

/* signed deltas in table cells */
.rh-page .chg-pos  { color: var(--green); font-weight: 600; }
.rh-page .chg-neg  { color: var(--red);   font-weight: 600; }
.rh-page .chg-zero { color: var(--text-mute); }

/* recency traffic light (mono, no pill) */
.rh-page .rh-recency { font-family: var(--mono); font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.rh-page .rh-recency.ok   { color: var(--green); }
.rh-page .rh-recency.warn { color: var(--amber); }
.rh-page .rh-recency.late { color: var(--red); }

/* ── Forms ────────────────────────────────────────────────── */
.rh-page .rh-label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-mute); margin-bottom: 5px; }
.rh-page .rh-input, .rh-page textarea.rh-input {
    font-family: var(--sans);
    font-size: 13.5px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    width: 100%;
}
.rh-page .rh-input:focus { outline: 2px solid var(--text); outline-offset: 0; border-color: var(--text); }

/* ── Empty state ──────────────────────────────────────────── */
.rh-page .rh-empty { padding: 48px 20px; text-align: center; color: var(--text-sub); font-size: 14px; }
.rh-page .rh-empty .hint { color: var(--text-mute); font-size: 13px; margin-top: 4px; }

/* ── Compatibility layer: site-wide underline tabs (.etabs) on rh pages ── */
.rh-page .etabs { border-bottom-color: var(--border); }
.rh-page .etabs::after { background: var(--text); }
.rh-page .tab a, .rh-page .tabred a { font-family: var(--sans); }
.rh-page .tab a { color: var(--text-sub); }
.rh-page .tab a:hover { color: var(--text); background: var(--hover); }
.rh-page .tab a.active, .rh-page .tab.active a { color: var(--text); font-weight: 600; }
.rh-page .tab-count { font-family: var(--mono); font-weight: 600; background: var(--gray-soft); color: var(--text-sub); }
.rh-page .tab.active .tab-count,
.rh-page .tab a.active .tab-count { background: var(--text); color: #fff; }
.rh-page .tabred a { color: var(--red); }
.rh-page .tabred a:hover, .rh-page .tabred a.active, .rh-page .tabred.active a { color: var(--red); background: var(--red-soft); }

/* ── Compatibility layer: modern-forms (.mf-*) vocabulary on rh pages ── */
/* modern-forms caps .mf-container at 900px; rh pages are fluid like the
   rest of the system (the .wrapper 90% margin is the only constraint) */
.rh-page .mf-container { max-width: none; }
.rh-page .mf-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}
.rh-page .mf-card-title, .rh-page h4.mf-card-title {
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-mute);
    border-bottom: none;
}
.rh-page .mf-label {
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-mute);
}
.rh-page .mf-input, .rh-page .mf-select, .rh-page textarea.mf-input, .rh-page .mf-textarea {
    font-family: var(--sans);
    font-size: 13.5px;
    color: var(--text);
    background-color: var(--surface); /* NOT the `background:` shorthand — it would erase the select chevron */
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.rh-page .mf-input:focus, .rh-page .mf-select:focus, .rh-page .mf-textarea:focus {
    outline: 2px solid var(--text);
    border-color: var(--text);
    box-shadow: none;
}
.rh-page .mf-hint { color: var(--text-mute); font-size: 11.5px; }
.rh-page .mf-btn {
    font-family: var(--sans);
    border-radius: var(--radius-pill);
    font-weight: 600;
    font-size: 13.5px;
    height: auto;
    line-height: normal;
    box-sizing: border-box;
    /* modern-forms buttons have NO vertical padding (they sized via a fixed
       height, which this layer removes) — without this they collapse to text
       height. Metrics match .btn-pill. */
    padding: 8px 16px;
    margin: 0;
    box-shadow: none;
    background-image: none;
}
.rh-page .mf-btn-sm { padding: 5px 12px; font-size: 12.5px; }
.rh-page .mf-btn-primary { background: var(--text); color: #fff; border: 1px solid var(--text); }
.rh-page .mf-btn-primary:hover { background: #26282E; color: #fff; }
.rh-page .mf-btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.rh-page .mf-btn-secondary:hover { background: var(--hover); }
.rh-page .mf-btn-danger { background: var(--red); color: #fff; border: 1px solid var(--red); }

/* ── Explainer tooltip (.rh-tip) ──────────────────────────────
   Markup contract:
     <span class="rh-tip" tabindex="0" data-tip="Plain copy.">?</span>
   A 14px circled "?" that shows a dark bubble above itself on hover
   or keyboard focus. Copy stays short and plain (no jokes below
   greeting level). PHP helper on Tasks pages: pmTip($text, $mod).
   Edge modifiers when the centered bubble would clip:
     .tip-right  pins the bubble's LEFT edge to the icon (use near
                 the viewport's / a scroll container's left edge)
     .tip-left   pins the bubble's RIGHT edge to the icon (right edge)
     .tip-down   drops the bubble BELOW the icon (use inside
                 .rh-sheet / .sheet-scroll headers, where an upward
                 bubble would be clipped by the sheet's overflow)
   The bubble is display-gated (not just opacity) so the hidden
   bubble can never widen a scroll container or the page. */
.rh-page .rh-tip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    flex: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-mute);
    font-family: var(--sans);
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    cursor: help;
    margin-left: 5px;
    vertical-align: middle;
    user-select: none;
}
.rh-page .rh-tip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    display: none;
    background: var(--text);
    color: var(--surface);
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.45;
    max-width: 260px;
    width: max-content;
    white-space: normal;
    text-align: left;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s;
    z-index: 10600; /* above the task drawer panel (10501) */
}
.rh-page .rh-tip:hover::after,
.rh-page .rh-tip:focus::after {
    display: block;
    opacity: 1;
    animation: rhTipIn 0.12s ease;
}
@keyframes rhTipIn { from { opacity: 0; } to { opacity: 1; } }
.rh-page .rh-tip.tip-right::after { left: 0; transform: none; }
.rh-page .rh-tip.tip-left::after { right: 0; left: auto; transform: none; }
.rh-page .rh-tip.tip-down::after { bottom: auto; top: calc(100% + 8px); }
