:root {
    --bg: #0b1220;
    --panel: #111a2e;
    --text: #e7eefc;
    --muted: #a9b4cc;
    --border: rgba(255,255,255,0.12);
}

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background: linear-gradient(180deg, var(--bg), #050813);
    color: var(--text);
}

    /* Blazor injects a wrapper <div> between <body> and .app-shell -- it must also fill the viewport */
    body > div {
        height: 100%;
    }

a {
    color: #93c5fd;
}

h1 {
    outline: none;
}

code {
    background: rgba(255,255,255,0.08);
    padding: 2px 6px;
    border-radius: 8px;
}

.app-shell {
    display: block;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100vh;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    background: rgba(17,26,46,0.95);
    backdrop-filter: blur(12px);
    padding: 18px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    z-index: 100;
}

.brand-title {
    font-weight: 700;
    font-size: 18px;
}

.brand-sub {
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
}

.nav {
    margin-top: 18px;
    display: grid;
    gap: 8px;
}

.nav-link {
    display: block;
    padding: 10px 12px;
    border-radius: 12px;
    text-decoration: none;
    color: var(--text);
    border: 1px solid transparent;
}

    .nav-link.active {
        border-color: var(--border);
        background: rgba(255,255,255,0.06);
    }

.content {
    margin-left: 260px;
    padding: 22px;
}

.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.search {
    min-width: 260px;
    flex: 1;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 10px 12px;
    background: rgba(255,255,255,0.06);
    color: var(--text);
}

    .search::placeholder {
        color: rgba(169,180,204,0.85);
    }

/* When .search is used on a <select> (e.g. the audit Action filter), the OPEN
   option list is drawn by the OS using inherited colors — which renders light
   text on a default white popup and is unreadable. Give the options a solid dark
   background and readable text, matching the other dropdowns (.field-input). */
select.search {
    background: rgba(255,255,255,0.06);
    color: var(--text);
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

    select.search option {
        background: #111a2e;
        color: var(--text);
    }

.sortbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.sortlabel {
    color: var(--muted);
    font-size: 12px;
}

.sortbtn {
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.06);
    color: var(--text);
    padding: 8px 12px;
    cursor: pointer;
}

    .sortbtn:hover {
        background: rgba(255,255,255,0.10);
    }

.count {
    color: var(--muted);
    font-size: 12px;
    margin-left: auto;
}

.device-list-simple {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}

.device-row {
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    background: rgba(15,23,42,0.65);
}

    .device-row:hover {
        background: rgba(255,255,255,0.06);
    }

.simple-list {
    background: rgba(15,23,42,0.65);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}

.simple-row {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

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

    .simple-row:hover {
        background: rgba(255,255,255,0.04);
    }

.user-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.user-name {
    font-size: 15px;
    font-weight: 600;
}

.user-username {
    font-size: 12px;
    color: var(--muted);
    font-weight: 400;
    margin-left: 4px;
}

.user-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.user-customers {
    font-size: 12px;
    color: var(--muted);
}

.user-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    border: 1px solid transparent;
}

.badge-superadmin {
    background: rgba(168,85,247,0.18);
    border-color: rgba(168,85,247,0.45);
    color: #d8b4fe;
}

.badge-admin {
    background: rgba(59,130,246,0.18);
    border-color: rgba(59,130,246,0.45);
    color: #93c5fd;
}

.badge-tech {
    background: rgba(34,197,94,0.18);
    border-color: rgba(34,197,94,0.45);
    color: #86efac;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    display: inline-block;
    box-shadow: 0 0 0 2px rgba(0,0,0,0.25);
}

.dot-online {
    background: #22c55e;
}

.dot-warn {
    background: #f59e0b;
}

.dot-offline {
    background: #ef4444;
}

.devlink {
    text-decoration: none;
    color: var(--muted);
    font-size: 11px;
    font-style: italic;
}

    .devlink:hover {
        text-decoration: none;
    }

.customer {
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}

.notes {
    color: var(--muted);
    font-size: 12px;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.btn {
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.06);
    color: var(--text);
    padding: 8px 12px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

    .btn:hover {
        background: rgba(255,255,255,0.10);
    }

.btn-primary {
    border-color: rgba(59,130,246,0.55);
    background: rgba(59,130,246,0.20);
}

    .btn-primary:hover {
        background: rgba(59,130,246,0.28);
    }

.btn-secondary {
    border-color: rgba(148,163,184,0.45);
    background: rgba(148,163,184,0.12);
}

    .btn-secondary:hover {
        background: rgba(148,163,184,0.22);
    }

.btn-danger {
    border-color: rgba(239,68,68,0.55);
    background: rgba(239,68,68,0.20);
}

    .btn-danger:hover {
        background: rgba(239,68,68,0.30);
    }

.btn-success {
    border-color: rgba(34,197,94,0.55);
    background: rgba(34,197,94,0.20);
}

    .btn-success:hover {
        background: rgba(34,197,94,0.30);
    }

.input-text {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 7px 10px;
    font-size: 13px;
    outline: none;
}

    .input-text:focus {
        border-color: rgba(59,130,246,0.6);
    }

.detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.detail-header-left {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.detail-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

/* -- Commands dropdown (device-details header) ---------------------------- */
.cmd-dropdown {
    position: relative;
    display: inline-block;
}

/* Transparent full-screen layer so a click anywhere closes the menu (no JS). */
.cmd-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: transparent;
}

.cmd-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 201;
    min-width: 260px;
    max-width: 320px;
    padding: 6px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.45);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cmd-menu-item {
    display: flex;
    flex-direction: column;
    gap: 1px;
    text-align: left;
    padding: 8px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}

    .cmd-menu-item:hover {
        background: rgba(255,255,255,0.06);
    }

    .cmd-menu-item:disabled {
        opacity: 0.6;
        cursor: not-allowed;
    }

        .cmd-menu-item:disabled:hover {
            background: transparent;
        }

.cmd-menu-req {
    display: block;
    margin-top: 3px;
    color: #fca5a5;
    font-size: 11px;
}

.cmd-menu-name {
    font-size: 13px;
    font-weight: 600;
}

.cmd-menu-desc {
    font-size: 11px;
    color: var(--muted);
}

.detail-back {
    font-size: 12px;
    color: var(--muted);
    text-decoration: none;
    letter-spacing: 0.3px;
}

    .detail-back:hover {
        color: var(--text);
    }

.details-title {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.details-sub {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.details-subtext {
    color: var(--muted);
    font-size: 12px;
}

    .details-subtext + .details-subtext::before {
        content: "↑";
        margin-right: 8px;
        color: var(--border);
    }

.details-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.action-spacer {
    flex: 1;
}

.badge {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    white-space: nowrap;
}

.badge-online {
    background: rgba(34,197,94,0.18);
    border-color: rgba(34,197,94,0.45);
    color: #86efac;
}

.badge-warn {
    background: rgba(245,158,11,0.18);
    border-color: rgba(245,158,11,0.45);
    color: #fde68a;
}

.badge-offline {
    background: rgba(239,68,68,0.18);
    border-color: rgba(239,68,68,0.45);
    color: #fca5a5;
}

.badge-danger {
    background: rgba(239,68,68,0.18);
    border-color: rgba(239,68,68,0.55);
    color: #fca5a5;
}

/* Legacy (v3) device tag — neutral slate tone, distinct from warn/danger. */
.badge-legacy {
    background: rgba(148,163,184,0.16);
    border-color: rgba(148,163,184,0.45);
    color: #cbd5e1;
}

/* Maintenance mode — distinct sky-blue tone (not green/yellow/red). */
.badge-maintenance {
    background: rgba(56,189,248,0.18);
    border-color: rgba(56,189,248,0.50);
    color: #bae6fd;
}

.btn-maintenance {
    background: rgba(56,189,248,0.18);
    border: 1px solid rgba(56,189,248,0.55);
    color: #bae6fd;
}

    .btn-maintenance:hover {
        background: rgba(56,189,248,0.28);
    }

.maintenance-banner {
    background: rgba(56,189,248,0.12);
    border: 1px solid rgba(56,189,248,0.45);
    color: #bae6fd;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.details-grid {
    display: grid;
    /* minmax(0, 1fr) instead of 1fr: a bare 1fr track has an implicit min-width of
       auto (its content's intrinsic width), so a card with a wide table or a long
       unbroken string forces the whole grid past the viewport and the page scrolls
       sideways. Allowing the tracks to shrink to 0 keeps the grid within the
       content area; wide inner content wraps or scrolls inside its own card. */
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 14px;
}

.card {
    background: rgba(15,23,42,0.65);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px 18px;
    /* Permit the card (a grid item) to shrink below its content's intrinsic width
       so the minmax(0, 1fr) tracks above can actually take effect. */
    min-width: 0;
}

.card-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.kv {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

    .kv:last-child {
        border-bottom: none;
    }

/* Cards that opt into wider key labels (e.g. the Batteries/Power card, whose
   device-supplied labels like "Generator Battery Voltage" need more room to stay
   on one line). Scoped so other cards keep the compact default column. */
.card.wide-labels .kv {
    grid-template-columns: 185px 1fr;
}

.k {
    color: var(--muted);
    font-size: 12px;
    padding-top: 1px;
}

.v {
    color: var(--text);
    font-size: 13px;
}

.mapthumb {
    width: 100%;
    height: 420px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.device-meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

pre {
    margin: 0;
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    white-space: pre-wrap;
}

.error {
    margin-bottom: 12px;
    padding: 10px 12px;
    border: 1px solid rgba(239,68,68,0.45);
    border-radius: 12px;
    background: rgba(239,68,68,0.12);
    color: #fecaca;
}

.info {
    margin-bottom: 12px;
    padding: 10px 12px;
    border: 1px solid rgba(59,130,246,0.45);
    border-radius: 12px;
    background: rgba(59,130,246,0.12);
    color: #dbeafe;
}

.hint {
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.modal {
    width: min(520px, 90vw);
    box-sizing: border-box;
    background: rgba(17,26,46,0.92);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 14px;
}

.modal-title {
    font-weight: 700;
    margin-bottom: 10px;
}

.modal-body {
    color: var(--text);
    box-sizing: border-box;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 14px;
}

/* -- Mobile nav elements: hidden by default on desktop, revealed in the
      max-width:900px media query below. These MUST come before that media
      query: equal-specificity rules resolve by source order, so if these
      sat after it they would always win and the mobile nav would never show. */
.nav-hamburger {
    display: none;
}

.nav-close {
    display: none;
}

.nav-backdrop {
    display: none;
}

.sidebar-top {
    display: block;
}

.mobile-topbar {
    display: none;
}

@media (max-width: 900px) {
    html, body {
        height: auto;
        overflow: auto;
    }

    .app-shell {
        display: block;
        height: auto;
        overflow: visible;
    }

    /* Map reads fine short on narrow screens; the taller desktop height would
       dominate a phone viewport. */
    .mapthumb {
        height: 220px;
    }

    /* Fixed top bar */
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 12px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 52px;
        background: rgba(17,26,46,0.97);
        border-bottom: 1px solid var(--border);
        padding: 0 16px;
        z-index: 198;
        backdrop-filter: blur(12px);
    }

    /* Push content below the top bar */
    .content {
        margin-left: 0;
        padding: 14px;
        padding-top: 66px;
    }

    /* Sidebar hidden off-screen, slides in over the top bar */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 200;
        overflow-y: auto;
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    }

        .sidebar.sidebar-open {
            transform: translateX(0);
        }

    /* Backdrop */
    .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.55);
        z-index: 199;
    }

    /* Show hamburger and close button */
    .nav-hamburger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        background: rgba(255,255,255,0.08);
        border: 1px solid var(--border);
        border-radius: 8px;
        color: var(--text);
        font-size: 20px;
        cursor: pointer;
        flex-shrink: 0;
    }

        .nav-hamburger:hover {
            background: rgba(255,255,255,0.14);
        }

    .nav-close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 30px;
        height: 30px;
        background: transparent;
        border: none;
        color: var(--muted);
        font-size: 16px;
        cursor: pointer;
        border-radius: 6px;
        flex-shrink: 0;
    }

        .nav-close:hover {
            color: var(--text);
        }

    .sidebar-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 4px;
    }

    /* Layout adjustments */
    .detail-header {
        flex-direction: column;
        gap: 10px;
    }

    .detail-header-right {
        flex-wrap: wrap;
    }

    .details-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .kv {
        grid-template-columns: 110px 1fr;
    }

    .device-list-simple {
        grid-template-columns: 1fr;
    }

    .device-row {
        flex-wrap: wrap;
    }

    .data-table .col-target {
        display: none;
    }

    .simple-row {
        flex-wrap: wrap;
        gap: 8px;
    }

    .user-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .map-page {
        height: auto;
    }

    .map-container {
        height: 60vh;
    }

    .rangebar {
        flex-wrap: wrap;
    }
}

/* -- Auth / Login ------------------------------------------------------------ */
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: min(420px, 100%);
    background: rgba(17,26,46,0.92);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px;
}

.login-logo {
    display: block;
    width: 180px;
    max-width: 70%;
    height: auto;
    margin-bottom: 18px;
}

.sidebar-logo {
    display: block;
    width: 150px;
    max-width: 100%;
    height: auto;
    margin-bottom: 10px;
}

.login-brand {
    font-weight: 700;
    font-size: 22px;
    margin-bottom: 4px;
}

.login-sub {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 24px;
}

.field {
    margin-bottom: 16px;
}

.field-label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 6px;
}

.field-hint {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.field-input {
    width: 100%;
    box-sizing: border-box;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 10px 12px;
    background: rgba(255,255,255,0.06);
    color: var(--text);
    font-size: 14px;
}

    .field-input:focus {
        outline: none;
        border-color: rgba(59,130,246,0.6);
        background: rgba(255,255,255,0.09);
    }

    .field-input option {
        background: #111a2e;
        color: var(--text);
    }

.toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
    padding: 2px 0;
}

    .toggle-row input[type="checkbox"] {
        accent-color: #3b82f6;
        width: 15px;
        height: 15px;
        cursor: pointer;
    }

.customer-checklist {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    margin-top: 4px;
}

/* -- Sidebar footer ---------------------------------------------------------- */
.sidebar-footer {
    margin-top: auto;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.sidebar-user {
    padding: 6px 0;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

.nav {
    flex: 1;
}


/* -- Telemetry range selector ----------------------------------------------- */
.rangebar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 10px 0 14px;
}

.rangebtn {
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.06);
    color: var(--text);
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
}

    .rangebtn:hover {
        background: rgba(255,255,255,0.10);
    }

    .rangebtn.active {
        border-color: rgba(59,130,246,0.65);
        background: rgba(59,130,246,0.22);
    }


/* -- ApexCharts toolbar (reset-zoom control) ------------------------------ */
/* Only the reset tool is surfaced (see TelemetryChart). The zoom tool stays
   ENABLED so drag-select-to-zoom keeps working, but its magnifier icon is hidden
   here to keep the toolbar limited to the reset button. Recolor reset for the
   dark theme and lift it clear of the plot so it's easy to find and click. */
.apexcharts-toolbar {
    z-index: 5;
    opacity: 0.85;
}

    .apexcharts-toolbar .apexcharts-zoom-icon,
    .apexcharts-toolbar .apexcharts-selection-icon,
    .apexcharts-toolbar .apexcharts-zoomin-icon,
    .apexcharts-toolbar .apexcharts-zoomout-icon,
    .apexcharts-toolbar .apexcharts-pan-icon,
    .apexcharts-toolbar .apexcharts-menu-icon {
        display: none;
    }

    .apexcharts-toolbar .apexcharts-reset-icon svg {
        fill: var(--muted);
        transform: scale(1.05);
    }

    .apexcharts-toolbar .apexcharts-reset-icon:hover svg {
        fill: var(--text);
    }

/* -- ApexCharts tooltip --------------------------------------------------- */
.apex-tip {
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(17,26,46,0.95);
    border: 1px solid var(--border);
    color: var(--text);
}

.apex-tip-ts {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 4px;
}

.apex-tip-val {
    font-size: 13px;
    font-weight: 700;
}

.apex-tip-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
}

.apex-tip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.apex-tip-label {
    font-size: 11px;
    color: var(--muted);
    flex: 1;
}

.apex-tip-row .apex-tip-val {
    font-size: 12px;
}

/* Sidebar nav cleanup */
.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 16px;
}

/* Make links less "button-like" */
.nav-link {
    padding: 6px 10px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    transition: background 0.15s ease;
}

    /* Hover effect */
    .nav-link:hover {
        background: rgba(255,255,255,0.06);
    }

    /* Active state (clean highlight instead of block button) */
    .nav-link.active {
        background: rgba(59,130,246,0.16);
        border-left: 3px solid #3b82f6;
        padding-left: 7px; /* compensate border */
    }

/* Section headers (Admin / System) */
.nav-section {
    margin-top: 14px;
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

/* Indented sub-items */
.sub-link {
    padding-left: 16px;
    font-size: 13px;
    color: var(--muted);
}

    /* Slight hover emphasis for sub-links */
    .sub-link:hover {
        color: var(--text);
    }

/* -- Device Map ----------------------------------------- */
.map-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 44px);
}

.map-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.map-container {
    flex: 1;
    border-radius: 16px;
    border: 1px solid var(--border);
    overflow: hidden;
    min-height: 0;
    /* Establish a stacking context so Leaflet's internal panes/controls (which
       use z-index up to ~700) are confined to this container and can't render
       above the mobile sidebar/backdrop, while their relative layering inside
       the map (tiles < markers < popups) is preserved. */
    position: relative;
    z-index: 0;
}

/* Leaflet popup dark theme */
.device-popup .leaflet-popup-content-wrapper {
    background: rgba(17,26,46,0.97);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    color: #e7eefc;
    box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

.device-popup .leaflet-popup-tip {
    background: rgba(17,26,46,0.97);
}

.device-popup .leaflet-popup-close-button {
    color: #a9b4cc;
}


/* ── Audit Log ────────────────────────────────────────────────────────────── */
.audit-list {
    background: rgba(15,23,42,0.65);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}

.audit-row {
    display: grid;
    grid-template-columns: 140px 90px 160px 110px 1fr;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    align-items: start;
}

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

    .audit-row:not(.audit-header):hover {
        background: rgba(255,255,255,0.04);
    }

.audit-header {
    background: rgba(255,255,255,0.04);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--muted);
    padding: 8px 16px;
}



.audit-date {
    font-size: 12px;
    color: var(--text);
}

.audit-clock {
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.audit-meta {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

.audit-footer {
    margin-top: 10px;
    font-size: 11px;
    color: var(--muted);
    text-align: center;
}

/* ── Data table (used by Audit Log) ──────────────────── */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

    .data-table th {
        text-align: left;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.6px;
        text-transform: uppercase;
        color: var(--muted);
        padding: 6px 20px 6px 12px;
        border-bottom: 1px solid var(--border);
        white-space: nowrap;
    }

    .data-table td {
        padding: 7px 20px 7px 12px;
        border-bottom: 1px solid rgba(255,255,255,0.05);
        vertical-align: middle;
    }

    .data-table tr:last-child td {
        border-bottom: none;
    }

    .data-table tbody tr:hover td {
        background: rgba(255,255,255,0.04);
    }

    .data-table .col-time {
        white-space: nowrap;
        min-width: 175px;
        font-size: 12px;
        font-variant-numeric: tabular-nums;
        color: var(--muted);
    }

    .data-table .col-user {
        white-space: nowrap;
        min-width: 90px;
        font-weight: 600;
        color: var(--text);
    }

    .data-table .col-action {
        white-space: nowrap;
        min-width: 170px;
    }

    .data-table .col-target {
        white-space: nowrap;
        min-width: 110px;
        color: var(--muted);
        font-size: 12px;
    }

    .data-table .col-detail {
        width: 100%;
    }

.audit-date {
    font-size: 13px;
    font-weight: 500;
}

.audit-clock {
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.audit-meta {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

.detail-clamp {
    height: 2.6em;
    overflow: hidden;
    position: relative;
}

    .detail-clamp::after {
        content: "";
        position: absolute;
        bottom: 0;
        right: 0;
        width: 30%;
        height: 1.3em;
        background: linear-gradient(to right, transparent, rgba(15,23,42,0.95));
        pointer-events: none;
    }

.detail-full {
    white-space: pre-wrap;
    word-break: break-word;
}

.detail-expand-btn {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.06);
    color: var(--text);
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
}

    .detail-expand-btn:hover {
        background: rgba(255,255,255,0.10);
    }

#reconnect-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    z-index: 2000;
}

    #reconnect-overlay.show {
        display: flex;
    }

    #reconnect-overlay .reconnect-box {
        background: #1f2937;
        color: #fff;
        padding: 22px 26px;
        border-radius: 12px;
        border: 1px solid rgba(255, 255, 255, 0.12);
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
        text-align: center;
        max-width: 360px;
    }

        #reconnect-overlay .reconnect-box h4 {
            margin: 0 0 8px;
            font-size: 16px;
        }

        #reconnect-overlay .reconnect-box p {
            margin: 0 0 16px;
            font-size: 13px;
            color: #cbd5e1;
        }

        #reconnect-overlay .reconnect-box button {
            background: #3b82f6;
            color: #fff;
            border: none;
            border-radius: 8px;
            padding: 9px 18px;
            font-size: 13px;
            cursor: pointer;
        }

            #reconnect-overlay .reconnect-box button:hover {
                background: #2563eb;
            }
/* ── Loading spinner ─────────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 22px;
    height: 22px;
    border: 3px solid rgba(148, 163, 184, 0.25);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex: none;
}

.spinner-sm {
    width: 15px;
    height: 15px;
    border-width: 2px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* A centered loading panel used in place of content while it loads. */
.loading-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--muted);
    font-size: 14px;
}

/* Inline loading row (left-aligned, e.g. inside a card). */
.loading-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 4px;
    color: var(--muted);
    font-size: 13px;
}

/* Centered spinner shown inside a chart card while its series load. The min
   height roughly matches a rendered chart so the tile doesn't jump when the
   chart appears. */
.chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 220px;
    color: var(--muted);
    font-size: 13px;
}

/* Wrapper that lets a spinner overlay sit on top of a chart while it draws. */
.chart-wrap {
    position: relative;
    min-height: 220px;
}

/* Spinner overlay covering the chart area until the chart fires OnRendered. */
.chart-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: #0f172a;
    color: var(--muted);
    font-size: 13px;
    z-index: 5;
}

/* Inline "last response" line under the device header: timestamp + payload on a
   single row. The payload can be long, so clamp it to one line with an ellipsis
   (full text is available via the title tooltip). */
.last-response-line {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-top: 6px;
    max-width: 100%;
    overflow: hidden;
}

.last-response-ts {
    flex: none;
    color: var(--muted);
}

.last-response-payload {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.85;
}

/* Command-response banner: shown after sending a command to a device while we
   wait for (and then display) the device's reply. */
.cmd-response {
    margin-top: 10px;
}

.cmd-response-waiting {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cmd-response-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

    .cmd-response-head .details-subtext {
        flex: 1 1 auto;
        min-width: 0;
    }

.cmd-response-dismiss {
    flex: none;
    background: none;
    border: none;
    color: inherit;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.7;
    padding: 0 2px;
}

    .cmd-response-dismiss:hover {
        opacity: 1;
    }

.cmd-response-body {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 220px;
    overflow: auto;
    font-size: 12px;
}

/* Active-alarm indicators. A device is "in alarm" when any alert condition is
   currently triggered (low fuel/battery, offline, generator error). */

/* Devices list: left accent bar + subtle red wash on alarming rows. */
.device-row-alarm {
    border-left: 3px solid #ef4444;
    background: rgba(239,68,68,0.08);
}

    .device-row-alarm:hover {
        background: rgba(239,68,68,0.14);
    }

/* Warning (less severe than alarm): yellow accent instead of red. */
.device-row-warn {
    border-left: 3px solid #eab308;
    background: rgba(234,179,8,0.08);
}

    .device-row-warn:hover {
        background: rgba(234,179,8,0.14);
    }

.warn-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0;
    padding: 12px 14px;
    border: 1px solid rgba(234,179,8,0.55);
    border-left: 4px solid #eab308;
    border-radius: 10px;
    background: rgba(234,179,8,0.10);
}

    .warn-banner .alarm-banner-icon,
    .warn-banner .alarm-banner-body b {
        color: #fde047;
    }

/* Device details: small pulsing alarm badge in the status row. */
.alarm-badge {
    animation: alarm-pulse 1.6s ease-in-out infinite;
}

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

    50% {
        opacity: 0.55;
    }
}

/* Device details: prominent banner listing the active alarm condition(s). */
.alarm-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0;
    padding: 12px 14px;
    border: 1px solid rgba(239,68,68,0.55);
    border-left: 4px solid #ef4444;
    border-radius: 10px;
    background: rgba(239,68,68,0.10);
}

.alarm-banner-icon {
    font-size: 20px;
    line-height: 1;
    color: #fca5a5;
}

.alarm-banner-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

    .alarm-banner-body b {
        color: #fca5a5;
    }

/* Count badge next to the "Alarmed" filter button on the Devices list. */
.alarm-count {
    display: inline-block;
    margin-left: 6px;
    min-width: 18px;
    padding: 0 6px;
    border-radius: 9px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
}

.warn-count {
    display: inline-block;
    margin-left: 6px;
    min-width: 18px;
    padding: 0 6px;
    border-radius: 9px;
    background: #eab308;
    color: #1a1a1a;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
}

/* Count badge for the Online/Offline filter buttons — neutral tone so a high
   offline count isn't alarming by color alone (the red alarm-count is distinct). */
.status-count {
    display: inline-block;
    margin-left: 6px;
    min-width: 18px;
    padding: 0 6px;
    border-radius: 9px;
    background: rgba(148, 163, 184, 0.25);
    color: var(--text);
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
}

/* Fault history: clickable rows + expandable Cummins detail panel. */
.fault-row {
    cursor: pointer;
}

    .fault-row:hover {
        background: rgba(148, 163, 184, 0.08);
    }

.fault-chevron {
    color: var(--muted);
    width: 24px;
    text-align: center;
    user-select: none;
}

.fault-detail-row > td {
    background: rgba(148, 163, 184, 0.06);
}

.fault-detail {
    padding: 10px 4px 12px;
}

.fault-detail-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 2px;
}

.fault-detail-text {
    color: var(--text);
    font-size: 13px;
    line-height: 1.5;
}

/* Fault detail drill-down: back link + header spacing. */
.fault-detail-header {
    margin-bottom: 8px;
}

.link-button {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent, #3b82f6);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}

    .link-button:hover {
        text-decoration: underline;
    }

/* Login disclaimer text box: scrollable, readable block on the BlankLayout card. */
.disclaimer-box {
    max-height: 320px;
    overflow-y: auto;
    text-align: left;
    margin: 4px 0 18px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255,255,255,0.03);
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text, #d8dee9);
}

    .disclaimer-box p {
        margin: 0 0 10px;
    }

        .disclaimer-box p:last-child {
            margin-bottom: 0;
        }

/* -- Per-user card layout (drag-and-drop reordering) ---------------------- */
.layout-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 12px;
}

.layout-hint {
    color: var(--muted);
    font-size: 13px;
    margin-right: auto;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

/* Edit mode: each card becomes a draggable surface with a clear affordance. */
.details-grid.layout-edit .card {
    cursor: grab;
    outline: 1px dashed rgba(56, 189, 248, 0.6);
    outline-offset: -2px;
}

    .details-grid.layout-edit .card.card-dragging {
        opacity: 0.5;
        cursor: grabbing;
    }

/* While editing, inner controls/charts shouldn't capture the drag. */
.details-grid.layout-edit .card * {
    pointer-events: none;
}

/* -- Warranty card -------------------------------------------------------- */
.warranty-countdown {
    margin-top: 10px;
    font-weight: 600;
    font-size: 14px;
}

.warranty-ok { color: #86efac; }
.warranty-warn { color: #fde68a; }
.warranty-critical { color: #fca5a5; }
.warranty-expired { color: #fca5a5; }

.warranty-edit {
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.warranty-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

    .warranty-field label {
        font-size: 12px;
        color: var(--muted);
    }

    .warranty-field .input-text {
        max-width: 260px;
    }

.warranty-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 4px;
}

.warranty-status {
    color: #86efac;
    font-size: 13px;
}
