body {
    background-color: #ffffff;
}

/* ── Sidebar layout ──────────────────────────────────── */
:root {
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 76px;
    --sidebar-transition: 0.25s ease;
}

/* Grid wrapper */
.admin-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
    transition: grid-template-columns var(--sidebar-transition);
}

.admin-layout.sidebar-collapsed {
    grid-template-columns: var(--sidebar-collapsed-width) 1fr;
}

/* Sidebar */
.admin-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-color);
    display: flex;
    flex-direction: column;
    overflow: visible;
    transition: width var(--sidebar-transition);
    width: var(--sidebar-width);
    z-index: 1040;
}

.sidebar-collapsed .admin-sidebar {
    width: var(--sidebar-collapsed-width);
}

/* Brand — styled like a nav-link */
.sidebar-brand {
    position: relative;
    padding: 0.75rem 0 0.25rem;
    white-space: nowrap;
    border-bottom: 1px solid var(--sidebar-border-color);
}

.sidebar-brand-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    color: var(--sidebar-color);
    text-decoration: none;
    white-space: nowrap;
    border-radius: 0.375rem;
    margin: 0.125rem 0.5rem;
    transition: background var(--sidebar-transition), color var(--sidebar-transition);
}

.sidebar-brand-link:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-hover-color);
}

.sidebar-brand img,
.sidebar-brand-link > i {
    font-size: 1.15rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-brand img {
    max-height: 28px;
}

.sidebar-brand-text {
    overflow: hidden;
    font-weight: 600;
    transition: opacity var(--sidebar-transition), width var(--sidebar-transition);
    opacity: 1;
}

.sidebar-collapsed .sidebar-brand-text {
    opacity: 0;
    width: 0;
}

/* Two-logo mode: remove gap so invisible icon doesn't create asymmetric left space */
.sidebar-brand-link:has(.sidebar-brand-icon) {
    gap: 0;
}

/* Two-logo mode: icon hidden when expanded, wide logo fills width; icon shows when collapsed */
.sidebar-brand img.sidebar-brand-icon {
    opacity: 0;
    width: 0;
    overflow: hidden;
    flex-shrink: 0;
    transition: opacity var(--sidebar-transition), width var(--sidebar-transition);
}

.sidebar-collapsed .sidebar-brand img.sidebar-brand-icon {
    opacity: 1;
    width: 1.25rem;
}

.sidebar-brand img.sidebar-brand-expanded {
    width: 100%;
    height: auto;
    max-height: none;
    flex-shrink: 1;
    min-width: 0;
    transition: opacity var(--sidebar-transition), max-width var(--sidebar-transition);
    opacity: 1;
}

.sidebar-collapsed .sidebar-brand img.sidebar-brand-expanded {
    opacity: 0;
    max-width: 0;
    overflow: hidden;
}

/* Toggle button — floating circle on sidebar edge */
.sidebar-toggle {
    position: absolute;
    bottom: -12px;
    right: -12px;
    z-index: 1;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border-color);
    color: var(--sidebar-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: transform var(--sidebar-transition), background var(--sidebar-transition);
}

.sidebar-toggle:hover {
    color: var(--sidebar-hover-color);
    background: var(--sidebar-toggle-hover-bg);
    border-color: var(--sidebar-border-color);
}

.sidebar-collapsed .sidebar-toggle {
    transform: rotate(180deg);
}

/* Nav links */
.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-gutter: stable;
}

.sidebar-nav::-webkit-scrollbar {
    width: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    color: var(--sidebar-color);
    text-decoration: none;
    white-space: nowrap;
    border-radius: 0.375rem;
    margin: 0.125rem 0.5rem;
    transition: background var(--sidebar-transition), color var(--sidebar-transition);
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-hover-color);
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-color);
}

.sidebar-nav .nav-link i {
    font-size: 1.15rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.notification-badge {
    background: #dc3545;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 1.15rem;
    height: 1.15rem;
    line-height: 1.15rem;
    text-align: center;
    border-radius: 999px;
    padding: 0 0.3rem;
    margin-left: auto;
    flex-shrink: 0;
}

.sidebar-collapsed .notification-badge {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    min-width: 0.75rem;
    height: 0.75rem;
    font-size: 0;
    padding: 0;
}

.sidebar-nav .nav-link {
    position: relative;
}

.sidebar-label {
    overflow: hidden;
    transition: opacity var(--sidebar-transition), width var(--sidebar-transition);
    opacity: 1;
}

.sidebar-collapsed .sidebar-label {
    opacity: 0;
    width: 0;
}

/* Footer (user + logout) */
.sidebar-footer {
    border-top: 1px solid var(--sidebar-border-color);
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-footer .sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--sidebar-color);
    font-size: 0.875rem;
    padding: 0.25rem 0;
    text-decoration: none;
    transition: color var(--sidebar-transition);
}

.sidebar-footer .sidebar-user:hover {
    color: var(--sidebar-hover-color);
}

.sidebar-footer .sidebar-user i {
    font-size: 1.15rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer .sidebar-logout {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--sidebar-color);
    text-decoration: none;
    padding: 0.4rem 0;
    font-size: 0.875rem;
    transition: color var(--sidebar-transition);
}

.sidebar-footer .sidebar-logout:hover {
    color: var(--sidebar-hover-color);
}

.sidebar-footer .sidebar-logout i {
    font-size: 1.15rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

/* Main content */
.admin-main {
    min-width: 0;
    background: #ffffff;
}

/* Backdrop (mobile only) */
.sidebar-backdrop {
    display: none;
}

/* Mobile header (hamburger bar) */
.sidebar-mobile-header {
    display: none;
}

/* ── Mobile (< 768px) ────────────────────────────────── */
@media (max-width: 767.98px) {
    .admin-layout {
        grid-template-columns: 1fr;
    }

    .admin-layout.sidebar-collapsed {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform var(--sidebar-transition);
        z-index: 1050;
    }

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

    /* Always show labels on mobile (never collapsed state) */
    .sidebar-collapsed .sidebar-label,
    .sidebar-collapsed .sidebar-brand-text {
        opacity: 1;
        width: auto;
    }

    .sidebar-collapsed .admin-sidebar {
        width: var(--sidebar-width);
    }

    .sidebar-collapsed .sidebar-toggle {
        transform: none;
    }

    /* Hide desktop toggle on mobile */
    .sidebar-toggle {
        display: none;
    }

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

    .sidebar-open .sidebar-backdrop {
        display: block;
    }

    /* Mobile header bar */
    .sidebar-mobile-header {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
        background: var(--sidebar-bg);
        color: var(--sidebar-hover-color);
    }

    .sidebar-mobile-header .btn {
        color: var(--sidebar-color);
        border: none;
        font-size: 1.25rem;
        padding: 0.25rem 0.5rem;
    }

    .sidebar-mobile-header .btn:hover {
        color: var(--sidebar-hover-color);
    }

    .sidebar-mobile-header .mobile-brand {
        font-weight: 600;
        font-size: 1.1rem;
        color: var(--sidebar-hover-color);
        text-decoration: none;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .sidebar-mobile-header .mobile-brand img {
        max-height: 28px;
    }

    .sidebar-mobile-header .mobile-brand .mobile-brand-expanded {
        max-height: 32px;
        width: auto;
        max-width: 160px;
    }

    .admin-main .container-fluid { padding: 1rem !important; }

    [data-geozone-map-target="container"] { height: 300px !important; }

    .card-header-tabs.overflow-auto {
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .card-header-tabs.overflow-auto::-webkit-scrollbar { display: none; }
}

/* ── Viewport-locked pages ───────────────────────────────
   Opt-in via {% block admin_layout_class %}admin-layout-viewport{% endblock %}.
   The layout fills exactly the window height and the page itself never
   scrolls — inner panes scroll instead. Structural (no hardcoded header
   height), so it stays correct whatever the tenant logo does to the
   mobile header. */
.admin-layout-viewport {
    height: 100vh;
    grid-template-rows: 1fr;
}

@supports (height: 100dvh) {
    .admin-layout-viewport {
        height: 100dvh;
    }
}

.admin-layout-viewport .admin-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.admin-layout-viewport .admin-main > .container-fluid {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* ── History Map Layout ──────────────────────────────── */
.history-map-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    /* cancels the .container-fluid p-4 padding on all four sides */
    margin: -1.5rem;
    overflow: hidden;
}

.history-map-panel {
    width: 320px;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #dee2e6;
    background: #fff;
}

.panel-header {
    padding: 0.75rem 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

/* The header doubles as the mobile bottom-sheet handle. Everything but the
   title is d-md-none in the markup, so on desktop this row renders exactly as
   the plain heading it has always been. */
.sheet-headline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* The whole header strip toggles the sheet; this button is the keyboard- and
   screen-reader-facing control, so it still needs a real hit area. */
.sheet-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    margin-left: auto;
    margin-right: -0.25rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: #6c757d;
    line-height: 1;
}

.sheet-chevron {
    display: block;
    font-size: 0.8rem;
    transition: transform 0.28s ease;
}

/* Peek-strip chips (mobile only) — readout when collapsed, tabs when open */
.sheet-chips {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.sheet-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
    padding: 0.2rem 0.6rem;
    border: 1px solid #dee2e6;
    border-radius: 999px;
    background: #fff;
    color: #212529;
    font-size: 0.8125rem;
    line-height: 1.5;
}

.sheet-chip > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* When room runs short it is the period label (the variable one) that gives
   way — the device chip's single word should never be cut. */
.sheet-chips > .sheet-chip {
    flex-shrink: 0;
}

.sheet-chips > .sheet-chip:last-child {
    flex-shrink: 1;
}

.sheet-chip > i {
    color: #6c757d;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.sheet-full .sheet-chip.is-active {
    border-color: var(--theme-primary);
    color: var(--theme-primary);
}

.sheet-full .sheet-chip.is-active > i {
    color: inherit;
}

.sheet-chip-count {
    flex-shrink: 0;
    min-width: 1.25rem;
    padding: 0 0.3rem;
    border-radius: 999px;
    background: var(--theme-primary);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.25rem;
    text-align: center;
}

/* Period pane — only ever visible below md, on the "period" tab */
.sheet-pane-period {
    display: none;
}

.period-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    padding: 0.65rem 0.25rem;
    border: 0;
    border-bottom: 1px solid #f1f3f5;
    background: none;
    color: #212529;
    font-size: 0.95rem;
    text-align: left;
}

.period-row .period-row-mark {
    color: var(--theme-primary);
    font-size: 0.9rem;
    opacity: 0;
    transition: transform 0.2s ease;
}

.period-row.is-active {
    font-weight: 600;
}

.period-row.is-active .period-row-mark {
    opacity: 1;
}

.period-row-custom .period-row-mark {
    color: #6c757d;
    opacity: 1;
}

.period-row-custom[aria-expanded="true"] .period-row-mark {
    transform: rotate(180deg);
}

.period-custom {
    padding: 0.75rem 0.25rem 0.25rem;
}

.period-actions {
    padding-top: 1rem;
}

.panel-filters {
    padding: 0.75rem;
    border-bottom: 1px solid #dee2e6;
}

.panel-search-wrap {
    position: relative;
}

.panel-search-wrap input {
    padding-right: 1.75rem;
}

.panel-search-clear {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    color: #6c757d;
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
}

.panel-search-clear:hover {
    color: #212529;
}

.panel-user-list {
    flex: 1;
    overflow-y: auto;
}

.user-group-header {
    display: flex;
    align-items: center;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    user-select: none;
}

.user-group-header label {
    cursor: pointer;
    margin-bottom: 0;
}

.user-group-chevron {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.user-group-header[aria-expanded="false"] .user-group-chevron,
.user-group-header.collapsed .user-group-chevron {
    transform: rotate(-90deg);
}

.advanced-settings-chevron {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.collapsed .advanced-settings-chevron {
    transform: rotate(0deg);
}

a:not(.collapsed) .advanced-settings-chevron {
    transform: rotate(90deg);
}

.user-item {
    padding: 0.25rem 0.75rem 0.25rem 2rem;
    border-bottom: 1px solid #f5f5f5;
    transition: background-color 0.1s ease;
}

.user-item:hover {
    background-color: #f0f4ff;
}

.user-item label {
    cursor: pointer;
    margin-bottom: 0;
    min-width: 0;
}

.user-item label .small {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-actions {
    display: flex;
    gap: 0.2rem;
    padding-left: 0.25rem;
}

.user-action-icon {
    color: #6c757d;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    padding: 2px 4px;
    border-radius: 3px;
    text-decoration: none;
    line-height: 1;
}

.user-action-icon:hover {
    color: var(--theme-primary);
    background-color: rgba(0, 0, 0, 0.05);
}

/* ── Device Status Dot ── */
.device-status-dot {
    display: inline-flex;
    align-self: center;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin: 0 0.35rem;
    cursor: pointer;
    border: 1px solid rgba(0, 0, 0, 0.15);
    transition: transform 0.15s ease;
}
.device-status-dot:hover { transform: scale(1.3); }
.device-status-ok      { background-color: var(--bs-success); color: var(--bs-success); }
.device-status-warning { background-color: var(--bs-warning); color: var(--bs-warning); }
.device-status-silent  { background-color: var(--bs-danger);  color: var(--bs-danger); }

@keyframes statusPulse {
    0%   { box-shadow: 0 0 0 0 currentColor; }
    70%  { box-shadow: 0 0 0 6px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}
.device-status-pulse { animation: statusPulse 0.6s ease-out; }

.history-map-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.history-map-toolbar {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid #dee2e6;
    background: #fff;
}

/* Own classes rather than Bootstrap utilities: below md these same nodes are
   moved into the sheet, where they have to stack — and utility classes carry
   !important, which makes them impossible to restyle in the new context. */
.map-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.map-filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.map-filter-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.history-map-container {
    flex: 1;
    position: relative;
    /* queried by .history-map-status: what matters is how wide the *map* is,
       not the window (the side panel eats 320px of it) */
    container: map / inline-size;
}

/* Status readout — floats over the map (bottom-left, the corner Leaflet
   leaves free: zoom is top-left, legend + attribution are bottom-right)
   so it takes no vertical space away from the map.
   Capped at 52% so it can never run into the legend.
   pointer-events:none keeps the map draggable underneath it. */
.history-map-status {
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 1000;
    max-width: min(52%, 520px);
    padding: 0.3rem 0.65rem;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.15);
    pointer-events: none;
}

/* Narrow map (phones, or a desktop window squeezed next to the panel):
   52% would leave the text in a 2-3 line stub, so the pill moves to the free
   top strip instead — clear of the zoom control on the left, and of the
   legend + attribution which own the bottom of a narrow map. */
@container map (max-width: 640px) {
    .history-map-status {
        top: 10px;
        bottom: auto;
        left: 54px;
        right: 10px;
        max-width: none;
    }
}

.map-panel-backdrop {
    display: none;
}

#history-map {
    height: 100%;
    width: 100%;
    z-index: 0;
    border-radius: 0;
}

.leaflet-popup-content {
    font-size: 0.875rem;
}

/* ── History Map Mobile ─────────────────────────────── */
@media (max-width: 767.98px) {
    /* row 1 = mobile header (auto), row 2 = main (rest of the window) */
    .admin-layout-viewport {
        grid-template-rows: auto 1fr;
    }

    /* .container-fluid drops to 1rem padding on mobile — match it */
    .history-map-layout {
        margin: -1rem;
        /* How much of the sheet stays on screen when collapsed. The fallback
           covers the first paint; map_sheet_controller replaces it with the
           measured header height so the peek strip is exactly the handle. */
        --sheet-peek: 3.4rem;
    }

    /* ── Device panel → bottom sheet ──
       A left drawer read as a second navigation menu (the app menu is one too)
       and its icon-only trigger in the toolbar was easy to miss. As a sheet it
       is always partly on screen, so it advertises itself. Two states: peek
       (handle only) and full; map_sheet_controller drives the drag/snap. */
    .history-map-panel {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        min-width: 0;
        /* --sheet-h is set by the controller for the short "period" tab, so the
           sheet only takes the room that tab actually needs. */
        height: var(--sheet-h, 85vh);
        z-index: 1050;
        border-right: 0;
        border-top: 1px solid #dee2e6;
        border-radius: 1rem 1rem 0 0;
        box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.18);
        padding-bottom: env(safe-area-inset-bottom);
        transform: translateY(calc(100% - var(--sheet-peek)));
        transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1),
                    height 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    }

    @supports (height: 100dvh) {
        .history-map-panel {
            height: var(--sheet-h, 85dvh);
        }
    }

    .history-map-panel.sheet-full {
        transform: translateY(0);
    }

    /* While a finger is on the handle the transform follows it directly */
    .history-map-panel.sheet-dragging {
        transition: none;
    }

    .panel-header {
        padding: 0 1rem 0.65rem;
        border-radius: 1rem 1rem 0 0;
        /* the drag gesture owns this strip; the list below still scrolls */
        touch-action: none;
        user-select: none;
        cursor: pointer;
    }

    .sheet-grabber {
        display: block;
        width: 2.25rem;
        height: 0.25rem;
        margin: 0.5rem auto 0.5rem;
        border-radius: 999px;
        background: #ced4da;
    }

    /* Chips centred across the whole strip — the chevron is taken out of the
       flow so it cannot pull them off centre. */
    .sheet-headline {
        position: relative;
    }

    .sheet-chips {
        flex: 1;
        justify-content: center;
        /* symmetric room for the chevron, so a long period label neither runs
           under it nor pushes the pair off centre */
        padding: 0 2rem;
    }

    .sheet-toggle {
        position: absolute;
        right: -0.25rem;
        top: 50%;
        margin: 0;
        transform: translateY(-50%);
    }

    .sheet-full .sheet-chevron {
        transform: rotate(180deg);
    }

    /* ── Filter bar → the sheet's "period" tab ──
       The bar itself is gone below md (it cost 142px of a 844px screen for
       three rows of controls); its controls are moved into the pane below by
       map_sheet_controller. The <select> stays here, hidden but live. */
    .history-map-toolbar {
        display: none;
    }

    .history-map-panel.tab-period .panel-filters,
    .history-map-panel.tab-period .panel-user-list {
        display: none;
    }

    .history-map-panel.tab-period .sheet-pane-period {
        display: block;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 0.25rem 1rem 1rem;
    }

    /* Stacked, full width — the toolbar's inline layout makes no sense here */
    .period-custom .map-filter-group {
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
    }

    .period-custom .map-filter-group + .map-filter-group {
        margin-top: 0.75rem;
    }

    .period-actions .map-filter-actions {
        margin-left: 0;
    }

    .period-actions .btn {
        flex: 1;
    }

    .panel-user-list {
        overscroll-behavior: contain;
    }

    /* Legend + attribution live bottom-right; lift them above the peek strip */
    .history-map-container .leaflet-bottom {
        margin-bottom: calc(var(--sheet-peek) + env(safe-area-inset-bottom));
    }

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

    .history-map-panel.sheet-full ~ .map-panel-backdrop {
        display: block;
    }
}

/* Multi-select dropdown */
.multi-select-dropdown {
    max-height: 300px;
    overflow-y: auto;
}

.multi-select-dropdown .dropdown-item {
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
}

.multi-select-dropdown label {
    cursor: pointer;
    user-select: none;
}

/* Map legend */
.leaflet-legend {
    background: white;
    padding: 8px 12px;
    border-radius: 6px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
    font-size: 0.8rem;
    line-height: 1.6;
}

.leaflet-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.leaflet-legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.leaflet-marker-endpoint {
    background: none;
    border: none;
}

/* ── Share location public page ──────────────────────── */
.share-map-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: relative;
}

.share-map-header {
    background: #fff;
    border-bottom: 1px solid #dee2e6;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    z-index: 1000;
    flex-shrink: 0;
}

.share-map-header-inner {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.share-map-container {
    flex: 1;
    position: relative;
}

.share-map-container .leaflet-container {
    height: 100%;
    width: 100%;
}

.share-map-marker {
    color: #dc3545;
    font-size: 2rem;
    line-height: 1;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.share-expired-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.share-expired-overlay-inner {
    text-align: center;
    padding: 2rem;
}

/* ── Share expired standalone page ── */
.share-expired-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f8f9fa;
}

.share-expired-card {
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    padding: 2.5rem 3rem;
    text-align: center;
    max-width: 400px;
}

.share-expired-icon {
    font-size: 3rem;
    color: #6c757d;
}

/* ── Share page small-screen fix ────────────────────── */
@media (max-width: 575.98px) {
    .share-expired-card { padding: 1.5rem; margin: 0 1rem; }
}

/* ── Tom Select overrides ────────────────────────────── */
.ts-wrapper.form-select {
    padding: 0;
}

.ts-wrapper.form-select .ts-control {
    border: none;
    box-shadow: none;
    padding: 0.375rem 0.75rem;
    background: transparent;
    min-height: unset;
    position: relative;
    overflow: hidden;
}

/* Item text: single line with ellipsis, fills full width */
.ts-wrapper.form-select .ts-control .item {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Search input: absolutely positioned over the control — out of flex flow,
   so it never affects the control's height or the item's width */
.ts-wrapper.form-select .ts-control input {
    position: absolute;
    inset: 0;
    width: 100% !important;
    padding: 0.375rem 0.75rem 0.375rem 1rem !important;
    background: transparent;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    min-width: 0 !important;
    opacity: 0;
    pointer-events: none;
}

/* When open: show the input and fade out the item text */
.ts-wrapper.form-select.open .ts-control input,
.ts-wrapper.form-select.focus .ts-control input {
    opacity: 1;
    pointer-events: auto;
}

.ts-wrapper.form-select.open .ts-control .item,
.ts-wrapper.form-select.focus .ts-control .item {
    opacity: 0;
}

/* ── Locale select dropdown ──────────────────────────── */
.locale-dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.locale-flag {
    font-size: 1.25rem;
    line-height: 1;
}

.locale-check {
    color: var(--theme-primary, #0d6efd);
}

/* ── Sidebar submenu ─────────────────────────────────── */
.sidebar-submenu-items {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.submenu-open .sidebar-submenu-items {
    max-height: 300px;
}

.sidebar-submenu-link {
    padding-left: 2.5rem !important;
    font-size: 0.9rem;
}

.sidebar-submenu-chevron {
    margin-left: auto;
    transition: transform 0.25s ease;
    flex-shrink: 0;
}

.submenu-open .sidebar-submenu-chevron {
    transform: rotate(180deg);
}

/* Collapsed sidebar: hide submenu items unless the submenu is toggled open */
.sidebar-collapsed .sidebar-submenu:not(.submenu-open) .sidebar-submenu-items {
    max-height: 0 !important;
}

/* Collapsed sidebar: align submenu icons with the top-level icons (drop the indent) */
.sidebar-collapsed .sidebar-submenu-link {
    padding-left: 1rem !important;
}

/* ── Geozone filter panel ────────────────────────────── */
.geozone-filter-panel {
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    overflow: hidden;
}

.geozone-filter-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.geozone-filter-search {
    flex: 1;
    max-width: 280px;
}

.geozone-filter-actions {
    white-space: nowrap;
}

.geozone-filter-list {
    max-height: 260px;
    overflow-y: auto;
}

.geozone-filter-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.75rem;
    border-bottom: 1px solid #f0f0f0;
    gap: 0.5rem;
}

.geozone-filter-option:last-child {
    border-bottom: none;
}

.geozone-filter-option:hover {
    background: #f8f9fa;
}

.geozone-filter-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    margin: 0;
    flex: 1;
    min-width: 0;
}

.geozone-filter-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.geozone-filter-radios {
    display: flex;
    gap: 0.75rem;
    flex-shrink: 0;
}

.geozone-filter-radios.disabled {
    opacity: 0.4;
}

.geozone-radio-label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin: 0;
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
}

.geozone-color-dot {
    display: inline-block;
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.15);
}

/* ── Device filter panel ────────────────────────────── */
.device-filter-panel {
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    overflow: hidden;
}

.device-filter-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.device-filter-search-wrap {
    position: relative;
    flex: 1;
}

.device-filter-search-wrap .form-control {
    padding-right: 1.75rem;
}

.device-filter-search-clear {
    position: absolute;
    right: 0.35rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0;
    line-height: 1;
    color: #6c757d;
    cursor: pointer;
}

.device-filter-search-clear:hover {
    color: #212529;
}

.device-filter-list {
    max-height: 260px;
    overflow-y: auto;
}

/* ── Device avatars (per-device icon + colour) ── */

/* The glyph as rendered next to a plate in lists (map panel, device table,
   share header). Sized relative to the surrounding text so it fits anywhere. */
.device-avatar {
    flex-shrink: 0;
    font-size: 1em;
    line-height: 1;
    width: 1.15em;
    text-align: center;
}

/* Map marker: the avatar glyph on a white disc (same look as the device list),
   same footprint as the generic truck marker it replaces. The glyph colour and
   the route-colour ring are set inline — see avatarMarkerHtml(). */
.leaflet-marker-avatar {
    background: none;
    border: none;
}

.map-avatar-marker {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
}

/* ── Avatar picker (device form) ── */
.avatar-picker-preview {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid #dee2e6;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.avatar-picker-groups {
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
}

.avatar-picker-group + .avatar-picker-group {
    margin-top: 0.5rem;
}

.avatar-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 4px;
}

.avatar-picker-option {
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 6px 0;
    font-size: 18px;
    color: #495057;
    line-height: 1;
    cursor: pointer;
}

.avatar-picker-option:hover {
    background-color: #f0f4ff;
}

.avatar-picker-option.is-selected {
    border-color: var(--theme-primary);
    background-color: #f0f4ff;
}

.avatar-picker-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.avatar-picker-swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid transparent;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
    padding: 0;
    cursor: pointer;
}

.avatar-picker-swatch.is-selected {
    border-color: #fff;
    box-shadow: 0 0 0 2px var(--theme-primary);
}
