/* ── CoopVote colour system — light & dark (the Smartpad POS colour system) ─────────────────────────────────────────
   MudBlazor's palettes (Theming/CoopVoteTheme.cs) colour every standard component. This file holds what is not a palette
   slot: page/sign-in surfaces, navigation fill, stat tiles, candidate rows and chart tokens. Tokens switch on
   html[data-cv-theme], which the server writes from the saved preference (coopvote-theme cookie) and js/theme.js updates
   on toggle. Values are Smartpad's approved palette; chart hues are the validated categorical palette (both modes pass the
   dataviz checks against these exact card surfaces: #FFFFFF light, #111827 dark). */

:root,
html[data-cv-theme="light"] {
    --cv-page: #F1F5F9;
    --cv-surface: #FFFFFF;
    --cv-surface-2: #F8FAFC;
    --cv-ink: #0F172A;
    --cv-ink-2: #475569;
    --cv-ink-3: #64748B;
    --cv-border: #E2E8F0;
    --cv-input-bg: #FFFFFF;
    --cv-input-border: #CBD5E1;
    --cv-link: #0B5D3B;
    --cv-accent: #15803D;
    --cv-brand-accent: #86EFAC;
    --cv-button-bg: #0B5D3B;
    --cv-button-hover: #064E3B;
    --cv-button-fg: #FFFFFF;
    --cv-button-2-bg: #475569;
    --cv-focus-ring: rgba(22, 163, 74, 0.25);
    --cv-error-fg: #B91C1C;
    --cv-error-bg: #FEF2F2;
    --cv-ok-fg: #166534;
    --cv-ok-bg: #F0FDF4;
    --cv-code-bg: #F1F5F9;
    --cv-banner-bg: #FEF3C7;
    --cv-banner-fg: #78350F;
    --cv-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);

    --cv-nav-active-bg: #DCFCE7;
    --cv-nav-active-fg: #0B5D3B;
    --cv-nav-active-icon: #0B5D3B;
    --cv-nav-hover-bg: #F0FDF4;

    /* Charts (light steps) */
    --cv-grid: #E2E8F0;
    --cv-track: #EEF2F6;
    --cv-bar: #2A78D6;
    --cv-s1: #2A78D6; --cv-s2: #EB6834; --cv-s3: #1BAF7A; --cv-s4: #EDA100; --cv-s5: #E87BA4;
}

html[data-cv-theme="dark"] {
    --cv-page: #0F172A;
    --cv-surface: #111827;
    --cv-surface-2: #1E293B;
    --cv-ink: #F8FAFC;
    --cv-ink-2: #CBD5E1;
    --cv-ink-3: #94A3B8;
    --cv-border: #334155;
    --cv-input-bg: #0B1220;
    --cv-input-border: #475569;
    --cv-link: #16A34A;
    --cv-accent: #16A34A;
    --cv-brand-accent: #16A34A;
    --cv-button-bg: #16A34A;
    --cv-button-hover: #0B5D3B;
    --cv-button-fg: #F8FAFC;
    --cv-button-2-bg: #334155;
    --cv-focus-ring: rgba(22, 163, 74, 0.35);
    --cv-error-fg: #FCA5A5;
    --cv-error-bg: rgba(127, 29, 29, 0.35);
    --cv-ok-fg: #86EFAC;
    --cv-ok-bg: rgba(6, 78, 59, 0.45);
    --cv-code-bg: #1E293B;
    --cv-banner-bg: #422006;
    --cv-banner-fg: #FDE68A;
    --cv-shadow: 0 1px 4px rgba(2, 6, 23, 0.6);

    --cv-nav-active-bg: #0B5D3B;
    --cv-nav-active-fg: #F8FAFC;
    --cv-nav-active-icon: #16A34A;
    --cv-nav-hover-bg: #064E3B;

    /* Charts (dark steps) */
    --cv-grid: #334155;
    --cv-track: #1E293B;
    --cv-bar: #3987E5;
    --cv-s1: #3987E5; --cv-s2: #D95926; --cv-s3: #199E70; --cv-s4: #C98500; --cv-s5: #D55181;
}

html { color-scheme: light; }
html[data-cv-theme="dark"] { color-scheme: dark; }
body { background: var(--cv-page); color: var(--cv-ink); }

/* Plain links in page content (MudBlazor components colour their own). */
.mud-main-content a:not([class]),
.account-card a { color: var(--cv-link); }

/* ── App bar brand ─────────────────────────────────────────────────────────── */
a.brand { color: inherit; text-decoration: none; font-weight: 600; font-size: 1.1rem; letter-spacing: 0.01em; display: inline-flex; align-items: center; }
.cv-appbar-brand { white-space: nowrap; }
.cv-brand-accent { color: var(--cv-brand-accent); }
.tenant-name { font-size: .9rem; opacity: .9; margin-right: .25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
@media (max-width: 599.98px) {
    .tenant-name { display: none; }
}

/* ── Sidebar (Smartpad navigation style) ───────────────────────────────────── */
.cv-drawer { border-right: 1px solid var(--cv-border); }
.cv-nav .mud-nav-link { border-radius: 8px; margin: 1px 8px; width: auto; }
.cv-nav .mud-nav-link:hover:not(.active) { background-color: var(--cv-nav-hover-bg); }
.cv-nav .mud-nav-link.active { background-color: var(--cv-nav-active-bg); color: var(--cv-nav-active-fg); font-weight: 600; }
.cv-nav .mud-nav-link.active .mud-nav-link-icon { color: var(--cv-nav-active-icon); }

/* ── Public (voter) pages ──────────────────────────────────────────────────── */
.public-container { max-width: 760px !important; }
.public-footer { text-align: center; color: var(--cv-ink-3); font-size: .8rem; padding: 1.5rem 1rem 2rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .06em; }
.receipt { font-size: 1.25rem; word-break: break-all; }
.candidate-row { display: flex; gap: .75rem; align-items: flex-start; padding: .6rem .25rem; border-bottom: 1px solid var(--cv-border); }
.candidate-row:last-child { border-bottom: 0; }
.candidate-photo { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--cv-surface-2); flex: none; }
.candidate-photo.sm { width: 40px; height: 40px; border-radius: 6px; }
.candidate-photo.lg { width: 88px; height: 88px; border-radius: 10px; border: 1px solid var(--cv-border); }
/* No photo: the candidate's initials in the same slot, so every candidate still has a recognisable mark. */
.candidate-initials { display: grid; place-items: center; font-weight: 600; letter-spacing: .04em; color: var(--cv-ink-2); font-size: 1.1rem; }
.candidate-initials.lg { font-size: 1.6rem; }
.candidate-initials.sm { font-size: .9rem; }
.candidate-pick { cursor: pointer; display: inline-flex; }
.review-choice { display: inline-flex; align-items: center; gap: .5rem; }
@media (max-width: 380px) { .candidate-photo.lg { width: 72px; height: 72px; } }

/* Candidate photo upload (admin ballot tab): a button-like label around a visually hidden file input. */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.photo-upload { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .7rem; border: 1px solid var(--cv-accent); border-radius: 8px;
    color: var(--cv-accent); font-size: .8125rem; font-weight: 500; cursor: pointer; white-space: nowrap; }
.photo-upload:hover { background: var(--cv-nav-hover-bg); }
.photo-upload:focus-within { outline: 2px solid var(--cv-accent); outline-offset: 2px; }
.photo-upload.disabled { opacity: .5; pointer-events: none; }
.statement { color: var(--cv-ink-2); font-size: .9rem; margin-top: .15rem; }

/* ── Stat tiles ────────────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.stat-tile { background: var(--cv-surface); border: 1px solid var(--cv-border); border-radius: 10px; padding: .8rem 1rem; }
.stat-tile .label { color: var(--cv-ink-2); font-size: .8rem; }
.stat-tile .value { color: var(--cv-ink); font-size: 1.6rem; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-tile .sub { color: var(--cv-ink-3); font-size: .75rem; }
.preformatted { white-space: pre-wrap; word-break: break-word; font-size: .8rem; color: var(--cv-ink-2); }

/* ── Charts ────────────────────────────────────────────────────────────────── */
.viz-root { color: var(--cv-ink); background: var(--cv-surface); border-radius: 10px; }
.viz-root svg { display: block; width: 100%; height: auto; }
.viz-label { fill: var(--cv-ink); font-size: 13px; }
.viz-value { fill: var(--cv-ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.viz-axis { stroke: var(--cv-grid); stroke-width: 1; }
.viz-bar { fill: var(--cv-bar); }
.viz-mark:hover .viz-bar, .viz-mark:focus .viz-bar { opacity: .8; }
.viz-hit { fill: transparent; }
.viz-legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .85rem; color: var(--cv-ink-2); margin-top: .5rem; }
.viz-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; }
.viz-table { width: 100%; border-collapse: collapse; font-size: .9rem; margin-top: .5rem; color: var(--cv-ink); }
.viz-table th, .viz-table td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid var(--cv-border); }
.viz-table td.num, .viz-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.viz-table caption { text-align: left; color: var(--cv-ink-2); font-size: .8rem; padding-bottom: .25rem; }

/* ── Account pages (Razor Pages, no Blazor) ────────────────────────────────── */
.account-page { font-family: Roboto, Arial, sans-serif; background: var(--cv-page); color: var(--cv-ink); margin: 0; padding: 0 16px; }
.account-header { max-width: 440px; margin: 0 auto; padding-top: 4vh; display: flex; align-items: center; justify-content: space-between; }
.account-brand { color: var(--cv-ink); text-decoration: none; font-weight: 600; font-size: 1.15rem; letter-spacing: 0.01em; }
.account-brand .cv-brand-accent { color: var(--cv-accent); }
.theme-toggle { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--cv-border); background: var(--cv-surface); color: var(--cv-ink); font-size: 1.1rem; line-height: 1; cursor: pointer; }
.theme-toggle:hover { border-color: var(--cv-accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--cv-accent); outline-offset: 2px; }
.account-card { max-width: 440px; margin: 2vh auto 8vh; background: var(--cv-surface); border: 1px solid var(--cv-border); border-radius: 12px; padding: 2rem; box-shadow: var(--cv-shadow); box-sizing: border-box; }
.account-page > .account-card:first-child { margin-top: 8vh; }
.account-card h1 { font-size: 1.4rem; margin-top: 0; }
.account-card label { display: block; font-weight: 500; margin: .9rem 0 .3rem; }
.account-card input[type=text], .account-card input[type=email], .account-card input[type=password] {
    width: 100%; box-sizing: border-box; padding: .65rem; font-size: 1rem; border-radius: 8px;
    background: var(--cv-input-bg); color: var(--cv-ink); border: 1px solid var(--cv-input-border);
}
.account-card input:focus { outline: none; border-color: #16A34A; box-shadow: 0 0 0 .2rem var(--cv-focus-ring); }
.account-card button { margin-top: 1.2rem; width: 100%; padding: .75rem; background: var(--cv-button-bg); color: var(--cv-button-fg); border: 0; border-radius: 8px; font-size: 1rem; cursor: pointer; }
.account-card button:hover { background: var(--cv-button-hover); }
.account-card button.secondary { background: var(--cv-button-2-bg); }
.account-card .error { color: var(--cv-error-fg); background: var(--cv-error-bg); padding: .6rem; border-radius: 8px; }
.account-card .ok { color: var(--cv-ok-fg); background: var(--cv-ok-bg); padding: .6rem; border-radius: 8px; }
.account-card .hint { color: var(--cv-ink-2); font-size: .9rem; }
.account-card code { word-break: break-all; background: var(--cv-code-bg); padding: .2rem .35rem; border-radius: 4px; }

#blazor-error-ui { background: var(--cv-banner-bg); color: var(--cv-banner-fg); bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); display: none; left: 0; padding: .6rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui a { color: inherit; font-weight: 600; }
