/* ---------------------------------------------------------------------------
 * ADMIN DASHBOARD
 * Scoped under body.home so nothing here reaches another page.
 * Neutrals match the Safe module - one product, one family.
 * Series and ramp colours were validated for colourblind separation and
 * lightness in both modes; do not substitute them by eye.
 * ------------------------------------------------------------------------- */

body.home {
    --db-bg:        #f2f5f6;
    --db-surface:   #ffffff;
    --db-surface-2: #e9edef;
    --db-line:      #d5dce0;
    --db-hairline:  #e7ecee;
    --db-text:      #121a20;
    --db-text-2:    #5c6b78;
    --db-text-3:    #8697a3;
    --db-brass:     #9a6a1f;

    /* categorical series - validated light: protan dE 31.7, normal dE 36.1 */
    --db-in:  #2563eb;
    --db-out: #c2410c;

    /* ordinal ramp for overdue age bands - one hue, monotone lightness */
    --db-age-1: #e5a077;
    --db-age-2: #d4813f;
    --db-age-3: #c2410c;
    --db-age-4: #8a2c08;

    /* status - reserved, never reused as a series colour */
    --db-critical:    #a3261a;
    --db-critical-bg: #f9e3e0;
    --db-warning:     #8a5a08;
    --db-warning-bg:  #f8ecd6;
    --db-calm:        #17604a;
    --db-calm-bg:     #dff0e8;

    --db-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --db-mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
    --db-figure: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
    --db-r: 3px;

    /* width reserved for the y-axis labels - the bars, the x-axis and the
       peak label all offset by this, so it is defined once */
    --db-gutter: 60px;
}

body.home.theme-dark,
html.dark body.home,
body.dark-theme.home {
    --db-bg: #0d1317; --db-surface: #151d23; --db-surface-2: #1c262d;
    --db-line: #2a353d; --db-hairline: #202b32;
    --db-text: #e7edf1; --db-text-2: #93a3af; --db-text-3: #6d7f8c;
    --db-brass: #cf9f4f;
    /* dark steps are chosen against the dark surface, not flipped */
    --db-in: #3b82f6; --db-out: #e2703a;
    --db-age-1: #8a4a22; --db-age-2: #b45f2c; --db-age-3: #e2703a; --db-age-4: #f2a173;
    --db-critical: #f08a7c; --db-critical-bg: #3a1d18;
    --db-warning: #d9a441; --db-warning-bg: #332811;
    --db-calm: #52c49b; --db-calm-bg: #12332a;
}

body.home .db { display: flex; flex-direction: column; gap: 18px; }
body.home .db :focus-visible { outline: 2px solid var(--db-brass); outline-offset: 2px; }

body.home .db-eyebrow {
    font-size: 13.5px; font-weight: 650; letter-spacing: .13em;
    text-transform: uppercase; color: var(--db-text-3);
}
body.home .db-greeting { font-size: 29px; font-weight: 620; letter-spacing: -.017em; margin: 2px 0 0; }
body.home .db-sub { color: var(--db-text-2); font-size: 16.5px; }

body.home .db-card {
    background: var(--db-surface); border: 1px solid var(--db-line);
    border-radius: var(--db-r);
}
body.home .db-card-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    padding: 13px 16px; border-bottom: 1px solid var(--db-line);
}
body.home .db-card-head h2 { font-size: 16.5px; font-weight: 620; margin: 0; color: var(--db-text); }
body.home .db-card-head .meta { font-size: 14.5px; color: var(--db-text-3); font-variant-numeric: tabular-nums; }

/* ---------- triage ---------- */
body.home .db-triage { display: flex; flex-direction: column; }
body.home .db-triage-row {
    display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center;
    padding: 13px 16px; border-bottom: 1px solid var(--db-hairline);
    text-decoration: none; color: inherit;
}
body.home .db-triage-row:last-child { border-bottom: 0; }
body.home .db-triage-row:hover { background: var(--db-surface-2); text-decoration: none; color: inherit; }
body.home .db-triage-row .what b { font-weight: 600; font-size: 17px; display: block; color: var(--db-text); }
body.home .db-triage-row .what span { font-size: 16px; color: var(--db-text-2); }
body.home .db-triage-row .fig {
    font-family: var(--db-mono); font-size: 17px; font-variant-numeric: tabular-nums;
    white-space: nowrap; text-align: right; color: var(--db-text);
}
body.home .db-triage-row .fig div + div { margin-top: 2px; font-size: 15px; color: var(--db-text-2); }
body.home .db-triage-row .go { color: var(--db-text-3); font-family: var(--db-mono); font-size: 18px; }

/* status always carries an icon AND a word - never colour alone */
body.home .db-badge {
    display: inline-flex; align-items: center; gap: 5px; flex: none;
    font-size: 13.5px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
    padding: 3px 8px; border-radius: 2px; white-space: nowrap;
}
body.home .db-badge.critical { background: var(--db-critical-bg); color: var(--db-critical); }
body.home .db-badge.warning  { background: var(--db-warning-bg);  color: var(--db-warning); }
body.home .db-badge.calm     { background: var(--db-calm-bg);     color: var(--db-calm); }

@media (max-width: 640px) {
    body.home .db-triage-row { grid-template-columns: auto 1fr; }
    body.home .db-triage-row .fig,
    body.home .db-triage-row .go { grid-column: 2; text-align: left; }
}

/* ---------- money ---------- */
body.home .db-money { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
body.home .db-stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 7px; }
body.home .db-stat .lbl { font-size: 14.5px; color: var(--db-text-2); }
body.home .db-stat .fig {
    font-family: var(--db-figure); font-size: 42px; letter-spacing: -.028em;
    font-variant-numeric: tabular-nums; line-height: 1.05; color: var(--db-text);
}
body.home .db-stat .fig div + div { font-size: 28px; color: var(--db-text-2); }
body.home .db-stat .note { font-size: 14.5px; color: var(--db-text-3); }
body.home .db-stat .note.alert { color: var(--db-critical); }

/* ---------- charts ---------- */
body.home .db-charts { display: grid; grid-template-columns: 1.55fr 1fr; gap: 12px; }
@media (max-width: 900px) { body.home .db-charts { grid-template-columns: 1fr; } }

body.home .db-legend { display: flex; gap: 14px; align-items: center; }
body.home .db-legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 14.5px; color: var(--db-text-2); }
body.home .db-swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
body.home .db-swatch.in { background: var(--db-in); }
body.home .db-swatch.out { background: var(--db-out); }

body.home .db-plot { padding: 16px 16px 10px; }
body.home .db-plot-grid { position: relative; height: 190px; }
/* hairline, recessive, never dashed */
body.home .db-gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--db-hairline); }
body.home .db-gridline span {
    position: absolute; left: 0; top: -7px; font-family: var(--db-mono); font-size: 12.5px;
    color: var(--db-text-3); background: var(--db-surface); padding-right: 5px;
}
body.home .db-bars { position: absolute; inset: 0 0 0 var(--db-gutter); display: flex; align-items: flex-end; gap: 5px; }
body.home .db-month { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; height: 100%; position: relative; }
/* 4px rounded data-end, anchored to the baseline; 2px gap between adjacent bars */
body.home .db-bar { width: 8px; border-radius: 4px 4px 0 0; min-height: 1px; transition: opacity .12s; }
body.home .db-bar.in { background: var(--db-in); }
body.home .db-bar.out { background: var(--db-out); }
body.home .db-month:hover .db-bar { opacity: .55; }
body.home .db-month.empty::after { content: ""; position: absolute; bottom: 0; width: 18px; border-top: 1px solid var(--db-line); }

body.home .db-xaxis { display: flex; gap: 5px; margin: 7px 0 0 var(--db-gutter); }
body.home .db-xaxis span { flex: 1; text-align: center; font-family: var(--db-mono); font-size: 12.5px; color: var(--db-text-3); }
body.home .db-xaxis span.yr { color: var(--db-text-2); font-weight: 600; }

/* a single direct label on the peak, never a number on every bar */
body.home .db-peak {
    position: absolute; transform: translateX(-50%); font-family: var(--db-mono);
    font-size: 13px; color: var(--db-text-2); white-space: nowrap; margin-bottom: 4px;
}

/* ---------- aging ---------- */
body.home .db-aging { padding: 16px 18px; display: flex; flex-direction: column; gap: 13px; }
body.home .db-age-row { display: flex; flex-direction: column; gap: 5px; }
body.home .db-age-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 15px; }
body.home .db-age-head .who { color: var(--db-text-2); }
body.home .db-age-head .amt { font-family: var(--db-mono); font-variant-numeric: tabular-nums; font-size: 15px; color: var(--db-text); }
body.home .db-age-track { height: 7px; background: var(--db-surface-2); border-radius: 4px; overflow: hidden; }
body.home .db-age-fill { height: 100%; border-radius: 4px; }

/* ---------- table view: every chart has one ---------- */
body.home details.db-tableview { border-top: 1px solid var(--db-hairline); }
body.home details.db-tableview summary {
    padding: 9px 16px; font-size: 14.5px; color: var(--db-text-2); cursor: pointer; list-style: none;
}
body.home details.db-tableview summary::-webkit-details-marker { display: none; }
body.home details.db-tableview summary::before { content: "\25B8 "; color: var(--db-text-3); }
body.home details.db-tableview[open] summary::before { content: "\25BE "; }
body.home .db-tvscroll { overflow-x: auto; }
body.home table.db-tv { width: 100%; border-collapse: collapse; font-size: 14.5px; margin: 0; }
body.home table.db-tv th,
body.home table.db-tv td {
    padding: 5px 16px; text-align: right; font-family: var(--db-mono);
    font-variant-numeric: tabular-nums; white-space: nowrap; border: 0;
}
body.home table.db-tv th:first-child,
body.home table.db-tv td:first-child { text-align: left; }
body.home table.db-tv thead th { color: var(--db-text-3); font-weight: 600; border-bottom: 1px solid var(--db-hairline); }
body.home table.db-tv tbody td { color: var(--db-text-2); border-bottom: 1px solid var(--db-hairline); }
body.home table.db-tv tbody tr:last-child td { border-bottom: 0; }

/* ---------- lower row ---------- */
body.home .db-lower { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { body.home .db-lower { grid-template-columns: 1fr; } }

body.home .db-feed { display: flex; flex-direction: column; }
body.home .db-feed-row {
    display: grid; grid-template-columns: auto 1fr auto; gap: 11px; align-items: baseline;
    padding: 10px 16px; border-bottom: 1px solid var(--db-hairline);
}
body.home .db-feed-row:last-child { border-bottom: 0; }
body.home .db-feed-row .d { font-family: var(--db-mono); font-size: 13.5px; color: var(--db-text-3); white-space: nowrap; }
body.home .db-feed-row .t { font-size: 16px; color: var(--db-text-2); }
body.home .db-feed-row .t b { color: var(--db-text); font-weight: 550; }
body.home .db-feed-row .v { font-family: var(--db-mono); font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
body.home .db-feed-row .v.in { color: var(--db-in); }
body.home .db-feed-row .v.out { color: var(--db-out); }

body.home .db-quiet { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
body.home .db-quiet-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 16px; }
body.home .db-quiet-row a { color: var(--db-text); text-decoration: none; }
body.home .db-quiet-row a:hover { color: var(--db-brass); }
body.home .db-quiet-row .n { font-family: var(--db-mono); font-variant-numeric: tabular-nums; color: var(--db-text-3); }
body.home .db-quiet-note {
    font-size: 14.5px; color: var(--db-text-3); line-height: 1.45;
    border-top: 1px solid var(--db-hairline); padding-top: 10px; margin: 0;
}

body.home .db-nothing { padding: 30px 16px; text-align: center; color: var(--db-text-3); font-size: 16.5px; }

/* ---------- tooltip ---------- */
body.home #db-tip {
    position: fixed; z-index: 1000; pointer-events: none; opacity: 0;
    background: var(--db-text); color: var(--db-bg); border-radius: var(--db-r);
    padding: 7px 10px; font-size: 14.5px; line-height: 1.5;
    box-shadow: 0 4px 14px rgba(0,0,0,.22); transition: opacity .1s; max-width: 240px;
}
body.home #db-tip b {
    display: block; font-size: 13.5px; letter-spacing: .06em; text-transform: uppercase;
    opacity: .7; margin-bottom: 2px;
}
body.home #db-tip .r {
    display: flex; justify-content: space-between; gap: 12px;
    font-family: var(--db-mono); font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) { body.home * { transition: none !important; } }
