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; }
}

/* ── History Map Layout ──────────────────────────────── */
.history-map-layout {
    display: flex;
    height: calc(100vh - 56px);
    margin: -1.5rem -0.5rem -1.5rem -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;
}

.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;
}

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

.history-map-status {
    padding: 0.35rem 1rem;
    border-top: 1px solid #dee2e6;
    background: #fff;
}

.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) {
    .history-map-layout {
        height: calc(100vh - 56px);
    }

    .history-map-panel {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    }

    .history-map-panel.panel-open {
        transform: translateX(0);
    }

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

    .history-map-panel.panel-open ~ .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 entirely */
.sidebar-collapsed .sidebar-submenu-items {
    max-height: 0 !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;
}
