/* ═══════════════════════════════════════════════════════════════════
   CBox App — CSS with Light/Dark Mode
   Auto-detects OS preference, user can override via toggle
   ═══════════════════════════════════════════════════════════════════ */

/* ── Light mode (default) ─────────────────────────────────────── */
:root {
    --cbox-primary: #2E6DB4;
    --cbox-accent: #4BA3D9;
    --cbox-light: #7DD4F0;
    --cbox-dark: #1B4F8A;
    --sidebar-width: 260px;

    /* Theme tokens */
    --bg-body: #f4f7fa;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --bg-sidebar: linear-gradient(180deg, #1B4F8A 0%, #2E6DB4 100%);
    --bg-input: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #6c757d;
    --text-muted: #9ca3af;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --gauge-track: #e5e7eb;
    --table-stripe: rgba(0,0,0,0.02);
    --badge-muted-bg: #e5e7eb;
    --badge-muted-text: #4b5563;
    --alert-bg: #fef3cd;
    --overlay-bg: rgba(255,255,255,0.85);
    color-scheme: light;
}

/* ── Dark mode ────────────────────────────────────────────────── */
[data-theme="dark"] {
    --bg-body: #0f1923;
    --bg-card: #1a2634;
    --bg-card-hover: #22303f;
    --bg-sidebar: linear-gradient(180deg, #0a1520 0%, #142233 100%);
    --bg-input: #1e2d3d;
    --text-primary: #e8edf2;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #2a3a4a;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --gauge-track: #2a3a4a;
    --table-stripe: rgba(255,255,255,0.02);
    --badge-muted-bg: #2a3a4a;
    --badge-muted-text: #94a3b8;
    --alert-bg: #332b00;
    --overlay-bg: rgba(15,25,35,0.85);
    color-scheme: dark;
}

/* Auto dark mode from OS */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-body: #0f1923;
        --bg-card: #1a2634;
        --bg-card-hover: #22303f;
        --bg-sidebar: linear-gradient(180deg, #0a1520 0%, #142233 100%);
        --bg-input: #1e2d3d;
        --text-primary: #e8edf2;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
        --border-color: #2a3a4a;
        --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
        --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
        --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
        --gauge-track: #2a3a4a;
        --table-stripe: rgba(255,255,255,0.02);
        --badge-muted-bg: #2a3a4a;
        --badge-muted-text: #94a3b8;
        --alert-bg: #332b00;
        --overlay-bg: rgba(15,25,35,0.85);
        color-scheme: dark;
    }
}

/* ── Global ───────────────────────────────────────────────────── */
html, body {
    font-family: 'Inter', 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    margin: 0;
    background: var(--bg-body);
    color: var(--text-primary);
    height: 100%;
    transition: background 0.3s, color 0.3s;
}

a { color: var(--cbox-accent); }
a:hover { color: var(--cbox-light); }

/* ── Layout ───────────────────────────────────────────────────── */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
    border-right: 1px solid rgba(255,255,255,0.05);
}

.sidebar-logo {
    padding: 1.5rem 1.25rem;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.15);
}

.sidebar-logo img {
    max-width: 170px;
    height: auto;
    filter: brightness(1.1);
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
}

.sidebar-nav .nav-item {
    padding: 0;
}

.sidebar-nav .nav-link {
    color: rgba(255,255,255,0.7);
    padding: 0.7rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    transition: all 0.2s;
    font-size: 0.9rem;
    font-weight: 500;
    border-left: 3px solid transparent;
}

.sidebar-nav .nav-link:hover {
    color: white;
    background: rgba(255,255,255,0.08);
}

.sidebar-nav .nav-link.active {
    color: white;
    background: rgba(75,163,217,0.15);
    border-left-color: var(--cbox-accent);
}

.sidebar-nav .nav-link i {
    font-size: 1.1rem;
    width: 1.5rem;
    text-align: center;
    opacity: 0.85;
}

.sidebar-user {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0,0,0,0.1);
}

/* ── Main content ─────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 1.5rem 2rem;
    min-height: 100vh;
}

/* ── Cards ─────────────────────────────────────────────────────── */
.stat-card, .card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s, box-shadow 0.15s, background 0.3s;
    color: var(--text-primary);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--cbox-accent);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

/* ── Dashboard card (dark-style widget) ───────────────────────── */
.dash-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
    position: relative;
    overflow: hidden;
}

.dash-card h6 {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.dash-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--cbox-accent);
    line-height: 1.1;
}

.dash-value small {
    font-size: 0.45em;
    color: var(--text-muted);
    font-weight: 500;
    margin-left: 0.25rem;
}

.dash-value.status-good { color: #22c55e; }
.dash-value.status-warn { color: #eab308; }
.dash-value.status-bad  { color: #ef4444; }

/* ── Pump widget ──────────────────────────────────────────────── */
.pump-widget {
    text-align: center;
    padding: 0.75rem 0.5rem;
    border-radius: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s;
}

.pump-widget.pump-active {
    border-color: #22c55e;
    background: rgba(34,197,94,0.05);
}

.pump-widget .pump-icon {
    font-size: 2.5rem;
    margin-bottom: 0.25rem;
}

.pump-widget .pump-icon.running {
    color: #22c55e;
    animation: pump-spin 1.2s linear infinite;
}

.pump-widget .pump-icon.stopped {
    color: var(--text-muted);
}

.pump-widget .pump-icon.disabled {
    color: var(--badge-muted-bg);
    opacity: 0.4;
}

.pump-widget .pump-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.pump-widget .pump-status {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.pump-widget .pump-status.on { color: #22c55e; }
.pump-widget .pump-status.off { color: var(--text-muted); }

/* ── Status badges ────────────────────────────────────────────── */
.status-online { color: #22c55e; }
.status-warning { color: #eab308; }
.status-offline { color: #ef4444; }

.badge-status-1, .badge-status-2 {
    background-color: #22c55e;
    color: white;
}

.badge-status-3 {
    background-color: #ef4444;
    color: white;
}

/* ── Indicator light ──────────────────────────────────────────── */
.indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.5rem;
}
.indicator.green { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,0.4); }
.indicator.red   { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,0.4); }
.indicator.yellow { background: #eab308; box-shadow: 0 0 6px rgba(234,179,8,0.4); }
.indicator.gray  { background: var(--text-muted); }

/* ── Login page ───────────────────────────────────────────────── */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0a1520 0%, #142233 50%, #1B4F8A 100%);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
}

.login-card img {
    max-width: 200px;
    margin-bottom: 1.5rem;
}

.login-card .form-control {
    background: var(--bg-input);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.login-card .form-control:focus {
    border-color: var(--cbox-accent);
    box-shadow: 0 0 0 0.2rem rgba(75,163,217,0.25);
}

/* ── Tables ────────────────────────────────────────────────────── */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    color: var(--text-primary);
    transition: background 0.3s;
}

.table {
    color: var(--text-primary);
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--border-color);
    --bs-table-striped-bg: var(--table-stripe);
    --bs-table-striped-color: var(--text-primary);
    --bs-table-hover-bg: var(--bg-card-hover);
    --bs-table-hover-color: var(--text-primary);
    --bs-table-active-bg: var(--bg-card-hover);
    --bs-table-active-color: var(--text-primary);
}

.table th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom-width: 1px;
}

.table td {
    vertical-align: middle;
}

/* Expanded detail rows (e.g. Municipalities drill-down) must track the theme,
   otherwise dark-mode shows light text on a beige background. */
.muni-expand-cell {
    background: var(--bg-card-hover);
    padding: 0;
}

.muni-expand-cell .table {
    background: var(--bg-card);
    --bs-table-bg: transparent;
}

/* Clickable station tile on the Home page — uses its own typography classes
   instead of Bootstrap `.text-muted` because the Bootstrap utility hardcodes
   #6c757d which is too dim against our dark-mode card background. */
.station-tile {
    display: block;
    color: var(--text-primary);
    transition: transform 0.12s, box-shadow 0.12s, background 0.15s;
    border-color: var(--border-color);
    background: var(--bg-card);
}
.station-tile:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
    background: var(--bg-card-hover);
    color: var(--text-primary);
}
.station-tile-name {
    font-weight: 600;
    color: var(--text-primary);
}
.station-tile-sub {
    font-size: 0.85em;
    color: var(--text-secondary);
}

/* Shared top bar for all station sub-pages. Active tab gets a solid brand background. */
.station-nav {
    gap: 0.3rem;
    flex-wrap: wrap;
}
.station-nav .nav-link {
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.9rem;
    font-size: 0.9rem;
    background: var(--bg-card);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.station-nav .nav-link:hover {
    color: var(--text-primary);
    border-color: var(--cbox-accent);
    background: var(--bg-card-hover);
}
.station-nav .nav-link.active {
    background: var(--cbox-accent);
    color: white;
    border-color: var(--cbox-accent);
}
.station-nav .nav-link.active:hover {
    color: white;
}

/* Water-droplet loader. Three columns of drops falling simultaneously (left, middle,
   right). Each drop grows from small → full → small as it travels from top to
   bottom. The middle column is delayed by half a cycle, so the middle drop is at
   its biggest exactly when the outside drops are at their smallest (and vice versa).
   Animation uses linear timing + many keyframes for smooth, evenly-paced motion. */
.cbox-loader {
    position: relative;
    display: inline-block;
    width: 70px;
    height: 56px;
    color: var(--cbox-accent);
    vertical-align: middle;
}
.cbox-loader-sm {
    width: 36px;
    height: 26px;
}
.cbox-loader-lg {
    width: 96px;
    height: 78px;
}
.cbox-loader .cbox-drop {
    position: absolute;
    top: 0;
    width: 16px;
    height: 16px;
    margin-left: -8px;
    background: currentColor;
    /* Three rounded corners + one sharp = teardrop; rotated 45° so the tip points up. */
    border-radius: 0 100% 100% 100%;
    animation: cbox-drop-fall 1.8s linear infinite;
    box-shadow: 0 0 6px rgba(75, 163, 217, 0.35);
    will-change: top, transform, opacity;
}
.cbox-loader-sm .cbox-drop {
    width: 8px;
    height: 8px;
    margin-left: -4px;
    box-shadow: 0 0 2px rgba(75, 163, 217, 0.35);
}
.cbox-loader-lg .cbox-drop {
    width: 22px;
    height: 22px;
    margin-left: -11px;
}

/* Three columns via absolute positioning — left at 15%, middle at 50%, right at 85%.
   The middle is offset by half the animation duration (−0.9s for a 1.8s cycle) so
   center and sides breathe in opposite phase. */
.cbox-loader .cbox-drop:nth-child(1) { left: 15%; }
.cbox-loader .cbox-drop:nth-child(2) { left: 50%; animation-delay: -0.9s; }
.cbox-loader .cbox-drop:nth-child(3) { left: 85%; }

@keyframes cbox-drop-fall {
    0%   { top: 0%;   transform: rotate(45deg) scale(0.2);  opacity: 0;    }
    10%  { top: 6%;   transform: rotate(45deg) scale(0.45); opacity: 0.6;  }
    25%  { top: 20%;  transform: rotate(45deg) scale(0.75); opacity: 0.95; }
    50%  { top: 48%;  transform: rotate(45deg) scale(1);    opacity: 1;    }
    75%  { top: 78%;  transform: rotate(45deg) scale(0.75); opacity: 0.95; }
    90%  { top: 92%;  transform: rotate(45deg) scale(0.45); opacity: 0.6;  }
    100% { top: 100%; transform: rotate(45deg) scale(0.2);  opacity: 0;    }
}

/* Map legend */
.map-legend {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.6rem 0.9rem;
    color: var(--text-primary);
    font-size: 0.85rem;
}
.legend-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 0.4rem;
    vertical-align: middle;
    border: 1px solid rgba(0,0,0,0.15);
}
.legend-dot.legend-bounce {
    animation: cbox-bounce 0.6s ease infinite alternate;
}

/* ── Forms ─────────────────────────────────────────────────────── */
.form-control, .form-select {
    background: var(--bg-input);
    border-color: var(--border-color);
    color: var(--text-primary);
    transition: background 0.3s, border-color 0.3s;
}

.form-control:focus, .form-select:focus {
    background: var(--bg-input);
    border-color: var(--cbox-accent);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(75,163,217,0.2);
}

.form-control::placeholder {
    color: var(--text-muted);
}

.form-label {
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
}

/* ── Buttons ──────────────────────────────────────────────────── */
.btn-cbox {
    background: var(--cbox-primary);
    color: white;
    border: none;
    font-weight: 500;
}

.btn-cbox:hover {
    background: var(--cbox-dark);
    color: white;
}

.btn-outline-primary {
    color: var(--cbox-accent);
    border-color: var(--cbox-accent);
}

.btn-outline-secondary {
    color: var(--text-secondary);
    border-color: var(--border-color);
}

.btn-outline-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* ── Page header ──────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.page-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.5rem;
}

/* ── Theme toggle ─────────────────────────────────────────────── */
.theme-toggle {
    cursor: pointer;
    border: none;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.7);
    border-radius: 0.375rem;
    padding: 0.35rem 0.6rem;
    font-size: 1rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.theme-toggle:hover {
    background: rgba(255,255,255,0.2);
    color: white;
}

/* ── Alert banner (dashboard) ─────────────────────────────────── */
.alarm-banner {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: white;
    border-radius: 0.75rem;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 2px 8px rgba(220,38,38,0.3);
    margin-bottom: 1rem;
    animation: alarm-pulse 2s ease-in-out infinite;
}

.alarm-banner.warning {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    box-shadow: 0 2px 8px rgba(217,119,6,0.3);
    animation: none;
}

@keyframes alarm-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

/* ── Sensor row ───────────────────────────────────────────────── */
.sensor-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.sensor-row:last-child {
    border-bottom: none;
}

.sensor-name {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.sensor-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.sensor-unit {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: 0.2rem;
}

/* ── Map markers ──────────────────────────────────────────────── */
.cbox-marker-wrap {
    background: none !important;
    border: none !important;
}

.cbox-pin {
    display: inline-block;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.35));
    transition: transform 0.2s;
}

.cbox-pin:hover {
    transform: scale(1.2);
}

.cbox-bounce {
    animation: cbox-bounce 0.6s ease infinite alternate;
}

@keyframes cbox-bounce {
    0%   { transform: translateY(0); }
    100% { transform: translateY(-12px); }
}

.cbox-pulse {
    animation: cbox-pulse 1.5s ease-in-out infinite;
}

@keyframes cbox-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.45; }
}

/* ── Pump mode badge ─────────────────────────────────────────── */
.pump-mode {
    display: inline-block;
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
    border-radius: 0.25rem;
    margin-top: 0.15rem;
}

.pump-mode.manual { background: rgba(249,115,22,0.15); color: #f97316; }
.pump-mode.auto   { background: rgba(34,197,94,0.15); color: #22c55e; }
.pump-mode.local  { background: rgba(234,179,8,0.15); color: #eab308; }
.pump-mode.remote { background: rgba(75,163,217,0.15); color: #4BA3D9; }

/* ── Level bargraph ──────────────────────────────────────────── */
.level-gauge-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    min-height: 280px;
}

.level-gauge-wrapper {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 0;
    flex: 1;
}

.level-gauge {
    position: relative;
    width: 90px;
    height: 220px;
    background: var(--gauge-track, #f1f5f9);
    border-radius: 12px;
    border: 1px solid var(--border-color, #e2e8f0);
    overflow: visible;
    flex-shrink: 0;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.06);
}

.level-gauge-inner {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    overflow: hidden;
}

.level-gauge-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(180deg, #56b8f7 0%, #4BA3D9 30%, #2E6DB4 100%);
    transition: height 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.level-gauge-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 6px;
    background: linear-gradient(180deg, rgba(255,255,255,0.35) 0%, transparent 100%);
}

.level-gauge-fill.alarm-high {
    background: linear-gradient(180deg, #f87171 0%, #ef4444 30%, #4BA3D9 60%, #2E6DB4 100%);
}

.level-gauge-fill.alarm-low {
    background: linear-gradient(180deg, #56b8f7 0%, #eab308 75%, #ef4444 100%);
}

.level-gauge-value {
    position: absolute;
    bottom: 12px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 1.15rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 1px 4px rgba(0,0,0,0.4);
    z-index: 2;
    letter-spacing: -0.02em;
}

.level-gauge-unit {
    font-size: 0.7rem;
    font-weight: 500;
    opacity: 0.8;
    margin-left: 1px;
}

/* Threshold markers on the gauge */
.level-threshold {
    position: absolute;
    left: 0;
    right: 0;
    height: 0;
    z-index: 3;
    transition: bottom 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.level-threshold::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: -1px;
    height: 2px;
}

.level-threshold.start-p1::before { background: #22c55e; opacity: 0.7; }
.level-threshold.stop-p1::before  { background: #eab308; opacity: 0.7; }
.level-threshold.start-p2::before { background: #f97316; opacity: 0.7; }
.level-threshold.alarm-high::before { background: #ef4444; opacity: 0.8; }
.level-threshold.alarm-low::before  { background: #ef4444; opacity: 0.6; }

/* Threshold label column — right side of gauge */
.gauge-right-col {
    position: relative;
    margin-left: 8px;
    min-width: 130px;
    height: 220px;
}

.threshold-labels {
    position: absolute;
    top: 14px;
    left: 0;
    width: 130px;
    height: 206px;
}

.threshold-label {
    position: absolute;
    left: 0;
    transform: translateY(-50%);
    white-space: nowrap;
    line-height: 1;
    display: flex;
    align-items: center;
    gap: 5px;
    height: 18px;
}

.threshold-label .tl-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    flex-shrink: 0;
}

.threshold-label .tl-content {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.threshold-label .tl-text {
    font-weight: 600;
    font-size: 0.6rem;
    opacity: 0.75;
    text-transform: uppercase;
    letter-spacing: 0.2px;
}

.threshold-label .tl-value {
    font-weight: 700;
    font-size: 0.7rem;
}

.threshold-label .tl-unit {
    font-weight: 400;
    font-size: 0.55rem;
    opacity: 0.6;
}

.threshold-label.alarm-high { color: #ef4444; }
.threshold-label.alarm-high .tl-dot { background: #ef4444; }
.threshold-label.alarm-low { color: #ef4444; }
.threshold-label.alarm-low .tl-dot { background: #ef4444; }
.threshold-label.start-p1 { color: #22c55e; }
.threshold-label.start-p1 .tl-dot { background: #22c55e; }
.threshold-label.stop-p1 { color: #eab308; }
.threshold-label.stop-p1 .tl-dot { background: #eab308; }
.threshold-label.start-p2 { color: #f97316; }
.threshold-label.start-p2 .tl-dot { background: #f97316; }

/* Float switches — positioned at bottom of right column */
.float-switches-right {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

.float-switches-title {
    font-size: 0.6rem;
    color: var(--text-muted, #94a3b8);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 0.3rem;
}

.float-switch-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
}

.float-switch-row .indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.float-switch-row .float-label {
    font-size: 0.65rem;
    color: var(--text-muted, #64748b);
    white-space: nowrap;
}

.indicator.blink {
    animation: blink-red 1s ease-in-out infinite;
}

@keyframes blink-red {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.25; }
}

.level-sensor-type {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    margin-top: 0.5rem;
}

.level-sensor-type.analog { background: rgba(75,163,217,0.15); color: #4BA3D9; }
.level-sensor-type.float  { background: rgba(168,85,247,0.15); color: #a855f7; }

/* ── Level chart container ───────────────────────────────────── */
.level-chart-container {
    position: relative;
    width: 100%;
    height: 280px;
}

/* ── Events list ─────────────────────────────────────────────── */
.event-list {
    max-height: 300px;
    overflow-y: auto;
    padding: 0;
    margin: 0;
    list-style: none;
}

.event-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
}

.event-item:last-child { border-bottom: none; }

.event-time {
    color: var(--text-muted);
    font-size: 0.72rem;
    white-space: nowrap;
    min-width: 90px;
    font-variant-numeric: tabular-nums;
}

.event-desc {
    flex: 1;
    color: var(--text-secondary);
}

.event-item.alarm .event-desc {
    color: #ef4444;
    font-weight: 600;
}

/* Overview rows — bigger type + secondary trigger line underneath. */
.event-item.event-overview {
    padding: 0.55rem 0;
    font-size: 0.85rem;
}
.event-item.event-overview .event-desc { display: flex; flex-direction: column; gap: 2px; }
.event-overview-title { color: var(--text-primary); font-weight: 500; }
.event-overview-trigger {
    color: var(--text-muted);
    font-size: 0.75rem;
}
.event-overview-trigger em {
    font-style: normal;
    color: var(--text-secondary);
    font-weight: 500;
}

.event-tag {
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-card-hover);
    padding: 0.1rem 0.3rem;
    border-radius: 0.2rem;
}

/* ── Alarm count badge ───────────────────────────────────────── */
.alarm-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 800;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 3px solid;
}

.alarm-count-badge.ok {
    border-color: #22c55e;
    color: #22c55e;
    background: rgba(34,197,94,0.08);
}

.alarm-count-badge.warning {
    border-color: #ef4444;
    color: #ef4444;
    background: rgba(239,68,68,0.08);
    animation: alarm-pulse 2s ease-in-out infinite;
}

/* ── Pump animations ──────────────────────────────────────────── */
@keyframes pump-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.spin {
    animation: pump-spin 0.8s linear infinite;
}

/* ── Config section ───────────────────────────────────────────── */
.config-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
    overflow: hidden;
}

.config-section-header {
    padding: 0.75rem 1.25rem;
    background: var(--bg-card-hover);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    user-select: none;
}

.config-section-header:hover {
    background: var(--border-color);
}

.config-section-body {
    padding: 1rem 1.25rem;
}

/* ── Online status dot ────────────────────────────────────────── */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.4rem;
    vertical-align: middle;
}

.status-dot.online { background: #22c55e; box-shadow: 0 0 4px rgba(34,197,94,0.5); }
.status-dot.offline { background: #ef4444; box-shadow: 0 0 4px rgba(239,68,68,0.5); }
.status-dot.unknown { background: #6b7280; }

/* ── Mobile topbar (shown only on small viewports) ────────────── */
.mobile-topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 90;
    background: var(--bg-sidebar);
    color: white;
    padding: 0.5rem 0.75rem;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.mobile-topbar .mobile-brand {
    font-weight: 700;
    letter-spacing: 0.5px;
}
.mobile-topbar .hamburger {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    border-radius: 0.3rem;
    padding: 0.25rem 0.55rem;
    font-size: 1.1rem;
    cursor: pointer;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
    .mobile-topbar { display: flex; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        width: 260px;
        box-shadow: 2px 0 12px rgba(0,0,0,0.25);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-backdrop.open {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
    }
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    /* Stat cards stack on phones but keep consistent padding */
    .stat-card, .card.stat-card { padding: 0.75rem; }
}

/* ── Misc ──────────────────────────────────────────────────────── */
.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "Une erreur est survenue."
}

/* Override Bootstrap dark table classes */
.table-danger { --bs-table-bg: rgba(239,68,68,0.1); --bs-table-color: var(--text-primary); }
.table-success { --bs-table-bg: rgba(34,197,94,0.1); --bs-table-color: var(--text-primary); }
.table-warning { --bs-table-bg: rgba(234,179,8,0.1); --bs-table-color: var(--text-primary); }

/* Scrollbar styling for dark mode */
[data-theme="dark"] ::-webkit-scrollbar { width: 8px; }
[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--bg-body); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

/* Modal / dropdown in dark mode */
.dropdown-menu {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.modal-content {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-primary);
}
