/* PlatinumWeigh PWA — base styles layered on top of MudBlazor.
   Uses MudBlazor CSS custom-properties (--mud-palette-*) so everything
   adapts automatically when the user switches dark / light mode. */

:root {
    /* Radius scale — one card standard everywhere; pills stay full-round. */
    --pw-radius-card: 16px;
    --pw-radius-control: 8px;
    --pw-radius-pill: 999px;

    /* Caption/metadata type scale — two steps below body (0.875rem), not a dozen one-offs. */
    --pw-font-caption: 0.75rem;
    --pw-font-micro: 0.6875rem;

    /* z-index scale. MudBlazor's own portaled overlays (menus/dialogs/snackbars) occupy
       roughly 1200–1400; app-level fixed elements stay below that band except the boot
       splash, which must sit above literally everything until it is dismissed. */
    --pw-z-app-banner: 1000;
    --pw-z-assistant-fab: 1050;
    --pw-z-splash: 9999;

    /* Waste Calculator tile — a teal blend derived from theme tokens (Info + Success) so it
       tracks light/dark mode automatically instead of a hardcoded hex pair. */
    --pw-tile-calculator-start: color-mix(in srgb, var(--mud-palette-info) 55%, var(--mud-palette-success) 45%);
    --pw-tile-calculator-end: color-mix(in srgb, var(--mud-palette-info-darken) 55%, var(--mud-palette-success-darken) 45%);
}

html, body {
    margin: 0;
    font-family: Inter, 'Segoe UI', system-ui, Roboto, Helvetica, Arial, sans-serif;
}

h1:focus { outline: none; }
h1:focus-visible { outline: 2px solid var(--mud-palette-primary); outline-offset: 4px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Shared content-card treatment ────────────────────────────────────────
   One flat, bordered surface style for every static content card (charts,
   calculator result, auth gates) — replaces five previously-divergent
   Elevation/shadow combinations (2, 3, 4, and none) with a single consistent
   look: border at rest, no drop shadow (never both — see the ghost-card ban
   in the platinum-ui skill). Pair with Elevation="0" on MudCard usages. */
.pw-card {
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-divider);
    border-radius: var(--pw-radius-card);
    overflow: hidden;
}

/* ── Dashboard brand header ──────────────────────────────────────────── */
.rw-brand-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.rw-brand-text { flex: 1 1 auto; min-width: 0; }
.rw-brand-logo-wrap {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
}
.rw-brand-logo {
    max-height: 72px;
    max-width: 180px;
    width: auto;
    height: auto;
    object-fit: contain;
}
@media (max-width: 480px) {
    .rw-brand-header { flex-direction: column; align-items: flex-start; }
    .rw-brand-logo   { max-height: 52px; max-width: 140px; }
}

/* ── Dashboard action tiles ───────────────────────────────────────────── */
.w8-tile {
    cursor: pointer;
    transition: transform .2s cubic-bezier(0.2, 0, 0, 1), box-shadow .2s cubic-bezier(0.2, 0, 0, 1);
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    border-radius: var(--pw-radius-card) !important;
}
.w8-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, .08) !important;
}
.w8-tile:active {
    transform: translateY(0);
    box-shadow: 0 4px 10px rgba(0, 0, 0, .05) !important;
}
.w8-tile:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

/* Count badge on the Multi-Weigh tile: loads awaiting their second weigh. */
.rw-pending-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .22);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

/* ── Selection list items (Weigh / MultiWeigh pickers) ───────────────── */
.w8-select-item {
    cursor: pointer;
    min-height: 64px;
    transition: background .12s ease, transform .1s ease, box-shadow .12s ease;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.w8-select-item:hover {
    background: var(--mud-palette-action-default-hover) !important;
    transform: translateX(3px);
}
.w8-select-item:active { transform: translateX(1px); }
.w8-select-item:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: -2px;
}

/* ── Live weight panel states ─────────────────────────────────────────── */
/* Applied as CSS classes; colour automatically tracks the palette vars.  */
.w8-weight-stable {
    background: linear-gradient(135deg,
        var(--mud-palette-primary),
        var(--mud-palette-primary-darken)) !important;
}
.w8-weight-moving {
    background: linear-gradient(135deg,
        var(--mud-palette-warning),
        var(--mud-palette-tertiary, #E88F1A)) !important;
}
.w8-weight-disconnected {
    background: var(--mud-palette-lines-default, #DEE3EA) !important;
}

/* Text on the coloured weight panel */
.w8-weight-live-text   { color: rgba(255, 255, 255, 0.92); }
.w8-weight-live-label  { color: rgba(255, 255, 255, 0.70); }
.w8-weight-idle-text   { color: var(--mud-palette-text-secondary); }

/* ── Big weight readout ───────────────────────────────────────────────── */
.weight-readout {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    letter-spacing: -2px;
    line-height: 1;
    font-size: 4rem;
}

/* ── Step-indicator chips (Weigh / MultiWeigh stepper) ───────────────── */
.w8-step-done {
    opacity: 0.85;
}

/* ── KPI / summary stat cards ────────────────────────────────────────── */
/* A full-tint icon chip carries the status colour instead of a side stripe. */
.w8-stat-icon {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: var(--pw-radius-control);
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--mud-palette-primary) 14%, transparent);
    color: var(--mud-palette-primary);
}
.w8-stat-card.success .w8-stat-icon { background: color-mix(in srgb, var(--mud-palette-success) 14%, transparent); color: var(--mud-palette-success); }
.w8-stat-card.info    .w8-stat-icon { background: color-mix(in srgb, var(--mud-palette-info) 14%, transparent);    color: var(--mud-palette-info); }
.w8-stat-card.warning .w8-stat-icon { background: color-mix(in srgb, var(--mud-palette-warning) 14%, transparent); color: var(--mud-palette-warning); }

/* ── Page-level layout helpers ───────────────────────────────────────── */
.w8-page-content {
    padding-top: 8px;
    padding-bottom: 40px;
}

/* ── Blazor WASM boot UI ──────────────────────────────────────────────── */
.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}
.loading-progress circle {
    fill: none;
    stroke: #e0e0e0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}
.loading-progress circle:last-child {
    stroke: #1A73E8;
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
    color: #606A7B;
}
.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

/* ── Animated splash screen (canvas particle effect, light + dark modes) ── */
#splash-screen {
    position: fixed;
    inset: 0;
    z-index: var(--pw-z-splash, 9999);
    overflow: hidden;
    transition: opacity 0.6s ease;
}
#splash-screen.splash-fade {
    opacity: 0;
    pointer-events: none;
}
/* Canvas fills the entire splash — splash.js sets its background colour. */
#splashCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}
/* Overlay: logo + tagline centred on top of the canvas. */
.splash-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 10;
}
.splash-logo-wrap {
    position: relative;
    margin-bottom: 2rem;
}
/* Ambient glow behind the logo */
.splash-glow {
    position: absolute;
    top: -50%; left: -50%; right: -50%; bottom: -50%;
    background: #003366;
    filter: blur(60px);
    opacity: 0.18;
    border-radius: 50%;
}
.splash-logo {
    position: relative;
    z-index: 10;
    width: min(18rem, 72vw);
    height: auto;
    filter: drop-shadow(0 0 24px rgba(0,51,102,0.55));
}
/* Dark-mode tagline: white text */
#splash-screen.splash-dark .splash-tagline {
    color: rgba(255,255,255,0.70);
    text-shadow: 0 0 10px rgba(0,51,102,0.5);
}
/* Light-mode tagline: dark text */
#splash-screen.splash-light .splash-tagline,
#splash-screen:not(.splash-dark) .splash-tagline {
    color: #444746;
    text-shadow: none;
}
.splash-tagline {
    font-family: Inter, 'Segoe UI', system-ui, Roboto, Helvetica, Arial, sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    margin: 0;
}

/* ── Login page ──────────────────────────────────────────────────────── */
.rw-login-root {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--mud-palette-background, #EEF2F5);
    padding: 24px 16px;
}

.rw-login-card {
    padding: 40px 40px 32px;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.rw-login-logo {
    max-width: 180px;
    max-height: 140px;
    width: auto;
    height: auto;
    object-fit: contain;
    align-self: center;
    margin-bottom: 4px;
}

.rw-login-footer {
    margin-top: 24px;
    text-align: center;
}

@media (max-width: 480px) {
    .rw-login-card { padding: 28px 20px 24px; }
    .rw-login-logo { max-width: 140px; max-height: 110px; }
}

/* ── First-login disclaimer gate ────────────────────────────────── */
.rw-disclaimer-card {
    padding: 32px 32px 24px;
    width: 100%;
    max-width: 640px;
    display: flex;
    flex-direction: column;
}
.rw-disclaimer-body {
    max-height: min(48vh, 440px);
    overflow-y: auto;
    padding-right: 8px;
}
.rw-disclaimer-h {
    font-weight: 700;
    margin-bottom: 4px;
}
@media (max-width: 480px) {
    .rw-disclaimer-card { padding: 24px 18px 20px; }
    .rw-disclaimer-body { max-height: 52vh; }
}

/* ── Nav drawer overrides ───────────────────────────────────────────────
   The drawer is a fixed column: header, nav region, pinned footer. It must
   NEVER scroll sideways, and on a 1080p screen the whole admin menu — Setup
   group expanded — has to fit without scrolling at all.

   The menu used to do both. `.mud-nav-link` is `width:100%`, so the old
   `margin: 2px 12px` pushed every link 24px past the drawer's right edge (36px
   for Setup's children, which added another `margin-left:24px` on top of
   MudBlazor's own padding-based indent). That put a horizontal scrollbar on the
   nav region — and because `overflow-y:auto` alone makes the computed
   `overflow-x` `auto` too, there was nothing stopping it. On Windows (classic,
   space-consuming scrollbars, unlike macOS overlay ones) that horizontal bar
   then ate ~15px of height and raised a *vertical* scrollbar on a menu that
   otherwise fitted — the "scrolls up and down for no apparent reason" part.

   So: the horizontal inset lives on the menu container as padding (border-box,
   so `width:100%` links land inside it), sub-items indent with padding only,
   overflow-x is pinned hidden, and the rows are compact enough that the worst
   case — 19 rows, admin with Setup open — fits a Full HD viewport. */
.rw-drawer-nav {
    flex: 1 1 auto;
    min-height: 0;          /* lets the flex child shrink rather than overflow */
    overflow-x: hidden;     /* never sideways — see above */
    overflow-y: auto;       /* fallback only, for genuinely short screens */
}
/* Header and footer are flex-fixed: only the nav region between them flexes,
   and they give the menu back the height MudBlazor's 64px min-height took. */
.rw-drawer-header {
    flex: 0 0 auto;
    min-height: 0;
    padding: 14px 20px;
}
.rw-drawer-footer {
    flex: 0 0 auto;
    padding: 8px 12px;
    font-size: 0.66rem;
    line-height: 1.35;
    color: var(--mud-palette-text-secondary);
}
.mud-drawer {
    overflow: hidden;       /* the nav region owns the only scrollable area */
}
.rw-drawer-nav > .mud-navmenu {
    padding: 0 8px;         /* the links' horizontal inset, inside the width.
                               Outer menu only — a nested one (Setup's children)
                               would stack another inset and re-indent them. */
}
.mud-drawer .mud-nav-link {
    border-radius: var(--pw-radius-control);
    margin: 1px 0;
    padding: 6px 12px;
    font-size: 0.85rem;
    line-height: 1.4;
    align-items: center;
    transition: background-color 0.2s ease, color 0.2s ease;
}
.mud-drawer .mud-nav-link .mud-nav-link-text {
    margin-inline-start: 10px;
    overflow-wrap: anywhere;   /* a long label wraps; it never widens the menu */
}
.mud-drawer .mud-nav-link .mud-icon-root {
    font-size: 1.2rem;
}
.mud-drawer .mud-nav-link:hover,
.mud-drawer .mud-nav-link:focus-visible {
    background-color: var(--mud-palette-action-default-hover) !important;
}
.mud-drawer .mud-nav-link:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: -2px;
}
.mud-drawer .mud-nav-link.active {
    background-color: var(--mud-palette-primary-lighten) !important;
    color: var(--mud-palette-primary) !important;
    font-weight: 700;
}
.mud-drawer .mud-nav-link.active .mud-icon-root {
    color: var(--mud-palette-primary) !important;
}
/* Setup's children indent with padding, not margin, so the row stays exactly as
   wide as the drawer (MudBlazor's own rule already sets padding-inline-start;
   this only tightens it and restores the right padding it unsets). */
.mud-drawer .mud-nav-group .mud-nav-link {
    padding-inline-start: 30px;
    padding-inline-end: 12px;
}

/* Section labels ("Operations" / "Oversight") — tight, so they cost a row of
   height rather than the ~28px MudBlazor's overline line-height would give. */
.rw-nav-section {
    display: block;
    padding: 8px 20px 2px;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--mud-palette-text-secondary);
}

/* Legend dot (small circle beside series label) */
.rw-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── Weekly activity sparkline (custom responsive SVG) ───────────────────
   A fixed 0–100 viewBox stretched edge-to-edge (preserveAspectRatio="none").
   Strokes use vector-effect:non-scaling-stroke so they stay crisp & uniform
   regardless of the non-uniform stretch; data dots are HTML so they stay
   perfectly round. This fills the full card width on every screen size. */
.rw-spark {
    position: relative;
    width: 100%;
    height: 250px;
}
.rw-spark--center {
    display: flex;
    align-items: center;
    justify-content: center;
}
.rw-spark-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
}
.rw-spark-grid {
    stroke: var(--mud-palette-divider, #e2e8f0);
    stroke-width: 1;
    stroke-dasharray: 3 4;
    opacity: 0.5;
}
.rw-spark-dot {
    position: absolute;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--mud-palette-surface, #fff);
    transform: translate(-50%, -50%);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
    transition: width .12s ease, height .12s ease;
    cursor: default;
    z-index: 2;
}
.rw-spark-dot--dump    { border: 2.5px solid var(--mud-palette-error); }
.rw-spark-dot--removal { border: 2.5px solid var(--mud-palette-success); }
.rw-spark-dot:hover {
    width: 14px;
    height: 14px;
    z-index: 3;
}
.rw-spark-ymax {
    position: absolute;
    top: 10%;
    left: 0;
    transform: translateY(-50%);
    font-size: var(--pw-font-micro);
    font-weight: 600;
    line-height: 1;
    color: var(--mud-palette-text-secondary);
    background: var(--mud-palette-surface, #fff);
    padding: 1px 5px;
    border-radius: var(--pw-radius-control);
    opacity: 0.9;
    pointer-events: none;
}
.rw-spark-axis {
    position: relative;
    width: 100%;
    height: 16px;
    margin-top: 8px;
}
.rw-spark-axis span {
    position: absolute;
    transform: translateX(-50%);
    font-size: var(--pw-font-caption);
    font-weight: 500;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
}
@media (max-width: 480px) {
    .rw-spark { height: 210px; }
    .rw-spark-axis span { font-size: 0.62rem; }
}

/* ── Stockpile donut cards ────────────────────────────────────────────── */
.rw-stockpile-header {
    padding: 14px 20px;
}

.rw-stockpile-header--dump {
    background: linear-gradient(135deg, var(--mud-palette-error-darken) 0%, var(--mud-palette-error) 100%);
}

.rw-stockpile-header--removal {
    background: linear-gradient(135deg, var(--mud-palette-success-darken) 0%, var(--mud-palette-success) 100%);
}

/* Header title/total — one shared size (not four repeated one-off inline styles). */
.rw-stockpile-title {
    color: #fff;
    font-weight: 700;
    font-size: 0.9375rem;
}
.rw-stockpile-total {
    color: rgba(255, 255, 255, 0.85);
    font-size: var(--pw-font-caption);
}

/* Legend swatch (square colour indicator in the legend table) */
.rw-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* ── Waste Calculator ─────────────────────────────────────────────────── */
.rw-calc-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.rw-calc-chip {
    min-width: 56px;
    border-radius: var(--pw-radius-control) !important;
    font-weight: 600;
}
.rw-calc-chip--fill {
    min-width: 72px;
    font-size: 1.05rem;
}
.rw-calc-result-header {
    padding: 20px 24px 18px;
    background: linear-gradient(135deg,
        var(--mud-palette-primary) 0%,
        var(--mud-palette-primary-darken, #114a2e) 100%);
}
.rw-calc-summary td {
    padding: 4px 0;
    border: none;
    font-size: 0.875rem;
}
.rw-calc-summary td:last-child {
    font-weight: 600;
    text-align: right;
}

/* ── Page footer (every page) ────────────────────────────────────────── */
.rw-page-footer {
    padding: 12px 16px 20px;
    border-top: 1px solid var(--mud-palette-divider, #DEE3EA);
    text-align: center;
}

/* ── Blazor error boundary ────────────────────────────────────────────── */
.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}
.blazor-error-boundary::after { content: "An error has occurred."; }

#blazor-error-ui {
    color: #fff;
    background: #C62828;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: var(--pw-z-app-banner, 1000);
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}
