/* Dirty Water Tracker — shared styles.
 *
 * Loaded first by every page; each page's own sheet (css/<page>.css) follows
 * and may override. The look is deliberately quiet: neutral chrome, hairline
 * borders, one accent for links and focus, and colour reserved for the data
 * (venue types, sync status, map pins), so a coloured element always means
 * something. Tokens first, then components.
 */

/* Tokens ------------------------------------------------------------------ */

:root {
    color-scheme: light;

    --font-sans: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;

    /* Chrome */
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f1f3f6;
    --surface-3: #e7eaef;
    --border: #e4e7ec;
    --border-strong: #cdd3dc;
    --text: #16191f;
    --text-2: #5c6675;
    --text-3: #8b94a3;
    --inverse: #16191f;
    --inverse-text: #ffffff;
    --accent: #2f6feb;
    --accent-text: #1f5bd0;
    --ring: rgba(47, 111, 235, 0.28);
    --shadow-float: 0 8px 24px rgba(16, 24, 40, 0.10), 0 1px 2px rgba(16, 24, 40, 0.06);

    /* Data: venue types and states. -soft is a tint for badges, -text the
       readable ink on that tint. */
    --bar: #2b7fd0;      --bar-soft: #e3effb;      --bar-text: #1c5ea3;
    --store: #1f9d55;    --store-soft: #e1f5ea;    --store-text: #176f3f;
    --new: #e0a100;      --new-soft: #fbf1d3;      --new-text: #7a5600;
    --removed: #d9463f;  --removed-soft: #fbe5e3;  --removed-text: #a4302b;
    --unknown: #8b94a3;  --unknown-soft: #eceff3;  --unknown-text: #4f5866;
    --transit: #e5721e;  --transit-soft: #fdeada;  --transit-text: #9a4a0e;
    --reactivated: #7c5cd6; --reactivated-soft: #ede8fb; --reactivated-text: #553bb0;

    /* Status */
    --ok: var(--store);       --ok-soft: var(--store-soft);       --ok-text: var(--store-text);
    --warn: #c27c0e;          --warn-soft: #fbf0dc;               --warn-text: #7a4e08;
    --err: var(--removed);    --err-soft: var(--removed-soft);    --err-text: var(--removed-text);

    --radius: 10px;
    --radius-sm: 6px;
    --radius-pill: 999px;
    --control-h: 34px;

    /* Names the earlier sheets and scripts used; kept as aliases. */
    --bg-primary: var(--bg);
    --bg-secondary: var(--surface-2);
    --bg-card: var(--surface);
    --text-primary: var(--text);
    --text-secondary: var(--text-2);
    --text-light: var(--text-3);
    --border-color: var(--border);
    --border-light: var(--border);
    --accent-blue: var(--bar);
    --accent-green: var(--store);
    --accent-red: var(--removed);
    --accent-gold: var(--new);
    --accent-yellow: var(--warn);
    --accent-orange: var(--transit);
    --accent-purple: var(--reactivated);
    --page-accent: var(--accent);
}

.dark-theme {
    color-scheme: dark;

    --bg: #0e1015;
    --surface: #151922;
    --surface-2: #1b2029;
    --surface-3: #232935;
    --border: #262c37;
    --border-strong: #353d4b;
    --text: #e7eaf0;
    --text-2: #9aa3b2;
    --text-3: #6b7583;
    --inverse: #e7eaf0;
    --inverse-text: #0e1015;
    --accent: #6ea0ff;
    --accent-text: #8fb5ff;
    --ring: rgba(110, 160, 255, 0.35);
    --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.4);

    --bar: #5aa2ea;      --bar-soft: rgba(90, 162, 234, 0.16);   --bar-text: #8fc0f4;
    --store: #3fbf76;    --store-soft: rgba(63, 191, 118, 0.16); --store-text: #7ad9a1;
    --new: #e9b949;      --new-soft: rgba(233, 185, 73, 0.16);   --new-text: #f1cf7a;
    --removed: #f0716c;  --removed-soft: rgba(240, 113, 108, 0.16); --removed-text: #f7a09c;
    --unknown: #8b94a3;  --unknown-soft: rgba(139, 148, 163, 0.16); --unknown-text: #b3bac6;
    --transit: #f08a3e;  --transit-soft: rgba(240, 138, 62, 0.16);  --transit-text: #f5ad78;
    --reactivated: #a68cf0; --reactivated-soft: rgba(166, 140, 240, 0.16); --reactivated-text: #c4b3f6;

    --warn: #e2a33a;     --warn-soft: rgba(226, 163, 58, 0.16);  --warn-text: #efc06e;
}

/* Base ------------------------------------------------------------------- */

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
    font-feature-settings: "tnum" 1, "cv11" 1;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

button, input, select {
    font: inherit;
    color: inherit;
}
button { cursor: pointer; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.icon {
    width: 16px;
    height: 16px;
    flex: none;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -3px;
}

/* Top bar ---------------------------------------------------------------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    min-height: 52px;
    padding: 0 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
    white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 24px;
    height: 24px;
    flex: none;
    color: var(--accent);
}
.nav {
    display: flex;
    align-items: stretch;
    gap: 0.25rem;
    align-self: stretch;
}
.nav a {
    display: inline-flex;
    align-items: center;
    padding: 0 0.7rem;
    color: var(--text-2);
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}
.nav a:hover { color: var(--text); text-decoration: none; }
.nav a.active {
    color: var(--text);
    border-bottom-color: var(--text);
}
.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.version {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text-3);
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface-2);
}
.version:hover { color: var(--text); text-decoration: none; border-color: var(--border-strong); }
.theme-toggle {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-2);
}
.theme-toggle:hover { color: var(--text); background: var(--surface-2); }
.theme-toggle .icon-sun { display: none; }
.dark-theme .theme-toggle .icon-sun { display: block; }
.dark-theme .theme-toggle .icon-moon { display: none; }

@media (max-width: 720px) {
    .topbar { padding: 0.5rem 1rem; gap: 0.5rem 1rem; }
    .nav { order: 3; width: 100%; overflow-x: auto; margin-bottom: -0.5rem; scrollbar-width: none; }
    .nav::-webkit-scrollbar { display: none; }
    .nav a { padding: 0.5rem 0.5rem; font-size: 14px; }
    .nav a:first-child { margin-left: -0.5rem; }
}

/* Layout ------------------------------------------------------------------ */

.container {
    width: 100%;
    padding: 1rem 1.25rem 1.5rem;
    display: grid;
    gap: 0.75rem;
    align-content: start;
}
@media (max-width: 720px) { .container { padding: 0.75rem 1rem 1rem; } }

.page-head { display: grid; gap: 0.15rem; padding: 0.25rem 0 0.25rem; }
.page-head h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.page-head p { color: var(--text-2); }

/* Surfaces ---------------------------------------------------------------- */

.panel,
.stat-card,
.dashboard-card,
.chart-container,
.controls,
.filters,
.locations-table,
.logs-table,
.content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.card-title,
.dashboard-card h2,
.chart-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.005em;
}

/* Stat tiles */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
}
.stat-card { padding: 0.75rem 1rem; display: grid; gap: 0.2rem; }
.stat-card h3,
.stat-card .stat-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
    margin: 0;
}
.stat-card .value,
.stat-card .stat-value {
    font-size: 24px;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.02em;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
@media (max-width: 520px) {
    .stats { grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 0.5rem; }
    .stat-card { padding: 0.6rem 0.75rem; }
    .stat-card .value, .stat-card .stat-value { font-size: 20px; }
}
.stat-card .value.green, .stat-card .value.ok { color: var(--store-text); }
.stat-card .value.blue { color: var(--bar-text); }
.stat-card .value.red { color: var(--removed-text); }

/* Control bars */
.controls,
.filters {
    padding: 0.6rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}
.spacer { flex: 1; }

/* Buttons ------------------------------------------------------------------ */

.btn,
.controls button,
.export-btn,
.sync-button,
.fullscreen-btn,
.view-toggle button,
.pagination-controls button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    height: var(--control-h);
    padding: 0 0.85rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover,
.controls button:hover,
.fullscreen-btn:hover,
.pagination-controls button:hover:not(:disabled) {
    background: var(--surface-2);
    text-decoration: none;
}
.btn-primary,
.export-btn,
.sync-button {
    background: var(--inverse);
    border-color: var(--inverse);
    color: var(--inverse-text);
}
.btn-primary:hover,
.export-btn:hover,
.sync-button:hover:not(:disabled) {
    background: color-mix(in srgb, var(--inverse) 88%, var(--surface));
    border-color: color-mix(in srgb, var(--inverse) 88%, var(--surface));
}
.btn:disabled,
.sync-button:disabled,
.pagination-controls button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.btn-sm { height: 28px; padding: 0 0.6rem; font-size: 12.5px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

/* Segmented control (a group of toggle buttons; the active one is filled) */
.segmented,
.view-toggle {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.segmented > *,
.view-toggle button {
    height: calc(var(--control-h) - 8px);
    padding: 0 0.7rem;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-2);
    font-size: 13px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
}
.segmented > *:hover,
.view-toggle button:hover:not(.active) { color: var(--text); background: color-mix(in srgb, var(--surface) 60%, transparent); }
.segmented > .active,
.segmented > :has(input:checked),
.view-toggle button.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12);
}
.dark-theme .segmented > .active,
.dark-theme .segmented > :has(input:checked),
.dark-theme .view-toggle button.active { background: var(--surface-3); }
.segmented input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }

/* Chips (filters that can be multi-row) */
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 28px;
    padding: 0 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 500;
    transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.chip.active {
    background: var(--inverse);
    border-color: var(--inverse);
    color: var(--inverse-text);
}
.chip.active .dot { box-shadow: 0 0 0 2px color-mix(in srgb, var(--inverse-text) 55%, transparent); }

/* Coloured dots: a legend swatch, a chip marker, a status light */
.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: none;
    background: var(--unknown);
}
.dot-bar { background: var(--bar); }
.dot-store { background: var(--store); }
.dot-new { background: var(--new); }
.dot-removed { background: var(--removed); }
.dot-unknown { background: var(--unknown); }

/* Inputs ------------------------------------------------------------------- */

.input,
.controls input[type="text"],
.controls input[type="search"],
.controls select,
.pagination-controls select {
    height: var(--control-h);
    padding: 0 0.7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 13.5px;
    min-width: 0;
}
.controls input[type="text"] { flex: 1 1 220px; }
.controls input::placeholder { color: var(--text-3); }
.input:focus, .controls input:focus, .controls select:focus, .pagination-controls select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--ring);
}
.controls select, .pagination-controls select {
    appearance: none;
    padding-right: 1.9rem;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b94a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0.55rem center;
}
.search-field { position: relative; flex: 1 1 220px; display: flex; }
.search-field .icon { position: absolute; left: 0.65rem; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
/* Specific enough to beat `.controls input[type="text"]` above. */
.search-field input, .controls .search-field input[type="text"] { width: 100%; padding-left: 2.1rem; }

/* Checkbox + switch */
.check {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-2);
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}
.check:hover { color: var(--text); }
.check input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--inverse);
    cursor: pointer;
    margin: 0;
}
.switch { display: inline-flex; align-items: center; gap: 0.55rem; color: var(--text-2); font-size: 13px; cursor: pointer; user-select: none; }
.switch:hover { color: var(--text); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
    width: 32px;
    height: 18px;
    border-radius: var(--radius-pill);
    background: var(--border-strong);
    position: relative;
    flex: none;
    transition: background-color 0.15s;
}
.switch .track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--inverse); }
.dark-theme .switch input:checked + .track::after { background: var(--inverse-text); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .hint { color: var(--text-3); font-size: 12px; }

/* Badges ------------------------------------------------------------------- */

.badge,
.status-badge,
.type-badge,
.detail-action,
.pattern-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    height: 22px;
    padding: 0 0.55rem;
    border-radius: var(--radius-pill);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
    background: var(--unknown-soft);
    color: var(--unknown-text);
    line-height: 1;
}
.badge-bar, .type-badge.bar { background: var(--bar-soft); color: var(--bar-text); }
.badge-store, .type-badge.store { background: var(--store-soft); color: var(--store-text); }
.badge-unknown, .type-badge.unknown { background: var(--unknown-soft); color: var(--unknown-text); }
.badge-new { background: var(--new-soft); color: var(--new-text); }
.badge-removed { background: var(--removed-soft); color: var(--removed-text); }
.badge-county { background: var(--surface-2); color: var(--text-2); font-weight: 500; }
.status-healthy, .status-completed, .badge-ok { background: var(--ok-soft); color: var(--ok-text); }
.status-warning, .status-running, .badge-warn { background: var(--warn-soft); color: var(--warn-text); }
.status-error, .status-failed, .badge-err { background: var(--err-soft); color: var(--err-text); }
.status-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Tables ------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-2);
    color: var(--text-2);
    text-align: left;
    padding: 0.55rem 0.85rem;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    user-select: none;
}
th[data-action] { cursor: pointer; }
th[data-action]:hover { color: var(--text); }
th .sort-indicator { margin-left: 0.3rem; opacity: 0.45; font-size: 10px; }
th.sorted .sort-indicator { opacity: 1; color: var(--text); }
td {
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover > td { background: var(--surface-2); }
td small { color: var(--text-3); font-size: 12px; }
td.muted, .muted { color: var(--text-3); }
td .loading { padding: 2rem; }

/* Metric rows (dashboard cards) */
.metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--border);
}
.metric:last-child { border-bottom: 0; }
.metric-label { color: var(--text-2); font-size: 13px; flex: none; }
.metric-value { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; min-width: 0; }
.metric-value--stack { display: grid; gap: 0.1rem; }
.metric-value--stack small { font-weight: 400; font-size: 11.5px; color: var(--text-3); }
.metric-value--stack small:empty { display: none; }

/* Loading states ----------------------------------------------------------- */

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-3);
}
.loading-overlay {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: inherit;
}
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
.loading-text { margin-top: 0.75rem; color: var(--text-2); font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation-duration: 0.01ms !important; }
}
