/* =======================================================================
   Theme tokens
   - :root holds the LIGHT theme (default).
   - [data-theme="..."] blocks remap the same tokens for other themes.
   - Component rules below should reference these vars, not hard-coded
     colors, so adding a new theme is just another remap block.
   ======================================================================= */
:root {
    /* Brand / semantic colors — mirrors mobile Light palette
       (mobile/src/constants/config.js COLORS) so the two apps feel like
       one product. */
    --primary: #4F7DF5;
    --primary-dark: #3A68E3;
    --primary-light: #EBF0FD;
    --primary-rgb: 79, 125, 245;       /* keep in sync with --primary; used for rgba() shadows */
    --success: #10B981;
    --info: #4F7DF5;
    --warning: #F59E0B;
    --danger: #EF4444;
    --secondary: #858796;              /* kept as Bootstrap-gray; mobile uses 'secondary' as green which collides with --success */

    /* Surfaces — match mobile (single white canvas, cards lift via shadow) */
    --bg: #FFFFFF;
    --surface: #FFFFFF;
    --surface-2: #F3F4F6;          /* hover, input bg, subtle fills */
    --surface-muted: #F7F8FB;      /* .bg-light replacement */

    /* Text — match mobile (text=#1A1F36, textSecondary=#6B7280) */
    --text: #1A1F36;
    --text-muted: #6B7280;
    --text-strong: #1A1F36;
    --link: #4F7DF5;

    /* Borders / shadows — tight, layered, low-opacity (modern card feel) */
    --border: rgba(15, 23, 42, 0.06);
    --border-strong: #E5E7EB;
    --shadow-color: rgba(15, 23, 42, 0.06);
    --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.04);

    /* Chrome — light sidebar with subtle hairlines, white topbar with a
       single border-bottom (no card-like shadow). Brand presence comes
       through the logo + the blue accent on the active nav row, not a
       full coloured strip. This is the Linear / Vercel / Notion pattern. */
    --sidebar-bg: var(--surface);
    --sidebar-text: var(--text);
    --sidebar-text-muted: var(--text-muted);
    --sidebar-active-bg: rgba(var(--primary-rgb), 0.10);
    --sidebar-active-text: var(--primary);
    --sidebar-border: var(--border);
    --sidebar-brand-gradient: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    --topbar-bg: var(--surface);
    --topbar-border: var(--border);

    /* Layout */
    --sidebar-width: 250px;
    --sidebar-collapsed: 0px;
    --topbar-height: 60px;

    /* Legacy aliases — referenced by per-template <style> blocks. Aliasing
       them to current tokens means those rules now follow the active theme
       automatically (a var() resolves at use-site, so when --surface changes
       per [data-theme], --card-bg follows). */
    --light: var(--bg);
    --dark: var(--text-strong);
    --card-bg: var(--surface);
    --bg-light: var(--surface-muted);

    /* Bootstrap 5 reads --bs-body-bg / --bs-body-color and a stack of
       per-component vars from :root. Mapping them to our tokens makes
       every Bootstrap component theme-aware without per-class overrides. */
    --bs-body-bg: var(--bg);
    --bs-body-color: var(--text);
    --bs-secondary-color: var(--text-muted);
    --bs-tertiary-bg: var(--surface-2);
    --bs-border-color: var(--border-strong);
    --bs-card-bg: var(--surface);
    --bs-card-color: var(--text);
    --bs-card-border-color: var(--border);
    --bs-modal-bg: var(--surface);
    --bs-modal-color: var(--text);
    --bs-modal-border-color: var(--border);
    --bs-dropdown-bg: var(--surface);
    --bs-dropdown-color: var(--text);
    --bs-dropdown-border-color: var(--border);
    --bs-dropdown-link-color: var(--text);
    --bs-dropdown-link-hover-bg: var(--surface-2);
    --bs-dropdown-link-hover-color: var(--text);
    --bs-list-group-bg: var(--surface);
    --bs-list-group-color: var(--text);
    --bs-list-group-border-color: var(--border);
    --bs-list-group-action-color: var(--text);
    --bs-list-group-action-hover-bg: var(--surface-2);
    --bs-list-group-action-hover-color: var(--text);
}

/* --- Dark theme (Linear-inspired deep slate — clean, focused, modern) - */
[data-theme="dark"] {
    /* Brighter primary so it pops against the dark canvas without
       sacrificing readability against light text on filled buttons. */
    --primary: #6B8FFF;
    --primary-dark: #547BF5;
    --primary-rgb: 107, 143, 255;
    --success: #34D399;
    --info: #60C7D9;
    --warning: #FBBF24;
    --danger: #F87171;
    --secondary: #9095A1;

    /* Surfaces — deep slate, slight blue tint (not pure black) */
    --bg: #0B0D11;
    --surface: #14171C;
    --surface-2: #1C2027;          /* hover, input bg, subtle fills */
    --surface-muted: #14171C;

    /* Text */
    --text: #E5E7EB;
    --text-muted: #8A8F99;
    --text-strong: #FFFFFF;
    --link: #6B8FFF;

    /* Borders / shadows — soft hairlines, long-spread shadows for depth */
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: #2A2F38;
    --shadow-color: rgba(0, 0, 0, 0.50);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.30), 0 6px 20px rgba(0, 0, 0, 0.35);

    /* Sidebar/topbar match the body so chrome melts into the canvas
       (the Linear / Vercel feel) instead of standing out as a brand-blue strip. */
    --sidebar-bg: linear-gradient(180deg, #14171C 0%, #0B0D11 100%);
    --sidebar-text: #E5E7EB;
    --sidebar-text-muted: rgba(229, 231, 235, 0.62);
    --sidebar-active-bg: rgba(107, 143, 255, 0.16);
    --sidebar-active-text: #FFFFFF;
    --sidebar-border: rgba(255, 255, 255, 0.06);
    --sidebar-brand-gradient: linear-gradient(135deg, #6B8FFF 0%, #547BF5 100%);
    --topbar-bg: #14171C;
    --topbar-border: rgba(255, 255, 255, 0.06);

    /* Legacy alias used by per-template `body.dark-mode` overrides in
       reports.html and dashboard.html. Pointed at --surface so those
       cards follow the new dark surface color instead of resolving to
       empty (which would inherit body bg and lose the card boundary). */
    --dark-card: var(--surface);
}

* { box-sizing: border-box; }

body {
    /* Inter — variable axis font, gives modern product feel. System-font
       fallbacks keep things sane during the brief Google Fonts fetch. */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    /* Inter looks blocky without these — render hint for modern grayscale */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
    line-height: 1.5;
    letter-spacing: -0.01em;
}

/* Heading hierarchy — tighter tracking, weightier hierarchy. */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-strong);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.25;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }

/* Tabular figures for numeric content (counts, stats, table cells). */
.tabular-nums,
.summary-card .card-info h3,
.admin-stat-num,
.admin-stat-label,
.admin-quick-stat .stat-value {
    font-variant-numeric: tabular-nums;
}

/* =======================================================================
   Component overrides — single set, all themes, all driven by vars.
   These exist because Bootstrap ships fixed colors we need to neutralise.
   ======================================================================= */
.card {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-card);
    margin-bottom: 24px;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.card-header {
    background: transparent;
    color: var(--text-strong);
    border-bottom: 1px solid var(--border);
    padding: 18px 22px;
    font-weight: 600;
    font-size: 0.98rem;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-body { padding: 22px; }
.card-footer { background: transparent; border-top-color: var(--border); padding: 16px 22px; }

.modal-content { background: var(--surface); color: var(--text); border-color: var(--border); }
.modal-header  { border-bottom-color: var(--border); color: var(--text); }
.modal-footer  { border-top-color: var(--border); }
.modal-body    { color: var(--text); }

.dropdown-menu    { background: var(--surface); border-color: var(--border); }
.dropdown-item    { color: var(--text); }
.dropdown-item:hover,
.dropdown-item:focus { background: var(--surface-2); color: var(--text); }
.dropdown-divider { border-top-color: var(--border); }

.form-control,
.form-select {
    background: var(--surface);
    color: var(--text);
    border: 1.5px solid var(--border-strong);
    border-radius: 9px;
    padding: 0.55rem 0.85rem;
    font-size: 0.94rem;
    min-height: 42px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.form-control:hover,
.form-select:hover {
    border-color: color-mix(in srgb, var(--primary) 35%, var(--border-strong));
}
.form-control:focus,
.form-select:focus {
    background: var(--surface);
    color: var(--text);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.14);
}
.form-control::placeholder { color: var(--text-muted); }
.form-label {
    color: var(--text);
    font-weight: 500;
    font-size: 0.88rem;
    margin-bottom: 0.4rem;
    letter-spacing: -0.005em;
}
.input-group-text {
    background: var(--surface-2);
    color: var(--text);
    border: 1.5px solid var(--border-strong);
    font-size: 0.92rem;
}

.list-group-item { background: var(--surface); color: var(--text); border-color: var(--border); }
.list-group-item .text-muted,
.list-group-item small.text-muted { color: var(--text-muted) !important; }

.page-link { background: var(--surface); color: var(--text); border-color: var(--border); }
.page-link:hover { background: var(--surface-2); color: var(--text); }
.page-item.active .page-link { background: var(--primary); border-color: var(--primary); color: #fff; }

.text-muted, .text-secondary { color: var(--text-muted) !important; }
.bg-light  { background: var(--surface-muted) !important; color: var(--text); }
.border-bottom { border-bottom-color: var(--border) !important; }

a:not(.btn):not(.nav-item a):not(.page-link):not(.dropdown-item) { color: var(--link); }
code { color: var(--link); }

/* Base button — modern proportions, semibold text, smooth transitions.
   Sizes: default ~40px tall; .btn-sm 32px; .btn-lg 48px (Bootstrap defaults
   already cover the size variants, we only need the base look). */
.btn {
    border-radius: 9px;
    padding: 0.55rem 1.1rem;
    font-weight: 600;
    font-size: 0.92rem;
    letter-spacing: -0.005em;
    min-height: 40px;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease, color 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-sm { min-height: 32px; padding: 0.35rem 0.8rem; font-size: 0.85rem; border-radius: 7px; }
.btn-lg { min-height: 48px; padding: 0.75rem 1.4rem; font-size: 1rem; border-radius: 10px; }

/* Make Bootstrap outline buttons follow the theme palette */
.btn-outline-secondary { color: var(--text); border-color: var(--border-strong); }
.btn-outline-secondary:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

/* Bootstrap 5.3 sets per-button --bs-btn-* tokens on each .btn-* class with
   hardcoded brand colors, so just remapping --bs-primary at :root has no
   effect on .btn-primary / .btn-outline-primary. We have to override the
   per-button tokens directly for them to follow our theme. */
.btn-primary {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--primary-dark);
    --bs-btn-hover-border-color: var(--primary-dark);
    --bs-btn-focus-shadow-rgb: var(--primary-rgb);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--primary);
    --bs-btn-disabled-border-color: var(--primary);
}
.btn-outline-primary {
    --bs-btn-color: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--primary);
    --bs-btn-hover-border-color: var(--primary);
    --bs-btn-focus-shadow-rgb: var(--primary-rgb);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--primary);
    --bs-btn-active-border-color: var(--primary);
    --bs-btn-disabled-color: var(--primary);
}
/* Bootstrap utility classes that hardcode the brand blue */
.text-primary { color: var(--primary) !important; }
.bg-primary { background-color: var(--primary) !important; }
.border-primary { border-color: var(--primary) !important; }
.link-primary { color: var(--primary) !important; }

/* Reusable themed brand gradient — used by hero/banner panels so they
   recolor with the active theme instead of staying brand-blue. */
.theme-gradient {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

/* Login / Register — auth pages keep a brand-coloured backdrop so the
   sign-in moment feels distinct from the in-app navigation chrome. The
   gradient uses the same primary tokens so it follows the active theme. */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 0%, rgba(255,255,255,0.10), transparent 50%),
        radial-gradient(circle at 100% 100%, rgba(255,255,255,0.08), transparent 50%),
        linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}
[data-theme="dark"] .auth-wrapper {
    background:
        radial-gradient(circle at 20% 0%, rgba(107,143,255,0.15), transparent 50%),
        radial-gradient(circle at 100% 100%, rgba(107,143,255,0.10), transparent 50%),
        linear-gradient(135deg, #14171C 0%, #0B0D11 100%);
}
.auth-card {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 40px 36px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.18);
}
.auth-card h2 {
    color: var(--text-strong);
    font-weight: 700;
    margin-bottom: 6px;
    font-size: 1.6rem;
    letter-spacing: -0.025em;
}
.auth-card .subtitle {
    color: var(--text-muted);
    margin-bottom: 28px;
    font-size: 0.92rem;
}
.auth-card .form-control { border-radius: 9px; }
.auth-card .btn-primary {
    width: 100%;
    padding: 0.7rem 1rem;
    min-height: 44px;
    border-radius: 9px;
    font-weight: 600;
    font-size: 0.96rem;
}

/* Password field with inline eye toggle */
.pw-field { position: relative; }
.pw-field .form-control { padding-right: 42px; }
.pw-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 4px;
    color: var(--text-muted);
    cursor: pointer;
    z-index: 4;
    line-height: 1;
}
.pw-toggle:hover { color: var(--text); }

/* Sidebar — clean canvas with subtle hairlines, brand-blue accent only on
   the active link. The logo block keeps brand presence via the gradient
   square; the rest of the sidebar reads as a calm navigation column. */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    border-right: 1px solid var(--sidebar-border);
    z-index: 1000;
    transition: transform 0.3s ease;
    overflow-y: auto;
}
.sidebar .brand {
    padding: 20px 22px 18px;
    border-bottom: 1px solid var(--sidebar-border);
}
.sidebar .brand h4 {
    margin: 0 0 2px;
    font-weight: 700;
    font-size: 1.02rem;
    letter-spacing: -0.02em;
    color: var(--sidebar-text);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar .brand small {
    display: block;
    color: var(--sidebar-text-muted);
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-weight: 600;
    padding-left: 2px;
}
.sidebar .nav-menu { padding: 12px 10px; list-style: none; margin: 0; }
.sidebar .nav-item a {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 12px;
    margin: 1px 0;
    border-radius: 8px;
    color: var(--sidebar-text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: -0.005em;
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar .nav-item a:hover {
    color: var(--sidebar-text);
    background: color-mix(in srgb, var(--sidebar-active-bg) 50%, transparent);
}
.sidebar .nav-item a.active {
    color: var(--sidebar-active-text);
    background: var(--sidebar-active-bg);
    font-weight: 600;
}
.sidebar .nav-item a i {
    width: 18px;
    text-align: center;
    font-size: 0.95rem;
    opacity: 0.9;
}
.sidebar .nav-divider {
    border-top: 1px solid var(--sidebar-border);
    margin: 10px 14px;
}

/* Topbar — single hairline at the bottom, no shadow. Reads as a clean
   strip rather than a floating bar. */
.topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-height);
    background: var(--topbar-bg);
    color: var(--text);
    border-bottom: 1px solid var(--topbar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    z-index: 999;
    transition: left 0.3s ease;
}
.topbar .page-title {
    font-weight: 600;
    color: var(--text-strong);
    font-size: 1.05rem;
    letter-spacing: -0.015em;
}
.topbar .topbar-right { display: flex; align-items: center; gap: 18px; color: var(--text); }
.topbar .btn-toggle-sidebar {
    display: none; background: none; border: none;
    font-size: 1.3rem; color: var(--text); cursor: pointer;
}

/* Main content — generous breathing room, predictable spacing scale. */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: 32px;
    min-height: calc(100vh - var(--topbar-height));
    transition: margin-left 0.3s ease;
}

/* Summary Cards */
.summary-card {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-card);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    overflow: hidden;
}
.summary-card:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--primary) 22%, var(--border));
    box-shadow: 0 1px 2px rgba(15,23,42,0.04), 0 12px 28px rgba(15,23,42,0.08);
}
.summary-card .card-body {
    padding: 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.summary-card .card-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}
.summary-card .card-info h3 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-strong);
    letter-spacing: -0.025em;
    line-height: 1.1;
}
.summary-card .card-info p {
    margin: 4px 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.01em;
}
.card-icon.bg-primary-light { background: rgba(var(--primary-rgb),0.12); color: var(--primary); }
.card-icon.bg-success-light { background: rgba(16,185,129,0.12); color: var(--success); }
.card-icon.bg-warning-light { background: rgba(245,158,11,0.12); color: var(--warning); }
.card-icon.bg-danger-light  { background: rgba(239,68,68,0.12); color: var(--danger); }
.card-icon.bg-info-light    { background: rgba(79,125,245,0.12); color: var(--info); }

/* Soft badges — light background with colored text, no chunky look */
.soft-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px; border-radius: 12px;
    font-size: 0.78rem; font-weight: 600;
    background: rgba(133,135,150,0.12); color: var(--text-muted);
}
.soft-badge.success   { background: rgba(16,185,129,0.14); color: var(--success); }
.soft-badge.danger    { background: rgba(239,68,68,0.14);  color: var(--danger); }
.soft-badge.warning   { background: rgba(245,158,11,0.18); color: #B45309; }
.soft-badge.info      { background: rgba(var(--primary-rgb),0.14); color: var(--info); }
.soft-badge.primary   { background: rgba(var(--primary-rgb),0.14); color: var(--primary); }
.soft-badge.secondary { background: rgba(133,135,150,0.12); color: var(--text-muted); }
.soft-badge .status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
[data-theme="dark"] .soft-badge.warning { color: #FBBF24; }

/* Date DD/MM/YYYY */
.date-dmy-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.date-dmy-wrap input.date-dmy {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
    margin: 0;
    padding: 0;
    border: none;
}
.date-dmy-label {
    display: flex;
    align-items: center;
    height: 38px;
    padding: 0 32px 0 12px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 0.375rem;
    white-space: nowrap;
    pointer-events: none;
}
.date-dmy-label::after {
    content: '\f073';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    right: 10px;
    font-size: 0.8rem;
    color: var(--text-muted);
    pointer-events: none;
}

/* Map */
#map, #dashboard-map, #geofence-map { border-radius: 12px; }
.map-fullscreen { height: calc(100vh - var(--topbar-height) - 48px); }

/* Alerts badge */
.alert-badge {
    display: inline-block; padding: 4px 10px; border-radius: 20px;
    font-size: 0.75rem; font-weight: 600;
}
.alert-badge.critical { background: rgba(239,68,68,0.18);  color: var(--danger); }
.alert-badge.high     { background: rgba(245,158,11,0.18); color: #B45309; }
.alert-badge.medium   { background: rgba(var(--primary-rgb),0.18); color: var(--info); }
.alert-badge.low      { background: rgba(133,135,150,0.18); color: var(--text-muted); }
[data-theme="dark"] .alert-badge.high { color: #FCD34D; }

/* Status indicators */
.status-dot {
    display: inline-block; width: 8px; height: 8px;
    border-radius: 50%; margin-right: 5px;
}
.badge .status-dot { width: 7px; height: 7px; margin-right: 4px; }
.status-dot.online { background: #fff; }
.status-dot.offline { background: #fff; }
.status-dot.low_battery { background: #856404; }

/* Battery */
.battery-indicator { display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.battery-bar {
    width: 40px; height: 16px; border: 2px solid var(--text-muted);
    border-radius: 3px; position: relative; padding: 2px;
}
.battery-bar::after {
    content: ''; position: absolute; right: -5px; top: 4px;
    width: 3px; height: 6px; background: var(--text-muted); border-radius: 0 2px 2px 0;
}
.battery-fill {
    height: 100%; border-radius: 1px; transition: width 0.3s;
}
.battery-fill.high { background: var(--success); }
.battery-fill.medium { background: var(--warning); }
.battery-fill.low { background: var(--danger); }
.battery-fill.offline { background: #c0c0c0; }
.battery-offline .battery-bar { border-color: #c0c0c0; opacity: 0.5; }
.battery-offline .battery-bar::after { background: #c0c0c0; }
.battery-offline small { color: var(--text-muted); opacity: 0.6; }

/* Table — override Bootstrap's internal --bs-table-* vars so rows follow the
   active theme. Modern dashboard table: generous row height, subtle hover,
   muted uppercase headers. */
.table {
    font-size: 0.9rem;
    color: var(--text);
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--border);
    --bs-table-striped-bg: var(--surface-2);
    --bs-table-striped-color: var(--text);
    --bs-table-hover-bg: var(--surface-2);
    --bs-table-hover-color: var(--text);
    --bs-table-active-bg: var(--surface-2);
    --bs-table-active-color: var(--text);
}
.table > :not(caption) > * > * { padding: 0.85rem 1rem; }
.table th {
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-top: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
}
.table td {
    vertical-align: middle;
    color: var(--text);
    border-bottom-color: var(--border);
    transition: background 0.12s ease;
}
.table td small { color: var(--text-muted); }
.table tbody tr { transition: background 0.12s ease; }
.table-warning {
    --bs-table-bg: rgba(245,158,11,0.18);
    --bs-table-color: var(--text);
}
.table-warning td { color: var(--text); }

/* SOS pulse */
.sos-pulse { animation: pulse 1.5s infinite; }
@keyframes pulse {
    0%   { box-shadow: 0 0 0 0    rgba(239,68,68,0.5); }
    70%  { box-shadow: 0 0 0 15px rgba(239,68,68,0); }
    100% { box-shadow: 0 0 0 0    rgba(239,68,68,0); }
}

/* Toast notifications */
.toast-container {
    position: fixed; top: 80px; right: 24px; z-index: 9999;
}

/* Mobile responsive */
@media (max-width: 992px) {
    /* Tablet — keep sidebar but compress its width so content gets more room */
    .topbar { padding: 0 16px; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .topbar { left: 0; padding: 0 14px; }
    .topbar .btn-toggle-sidebar { display: block; }
    .topbar .page-title { font-size: 1rem; }
    .topbar .topbar-right { gap: 10px; }
    .main-content { margin-left: 0; padding: 18px 16px; }
    .auth-card { margin: 16px; padding: 24px; }
    .card { margin-bottom: 16px; }
    .card-header { padding: 14px 16px; }
}

@media (max-width: 576px) {
    .main-content { padding: 14px 12px; }
    .topbar .topbar-right .dropdown-toggle span { display: none; } /* hide username, keep icon */
    .summary-card .card-body { padding: 12px; gap: 8px; }
    .summary-card .card-icon { width: 40px; height: 40px; font-size: 1.05rem; }
    .summary-card .card-info h3 { font-size: 1.15rem; }
    .summary-card .card-info p { font-size: 0.72rem; }
    .table { font-size: 0.82rem; }
    .table th, .table td { padding: 0.55rem 0.5rem; }
    .toast-container { right: 12px; left: 12px; top: 70px; }
}

@media (max-width: 420px) {
    .auth-card { padding: 20px 16px; }
    .auth-card h2 { font-size: 1.4rem; }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none; position: fixed; top: 0; left: 0;
    width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 999;
}
.sidebar-overlay.show { display: block; }

/* Notification bell */
.notification-bell { position: relative; cursor: pointer; color: var(--text); }
.notification-bell .badge {
    position: absolute; top: -5px; right: -5px;
    font-size: 0.65rem; padding: 2px 5px;
}

/* Child avatar */
.child-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 1rem;
    overflow: hidden; flex-shrink: 0;
}
.child-avatar-photo { background: transparent; }
.child-avatar-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Loading overlay */
.page-loader {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    min-height: 300px; width: 100%;
    gap: 18px;
}
.page-loader-dots {
    display: flex; align-items: center; gap: 8px;
}
.page-loader-dots span {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--primary);
    opacity: 0.3;
    will-change: transform, opacity;
    animation: dotPulse 1.2s ease-in-out infinite;
}
.page-loader-dots span:nth-child(2) { animation-delay: 0.15s; }
.page-loader-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dotPulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}
.page-loader-text {
    font-size: 0.85rem; color: var(--text-muted);
    letter-spacing: 0.3px;
    animation: textFadeIn 0.4s ease both;
}
@keyframes textFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Full page loader overlay */
.page-loader-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 18px;
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    z-index: 50; border-radius: 8px;
    min-height: 200px;
    will-change: opacity;
    animation: overlayIn 0.15s ease both;
}
@keyframes overlayIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Legacy spinner (keep for backwards compat) */
.loading-spinner {
    display: flex; align-items: center; justify-content: center;
    padding: 40px;
}

/* Theme selector in topbar */
.theme-switcher { position: relative; }
.theme-switcher .theme-btn {
    background: none; border: none; cursor: pointer;
    font-size: 1.2rem; color: var(--text);
    padding: 4px 6px;
}
.theme-switcher .theme-btn:hover { color: var(--primary); }
.theme-switcher .dropdown-menu {
    min-width: 180px;
    padding: 6px 0;
}
.theme-switcher .dropdown-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 14px;
    font-size: 0.88rem;
}
.theme-switcher .dropdown-item .theme-swatch {
    width: 16px; height: 16px; border-radius: 50%;
    border: 1px solid var(--border-strong);
    flex-shrink: 0;
}
.theme-switcher .dropdown-item.active {
    background: var(--surface-2);
    font-weight: 600;
}
.theme-switcher .dropdown-item .theme-check {
    margin-left: auto;
    color: var(--primary);
    opacity: 0;
}
.theme-switcher .dropdown-item.active .theme-check { opacity: 1; }

/* Admin dashboard stat tiles */
.admin-stat-tile {
    text-align: center;
    padding: 16px 8px;
    border-radius: 10px;
}
.admin-stat-tile.success   { background: rgba(16,185,129,0.12); }
.admin-stat-tile.secondary { background: rgba(133,135,150,0.14); }
.admin-stat-tile.warning   { background: rgba(245,158,11,0.14); }
.admin-stat-num {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
}
.admin-stat-tile.success   .admin-stat-num { color: var(--success); }
.admin-stat-tile.secondary .admin-stat-num { color: var(--text-muted); }
.admin-stat-tile.warning   .admin-stat-num { color: var(--warning); }
.admin-stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
    color: var(--text-muted);
}

/* Admin detail list */
.admin-detail-list .admin-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.admin-detail-list .admin-detail-row:last-child { border-bottom: none; }
.admin-detail-row .detail-label { color: var(--text-muted); }
.admin-detail-row .detail-value { font-weight: 600; color: var(--text); }

/* Admin alert row */
.admin-alert-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
}
.admin-alert-row .alert-icon-circle {
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; flex-shrink: 0;
}
.admin-alert-row .alert-icon-circle.danger    { background: rgba(239,68,68,0.14);  color: var(--danger); }
.admin-alert-row .alert-icon-circle.warning   { background: rgba(245,158,11,0.14); color: var(--warning); }
.admin-alert-row .alert-icon-circle.info      { background: rgba(79,125,245,0.14); color: var(--info); }
.admin-alert-row .alert-icon-circle.secondary { background: rgba(133,135,150,0.14); color: var(--text-muted); }
.admin-alert-row .alert-type-name { flex: 1; font-weight: 500; color: var(--text); }
.admin-alert-row .alert-type-count { font-size: 1.1rem; font-weight: 700; color: var(--text); }

/* Admin quick stat item */
.admin-quick-stat {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
}
.admin-quick-stat .stat-icon-circle {
    width: 38px; height: 38px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.9rem; flex-shrink: 0;
}
.admin-quick-stat .stat-icon-circle.primary { background: rgba(var(--primary-rgb),0.12); color: var(--primary); }
.admin-quick-stat .stat-icon-circle.info    { background: rgba(79,125,245,0.12); color: var(--info); }
.admin-quick-stat .stat-icon-circle.success { background: rgba(16,185,129,0.12); color: var(--success); }
.admin-quick-stat .stat-label { flex: 1; font-size: 0.9rem; color: var(--text); }
.admin-quick-stat .stat-value { font-size: 1.1rem; font-weight: 700; color: var(--text); }
