        :root {
            --bg-dark: #090e17;
            --bg-card: #111a2e;
            --bg-card-hover: #16223b;
            --bg-input: #0b121e;
            --border-color: #1e2c45;
            --border-focus: #00d2ff;

            --accent-cyan: #00d2ff;
            --accent-blue: #3a86ff;
            --accent-green: #10b981;
            --accent-green-glow: rgba(16, 185, 129, 0.35);
            --accent-amber: #f59e0b;
            --accent-red: #ef4444;
            --accent-red-glow: rgba(239, 68, 68, 0.35);
            --accent-purple: #a855f7;

            --text-main: #f8fafc;
            --text-muted: #94a3b8;
            --text-dim: #64748b;

            --header-h: 68px;
            --kpi-h: 90px;
            --radius-md: 14px;
            --radius-sm: 8px;
            --shadow-glow: 0 0 25px rgba(0, 210, 255, 0.15);
            --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.4);
            --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        }

        *,
        *::before,
        *::after {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            -webkit-tap-highlight-color: transparent;
        }

        html {
            background-color: var(--bg-dark);
            color: var(--text-main);
            width: 100%;
            height: 100%;
            overflow-x: hidden;
            font-size: 16px;
        }

        body {
            font-family: 'Cairo', sans-serif;
            background-color: var(--bg-dark);
            color: var(--text-main);
            height: 100%;
            height: 100vh;
            height: 100dvh;
            width: 100%;
            max-width: 100vw;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            margin: 0;
            padding: 0;
        }

        /* --- Header --- */
        header {
            height: var(--header-h);
            background: linear-gradient(180deg, #111a2e 0%, #0c1424 100%);
            border-bottom: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 1.25rem;
            z-index: 1000;
            flex-shrink: 0;
            width: 100%;
            max-width: 100vw;
            min-width: 0;
        }

        .header-brand {
            display: flex;
            align-items: center;
            gap: 0.85rem;
        }

        .logo-icon {
            width: 44px;
            height: 44px;
            background: linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-cyan) 100%);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 1.35rem;
            box-shadow: 0 0 18px rgba(0, 210, 255, 0.35);
        }

        .brand-text h1 {
            font-size: 1.15rem;
            font-weight: 800;
            color: var(--text-main);
            letter-spacing: -0.5px;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .brand-text span {
            font-size: 0.75rem;
            color: var(--accent-cyan);
            font-family: 'JetBrains Mono', monospace;
            font-weight: 600;
        }

        .header-actions {
            display: flex;
            align-items: center;
            gap: 0.65rem;
        }

        /* Firebase Status Indicator */
        .conn-pill {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            background: rgba(16, 185, 129, 0.12);
            border: 1px solid rgba(16, 185, 129, 0.3);
            color: var(--accent-green);
            padding: 0.4rem 0.85rem;
            border-radius: 50px;
            font-size: 0.78rem;
            font-weight: 700;
        }

        .conn-pill.disconnected {
            background: rgba(239, 68, 68, 0.12);
            border-color: rgba(239, 68, 68, 0.3);
            color: var(--accent-red);
        }

        .conn-pill.connecting {
            background: rgba(245, 158, 11, 0.12);
            border-color: rgba(245, 158, 11, 0.3);
            color: var(--accent-amber);
        }

        .pulse-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background-color: currentColor;
            animation: pulseAnim 1.8s infinite;
        }

        @keyframes pulseAnim {
            0% {
                transform: scale(0.9);
                opacity: 0.7;
            }

            50% {
                transform: scale(1.3);
                opacity: 1;
                filter: drop-shadow(0 0 6px currentColor);
            }

            100% {
                transform: scale(0.9);
                opacity: 0.7;
            }
        }

        .timeout-pill {
            display: flex;
            align-items: center;
            gap: 0.4rem;
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            padding: 0.35rem 0.65rem;
            border-radius: 50px;
            font-size: 0.76rem;
            color: var(--text-muted);
            transition: var(--transition);
        }

        .timeout-pill:hover {
            border-color: var(--accent-cyan);
        }

        .usage-pill {
            display: flex;
            align-items: center;
            gap: 0.45rem;
            background: rgba(56, 189, 248, 0.08);
            border: 1px solid rgba(56, 189, 248, 0.28);
            padding: 0.35rem 0.65rem;
            border-radius: 50px;
            font-size: 0.76rem;
            font-weight: 700;
            color: #38bdf8;
            cursor: pointer;
            transition: var(--transition);
        }

        .usage-pill:hover {
            background: rgba(56, 189, 248, 0.16);
            border-color: #38bdf8;
            box-shadow: 0 0 12px rgba(56, 189, 248, 0.25);
            transform: translateY(-1px);
        }

        .usage-period-btn {
            flex: 1;
            background: transparent;
            border: none;
            color: var(--text-dim);
            padding: 0.35rem 0.4rem;
            border-radius: 6px;
            font-size: 0.72rem;
            font-weight: 700;
            cursor: pointer;
            transition: var(--transition);
            text-align: center;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 0.3rem;
            white-space: nowrap;
        }

        .usage-period-btn.active {
            background: var(--bg-card);
            color: #38bdf8;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
            border: 1px solid rgba(56, 189, 248, 0.35);
        }

        .usage-period-btn:hover:not(.active) {
            color: #fff;
            background: rgba(255, 255, 255, 0.06);
        }

        .timeout-select {
            background: transparent;
            border: none;
            color: var(--accent-cyan);
            font-family: inherit;
            font-size: 0.76rem;
            font-weight: 700;
            outline: none;
            cursor: pointer;
        }

        .timeout-select option {
            background: #0c1424;
            color: #fff;
        }

        .btn-icon {
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            color: var(--text-muted);
            width: 38px;
            height: 38px;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: var(--transition);
            font-size: 0.95rem;
        }

        .btn-icon:hover {
            color: var(--text-main);
            border-color: var(--accent-cyan);
            background: var(--bg-card-hover);
        }

        .mobile-close-btn {
            display: none;
        }

        .sheet-drag-handle {
            display: none;
        }

        /* --- KPI Summary Bar --- */
        .kpi-container {
            background: #0d1524;
            border-bottom: 1px solid var(--border-color);
            padding: 0.65rem 1.25rem;
            display: flex;
            gap: 0.85rem;
            overflow-x: auto;
            scrollbar-width: thin;
            flex-shrink: 0;
            width: 100%;
            max-width: 100vw;
            min-width: 0;
        }

        .kpi-container::-webkit-scrollbar {
            height: 4px;
        }

        .kpi-container::-webkit-scrollbar-thumb {
            background: var(--border-color);
            border-radius: 4px;
        }

        .kpi-card {
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            border-radius: 12px;
            padding: 0.6rem 1rem;
            display: flex;
            align-items: center;
            gap: 0.85rem;
            min-width: 145px;
            flex: 1;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
            transition: var(--transition);
            cursor: pointer;
        }

        .kpi-card:hover,
        .kpi-card.active {
            border-color: var(--card-accent, var(--accent-cyan));
            transform: translateY(-1px);
        }

        .kpi-card.active {
            background: rgba(0, 210, 255, 0.08);
        }

        .kpi-icon {
            width: 38px;
            height: 38px;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.1rem;
            background: rgba(255, 255, 255, 0.05);
            color: var(--card-accent, var(--accent-cyan));
        }

        .kpi-content {
            display: flex;
            flex-direction: column;
        }

        .kpi-title {
            font-size: 0.72rem;
            color: var(--text-muted);
            font-weight: 600;
        }

        .kpi-value {
            font-size: 1.25rem;
            font-weight: 800;
            font-family: 'JetBrains Mono', monospace;
            color: var(--text-main);
            line-height: 1.2;
        }

        /* --- Main Layout: Map & Sidebar --- */
        .main-wrapper {
            flex: 1;
            display: flex;
            position: relative;
            overflow: hidden;
            width: 100%;
            max-width: 100vw;
            min-width: 0;
            min-height: 0;
        }

        /* Map Container */
        #map-container {
            flex: 1;
            height: 100%;
            position: relative;
            background: #090e17;
        }

        #map {
            width: 100%;
            height: 100%;
            z-index: 10;
        }

        /* Map Overlay Controls */
        .map-floating-controls {
            position: absolute;
            top: 1rem;
            right: 1rem;
            z-index: 500;
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
        }

        .floating-btn {
            background: rgba(17, 26, 46, 0.92);
            backdrop-filter: blur(12px);
            border: 1px solid var(--border-color);
            color: var(--text-main);
            padding: 0.55rem 0.9rem;
            border-radius: 10px;
            font-size: 0.8rem;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            cursor: pointer;
            box-shadow: var(--shadow-card);
            transition: var(--transition);
        }

        .floating-btn:hover {
            background: var(--bg-card-hover);
            border-color: var(--accent-cyan);
            color: var(--accent-cyan);
        }

        /* Sidebar Container (Desktop Side, Mobile Bottom Sheet or Drawer) */
        .sidebar {
            width: 420px;
            height: 100%;
            background: var(--bg-card);
            border-right: 1px solid var(--border-color);
            display: flex;
            flex-direction: column;
            z-index: 600;
            flex-shrink: 0;
            transition: transform 0.3s ease;
        }

        .sidebar-header {
            padding: 1rem;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            flex-direction: column;
            gap: 0.75rem;
            background: #0d1524;
        }

        .search-box {
            position: relative;
            width: 100%;
        }

        .search-box i {
            position: absolute;
            right: 0.85rem;
            top: 50%;
            transform: translateY(-50%);
            color: var(--text-dim);
            font-size: 0.85rem;
        }

        .search-input {
            width: 100%;
            background: var(--bg-input);
            border: 1px solid var(--border-color);
            padding: 0.6rem 2.4rem 0.6rem 0.85rem;
            border-radius: 10px;
            color: var(--text-main);
            font-family: inherit;
            font-size: 0.85rem;
            outline: none;
            transition: var(--transition);
        }

        .search-input:focus {
            border-color: var(--accent-cyan);
            box-shadow: 0 0 10px rgba(0, 210, 255, 0.2);
        }

        .filter-chips {
            display: flex;
            gap: 0.4rem;
            overflow-x: auto;
            padding-bottom: 2px;
        }

        .chip {
            background: var(--bg-input);
            border: 1px solid var(--border-color);
            color: var(--text-muted);
            padding: 0.25rem 0.65rem;
            border-radius: 20px;
            font-size: 0.72rem;
            font-weight: 600;
            cursor: pointer;
            white-space: nowrap;
            transition: var(--transition);
        }

        .chip:hover,
        .chip.active {
            background: var(--accent-blue);
            color: #fff;
            border-color: var(--accent-blue);
        }

        /* Devices List */
        .devices-list {
            flex: 1;
            overflow-y: auto;
            padding: 0.75rem;
            display: flex;
            flex-direction: column;
            gap: 0.6rem;
        }

        .devices-list::-webkit-scrollbar {
            width: 5px;
        }

        .devices-list::-webkit-scrollbar-thumb {
            background: var(--border-color);
            border-radius: 5px;
        }

        /* Device Card */
        .device-card {
            background: #0d1525;
            border: 1px solid var(--border-color);
            border-radius: 11px;
            padding: 0.75rem 0.85rem;
            display: flex;
            flex-direction: column;
            gap: 0.48rem;
            transition: var(--transition);
            cursor: pointer;
            position: relative;
        }

        .device-card:hover {
            border-color: var(--accent-cyan);
            background: #101b30;
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
        }

        .device-card.selected {
            border-color: var(--accent-cyan);
            background: rgba(0, 210, 255, 0.06);
            box-shadow: 0 0 16px rgba(0, 210, 255, 0.25);
        }

        @keyframes cardFlash {
            0% {
                transform: scale(1);
                box-shadow: 0 0 0 rgba(0, 210, 255, 0);
            }

            35% {
                transform: scale(1.02);
                box-shadow: 0 0 24px rgba(0, 210, 255, 0.65);
                border-color: var(--accent-cyan);
            }

            100% {
                transform: scale(1);
                box-shadow: 0 0 16px rgba(0, 210, 255, 0.25);
            }
        }

        .device-card.flash-highlight {
            animation: cardFlash 1.5s ease-out;
            border-color: var(--accent-cyan) !important;
        }

        .card-top {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 0.5rem;
        }

        .device-title-area {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            flex: 1;
            overflow: hidden;
        }

        .device-icon-box {
            width: 34px;
            height: 34px;
            border-radius: 9px;
            background: rgba(255, 255, 255, 0.05);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.95rem;
            flex-shrink: 0;
            color: var(--accent-cyan);
        }

        .device-names {
            display: flex;
            flex-direction: column;
            overflow: hidden;
            min-width: 0;
            gap: 0.15rem;
        }

        .device-custom-name {
            font-weight: 700;
            font-size: 0.92rem;
            color: var(--text-main);
            display: flex;
            align-items: center;
            gap: 0.4rem;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            line-height: 1.25;
        }

        .btn-rename {
            color: var(--text-dim);
            font-size: 0.72rem;
            cursor: pointer;
            transition: var(--transition);
        }

        .btn-rename:hover {
            color: var(--accent-cyan);
        }

        .device-mac {
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.68rem;
            color: var(--text-dim);
            line-height: 1.1;
        }

        .status-badge {
            padding: 0.22rem 0.55rem;
            border-radius: 12px;
            font-size: 0.7rem;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 0.32rem;
            white-space: nowrap;
            flex-shrink: 0;
        }

        .status-badge.online-moving {
            background: rgba(16, 185, 129, 0.15);
            color: var(--accent-green);
            border: 1px solid rgba(16, 185, 129, 0.3);
        }

        .status-badge.online-parked {
            background: rgba(58, 134, 255, 0.15);
            color: var(--accent-blue);
            border: 1px solid rgba(58, 134, 255, 0.3);
        }

        .status-badge.powersaving {
            background: rgba(245, 158, 11, 0.15);
            color: #fbbf24;
            border: 1px solid rgba(245, 158, 11, 0.35);
        }

        .status-badge.offline {
            background: rgba(100, 116, 139, 0.15);
            color: var(--text-dim);
            border: 1px solid rgba(100, 116, 139, 0.3);
        }

        .sort-select {
            background: var(--bg-input);
            border: 1px solid var(--border-color);
            color: var(--accent-cyan);
            font-family: inherit;
            font-size: 0.74rem;
            font-weight: 700;
            padding: 0.25rem 0.65rem;
            border-radius: 8px;
            outline: none;
            cursor: pointer;
            transition: var(--transition);
        }

        .sort-select:hover,
        .sort-select:focus {
            border-color: var(--accent-cyan);
        }

        .sort-select option {
            background: #0c1424;
            color: #fff;
        }

        /* Card Metrics Grid */
        .card-metrics {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            gap: 0.35rem;
            background: rgba(0, 0, 0, 0.25);
            padding: 0.45rem 0.6rem;
            border-radius: 8px;
            border: 1px solid rgba(255, 255, 255, 0.05);
        }

        .metric-cell {
            display: flex;
            flex-direction: column;
            min-width: 0;
        }

        .metric-label {
            font-size: 0.64rem;
            color: var(--text-dim);
            line-height: 1.1;
            margin-bottom: 3px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .metric-val {
            font-size: 0.78rem;
            font-weight: 700;
            font-family: 'JetBrains Mono', monospace;
            color: var(--text-main);
            display: flex;
            align-items: center;
            gap: 0.22rem;
            line-height: 1.2;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .card-footer {
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 0.72rem;
            color: var(--text-muted);
            border-top: 1px solid rgba(255, 255, 255, 0.05);
            padding-top: 0.38rem;
        }

        .card-actions {
            display: flex;
            align-items: center;
            gap: 0.3rem;
        }

        .mini-btn {
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            color: var(--text-muted);
            padding: 0.18rem 0.48rem;
            border-radius: 6px;
            font-size: 0.68rem;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
            gap: 0.22rem;
            line-height: 1.2;
        }

        .mini-btn:hover {
            color: var(--accent-cyan);
            border-color: var(--accent-cyan);
        }

        .mini-btn.btn-control {
            background: linear-gradient(135deg, rgba(0, 210, 255, 0.12) 0%, rgba(58, 134, 255, 0.22) 100%);
            border: 1px solid rgba(0, 210, 255, 0.35);
            color: var(--accent-cyan);
            font-weight: 700;
        }

        .mini-btn.btn-control:hover {
            background: linear-gradient(135deg, rgba(0, 210, 255, 0.25) 0%, rgba(58, 134, 255, 0.38) 100%);
            border-color: var(--accent-cyan);
            color: #fff;
            box-shadow: 0 0 10px rgba(0, 210, 255, 0.3);
        }

        .mini-btn.btn-delete {
            color: var(--accent-red);
            border-color: rgba(239, 68, 68, 0.35);
            background: rgba(239, 68, 68, 0.08);
        }

        .mini-btn.btn-delete:hover {
            background: rgba(239, 68, 68, 0.22);
            border-color: var(--accent-red);
            color: #fff;
            box-shadow: 0 0 10px rgba(239, 68, 68, 0.35);
        }

        .mini-btn.btn-reset-loc {
            color: #f59e0b;
            border-color: rgba(245, 158, 11, 0.35);
            background: rgba(245, 158, 11, 0.08);
        }

        .mini-btn.btn-reset-loc:hover {
            background: rgba(245, 158, 11, 0.22);
            border-color: #f59e0b;
            color: #fff;
            box-shadow: 0 0 10px rgba(245, 158, 11, 0.35);
        }

        /* Empty State */
        .empty-state {
            padding: 2.5rem 1rem;
            text-align: center;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 0.75rem;
            color: var(--text-muted);
        }

        .empty-state i {
            font-size: 2.5rem;
            color: var(--text-dim);
        }

        /* --- Mobile Bottom Nav Switcher --- */
        .mobile-bottom-nav {
            display: none;
            height: 56px;
            background: #0d1525;
            border-top: 1px solid var(--border-color);
            z-index: 1000;
            flex-shrink: 0;
        }

        .mobile-nav-btn {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 0.2rem;
            color: var(--text-muted);
            font-size: 0.75rem;
            font-weight: 600;
            background: transparent;
            border: none;
            cursor: pointer;
        }

        .mobile-nav-btn.active {
            color: var(--accent-cyan);
        }

        .mobile-nav-btn i {
            font-size: 1.1rem;
        }

        /* --- Modals (Rename & Add Device & Config) --- */
        .modal-backdrop {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.75);
            backdrop-filter: blur(6px);
            z-index: 2000;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 1rem;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease;
        }

        .modal-backdrop.open {
            opacity: 1;
            pointer-events: auto;
        }

        .modal-box {
            background: #111a2e;
            border: 1px solid var(--border-color);
            border-radius: var(--radius-md);
            width: 100%;
            max-width: 440px;
            box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
            overflow: hidden;
            display: flex;
            flex-direction: column;
            transform: translateY(20px);
            transition: transform 0.25s ease;
        }

        .modal-backdrop.open .modal-box {
            transform: translateY(0);
        }

        .modal-header {
            padding: 1rem 1.25rem;
            background: #0c1424;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .modal-header h3 {
            font-size: 1.05rem;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .modal-close {
            background: transparent;
            border: none;
            color: var(--text-dim);
            font-size: 1.1rem;
            cursor: pointer;
            transition: var(--transition);
        }

        .modal-close:hover {
            color: var(--accent-red);
        }

        .modal-body {
            padding: 1.25rem;
            display: flex;
            flex-direction: column;
            gap: 1rem;
        }

        .form-group {
            display: flex;
            flex-direction: column;
            gap: 0.4rem;
        }

        .form-group label {
            font-size: 0.8rem;
            font-weight: 600;
            color: var(--text-muted);
        }

        .form-control {
            background: var(--bg-input);
            border: 1px solid var(--border-color);
            padding: 0.65rem 0.85rem;
            border-radius: 8px;
            color: var(--text-main);
            font-family: inherit;
            font-size: 0.9rem;
            outline: none;
            transition: var(--transition);
        }

        .form-control:focus {
            border-color: var(--accent-cyan);
            box-shadow: 0 0 10px rgba(0, 210, 255, 0.2);
        }

        .modal-footer {
            padding: 0.85rem 1.25rem;
            background: #0c1424;
            border-top: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            justify-content: flex-end;
            gap: 0.65rem;
        }

        .btn-primary {
            background: linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-cyan) 100%);
            border: none;
            color: #fff;
            padding: 0.55rem 1.25rem;
            border-radius: 8px;
            font-family: inherit;
            font-weight: 700;
            font-size: 0.85rem;
            cursor: pointer;
            transition: var(--transition);
        }

        .btn-primary:hover {
            filter: brightness(1.15);
            box-shadow: 0 0 15px rgba(0, 210, 255, 0.4);
        }

        .btn-secondary {
            background: var(--bg-card);
            border: 1px solid var(--border-color);
            color: var(--text-muted);
            padding: 0.55rem 1rem;
            border-radius: 8px;
            font-family: inherit;
            font-size: 0.85rem;
            cursor: pointer;
        }

        .btn-danger {
            background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
            border: 1px solid rgba(239, 68, 68, 0.4);
            color: #fff;
            padding: 0.55rem 1.25rem;
            border-radius: 8px;
            font-family: inherit;
            font-weight: 700;
            font-size: 0.85rem;
            cursor: pointer;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            gap: 0.4rem;
        }

        .btn-danger:hover {
            filter: brightness(1.15);
            box-shadow: 0 0 15px rgba(239, 68, 68, 0.45);
        }

        .pin-last-badge {
            position: absolute;
            top: -5px;
            right: -5px;
            background: #f59e0b;
            color: #000;
            border-radius: 50%;
            width: 15px;
            height: 15px;
            font-size: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 1.5px solid #111a2e;
            box-shadow: 0 0 6px rgba(245, 158, 11, 0.8);
            z-index: 10;
        }

        .last-known-pin {
            border: 2px dashed #f59e0b !important;
            box-shadow: 0 0 12px rgba(245, 158, 11, 0.35) !important;
        }

        .last-loc-tag {
            font-size: 0.58rem;
            color: #fbbf24;
            background: rgba(245, 158, 11, 0.15);
            border: 1px solid rgba(245, 158, 11, 0.3);
            border-radius: 4px;
            padding: 0.05rem 0.25rem;
            display: inline-flex;
            align-items: center;
            margin-right: 0.25rem;
            font-family: 'Cairo', sans-serif;
            font-weight: 600;
        }

        /* --- Leaflet Custom Markers & Popups --- */
        .leaflet-popup-content-wrapper {
            background: #111a2e !important;
            color: var(--text-main) !important;
            border: 1px solid var(--border-color);
            border-radius: 12px !important;
            box-shadow: var(--shadow-card) !important;
            padding: 0 !important;
        }

        .leaflet-popup-content {
            margin: 7px 9px !important;
            line-height: 1.3 !important;
            direction: rtl !important;
            text-align: right !important;
        }

        .leaflet-popup-tip {
            background: #111a2e !important;
            border: 1px solid var(--border-color);
        }

        .leaflet-popup-close-button {
            top: 5px !important;
            right: auto !important;
            left: 6px !important;
            color: var(--text-dim) !important;
            padding: 0 !important;
            font-size: 15px !important;
            width: 18px !important;
            height: 18px !important;
            line-height: 18px !important;
            text-align: center;
        }

        .leaflet-popup-close-button:hover {
            color: var(--accent-red) !important;
        }

        .marker-pin {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background: var(--marker-color, var(--accent-blue));
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 1rem;
            box-shadow: 0 0 15px var(--marker-color, var(--accent-blue));
            border: 2px solid #ffffff;
            position: relative;
        }

        .marker-pin.pulsing::after {
            content: '';
            position: absolute;
            inset: -6px;
            border-radius: 50%;
            border: 2px solid var(--marker-color, var(--accent-green));
            animation: radarPulse 1.8s infinite;
        }

        @keyframes radarPulse {
            0% {
                transform: scale(0.9);
                opacity: 1;
            }

            100% {
                transform: scale(1.8);
                opacity: 0;
            }
        }

        .map-popup-card {
            font-family: 'Cairo', sans-serif;
            min-width: 240px;
            max-width: 280px;
            padding: 0.35rem 0.45rem;
            display: flex;
            flex-direction: column;
            gap: 0.28rem;
            direction: rtl !important;
            text-align: right !important;
            box-sizing: border-box;
            overflow: hidden;
            position: relative;
        }

        .popup-title {
            font-weight: 800;
            font-size: 0.88rem;
            color: var(--text-main);
            display: flex;
            align-items: center;
            justify-content: flex-start;
            gap: 0.35rem;
            padding-bottom: 0.12rem;
            padding-left: 24px; /* Prevent overlap with Leaflet X button on top-left */
            padding-right: 0;
            direction: rtl !important;
            text-align: right !important;
            width: 100%;
            box-sizing: border-box;
        }

        .popup-title-text {
            width: 100%;
            min-width: 0;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            direction: rtl !important;
            text-align: right !important;
            display: block;
        }

        .popup-subtitle {
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 0.64rem;
            color: var(--text-dim);
            padding-bottom: 0.2rem;
            border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        }

        .popup-subtitle code {
            font-family: 'JetBrains Mono', monospace;
            color: var(--accent-cyan);
            font-size: 0.65rem;
        }

        .popup-status-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 0.35rem;
            padding: 0.15rem 0.35rem;
            background: rgba(255, 255, 255, 0.035);
            border: 1px solid rgba(255, 255, 255, 0.06);
            border-radius: 6px;
        }

        .popup-lastknown-badge {
            background: rgba(245, 158, 11, 0.12);
            border: 1px solid rgba(245, 158, 11, 0.28);
            border-radius: 5px;
            padding: 0.15rem 0.35rem;
            font-size: 0.64rem;
            color: #fbbf24;
            display: flex;
            align-items: center;
            gap: 0.25rem;
        }

        .popup-table {
            display: flex;
            flex-direction: column;
            gap: 0.18rem;
            background: rgba(15, 23, 42, 0.65);
            border: 1px solid rgba(255, 255, 255, 0.08);
            border-radius: 8px;
            padding: 0.28rem 0.45rem;
        }

        .popup-item-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0.16rem 0;
            border-bottom: 1px solid rgba(255, 255, 255, 0.04);
            gap: 0.5rem;
        }

        .popup-item-row:last-child {
            border-bottom: none;
        }

        .cell-label {
            font-size: 0.63rem;
            color: var(--text-muted);
            display: flex;
            align-items: center;
            gap: 0.2rem;
            white-space: nowrap;
            flex-shrink: 0;
        }

        .cell-val {
            font-size: 0.72rem;
            font-weight: 700;
            color: var(--text-main);
            font-family: 'JetBrains Mono', 'Cairo', sans-serif;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            direction: ltr;
            text-align: left;
        }

        .popup-mini-footer {
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 0.64rem;
            color: var(--text-dim);
            padding: 0.05rem 0.15rem;
        }

        .popup-wake-chip {
            max-width: 130px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            font-size: 0.62rem;
            font-weight: 600;
        }

        .popup-actions-bar {
            display: flex;
            align-items: center;
            gap: 0.25rem;
            margin-top: 0.15rem;
        }

        .popup-btn {
            background: var(--accent-blue);
            color: #fff;
            text-align: center;
            text-decoration: none;
            padding: 0.28rem 0.42rem;
            border-radius: 6px;
            font-size: 0.72rem;
            font-weight: 700;
            white-space: nowrap;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 0.22rem;
            border: none;
            cursor: pointer;
            transition: var(--transition);
        }

        .popup-btn:hover {
            filter: brightness(1.15);
        }

        .popup-btn-control {
            flex: 1.2;
            background: linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-cyan) 100%) !important;
            color: #fff !important;
            box-shadow: 0 2px 8px rgba(0, 210, 255, 0.25);
        }

        .popup-btn-list {
            flex: 1;
            background: rgba(14, 165, 233, 0.16) !important;
            border: 1px solid rgba(14, 165, 233, 0.35) !important;
            color: #38bdf8 !important;
        }

        .popup-btn-icon {
            padding: 0.28rem 0.38rem;
            background: #16243d;
            border: 1px solid var(--border-color);
            color: var(--accent-cyan);
        }

        .popup-btn-amber {
            background: rgba(245, 158, 11, 0.15) !important;
            border: 1px solid rgba(245, 158, 11, 0.35) !important;
            color: #fbbf24 !important;
        }

        .popup-btn-red {
            background: rgba(239, 68, 68, 0.15) !important;
            border: 1px solid rgba(239, 68, 68, 0.35) !important;
            color: #ef4444 !important;
        }

        /* --- Fullscreen / Map Expanded Mode --- */
        .main-wrapper.map-expanded .sidebar {
            display: none !important;
        }

        .main-wrapper.map-expanded #map-container {
            width: 100% !important;
            flex: 1 !important;
        }

        /* --- Remote Control Modal Styles --- */
        .control-status-banner {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0.6rem 0.75rem;
            background: rgba(0, 0, 0, 0.28);
            border: 1px solid var(--border-color);
            border-radius: 10px;
        }

        .control-device-info h4 {
            font-size: 0.88rem;
            font-weight: 800;
            color: var(--text-main);
        }

        .control-device-info span {
            font-size: 0.66rem;
            font-family: 'JetBrains Mono', monospace;
            color: var(--text-dim);
        }

        .control-state-pill {
            font-size: 0.66rem;
            font-weight: 700;
            padding: 0.22rem 0.6rem;
            border-radius: 50px;
            display: flex;
            align-items: center;
            gap: 0.35rem;
        }

        .control-actions-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 0.6rem;
            margin-top: 0.2rem;
        }

        .btn-control-action {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 0.4rem;
            padding: 0.85rem 0.65rem;
            border-radius: 10px;
            border: 1px solid transparent;
            cursor: pointer;
            transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
            color: #fff;
            text-align: center;
            font-family: inherit;
        }

        .btn-control-action.unlock {
            background: linear-gradient(145deg, rgba(16, 185, 129, 0.2) 0%, rgba(5, 150, 105, 0.35) 100%);
            border-color: rgba(16, 185, 129, 0.45);
        }

        .btn-control-action.unlock:hover:not(:disabled) {
            background: linear-gradient(145deg, rgba(16, 185, 129, 0.35) 0%, rgba(5, 150, 105, 0.55) 100%);
            border-color: var(--accent-green);
            transform: translateY(-2px);
            box-shadow: 0 8px 24px rgba(16, 185, 129, 0.35);
        }

        .btn-control-action.lock {
            background: linear-gradient(145deg, rgba(239, 68, 68, 0.2) 0%, rgba(220, 38, 38, 0.35) 100%);
            border-color: rgba(239, 68, 68, 0.45);
        }

        .btn-control-action.lock:hover:not(:disabled) {
            background: linear-gradient(145deg, rgba(239, 68, 68, 0.35) 0%, rgba(220, 38, 38, 0.55) 100%);
            border-color: var(--accent-red);
            transform: translateY(-2px);
            box-shadow: 0 8px 24px rgba(239, 68, 68, 0.35);
        }

        .btn-control-action:disabled {
            opacity: 0.45;
            cursor: not-allowed;
            transform: none !important;
            filter: grayscale(0.5);
        }

        .btn-control-action i {
            font-size: 1.5rem;
        }

        .btn-control-action .action-title {
            font-weight: 800;
            font-size: 0.85rem;
        }

        .btn-control-action .action-desc {
            font-size: 0.65rem;
            opacity: 0.85;
            font-weight: 500;
            line-height: 1.3;
        }

        /* Secondary actions grid (Start, Stop, Alarm, Starter) */
        .control-subactions-grid {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            gap: 0.4rem;
            margin-top: 0.1rem;
        }

        @media (max-width: 480px) {
            .control-subactions-grid {
                grid-template-columns: repeat(3, 1fr);
            }
        }

        .btn-subaction {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 0.25rem;
            padding: 0.55rem 0.3rem;
            border-radius: 8px;
            border: 1px solid var(--border-color);
            background: rgba(0, 0, 0, 0.25);
            color: var(--text-main);
            cursor: pointer;
            transition: all 0.2s ease;
            font-family: inherit;
            text-align: center;
        }

        .btn-subaction:disabled {
            opacity: 0.45;
            cursor: not-allowed;
            transform: none !important;
            filter: grayscale(0.5);
        }

        .btn-subaction i {
            font-size: 1.1rem;
            transition: transform 0.2s ease;
        }

        .btn-subaction .subaction-title {
            font-size: 0.68rem;
            font-weight: 700;
            white-space: nowrap;
        }

        .btn-subaction .subaction-cmd {
            font-size: 0.56rem;
            font-family: 'JetBrains Mono', monospace;
            opacity: 0.7;
        }

        .btn-subaction.start {
            border-color: rgba(0, 210, 255, 0.35);
            background: linear-gradient(145deg, rgba(0, 210, 255, 0.1) 0%, rgba(58, 134, 255, 0.15) 100%);
            color: #38bdf8;
        }

        .btn-subaction.start:hover:not(:disabled) {
            border-color: var(--accent-cyan);
            background: linear-gradient(145deg, rgba(0, 210, 255, 0.22) 0%, rgba(58, 134, 255, 0.3) 100%);
            box-shadow: 0 4px 15px rgba(0, 210, 255, 0.3);
            transform: translateY(-2px);
            color: #fff;
        }

        .btn-subaction.stop {
            border-color: rgba(239, 68, 68, 0.35);
            background: linear-gradient(145deg, rgba(239, 68, 68, 0.1) 0%, rgba(185, 28, 28, 0.15) 100%);
            color: #f87171;
        }

        .btn-subaction.stop:hover:not(:disabled) {
            border-color: var(--accent-red);
            background: linear-gradient(145deg, rgba(239, 68, 68, 0.22) 0%, rgba(185, 28, 28, 0.3) 100%);
            box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
            transform: translateY(-2px);
            color: #fff;
        }

        .btn-subaction.alarm {
            border-color: rgba(245, 158, 11, 0.35);
            background: linear-gradient(145deg, rgba(245, 158, 11, 0.1) 0%, rgba(217, 119, 6, 0.15) 100%);
            color: #fbbf24;
        }

        .btn-subaction.alarm:hover:not(:disabled) {
            border-color: var(--accent-amber);
            background: linear-gradient(145deg, rgba(245, 158, 11, 0.22) 0%, rgba(217, 119, 6, 0.3) 100%);
            box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
            transform: translateY(-2px);
            color: #fff;
        }

        .btn-subaction.vib {
            border-color: rgba(56, 189, 248, 0.35);
            background: linear-gradient(145deg, rgba(56, 189, 248, 0.1) 0%, rgba(14, 165, 233, 0.15) 100%);
            color: var(--accent-cyan);
        }

        .btn-subaction.vib:hover:not(:disabled) {
            border-color: var(--accent-cyan);
            background: linear-gradient(145deg, rgba(56, 189, 248, 0.22) 0%, rgba(14, 165, 233, 0.3) 100%);
            box-shadow: 0 4px 15px rgba(56, 189, 248, 0.3);
            transform: translateY(-2px);
            color: #fff;
        }

        .btn-subaction.starter {
            border-color: rgba(168, 85, 247, 0.35);
            background: linear-gradient(145deg, rgba(168, 85, 247, 0.1) 0%, rgba(126, 34, 206, 0.15) 100%);
            color: #c084fc;
        }

        .btn-subaction.starter:hover:not(:disabled) {
            border-color: var(--accent-purple);
            background: linear-gradient(145deg, rgba(168, 85, 247, 0.22) 0%, rgba(126, 34, 206, 0.3) 100%);
            box-shadow: 0 4px 15px rgba(168, 85, 247, 0.3);
            transform: translateY(-2px);
            color: #fff;
        }

        .control-feedback-box {
            display: none;
            padding: 0.65rem 0.85rem;
            border-radius: 8px;
            font-size: 0.75rem;
            line-height: 1.4;
            align-items: flex-start;
            gap: 0.6rem;
            animation: fadeIn 0.3s ease;
        }

        .control-feedback-box i {
            margin-top: 3px;
            font-size: 1rem;
            flex-shrink: 0;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-5px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .control-feedback-box.show {
            display: flex;
        }

        .control-feedback-box.info {
            background: rgba(0, 210, 255, 0.1);
            border: 1px solid rgba(0, 210, 255, 0.3);
            color: var(--accent-cyan);
        }

        .control-feedback-box.success {
            background: rgba(16, 185, 129, 0.12);
            border: 1px solid rgba(16, 185, 129, 0.35);
            color: var(--accent-green);
        }

        .control-feedback-box.error {
            background: rgba(239, 68, 68, 0.12);
            border: 1px solid rgba(239, 68, 68, 0.35);
            color: var(--accent-red);
        }

        .password-input-wrapper {
            position: relative;
            display: flex;
            align-items: center;
        }

        .password-input-wrapper input {
            padding-left: 2.5rem;
        }

        .password-toggle-btn {
            position: absolute;
            left: 0.75rem;
            background: transparent;
            border: none;
            color: var(--text-dim);
            cursor: pointer;
            font-size: 0.95rem;
            padding: 0.25rem;
            transition: var(--transition);
        }

        .password-toggle-btn:hover {
            color: var(--accent-cyan);
        }

        /* --- Remote Control Modal Landscape & Responsive Enhancements --- */
        .modal-box-control {
            max-width: 840px !important;
            width: 94% !important;
            max-height: 90vh !important;
            border-radius: 14px;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        .modal-body-control {
            padding: 0.85rem 1.15rem !important;
            max-height: calc(90vh - 105px) !important;
            overflow-y: auto !important;
            overscroll-behavior: contain;
        }

        .control-landscape-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 0.95rem;
            align-items: start;
        }

        .control-col-primary,
        .control-col-diagnostics {
            display: flex;
            flex-direction: column;
            gap: 0.65rem;
            min-width: 0;
        }

        .ctrl-metrics-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 0.35rem;
            background: rgba(0, 0, 0, 0.22);
            padding: 0.42rem 0.5rem;
            border-radius: 8px;
            border: 1px solid var(--border-color);
            text-align: center;
        }

        /* --- Responsive Queries --- */

        /* Tablets & Small Laptops */
        @media (max-width: 960px) {
            .sidebar {
                width: 350px;
            }
        }

        /* Mobile Phones (< 768px) */
        @media (max-width: 768px) {
            :root {
                --header-h: 54px;
            }

            /* Single-row compact header: NO wrapping, NO overflow */
            header {
                height: 54px;
                padding: 0 0.65rem;
                gap: 0.35rem;
                flex-wrap: nowrap;
                justify-content: space-between;
                width: 100%;
                max-width: 100vw;
                min-width: 0;
            }

            .header-brand {
                gap: 0.45rem;
                flex-shrink: 0;
            }

            .logo-icon {
                width: 34px;
                height: 34px;
                border-radius: 9px;
                font-size: 1rem;
            }

            .brand-text h1 {
                font-size: 0.95rem;
                white-space: nowrap;
            }

            .brand-text h1 span {
                font-size: 0.68rem;
            }

            /* Hide verbose subtitle on mobile to fit nicely */
            .brand-text span#version-label {
                display: none;
            }

            .header-actions {
                gap: 0.3rem;
                flex-shrink: 0;
                flex-wrap: nowrap;
            }

            .conn-pill {
                padding: 0.22rem 0.45rem;
                font-size: 0.68rem;
                gap: 0.3rem;
                white-space: nowrap;
            }

            .conn-pill .pulse-dot {
                width: 6px;
                height: 6px;
            }

            .timeout-pill {
                padding: 0.2rem 0.35rem;
                font-size: 0.68rem;
                gap: 0.2rem;
            }

            .timeout-select {
                font-size: 0.68rem;
                max-width: 70px;
            }

            .usage-pill {
                padding: 0.2rem 0.4rem;
                font-size: 0.68rem;
                gap: 0.25rem;
                white-space: nowrap;
            }

            .btn-icon {
                width: 32px;
                height: 32px;
                border-radius: 8px;
                font-size: 0.8rem;
                flex-shrink: 0;
            }

            .mobile-close-btn {
                display: flex;
            }

            /* KPI Bar: horizontal scroll with touch momentum, compact cards */
            .kpi-container {
                padding: 0.35rem 0.5rem;
                gap: 0.4rem;
                width: 100%;
                max-width: 100vw;
                min-width: 0;
                overflow-x: auto;
                overflow-y: hidden;
                white-space: nowrap;
                -webkit-overflow-scrolling: touch;
                scrollbar-width: none;
            }

            .kpi-container::-webkit-scrollbar {
                display: none;
            }

            .kpi-card {
                min-width: 100px;
                max-width: 115px;
                padding: 0.35rem 0.5rem;
                gap: 0.4rem;
                border-radius: 10px;
                flex: 0 0 auto;
            }

            .kpi-icon {
                width: 28px;
                height: 28px;
                border-radius: 7px;
                font-size: 0.85rem;
            }

            .kpi-title {
                font-size: 0.58rem;
                white-space: nowrap;
            }

            .kpi-value {
                font-size: 1rem;
            }

            /* Main Workspace */
            .main-wrapper {
                flex: 1;
                min-height: 0;
                width: 100%;
                max-width: 100vw;
                min-width: 0;
                position: relative;
                overflow: hidden;
                padding-bottom: 56px;
                /* Leave space for bottom nav */
            }

            #map-container {
                width: 100%;
                height: 100%;
            }

            /* Sidebar acts as sleek bottom sheet drawer */
            .sidebar {
                width: 100%;
                max-width: 100vw;
                height: calc(80vh - 56px);
                position: fixed;
                left: 0;
                right: 0;
                bottom: 56px;
                top: auto;
                z-index: 900;
                border-right: none;
                border-top: 1px solid var(--border-color);
                border-radius: 20px 20px 0 0;
                box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.7);
                background: #0d1525;
                transform: translateY(100%);
                transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
                display: flex;
                flex-direction: column;
            }

            .sidebar.active-mobile {
                transform: translateY(0);
            }

            /* Interactive Drawer Drag Handle bar */
            .sheet-drag-handle {
                display: flex;
                align-items: center;
                justify-content: center;
                width: 100%;
                height: 28px;
                cursor: pointer;
                touch-action: none;
                flex-shrink: 0;
                padding: 6px 0;
            }

            .sheet-drag-pill {
                width: 48px;
                height: 5px;
                background: var(--text-dim);
                border-radius: 4px;
                opacity: 0.65;
                transition: var(--transition);
                pointer-events: none;
            }

            .sheet-drag-handle:active .sheet-drag-pill {
                opacity: 1;
                background: var(--accent-cyan);
                transform: scaleX(1.2);
            }

            .sidebar-header {
                padding: 0.55rem 0.75rem;
                gap: 0.45rem;
            }

            .search-input {
                padding: 0.5rem 2rem 0.5rem 0.75rem;
                font-size: 0.8rem;
            }

            .filter-chips {
                gap: 0.25rem;
            }

            .chip {
                padding: 0.2rem 0.5rem;
                font-size: 0.66rem;
            }

            /* Device cards inside list */
            .devices-list {
                padding: 0.5rem;
                gap: 0.45rem;
            }

            .device-card {
                padding: 0.65rem;
                gap: 0.45rem;
                border-radius: 10px;
            }

            .device-icon-box {
                width: 32px;
                height: 32px;
                border-radius: 8px;
                font-size: 0.88rem;
            }

            .device-custom-name {
                font-size: 0.82rem;
            }

            .device-mac {
                font-size: 0.64rem;
            }

            .status-badge {
                font-size: 0.62rem;
                padding: 0.18rem 0.4rem;
            }

            .card-metrics {
                grid-template-columns: repeat(5, 1fr) !important;
                padding: 0.35rem 0.45rem;
                gap: 0.25rem;
            }

            .metric-label {
                font-size: 0.58rem;
            }

            .metric-val {
                font-size: 0.7rem;
            }

            .card-footer {
                font-size: 0.65rem;
            }

            .mini-btn {
                font-size: 0.65rem;
                padding: 0.2rem 0.45rem;
            }

            /* Mobile Bottom Navigation Bar */
            .mobile-bottom-nav {
                display: flex;
                position: fixed;
                bottom: 0;
                left: 0;
                right: 0;
                height: 56px;
                background: #090e17;
                border-top: 1px solid var(--border-color);
                z-index: 1000;
                width: 100%;
                max-width: 100vw;
            }

            .mobile-nav-btn {
                flex: 1;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                gap: 0.2rem;
                color: var(--text-muted);
                font-size: 0.72rem;
                font-weight: 700;
                background: transparent;
                border: none;
                cursor: pointer;
                transition: var(--transition);
            }

            .mobile-nav-btn.active {
                color: var(--accent-cyan);
                background: rgba(0, 210, 255, 0.06);
            }

            .mobile-nav-btn i {
                font-size: 1.15rem;
            }

            /* Map floating controls on mobile */
            .map-floating-controls {
                top: 0.55rem;
                right: 0.55rem;
                gap: 0.4rem;
            }

            .floating-btn {
                padding: 0.4rem 0.65rem;
                font-size: 0.72rem;
                border-radius: 8px;
            }

            .floating-btn span {
                display: none;
            }

            /* Map Popup on mobile */
            .leaflet-popup-content {
                margin: 5px 7px !important;
                direction: rtl !important;
                text-align: right !important;
            }

            .map-popup-card {
                min-width: 200px !important;
                max-width: 235px !important;
                padding: 0.22rem 0.32rem !important;
                gap: 0.18rem !important;
                direction: rtl !important;
                text-align: right !important;
            }

            .popup-title {
                font-size: 0.74rem !important;
                padding-left: 20px !important;
                padding-right: 0 !important;
                direction: rtl !important;
                text-align: right !important;
                justify-content: flex-start !important;
                width: 100% !important;
            }

            .popup-title-text {
                direction: rtl !important;
                text-align: right !important;
                display: block !important;
                width: 100% !important;
            }

            .popup-subtitle {
                font-size: 0.58rem !important;
            }

            .cell-label {
                font-size: 0.59rem !important;
            }

            .cell-val {
                font-size: 0.66rem !important;
            }

            .popup-item-row {
                padding: 0.1rem 0 !important;
            }

            .popup-btn {
                padding: 0.18rem 0.28rem !important;
                font-size: 0.62rem !important;
            }

            /* Modals on mobile */
            .modal-box {
                max-width: 94vw;
            }

            .modal-header {
                padding: 0.75rem 1rem;
            }

            .modal-body {
                padding: 0.9rem;
            }

            /* --- Control Modal Mobile Optimization (Bottom Sheet) --- */
            #modal-control {
                align-items: flex-end;
                padding: 0;
            }

            #modal-control .modal-box,
            .modal-box-control {
                max-width: 100vw !important;
                width: 100vw !important;
                max-height: 92vh !important;
                border-radius: 18px 18px 0 0 !important;
                transform: translateY(100%);
            }

            #modal-control.open .modal-box,
            #modal-control.open .modal-box-control {
                transform: translateY(0);
            }

            #modal-control .modal-header {
                padding: 0.65rem 0.85rem;
                position: sticky;
                top: 0;
                z-index: 1;
            }

            #modal-control .modal-header h3 {
                font-size: 0.88rem;
                gap: 0.35rem;
            }

            #modal-control .modal-body,
            .modal-body-control {
                padding: 0.6rem 0.75rem !important;
                gap: 0.6rem !important;
                max-height: calc(92vh - 95px) !important;
                overflow-y: auto !important;
            }

            .control-landscape-grid {
                grid-template-columns: 1fr !important;
                gap: 0.65rem !important;
            }

            .control-status-banner {
                padding: 0.5rem 0.65rem;
                border-radius: 10px;
                flex-wrap: wrap;
                gap: 0.35rem;
            }

            .control-device-info h4 {
                font-size: 0.85rem;
            }

            .control-device-info span {
                font-size: 0.62rem;
            }

            .control-state-pill {
                font-size: 0.64rem;
                padding: 0.2rem 0.5rem;
            }

            /* Metrics grid inside control modal */
            .ctrl-metrics-grid {
                grid-template-columns: repeat(4, 1fr) !important;
                gap: 0.25rem !important;
                padding: 0.35rem 0.45rem !important;
            }

            .ctrl-metrics-grid [style*="font-size: 0.65rem"] {
                font-size: 0.58rem !important;
            }

            .ctrl-metrics-grid [style*="font-size: 0.8rem"] {
                font-size: 0.72rem !important;
                margin-top: 0.1rem !important;
            }

            /* Password section compact */
            #modal-control .form-group label {
                font-size: 0.7rem;
            }

            #modal-control .form-control {
                padding: 0.45rem 0.65rem;
                font-size: 0.78rem;
            }

            #modal-control .mini-btn {
                font-size: 0.58rem !important;
                padding: 0.12rem 0.3rem !important;
            }

            /* Main action buttons compact */
            .control-actions-grid {
                gap: 0.5rem;
                margin-top: 0.15rem;
            }

            .btn-control-action {
                padding: 0.7rem 0.45rem;
                gap: 0.25rem;
                border-radius: 10px;
            }

            .btn-control-action i {
                font-size: 1.35rem;
            }

            .btn-control-action .action-title {
                font-size: 0.76rem;
            }

            .btn-control-action .action-desc {
                font-size: 0.58rem;
            }

            /* Sub-action buttons compact */
            .control-subactions-grid {
                gap: 0.3rem;
                margin-top: 0.1rem;
            }

            .btn-subaction {
                padding: 0.45rem 0.2rem;
                gap: 0.2rem;
                border-radius: 8px;
            }

            .btn-subaction i {
                font-size: 0.95rem;
            }

            .btn-subaction .subaction-title {
                font-size: 0.62rem;
            }

            .btn-subaction .subaction-cmd {
                font-size: 0.5rem;
            }

            /* Feedback box compact */
            .control-feedback-box {
                padding: 0.5rem 0.65rem;
                font-size: 0.72rem;
                gap: 0.4rem;
            }

            /* Footer compact */
            #modal-control .modal-footer {
                padding: 0.5rem 0.7rem;
                position: sticky;
                bottom: 0;
                background: #111a2e;
                border-top: 1px solid var(--border-color);
            }

            #modal-control .modal-footer span {
                font-size: 0.62rem !important;
            }

            /* Save password checkbox compact */
            #modal-control #chk-save-pwd+label,
            #modal-control label[style*="font-size: 0.75rem"] {
                font-size: 0.65rem !important;
            }
        }

        /* Extra small phones (< 380px) */
        @media (max-width: 380px) {
            header {
                padding: 0 0.45rem;
            }

            .brand-text h1 {
                font-size: 0.88rem;
            }

            .conn-pill span#firebase-conn-text {
                display: none;
                /* Only show pulsing dot on super small screens */
            }

            .kpi-card {
                min-width: 88px;
                padding: 0.3rem 0.4rem;
            }

            .card-metrics {
                grid-template-columns: repeat(2, 1fr) !important;
            }
        }

#compass-icon {
    color: var(--accent-cyan);
    font-size: 1rem;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* --- Live Feature Status Buttons Bar (أزرار التحكم والحالة الحية للميزات - أيقونات مدمجة في صف واحد) --- */
.card-features-bar,
.popup-features-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.3rem;
    flex-wrap: nowrap !important; /* صف واحد فقط بدون التفاف */
    margin: 0.2rem 0;
    padding: 0.18rem 0.35rem;
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 7px;
    direction: rtl !important;
    text-align: center !important;
    box-sizing: border-box;
    width: 100%;
}

.feat-btn {
    flex: 1 1 0; /* توزيع العرض بالتساوي التام على الأيقونات الـ 5 */
    min-width: 0;
    height: 27px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    padding: 0;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    user-select: none;
    line-height: 1;
    box-sizing: border-box;
}

.feat-btn i {
    pointer-events: none;
    line-height: 1;
}

.feat-btn:hover {
    transform: translateY(-1px) scale(1.08);
    filter: brightness(1.3);
    z-index: 2;
}

.feat-btn:active {
    transform: translateY(0) scale(0.95);
}

/* Lock Locked: Red */
.feat-btn.feat-lock-locked {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.45);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.25);
}

/* Lock Unlocked: Green */
.feat-btn.feat-lock-unlocked {
    background: rgba(34, 197, 94, 0.16);
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.35);
}

/* Active Engine: Pulsing Emerald */
.feat-btn.feat-engine-on {
    background: rgba(16, 185, 129, 0.24);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.55);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
    animation: featPulseGreen 2s infinite ease-in-out;
}

.feat-btn.feat-engine-off {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-dim);
    border-color: rgba(255, 255, 255, 0.08);
}

/* Active Alarm: Crimson Alert */
.feat-btn.feat-alarm-on {
    background: rgba(239, 68, 68, 0.28);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.65);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.5);
    animation: featPulseRed 1.2s infinite ease-in-out;
}

.feat-btn.feat-alarm-off {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-dim);
    border-color: rgba(255, 255, 255, 0.08);
}

/* Active Touch / Shock */
.feat-btn.feat-touch-alert {
    background: rgba(245, 158, 11, 0.24);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.55);
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.35);
    animation: featPulseAmber 1.6s infinite ease-in-out;
}

.feat-btn.feat-touch-ready {
    background: rgba(56, 189, 248, 0.12);
    color: #38bdf8;
    border-color: rgba(56, 189, 248, 0.28);
}

.feat-btn.feat-touch-off {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-dim);
    border-color: rgba(255, 255, 255, 0.08);
}

/* Starter (Lightning Bolt ⚡) */
.feat-btn.feat-starter-active {
    background: rgba(234, 179, 8, 0.25);
    color: #fde047;
    border-color: #eab308;
    box-shadow: 0 0 10px rgba(234, 179, 8, 0.5);
    animation: featPulseAmber 1.2s infinite ease-in-out;
}

.feat-btn.feat-starter-ready {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-dim);
    border-color: rgba(255, 255, 255, 0.08);
}

.feat-btn.feat-starter-ready:hover {
    color: #fde047;
    border-color: rgba(253, 224, 71, 0.45);
    box-shadow: 0 0 8px rgba(253, 224, 71, 0.35);
}

@keyframes featPulseGreen {
    0%, 100% { box-shadow: 0 0 4px rgba(16, 185, 129, 0.2); }
    50% { box-shadow: 0 0 12px rgba(16, 185, 129, 0.6); }
}

@keyframes featPulseRed {
    0%, 100% { box-shadow: 0 0 4px rgba(239, 68, 68, 0.2); }
    50% { box-shadow: 0 0 14px rgba(239, 68, 68, 0.7); }
}

@keyframes featPulseAmber {
    0%, 100% { box-shadow: 0 0 4px rgba(245, 158, 11, 0.2); }
    50% { box-shadow: 0 0 12px rgba(245, 158, 11, 0.6); }
}

/* Modern Leaflet Zoom Control Styling */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5) !important;
    border-radius: 10px !important;
    overflow: hidden !important;
    margin-right: 18px !important;
    margin-bottom: 24px !important;
}

.leaflet-control-zoom a {
    background: rgba(15, 23, 42, 0.9) !important;
    backdrop-filter: blur(8px) !important;
    color: #f1f5f9 !important;
    border-color: rgba(255, 255, 255, 0.12) !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 19px !important;
    font-weight: 800 !important;
    transition: all 0.2s ease !important;
}

.leaflet-control-zoom a:hover {
    background: var(--accent-blue) !important;
    color: #fff !important;
}

/* ==========================================
   Phase 3B: Admin Login Overlay & VPS Metrics
   ========================================== */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: radial-gradient(circle at top right, rgba(0, 210, 255, 0.14), transparent 48%),
                radial-gradient(circle at bottom left, rgba(58, 134, 255, 0.14), transparent 48%),
                rgba(6, 10, 18, 0.96);
    backdrop-filter: blur(14px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-overlay.hidden {
    display: none !important;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65), 0 0 32px rgba(0, 210, 255, 0.08);
    padding: 1.6rem;
    display: flex;
    flex-direction: column;
    gap: 1.15rem;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding-bottom: 0.9rem;
    border-bottom: 1px solid var(--border-color);
}

.login-brand-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(0, 210, 255, 0.2), rgba(58, 134, 255, 0.25));
    border: 1px solid rgba(0, 210, 255, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    color: var(--accent-cyan);
    flex-shrink: 0;
}

.login-brand h2 {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-main);
    margin: 0;
}

.login-brand p {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin: 0.15rem 0 0;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.login-error {
    display: none;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.38);
    color: #fca5a5;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    line-height: 1.45;
}

.login-error.visible {
    display: block;
}

.vps-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
}

.vps-metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem 0.55rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.vps-metric-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.vps-metric-value {
    font-size: 1.08rem;
    font-weight: 800;
    color: #fff;
    font-family: 'JetBrains Mono', monospace;
}

.vps-metric-sub {
    font-size: 0.65rem;
    color: var(--text-muted);
}

@media (max-width: 560px) {
    .vps-metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .login-card {
        padding: 1.25rem;
    }
}
