/* portal.css — design tokens + layout primitives.
 * Vanilla CSS, no build step. Each business unit overrides --bu-* on the
 * report-workspace view via [data-business-unit="execcare|occufit|phila"].
 */

:root {
    /* Neutrals */
    --bg:           #0B1A26;   /* deep navy from phila-dashboard */
    --bg-elev-1:    #122433;
    --bg-elev-2:    #1A3045;
    --text:         #F2F4F7;
    --text-muted:   #9BB0C2;
    --text-dim:     #5F7689;
    --border:       #1F3A52;
    --border-soft:  #15293A;

    /* Status traffic-light */
    --status-green: #2EA391;
    --status-amber: #E0A33A;
    --status-red:   #D8533F;
    --status-grey:  #5F7689;

    /* Business-unit accents (override on the report workspace) */
    --bu-execcare:  #C99B5B;   /* bronze/amber */
    --bu-occufit:   #2EA391;   /* teal */
    --bu-phila:     #1A7A6D;   /* phila teal */

    /* Type */
    --font-ui:     'Inter Tight', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono:   'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
    --font-serif:  'Fraunces', Georgia, serif;

    /* Spacing scale (4px base) */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 24px;
    --sp-6: 32px;
    --sp-7: 48px;
    --sp-8: 64px;

    /* Sizing */
    --radius-sm: 4px;
    --radius:    6px;
    --radius-lg: 10px;
    --top-bar:   56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--text);
    text-decoration: none;
    border-bottom: 1px solid var(--border);
}
a:hover { border-bottom-color: var(--text); }

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

/* ----------------------------------------------------------------------- */
/* Top bar                                                                 */
/* ----------------------------------------------------------------------- */
.rp-top {
    height: var(--top-bar);
    background: var(--bg-elev-1);
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    gap: var(--sp-5);
    padding: 0 var(--sp-5);
    position: sticky;
    top: 0;
    z-index: 10;
}

.rp-lockup {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    flex: 0 0 auto;
}

.rp-lockup img {
    height: 28px;
    width: auto;
    display: block;
}

.rp-title {
    font-weight: 500;
    color: var(--text);
    letter-spacing: 0.01em;
}

.rp-top nav {
    display: flex;
    gap: var(--sp-4);
    flex: 1 1 auto;
}

.rp-top nav a {
    border-bottom: none;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-weight: 500;
}
.rp-top nav a:hover { background: var(--bg-elev-2); color: var(--text); }
.rp-top nav a[aria-current="page"] { color: var(--text); background: var(--bg-elev-2); }

.rp-user {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    color: var(--text-muted);
    font-size: 13px;
}
.rp-user button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius);
    font: inherit;
    cursor: pointer;
}
.rp-user button:hover { color: var(--text); border-color: var(--text-muted); }

/* ----------------------------------------------------------------------- */
/* Main route container                                                    */
/* ----------------------------------------------------------------------- */
main#rp-route {
    padding: var(--sp-6) var(--sp-6);
    max-width: 1400px;
    margin: 0 auto;
}

main#rp-route > section { margin-bottom: var(--sp-7); }

main#rp-route h1 {
    font-family: var(--font-serif);
    font-weight: 500;
    font-size: 28px;
    margin: 0 0 var(--sp-5);
}

main#rp-route h2 {
    font-weight: 500;
    font-size: 18px;
    margin: 0 0 var(--sp-4);
    color: var(--text-muted);
}

/* ----------------------------------------------------------------------- */
/* Queue table                                                             */
/* ----------------------------------------------------------------------- */
.rp-queue-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-3);
    align-items: center;
    margin-bottom: var(--sp-5);
    padding: var(--sp-3) var(--sp-4);
    background: var(--bg-elev-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
}
.rp-queue-filters label {
    color: var(--text-muted);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}
.rp-queue-filters select,
.rp-queue-filters input[type="text"] {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--sp-2) var(--sp-3);
    font: inherit;
}

table.rp-queue {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-elev-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    overflow: hidden;
}

table.rp-queue thead th {
    text-align: left;
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    background: var(--bg-elev-2);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
}

table.rp-queue tbody td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
}
table.rp-queue tbody tr:last-child td { border-bottom: none; }
table.rp-queue tbody tr:hover { background: var(--bg-elev-2); }

table.rp-queue td .num { color: var(--text); }
table.rp-queue td.due-overdue { color: var(--status-red); font-weight: 500; }
table.rp-queue td.due-soon    { color: var(--status-amber); }

/* Chips */
.rp-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
    border: 1px solid currentColor;
    line-height: 1.6;
    white-space: nowrap;
}
.rp-chip.bu-execcare { color: var(--bu-execcare); }
.rp-chip.bu-occufit  { color: var(--bu-occufit); }
.rp-chip.bu-phila    { color: var(--bu-phila); }
.rp-chip.state       { color: var(--text-muted); }
.rp-chip.state-active { color: var(--status-amber); }

/* CTA button */
button.rp-cta,
a.rp-cta {
    display: inline-block;
    padding: var(--sp-2) var(--sp-4);
    background: var(--text);
    color: var(--bg);
    border: 1px solid var(--text);
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid var(--text);
}
button.rp-cta:hover, a.rp-cta:hover { background: var(--text-muted); border-color: var(--text-muted); }

/* ----------------------------------------------------------------------- */
/* States: empty / loading / error / no-access                             */
/* ----------------------------------------------------------------------- */
.rp-empty,
.rp-error,
.rp-loading {
    padding: var(--sp-7) var(--sp-5);
    text-align: center;
    background: var(--bg-elev-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    color: var(--text-muted);
}
.rp-error { color: var(--status-red); }
.rp-loading::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: var(--sp-2);
    vertical-align: middle;
    border: 2px solid var(--text-dim);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: rp-spin 0.8s linear infinite;
}

@keyframes rp-spin { to { transform: rotate(360deg); } }

.rp-skeleton-row {
    height: 40px;
    background: linear-gradient(90deg, var(--bg-elev-1) 0%, var(--bg-elev-2) 50%, var(--bg-elev-1) 100%);
    background-size: 200% 100%;
    animation: rp-shimmer 1.4s ease-in-out infinite;
    border-bottom: 1px solid var(--border-soft);
}
@keyframes rp-shimmer { to { background-position: -200% 0; } }

/* No-access screen — visible when an authed user has zero portal roles */
#rp-no-access {
    max-width: 560px;
    margin: var(--sp-8) auto;
    padding: var(--sp-7);
    background: var(--bg-elev-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    text-align: center;
}
#rp-no-access h1 {
    font-family: var(--font-serif);
    font-weight: 500;
    margin: 0 0 var(--sp-4);
}
#rp-no-access p { color: var(--text-muted); margin: var(--sp-3) 0; }
#rp-no-access code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
}

/* Backend-unreachable banner — shows only when /api/me network-errors
 * (the deploy isn't wired, or we're previewing without a Function App). */
#rp-no-backend {
    margin: var(--sp-5) auto;
    max-width: 1400px;
    padding: var(--sp-3) var(--sp-4);
    background: var(--bg-elev-2);
    border: 1px solid var(--status-amber);
    border-left-width: 4px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 13px;
}

/* ----------------------------------------------------------------------- */
/* Report workspace (#/reports/{id})                                       */
/* ----------------------------------------------------------------------- */
.rp-workspace-header {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-4);
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-5);
    padding: var(--sp-3) var(--sp-4);
    background: var(--bg-elev-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
}
.rp-ws-meta { color: var(--text-muted); }
.rp-ws-meta strong { color: var(--text); font-weight: 500; }
.rp-ws-actions { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.rp-cta.secondary {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}
.rp-cta.secondary:hover { color: var(--text); border-color: var(--text-muted); background: var(--bg-elev-2); }

.rp-workspace-body {
    display: grid;
    grid-template-columns: 220px 1fr 320px;
    gap: var(--sp-4);
    align-items: start;
}
@media (max-width: 1100px) {
    .rp-workspace-body { grid-template-columns: 1fr; }
}

.rp-ws-pages,
.rp-ws-activity {
    background: var(--bg-elev-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: var(--sp-3);
    position: sticky;
    top: calc(var(--top-bar) + var(--sp-4));
    max-height: calc(100vh - var(--top-bar) - var(--sp-7));
    overflow-y: auto;
}

.rp-ws-rail { display: flex; flex-direction: column; gap: 2px; }
.rp-ws-rail a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sp-2) var(--sp-3);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13px;
}
.rp-ws-rail a:hover { background: var(--bg-elev-2); color: var(--text); }
.rp-ws-rail a[aria-current="page"] { background: var(--bg-elev-2); color: var(--text); font-weight: 500; }

.rp-ws-page {
    background: var(--bg-elev-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: var(--sp-5);
    min-height: 60vh;
}
.rp-ws-page h2 {
    font-family: var(--font-serif);
    font-weight: 500;
    font-size: 22px;
    margin: 0 0 var(--sp-4);
    text-transform: capitalize;
}

.rp-page-dl {
    display: grid;
    grid-template-columns: 280px 1fr;
    column-gap: var(--sp-5);
    row-gap: var(--sp-2);
    margin: 0;
}
.rp-page-dl dt { color: var(--text-muted); font-size: 12px; text-transform: lowercase; letter-spacing: 0.02em; }
.rp-page-dl dd { margin: 0; color: var(--text); font-family: var(--font-mono); font-size: 13px; }

/* Activity rail */
.rp-tabs h3 {
    margin: 0 0 var(--sp-3);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.rp-comment-form { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-5); }
.rp-comment-form textarea {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--sp-2) var(--sp-3);
    font: inherit;
    resize: vertical;
}
.rp-comment-form label { color: var(--text-muted); font-size: 12px; display: flex; align-items: center; gap: var(--sp-2); }

.rp-activity-history h4 {
    margin: 0 0 var(--sp-3);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.rp-timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.rp-timeline li {
    border-left: 2px solid var(--border);
    padding: 0 0 0 var(--sp-3);
    color: var(--text-muted);
    font-size: 13px;
}
.rp-timeline li strong { color: var(--text); }
.rp-timeline time { display: block; font-size: 11px; color: var(--text-dim); font-family: var(--font-mono); }
.rp-timeline-note { margin-top: var(--sp-1); padding: var(--sp-2); background: var(--bg); border-radius: var(--radius-sm); font-size: 12px; }

/* Business-unit accent applied at the workspace root */
main#rp-route[data-business-unit="execcare"] { --bu-accent: var(--bu-execcare); }
main#rp-route[data-business-unit="occufit"]  { --bu-accent: var(--bu-occufit); }
main#rp-route[data-business-unit="phila"]    { --bu-accent: var(--bu-phila); }

/* ----------------------------------------------------------------------- */
/* Page renderer components (KPI cards, bars, cover, page headings)        */
/* ----------------------------------------------------------------------- */
.rp-ws-page h3 {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: var(--sp-6) 0 var(--sp-3);
}
.rp-ws-page h3:first-of-type { margin-top: var(--sp-4); }

/* KPI grid — 2 to 4 columns based on viewport */
.rp-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--sp-3);
    margin-bottom: var(--sp-5);
}
.rp-kpi {
    padding: var(--sp-4);
    background: var(--bg-elev-2);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    border-left: 3px solid var(--bu-accent, var(--bu-occufit));
}
.rp-kpi-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin-bottom: var(--sp-1);
}
.rp-kpi-value {
    font-family: var(--font-mono);
    font-size: 24px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.2;
}
.rp-kpi-pct {
    font-size: 14px;
    color: var(--text-muted);
    margin-left: var(--sp-2);
}

/* Inline bar (table cell width) */
.rp-bar {
    width: 100%;
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
    min-width: 80px;
}
.rp-bar-fill { height: 100%; transition: width 0.3s; }
.rp-bar-green { background: var(--status-green); }
.rp-bar-amber { background: var(--status-amber); }
.rp-bar-red   { background: var(--status-red); }
.rp-bar-grey  { background: var(--status-grey); }
.rp-bar-teal  { background: var(--bu-occufit); }

/* Cover card — first page of a report */
.rp-cover-card {
    padding: var(--sp-7) var(--sp-6);
    background: var(--bg-elev-2);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    text-align: center;
}
.rp-cover-bu {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--bu-accent, var(--bu-occufit));
    margin-bottom: var(--sp-3);
}
.rp-cover-client {
    font-family: var(--font-serif);
    font-weight: 500;
    font-size: 32px;
    margin: 0 0 var(--sp-2);
    color: var(--text);
}
.rp-cover-site {
    color: var(--text-muted);
    font-size: 16px;
    margin-bottom: var(--sp-2);
}
.rp-cover-period {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text);
    margin: var(--sp-4) 0 var(--sp-2);
}
.rp-cover-type {
    color: var(--text-dim);
    font-size: 13px;
    text-transform: capitalize;
}

.rp-page-note {
    color: var(--text-dim);
    font-size: 12px;
    margin-top: var(--sp-4);
}

/* ----------------------------------------------------------------------- */
/* BWE report design tokens (ported from static/report-designs/occufit/    */
/* source-htmls/*.html — Vodacom/Rainbow-Epol/BWE-YTD all share this.)     */
/* These render on the dark portal AND in print where portal.css colour    */
/* tokens get re-mapped to white-background by print.css.                  */
/* ----------------------------------------------------------------------- */

.rp-bwe-section-title {
    font-family: var(--font-serif);
    font-size: 24px;
    font-weight: 500;
    color: var(--bu-occufit);
    margin: 0 0 var(--sp-2);
    letter-spacing: -0.01em;
}
.rp-bwe-section-intro {
    color: var(--text-muted);
    font-size: 13.5px;
    line-height: 1.6;
    margin-bottom: var(--sp-5);
    max-width: 760px;
}
.rp-bwe-h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--bu-occufit);
    text-transform: none;
    letter-spacing: 0;
    margin: var(--sp-6) 0 var(--sp-3);
}
.rp-bwe-h3:first-of-type { margin-top: var(--sp-4); }

/* KPI row — horizontal grid of bordered cards (BWE design) */
.rp-bwe-kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--sp-3);
    margin-bottom: var(--sp-5);
}
.rp-bwe-kpi-box {
    background: var(--bg-elev-2);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: var(--sp-4) var(--sp-5);
    text-align: center;
}
.rp-bwe-kpi-box .val {
    font-family: var(--font-mono);
    font-size: 28px;
    font-weight: 600;
    color: var(--bu-occufit);
    line-height: 1.1;
    display: block;
    margin-bottom: var(--sp-1);
}
.rp-bwe-kpi-box .lbl {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Chart row — pairs of side-by-side chart boxes */
.rp-bwe-chart-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--sp-4);
    margin-bottom: var(--sp-5);
}
.rp-bwe-chart-box {
    background: var(--bg-elev-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: var(--sp-4);
    min-height: 220px;
    display: flex;
    flex-direction: column;
}
.rp-bwe-chart-title {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: var(--sp-3);
    font-weight: 500;
}
.rp-bwe-chart-body {
    flex: 1;
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.rp-bwe-chart-placeholder {
    color: var(--text-dim);
    font-size: 12px;
    font-style: italic;
}

/* Risk card — biometric / lifestyle risk indicators */
.rp-bwe-risk-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--sp-3);
    margin-bottom: var(--sp-5);
}
.rp-bwe-risk-card {
    background: var(--bg-elev-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: var(--sp-3) var(--sp-4);
}
.rp-bwe-risk-card .r-title {
    font-size: 10.5px;
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--sp-2);
}
.rp-bwe-risk-card .r-val {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 600;
    margin-bottom: var(--sp-2);
    line-height: 1.1;
}
.rp-bwe-risk-card .r-val.red    { color: var(--status-red); }
.rp-bwe-risk-card .r-val.amber  { color: var(--status-amber); }
.rp-bwe-risk-card .r-val.green  { color: var(--status-green); }
.rp-bwe-risk-card .r-val.grey   { color: var(--text-muted); }
.rp-bwe-risk-card .r-bar {
    height: 4px;
    background: var(--bg-elev-2);
    border-radius: 2px;
    overflow: hidden;
}
.rp-bwe-risk-card .r-bar-fill { height: 100%; }

/* BWE-style data table */
table.rp-bwe-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: var(--sp-5);
    background: var(--bg-elev-1);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    overflow: hidden;
}
table.rp-bwe-table thead th {
    background: var(--bg-elev-2);
    color: var(--text);
    font-weight: 500;
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
table.rp-bwe-table tbody td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border-soft);
}
table.rp-bwe-table tbody tr:last-child td { border-bottom: none; }
table.rp-bwe-table tbody tr:last-child td { font-weight: 600; }
table.rp-bwe-table .num { color: var(--text); }
table.rp-bwe-table .col-num { text-align: right; }

/* Page-wide intro paragraph below the section title */
.rp-bwe-page > .rp-bwe-section-title + .rp-bwe-section-intro {
    margin-bottom: var(--sp-6);
}

/* ----------------------------------------------------------------------- */
/* Admin view (#/admin)                                                    */
/* ----------------------------------------------------------------------- */
.rp-admin-tabs { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4); border-bottom: 1px solid var(--border-soft); }
.rp-admin-tabs a {
    padding: var(--sp-2) var(--sp-4);
    border: none;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 2px solid transparent;
}
.rp-admin-tabs a:hover { color: var(--text); }
.rp-admin-tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--text); }
