/*
 * pfManager UI styling.
 *
 * Colours are the validated data-viz reference palette. Both modes are chosen rather than
 * flipped: the dark values are separate steps checked against the dark surface.
 */

:root {
    color-scheme: light;

    --surface: #fcfcfb;
    --plane: #f9f9f7;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #898781;
    --gridline: #e1e0d9;
    --baseline: #c3c2b7;
    --border: rgba(11, 11, 11, 0.10);
    --hover-wash: rgba(11, 11, 11, 0.04);

    --series: #2a78d6;
    --series-strong: #1c5cab;
    --up: #006300;
    --down: #d03b3b;

    --radius: 10px;
    --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;

        --surface: #1a1a19;
        --plane: #0d0d0d;
        --text-primary: #ffffff;
        --text-secondary: #c3c2b7;
        --text-muted: #898781;
        --gridline: #2c2c2a;
        --baseline: #383835;
        --border: rgba(255, 255, 255, 0.10);
        --hover-wash: rgba(255, 255, 255, 0.06);

        --series: #3987e5;
        --series-strong: #86b6ef;
        --up: #0ca30c;
        --down: #d03b3b;
    }
}

* {
    box-sizing: border-box;
}

/*
 * Author `display` rules outrank the user-agent's `[hidden] { display: none }`, so any
 * element given a display value would otherwise ignore the hidden attribute entirely.
 */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--plane);
}

:focus-visible {
    outline: 2px solid var(--series);
    outline-offset: 2px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

/* Fields ------------------------------------------------------------------ */

.field {
    margin-bottom: 16px;
}

.field label,
.field > span {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

input,
select {
    width: 100%;
    padding: 9px 11px;
    font: inherit;
    font-size: 15px;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--baseline);
    border-radius: 8px;
}

button {
    font: inherit;
    cursor: pointer;
}

.button-primary,
.button-secondary {
    width: 100%;
    padding: 10px 16px;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid transparent;
}

.button-primary {
    color: #ffffff;
    background: var(--series);
}

.button-primary:hover:not(:disabled) {
    background: var(--series-strong);
}

.button-secondary {
    color: var(--text-primary);
    background: var(--surface);
    border-color: var(--baseline);
}

.button-secondary:hover:not(:disabled) {
    background: var(--hover-wash);
}

.button-quiet {
    padding: 7px 14px;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.button-quiet:hover {
    background: var(--hover-wash);
    color: var(--text-primary);
}

button:disabled {
    opacity: 0.6;
    cursor: default;
}

/* Banner ----------------------------------------------------------------- */

.banner {
    margin: 0;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    background: var(--down);
}

/* Login ------------------------------------------------------------------ */

.login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 380px;
}

.login-title {
    margin: 0 0 24px;
    font-size: 22px;
    font-weight: 600;
}

.first-password {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.first-password summary {
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
}

.first-password[open] summary {
    margin-bottom: 12px;
}

.hint {
    margin: 0 0 16px;
    font-size: 13px;
    color: var(--text-muted);
}

/* Dashboard shell -------------------------------------------------------- */

.app-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.app-name {
    font-weight: 600;
}

.current-user {
    margin-left: auto;
    font-size: 14px;
    color: var(--text-secondary);
}

.app-main {
    max-width: 940px;
    margin: 0 auto;
    padding: 24px;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 20px;
}

.field-inline {
    margin-bottom: 0;
}

.field-inline select {
    width: auto;
    min-width: 220px;
}

.range-group {
    display: flex;
    gap: 2px;
}

/* The filter row is bottom-aligned, so its controls need a common height or their
 * labels sit at different heights. */
.field-inline select,
.range-group button {
    height: 40px;
}

.range-group button,
.view-toggle button {
    padding: 8px 14px;
    font-size: 14px;
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--baseline);
    border-radius: 0;
}

.range-group button:first-child,
.view-toggle button:first-child {
    border-radius: 8px 0 0 8px;
}

.range-group button:last-child,
.view-toggle button:last-child {
    border-radius: 0 8px 8px 0;
}

.range-group button:hover,
.view-toggle button:hover {
    background: var(--hover-wash);
}

.range-group button[aria-pressed="true"],
.view-toggle button[aria-pressed="true"] {
    font-weight: 600;
    color: var(--text-primary);
    background: var(--hover-wash);
    border-color: var(--text-muted);
}

.view-toggle {
    display: flex;
    gap: 2px;
}

/* Chart card ------------------------------------------------------------- */

.card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.card-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.card-subtitle {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

/* Proportional figures - tabular-nums makes a large number look loose. */
.hero-figure {
    margin: 20px 0 0;
    font-size: 48px;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -0.01em;
}

.hero-delta {
    margin: 6px 0 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.hero-delta .direction-up {
    color: var(--up);
    font-weight: 600;
}

.hero-delta .direction-down {
    color: var(--down);
    font-weight: 600;
}

/* Sized by the SVG it holds, which includes the x-axis band. */
.chart-container {
    position: relative;
    margin-top: 12px;
}

/* Refetch holds the previous render rather than flashing a skeleton. */
.chart-card.is-loading .chart-container,
.chart-card.is-loading .table-container,
.chart-card.is-loading .hero-figure,
.chart-card.is-loading .hero-delta {
    opacity: 0.45;
}

.chart-svg {
    display: block;
    max-width: 100%;
    overflow: visible;
}

.chart-empty {
    margin: 32px 0;
    color: var(--text-muted);
}

.chart-grid {
    stroke: var(--gridline);
    stroke-width: 1;
}

.chart-axis {
    stroke: var(--baseline);
    stroke-width: 1;
}

.chart-line {
    fill: none;
    stroke: var(--series);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.chart-dot {
    fill: var(--series);
    stroke: var(--surface);
    stroke-width: 2;
}

.chart-hover-dot {
    fill: var(--series);
    stroke: var(--surface);
    stroke-width: 2;
    pointer-events: none;
}

.chart-crosshair {
    stroke: var(--text-muted);
    stroke-width: 1;
    pointer-events: none;
}

.chart-hit-layer {
    fill: transparent;
}

/* Axis text and labels wear text tokens, never the series colour. */
.chart-tick {
    fill: var(--text-muted);
    font-family: var(--font);
    font-size: 11px;
}

.chart-tick-y {
    font-variant-numeric: tabular-nums;
}

.chart-end-label {
    fill: var(--text-primary);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
}

.chart-tooltip {
    position: absolute;
    transform: translateX(-50%);
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
    pointer-events: none;
}

/* Table view ------------------------------------------------------------- */

.table-container {
    margin-top: 16px;
    max-height: 340px;
    overflow-y: auto;
}

.value-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

.value-table caption {
    text-align: left;
    padding-bottom: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.value-table th,
.value-table td {
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid var(--gridline);
}

.value-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.value-table .numeric {
    text-align: right;
}

@media (max-width: 560px) {
    .app-main,
    .card {
        padding: 16px;
    }

    .hero-figure {
        font-size: 36px;
    }

    .field-inline,
    .field-inline select {
        width: 100%;
    }

    .filter-row {
        gap: 14px;
    }
}
