* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #1f2937;
    background: #f3f4f6;
    -webkit-font-smoothing: antialiased;
}

body {
    overflow: hidden;
}

.view {
    height: 100vh;
    width: 100vw;
}

[hidden] {
    display: none !important;
}

.btn {
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.35);
}

.btn-ghost {
    background: transparent;
    color: #4b5563;
    border: 1px solid #d1d5db;
}

.btn-ghost:hover:not(:disabled) {
    background: #f3f4f6;
}

.error-msg {
    color: #b91c1c;
    background: #fee2e2;
    border-radius: 6px;
    padding: 10px 12px;
    margin-top: 14px;
    font-size: 14px;
    display: none;
}

.error-msg.visible {
    display: block;
}

.login-view {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 36px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

.login-logo {
    display: block;
    width: 80px;
    height: 80px;
    object-fit: contain;
    flex-shrink: 0;
}

.login-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 20px;
}

.login-header-text {
    text-align: left;
}

.login-card h1 {
    font-size: 28px;
    color: #111827;
}

.login-card .subtitle {
    color: #6b7280;
    margin-top: 4px;
}

.info-box {
    background: #eff6ff;
    border-left: 4px solid #3b82f6;
    padding: 12px 14px;
    border-radius: 0 8px 8px 0;
    color: #1e3a8a;
    font-size: 13px;
    margin-bottom: 20px;
}

.info-box strong {
    display: block;
    margin-bottom: 4px;
    color: #1d4ed8;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: #374151;
    font-weight: 500;
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

#loginForm .btn-primary {
    width: 100%;
    margin-top: 6px;
    padding: 12px;
    font-size: 15px;
}

.dashboard-view {
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    z-index: 1000;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
    flex-shrink: 0;
}

.topbar-left h1 {
    font-size: 18px;
    color: #111827;
}

.user-tag {
    font-size: 12px;
    color: #6b7280;
    background: #f3f4f6;
    padding: 2px 8px;
    border-radius: 10px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.conn-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #4b5563;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #9ca3af;
    transition: background 0.2s;
}

.status-dot.online {
    background: #10b981;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5);
    animation: pulse 1.6s infinite;
}

.status-dot.offline {
    background: #ef4444;
}

.status-dot.connecting {
    background: #f59e0b;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
    70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.last-update {
    font-size: 12px;
    color: #6b7280;
}

.layout {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    min-height: 0;
}

:root {
    --sidebar-width: 460px;
}

.sidebar {
    position: fixed;
    left: 0;
    top: 56px;
    bottom: 0;
    width: var(--sidebar-width);
    z-index: 500;
    background: rgba(255, 255, 255, 0.45);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    backdrop-filter: blur(14px) saturate(160%);
    border-right: 1px solid rgba(255, 255, 255, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
}

.sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.1);
}

.sidebar-toggle {
    position: fixed;
    left: 0;
    top: 68px;
    width: 32px;
    height: 48px;
    z-index: 600;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-left: none;
    border-radius: 0 8px 8px 0;
    box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    color: #4b5563;
    transition: left 0.25s ease, color 0.15s, background 0.15s;
    padding: 0;
    line-height: 1;
}

.sidebar-toggle:hover {
    color: #111827;
    background: #f9fafb;
}

body.sidebar-open .sidebar-toggle {
    display: none;
}

.sidebar-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.sidebar-title {
    display: block;
    font-size: 15px;
    color: #111827;
    font-weight: 700;
}

.sidebar-close {
    display: none;
}

.sidebar-top .section-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.sidebar-top .stats-grid {
    width: 100%;
    order: 1;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.stat-card {
    background: transparent;
    border-radius: 6px;
    padding: 4px 2px;
    text-align: center;
    border: none;
}

.stat-card.stat-online {
    background: transparent;
    border-color: transparent;
}

.stat-card.stat-offline {
    background: transparent;
    border-color: transparent;
}

.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    color: #6b7280;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 16px;
    font-weight: 700;
    color: #111827;
    margin-top: 2px;
    line-height: 1.1;
}

.stat-card.stat-online .stat-value { color: #047857; }
.stat-card.stat-offline .stat-value { color: #b91c1c; }

.stat-unit {
    font-size: 11px;
    color: #6b7280;
    margin-top: 2px;
}

.devices-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.section-header h2 {
    font-size: 14px;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.devices-table-wrap {
    flex: 1;
    overflow-y: auto;
}

.device-card-list {
    display: none;
}

.devices-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 13px;
}

.devices-table th,
.devices-table td {
    padding: 8px 8px;
    text-align: left;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.devices-table th:nth-child(1) { width: 160px; }
.devices-table th:nth-child(2) { width: 100px; }
.devices-table th:nth-child(3) { width: 120px; }
.devices-table th:nth-child(4) { width: 90px; }

.cell-status-block {
    line-height: 1.3;
}

.cell-status-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    margin-top: 2px;
}

.cell-battery {
    font-weight: 600;
}
.cell-battery .batt { cursor: pointer; }
.cell-battery .batt-high { color: #059669; }
.cell-battery .batt-mid { color: #d97706; }
.cell-battery .batt-low { color: #dc2626; }

.cell-updated {
    color: #9ca3af;
}

.devices-table th {
    background: rgba(249, 250, 251, 0.7);
    color: #6b7280;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 1;
}

.devices-table tbody tr {
    cursor: pointer;
    transition: background 0.1s;
}

.devices-table tbody tr:hover {
    background: rgba(249, 250, 251, 0.7);
}

.devices-table tbody tr.active {
    background: rgba(239, 246, 255, 0.8);
}

.devices-table tbody tr.active td {
    border-bottom-color: rgba(219, 234, 254, 0.8);
}

.devices-table .device-name {
    font-weight: 600;
    color: #111827;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.devices-table .device-meta {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-online {
    background: #d1fae5;
    color: #065f46;
}

.badge-offline {
    background: #fee2e2;
    color: #991b1b;
}

.badge-unknown {
    background: #f3f4f6;
    color: #4b5563;
}

.badge-disabled {
    background: #fef3c7;
    color: #92400e;
}

.history-btn {
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 11px;
    color: #4b5563;
    cursor: pointer;
}

.history-btn:hover {
    background: #f3f4f6;
}

.empty {
    text-align: center;
    color: #9ca3af;
    padding: 24px !important;
    font-style: italic;
}

.map-pane {
    position: relative;
    min-height: 0;
}

#map {
    height: 100%;
    width: 100%;
}

.history-panel {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 480px;
    max-height: calc(100% - 24px);
    background: rgba(255, 255, 255, 0.5);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    padding: 14px;
    overflow-y: auto;
    z-index: 1000;
}

.history-float-icon {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1001;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.history-float-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.history-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.history-header h3 {
    font-size: 14px;
    color: #111827;
}

.history-panel.compact .history-header,
.history-panel.compact .quick-range,
.history-panel.compact .history-form,
.history-panel.compact .history-status,
.history-panel.compact .history-meta {
    display: none;
}

.history-panel.compact {
    padding: 10px;
}

.compact-inline {
    display: inline-flex;
}

.history-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 10px;
}

.history-form label {
    display: flex;
    flex-direction: column;
    font-size: 13px;
    color: #4b5563;
    gap: 4px;
}

.history-form input {
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
}

.history-form input:focus {
    outline: none;
    border-color: #667eea;
}

.quick-range {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.quick-range .flight-combine-toggle {
    margin-left: auto;
}

.chip {
    border: 1px solid #d1d5db;
    background: #fff;
    color: #4b5563;
    border-radius: 14px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.chip:hover:not(.active) {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.chip.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.35);
}

.history-status {
    font-size: 12px;
    color: #6b7280;
    min-height: 18px;
    margin-bottom: 6px;
}

.history-status.error {
    color: #b91c1c;
}

.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid #e5e7eb;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: -2px;
    margin-right: 6px;
}

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

.history-meta {
    font-size: 12px;
    color: #4b5563;
    line-height: 1.5;
}

.meta-empty {
    text-align: center;
    color: #9ca3af;
    font-style: italic;
    padding: 12px 0;
    font-size: 12px;
}

.replay-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 10px;
    margin-top: 10px;
}

.replay-buttons {
    display: flex;
    gap: 6px;
}

.replay-speed {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.replay-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.replay-speed {
    margin-left: auto;
}

.replay-speed-chip {
    font-size: 11px;
    padding: 4px 8px;
}

.flight-combine-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #4b5563;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}
.flight-combine-toggle .toggle-label {
    white-space: nowrap;
}
.flight-combine-badge {
    margin-top: 6px;
    font-size: 11px;
    color: #f59e0b;
    font-weight: 600;
}

.replay-progress {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
}

.replay-progress-track {
    width: 100%;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    overflow: visible;
    position: relative;
    cursor: pointer;
}

.replay-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 80ms linear;
    border-radius: 2px;
}

.replay-progress-handle {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid #667eea;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    cursor: grab;
    touch-action: none;
    z-index: 2;
    transition: transform 80ms ease, box-shadow 80ms ease;
}

.replay-progress-handle:active {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.15);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.replay-time {
    font-size: 11px;
    color: #6b7280;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
    line-height: 1.3;
}

.replay-time-stack {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.replay-point-time {
    font-size: 10px;
    color: #9ca3af;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    min-height: 12px;
    line-height: 1.3;
}

.replay-preview {
    position: absolute;
    top: -6px;
    left: 0;
    transform: translate(-50%, -100%);
    background: #1f2937;
    color: #ffffff;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    font-variant-numeric: tabular-nums;
}

.replay-preview::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid #1f2937;
}

.replay-marker-wrap {
    background: transparent;
    border: none;
}

.replay-marker {
    width: 18px;
    height: 18px;
    background: #f59e0b;
    border: 3px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
}

.replay-marker.pulse {
    animation: replayPulse 1.4s ease-in-out infinite;
}

@keyframes replayPulse {
    0%, 100% {
        box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(245, 158, 11, 0.15), 0 2px 6px rgba(0, 0, 0, 0.3);
    }
}

.airplane-marker-wrap {
    background: transparent;
    border: none;
}

.airplane-marker {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
    transition: transform 0.3s ease;
}

.meta-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
}

.meta-stat {
    display: flex;
    align-items: baseline;
    gap: 4px;
    padding: 8px 10px;
    background: #f9fafb;
    border: 1px solid #f3f4f6;
    border-radius: 8px;
}

.meta-stat .ico {
    font-size: 14px;
    line-height: 1;
    margin-right: 2px;
}

.meta-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
}

.meta-stat-label {
    font-size: 11px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.meta-endpoints {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.endpoint {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.endpoint.from {
    border-left: 3px solid #10b981;
}

.endpoint.to {
    border-left: 3px solid #ef4444;
}

.endpoint-badge {
    display: inline-block;
    align-self: flex-start;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 4px;
}

.endpoint-badge.from {
    background: #d1fae5;
    color: #065f46;
}

.endpoint-badge.to {
    background: #fee2e2;
    color: #991b1b;
}

.endpoint-time,
.endpoint-addr {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 11px;
    color: #4b5563;
    line-height: 1.4;
}

.endpoint-time .ico,
.endpoint-addr .ico {
    flex-shrink: 0;
    width: 14px;
    text-align: center;
    line-height: 1.4;
}

.endpoint-addr .addr-cell {
    word-break: break-word;
    color: #111827;
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #111827;
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.leaflet-popup-content {
    font-size: 13px;
    line-height: 1.5;
    margin: 10px 12px;
    min-width: 200px;
}
.leaflet-popup-close-button {
    display: none;
}

.leaflet-popup-content .popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #f3f4f6;
}

.leaflet-popup-content .popup-name {
    font-weight: 600;
    color: #111827;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaflet-popup-content .popup-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.leaflet-popup-content .popup-line {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 12px;
    color: #4b5563;
    line-height: 1.45;
}

.leaflet-popup-content .popup-line .ico {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
    line-height: 1.45;
}

.leaflet-popup-content .popup-line .addr-cell {
    color: #111827;
    word-break: break-word;
    flex: 1;
    min-width: 0;
}

.leaflet-popup-content .popup-line .addr-pending {
    color: #9ca3af;
    font-style: italic;
}

/* ============================
   Filter / freshness UI
   ============================ */

.badge-fresh {
    background: #d1fae5;
    color: #065f46;
}

.badge-recent {
    background: #dbeafe;
    color: #1e40af;
}

.badge-stale {
    background: #fef3c7;
    color: #92400e;
}

.badge-very_stale {
    background: #e5e7eb;
    color: #374151;
}

.badge-source {
    background: #f3f4f6;
    color: #6b7280;
    font-size: 10px;
    padding: 1px 5px;
}

.marker-stale {
    opacity: 0.55;
    filter: grayscale(0.4);
}

.marker-very_stale {
    opacity: 0.3;
    filter: grayscale(0.8);
}

.marker-outlier {
    opacity: 0.4;
    filter: hue-rotate(280deg);
}

.muted-meta {
    color: #9ca3af;
    font-size: 11px;
    margin-top: 6px;
}

.popup-line.cluster-info {
    color: #059669;
    font-weight: 500;
}

.popup-line.outlier-info {
    color: #b91c1c;
    font-style: italic;
}

.leaflet-popup-content .popup-actions {
    margin-top: 8px;
    display: flex;
    justify-content: flex-end;
}

/* Topbar toggle switch */
.toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    color: #4b5563;
}

.toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-track {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 18px;
    background: #d1d5db;
    border-radius: 999px;
    transition: background 0.15s;
    flex-shrink: 0;
}

.toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s;
}

.toggle input:checked + .toggle-track {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.toggle input:checked + .toggle-track .toggle-thumb {
    transform: translateX(16px);
}

.toggle-label {
    white-space: nowrap;
}

.toggle-icon {
    display: none;
}

.flight-pos-marker-wrap {
    background: none !important;
    border: none !important;
}
.flight-pos-marker-wrap::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border-radius: 50%;
    border: 2px solid #d97706;
    animation: flightPulse 1.5s ease-out infinite;
    pointer-events: none;
}
@keyframes flightPulse {
    0% { transform: scale(0.6); opacity: 0.8; }
    100% { transform: scale(1.6); opacity: 0; }
}
.flight-pos-marker {
    width: 32px;
    height: 32px;
    background: rgba(245, 158, 11, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.5);
    border: 2px solid #fff;
}
.flight-pos-marker svg {
    transition: transform 0.5s ease;
    transform-origin: center;
}

/* Flight bind side panel (slides from right) */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    pointer-events: none;
}
.modal.is-open {
    pointer-events: auto;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.15);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    cursor: pointer;
}
.modal.is-open .modal-backdrop {
    opacity: 1;
    pointer-events: auto;
}
.modal-card {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 520px;
    max-width: 100vw;
    background: rgba(255, 255, 255, 0.55);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    backdrop-filter: blur(14px) saturate(160%);
    border-left: 1px solid rgba(255, 255, 255, 0.4);
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.2);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    overflow: hidden;
}
.modal.is-open .modal-card {
    transform: translateX(0);
    pointer-events: auto;
}
.modal-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.55);
    border-bottom: 1px solid rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 16px;
    color: #1f2937;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.modal-body {
    flex: 1;
    min-height: 0;
    padding: 18px 20px;
    overflow-y: auto;
    position: relative;
}
.modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    background: rgba(249, 250, 251, 0.55);
    border-top: 1px solid rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
}
@media (max-width: 600px) {
    .modal-card {
        width: 100vw;
    }
}
body.modal-open {
    overflow: hidden;
}
.flight-search-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}
.flight-search-block label {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}
.flight-search-block .search-wrap {
    position: relative;
}
.search-wrap .spinner.spinner-input {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border-width: 2px;
    margin-right: 0;
    pointer-events: none;
    z-index: 1;
}
#flightSearchInput {
    width: 100%;
    padding: 10px 32px 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: #1f2937;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
#flightSearchInput:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.18);
}
.flight-search-hint {
    font-size: 12px;
    color: #6b7280;
}
.flight-suggestions {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    max-height: 420px;
    overflow-y: auto;
    list-style: none;
    padding: 4px 0;
    margin: 0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 5;
}
.flight-suggestions.hidden {
    display: none;
}
.flight-suggestions .flight-group-header {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: #6b7280;
    letter-spacing: 0.5px;
    background: #f3f4f6;
    border-top: 1px solid #e5e7eb;
    border-bottom: 1px solid #e5e7eb;
    z-index: 1;
}
.flight-suggestions .flight-group-header:first-child {
    border-top: none;
}
.flight-suggestions .flight-group-header.is-muted {
    background: #f9fafb;
    color: #9ca3af;
}
.flight-group-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    padding: 0 6px;
    height: 18px;
    background: #e5e7eb;
    color: #4b5563;
    border-radius: 9px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0;
}
.flight-suggestion {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.1s;
}
.flight-suggestion:last-child {
    border-bottom: none;
}
.flight-suggestion:not(.is-past):hover {
    background: #eef2ff;
}
.flight-suggestion.is-past {
    opacity: 0.5;
    cursor: not-allowed;
    background: repeating-linear-gradient(
        45deg,
        #fafafa,
        #fafafa 6px,
        #f3f4f6 6px,
        #f3f4f6 12px
    );
}
.flight-suggestion.is-past:hover {
    background: repeating-linear-gradient(
        45deg,
        #f3f4f6,
        #f3f4f6 6px,
        #e5e7eb 6px,
        #e5e7eb 12px
    );
}
.flight-suggestion-main {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.flight-suggestion-route {
    font-size: 13px;
    color: #1f2937;
    margin-top: 4px;
}
.flight-suggestion-route b {
    color: #111827;
    font-weight: 600;
}
.flight-suggestion-route .airport-code {
    color: #6366f1;
    font-weight: 600;
    font-size: 12px;
}
.flight-suggestion-route .route-arrow {
    color: #9ca3af;
    margin: 0 4px;
    font-weight: 700;
}
.flight-suggestion-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.flight-suggestion-meta .row-meta {
    font-size: 12px;
    color: #4b5563;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.flight-suggestion-meta .row-ico {
    opacity: 0.7;
}
.flight-suggestion-meta .row-tags {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.flight-suggestion .row-tag {
    display: inline-flex;
    align-items: center;
    background: #f3f4f6;
    color: #4b5563;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}
.flight-suggestion .row-status {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: #e5e7eb;
    color: #4b5563;
}
.flight-suggestion .row-status.state-green {
    background: #d1fae5;
    color: #047857;
}
.flight-suggestion .row-status.state-yellow {
    background: #fef3c7;
    color: #b45309;
}
.flight-suggestion .row-status.state-red {
    background: #fee2e2;
    color: #b91c1c;
}
.flight-suggestion .row-status.state-gray {
    background: #e5e7eb;
    color: #6b7280;
}
.flight-suggestion .row-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    background: #e5e7eb;
    color: #4b5563;
}
.flight-suggestion .row-badge.past {
    background: #fee2e2;
    color: #991b1b;
}
.flight-ico {
    font-size: 16px;
    line-height: 1;
}
.flight-suggestion-sub {
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
}
.flight-number {
    font-weight: 700;
    color: #1f2937;
    font-size: 14px;
}
.flight-airline {
    font-size: 12px;
    color: #6b7280;
}
.flight-preview {
    margin-top: 16px;
    padding: 16px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #f9fafb;
}
.flight-preview-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}
.flight-preview-number {
    font-size: 20px;
    font-weight: 700;
    color: #1f2937;
}
.flight-preview-airline {
    font-size: 13px;
    color: #6b7280;
    margin-top: 2px;
}
.flight-preview-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.flight-line {
    font-size: 13px;
    color: #374151;
    display: flex;
    align-items: center;
    gap: 8px;
}
.flight-line .ico {
    width: 18px;
    text-align: center;
    opacity: 0.7;
}
.flight-badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #e5e7eb;
    color: #374151;
}
.flight-badge.live {
    background: #d1fae5;
    color: #047857;
}
.flight-badge.state-green {
    background: #d1fae5;
    color: #047857;
}
.flight-badge.state-yellow {
    background: #fef3c7;
    color: #b45309;
}
.flight-badge.state-red {
    background: #fee2e2;
    color: #b91c1c;
}
.flight-badge.state-gray {
    background: #e5e7eb;
    color: #6b7280;
}
.flight-date-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-right: 6px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    vertical-align: 1px;
    border: 1px solid transparent;
}
.flight-date-badge.today {
    background: #fef3c7;
    color: #b45309;
    border-color: #fcd34d;
}
.flight-date-badge.tomorrow {
    background: #fef9c3;
    color: #854d0e;
    border-color: #fde047;
}
.flight-date-badge.week {
    background: #dbeafe;
    color: #1e40af;
    border-color: #93c5fd;
}
.flight-date-badge.far {
    background: #f3f4f6;
    color: #374151;
    border-color: #d1d5db;
}
.flight-date-badge.past {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
}
.time-hint {
    cursor: help;
    border-bottom: 1px dotted rgba(0, 0, 0, 0.3);
    transition: border-color 0.15s, color 0.15s;
}
.time-hint:hover {
    border-bottom-color: #4338ca;
    color: #4338ca;
}
.flight-error {
    margin-top: 12px;
    padding: 10px 12px;
    background: #fee2e2;
    color: #b91c1c;
    border-radius: 8px;
    font-size: 13px;
}
.flight-past-warning {
    margin-top: 8px;
    padding: 8px 12px;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

/* Device table - Flight column */
.flight-cell {
    vertical-align: top;
    max-width: 100%;
    overflow: hidden;
}
.flight-binding-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 4px;
}
.flight-binding-row {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    border-radius: 4px;
    padding: 1px 2px 1px 4px;
    font-size: 11px;
    max-width: 100%;
    overflow: hidden;
}
.flight-binding-fn {
    font-weight: 700;
    color: #1f2937;
    cursor: help;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
.flight-binding-status {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 1px 4px;
    border-radius: 999px;
    font-weight: 600;
    background: #e5e7eb;
    color: #4b5563;
    flex-shrink: 0;
    white-space: nowrap;
}
.flight-binding-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.85;
    flex-shrink: 0;
}
.flight-status-scheduled {
    background: #e0e7ff;
    color: #4338ca;
}
.flight-status-active {
    background: #d1fae5;
    color: #047857;
}
.flight-status-landed {
    background: #f3f4f6;
    color: #6b7280;
}
.flight-status-cancelled {
    background: #fee2e2;
    color: #b91c1c;
}
.flight-status-expired {
    background: #fee2e2;
    color: #b91c1c;
}
.flight-binding-sub {
    color: #6b7280;
    margin: 2px 0 4px;
    font-size: 11px;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.flight-binding-route-badge,
.flight-binding-route-detail {
    display: none;
}
.flight-binding-city {
    display: none;
}
.flight-binding-airline-badge {
    display: none;
}
.bind-btn,
.unbind-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #4b5563;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.bind-btn:hover,
.unbind-btn:hover {
    background: #f3f4f6;
}
.unbind-btn {
    color: #b91c1c;
    background: transparent;
    border-color: transparent;
}
.unbind-btn:hover {
    color: #7f1d1d;
    background: rgba(185, 28, 28, 0.08);
    border-color: transparent;
}

.flight-binding-row.flight-status-scheduled { background: #e0e7ff; }
.flight-binding-row.flight-status-active { background: #d1fae5; }
.flight-binding-row.flight-status-landed { background: #f3f4f6; }
.flight-binding-row.flight-status-cancelled,
.flight-binding-row.flight-status-expired { background: #fee2e2; }

.flight-binding-pending {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    padding: 1px 4px;
    border-radius: 999px;
    font-weight: 600;
    background: #fef3c7;
    color: #92400e;
    flex-shrink: 0;
    white-space: nowrap;
    cursor: help;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.section-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.actions-cell {
    white-space: nowrap;
    text-align: center;
    vertical-align: middle;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1.3;
    font-weight: 600;
    border: 1px solid #d1d5db;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s, color 0.15s;
    white-space: nowrap;
}

.edit-btn {
    background: #f3f4f6;
    color: #6b7280;
    border: 1px solid #e5e7eb;
}

.edit-btn:hover {
    background: #e5e7eb;
    color: #374151;
}

.form-divider {
    border-top: 1px solid #e5e7eb;
    margin: 20px 0 12px;
}

.delete-device-btn {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #fca5a5;
    background: #fef2f2;
    color: #b91c1c;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s, border-color 0.15s;
}

.delete-device-btn:hover {
    background: #fee2e2;
    border-color: #f87171;
}

#deviceFormModal .form-group {
    margin-bottom: 16px;
}

#deviceFormModal label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

#deviceFormModal input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    color: #1f2937;
    background: #fff;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

#deviceFormModal input[type="text"]:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

#deviceFormModal input[type="text"]:disabled {
    background: #f3f4f6;
    color: #6b7280;
    cursor: not-allowed;
}

#deviceFormModal #deviceFormError {
    margin-top: 0;
}

.error-detail {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    word-break: break-all;
    line-height: 1.4;
}

.auth-links {
    display: flex;
    justify-content: space-between;
    margin-top: 16px;
    font-size: 13px;
}

.link-btn {
    background: none;
    border: none;
    color: #667eea;
    cursor: pointer;
    font-size: 13px;
    padding: 0;
    text-decoration: underline;
}

.link-btn:hover {
    color: #764ba2;
}

.success-msg {
    color: #065f46;
    background: #d1fae5;
    border-radius: 6px;
    padding: 10px 12px;
    margin-top: 14px;
    font-size: 14px;
}

/* ============================
   Mobile Hamburger (hidden on desktop)
   ============================ */
.topbar-hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    color: #374151;
    cursor: pointer;
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
    line-height: 1;
    border-radius: 6px;
    transition: background 0.15s;
}
.topbar-hamburger:hover {
    background: #f3f4f6;
}

/* Sidebar close button (hidden on desktop) */
.sidebar-close {
    display: none;
    position: absolute;
    top: 10px;
    right: 12px;
    z-index: 10;
}

/* Sidebar backdrop (hidden on desktop) */
.sidebar-backdrop {
    display: none;
}

/* ============================
   TABLET: max-width 900px
   ============================ */
@media (max-width: 900px) {
    :root {
        --sidebar-width: min(85vw, 360px);
    }

    .topbar-right {
        gap: 10px;
    }

    .history-panel {
        width: calc(100% - 24px);
    }

    .meta-stats {
        grid-template-columns: 1fr 1fr;
    }

    .meta-endpoints {
        grid-template-columns: 1fr;
    }
}

/* ============================
   MOBILE: max-width 600px
   ============================ */
@media (max-width: 600px) {
    /* --- Topbar compact --- */
    .topbar {
        padding: 8px 10px;
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
        flex-wrap: nowrap;
        gap: 6px;
    }

    .topbar-hamburger {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        font-size: 26px;
        flex-shrink: 0;
    }

    .topbar-left {
        display: flex;
        align-items: center;
        gap: 6px;
        min-width: 0;
        flex: 1;
    }

    .topbar-logo {
        width: 24px;
        height: 24px;
    }

    .topbar-left h1 {
        font-size: 16px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .user-tag {
        display: none;
    }

    .topbar-right {
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 13px;
        flex-shrink: 0;
    }

    .topbar-right .last-update,
    .topbar-right .conn-status {
        display: none;
    }

    .topbar-right .btn-ghost {
        height: 25px;
        padding: 0 10px;
        font-size: 12px;
        border-radius: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1.5px solid #d1d5db;
        color: #6b7280;
        background: transparent;
        white-space: nowrap;
    }

    .topbar-right .btn-ghost:active {
        background: #f3f4f6;
        border-color: #ef4444;
        color: #ef4444;
    }

    .topbar-right .toggle {
        position: relative;
        height: 26px;
        padding: 0 8px;
        border-radius: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1.5px solid #d1d5db;
        background: transparent;
        cursor: pointer;
        flex-shrink: 0;
    }

    .topbar-right .toggle:active {
        background: #f3f4f6;
    }

    .topbar-right .toggle-track {
        display: none;
    }

    .topbar-right .toggle-label {
        display: none;
    }

    .topbar-right .toggle-icon {
        display: inline;
        font-size: 14px;
        font-weight: 500;
        line-height: 1;
    }

    .topbar-right .toggle input:checked + .toggle-track {
        display: none;
    }

    .topbar-right .toggle:has(input:checked) {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        border-color: transparent;
        box-shadow: 0 1px 4px rgba(102, 126, 234, 0.3);
    }

    .topbar-right .toggle:has(input:checked) .toggle-icon {
        color: #fff;
    }

    /* --- Sidebar full-screen --- */
    :root {
        --sidebar-width: 100vw;
    }

    .sidebar {
        position: fixed;
        top: env(safe-area-inset-top, 0px);
        left: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        z-index: 2000;
        background: rgba(255, 255, 255, 0.55);
        -webkit-backdrop-filter: blur(14px) saturate(160%);
        backdrop-filter: blur(14px) saturate(160%);
        border-right: none;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding-top: 0;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    .sidebar-close {
        display: block;
        position: static;
    }

    /* Sidebar backdrop */
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 1999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    body.sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    /* Hide desktop sidebar toggle on mobile */
    .sidebar-toggle {
        display: none;
    }

    body.sidebar-open .sidebar-toggle {
        display: none;
    }

    /* --- Sidebar top row: all on one line --- */
    .sidebar-top {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        padding: 32px 12px 16px;
        gap: 6px;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    }

    .sidebar-title {
        display: none;
    }

    .sidebar-close {
        display: block;
        position: static;
        flex-shrink: 0;
    }

    .sidebar-top .section-actions {
        display: flex;
        gap: 4px;
        flex-shrink: 0;
        order: 0;
    }

    .sidebar-top .stats-grid {
        display: flex;
        gap: 6px;
        flex: 1;
        min-width: 0;
        order: 1;
        padding: 0;
        border-bottom: none;
        justify-content: center;
        border: 2px solid rgba(0, 0, 0, 0.12);
        border-radius: 8px;
        overflow: hidden;
    }

    .sidebar-top .sidebar-close {
        order: 2;
    }

    .sidebar-top .stat-card {
        padding: 4px 0;
        text-align: center;
    }

    .sidebar-top .stat-label {
        font-size: 11px;
    }

    .sidebar-top .stat-value {
        font-size: 15px;
    }

    .sidebar-top .stat-unit {
        font-size: 11px;
    }

    .sidebar-top .section-actions .btn {
        padding: 5px 8px;
        font-size: 13px;
        border: 2px solid rgba(0, 0, 0, 0.12);
    }

    .sidebar-top .sidebar-close {
        border: 2px solid rgba(0, 0, 0, 0.12);
    }

    /* --- Device table → card layout --- */
    .devices-table {
        display: none;
    }

    .devices-table-wrap {
        overflow-y: auto;
    }

    .device-card-list {
        display: flex;
        flex-direction: column;
        gap: 8px;
        padding: 8px 12px;
    }

    .device-card {
        padding: 12px 14px;
        border-radius: 10px;
        cursor: pointer;
        transition: background 0.1s;
        background: rgba(255, 255, 255, 0.3);
        -webkit-backdrop-filter: blur(8px);
        backdrop-filter: blur(8px);
    }

    .device-card:active {
        background: rgba(239, 246, 255, 0.4);
    }

    .device-card.active {
        background: rgba(239, 246, 255, 0.5);
    }

    .device-card-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        margin-bottom: 4px;
    }

    .device-card-name {
        font-weight: 600;
        font-size: 16px;
        color: #111827;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        flex: 1;
        min-width: 0;
    }

    .device-card-meta {
        font-size: 13px;
        color: #9ca3af;
        margin-bottom: 6px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .device-card-info {
        display: flex;
        align-items: center;
        gap: 8px;
    flex-wrap: nowrap;
        margin-bottom: 6px;
    }

    .device-card-info .badge {
        font-size: 12px;
        padding: 2px 6px;
    }

    .device-card-battery {
        font-size: 13px;
        color: #6b7280;
    }

    .device-card-updated {
        font-size: 12px;
        color: #9ca3af;
    }

    .device-card-flight {
        margin-top: 4px;
        display: none;
    }

    .device-card-flight.expanded {
        display: block;
    }

    .device-card-flight-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 23px;
        height: 23px;
        border-radius: 50%;
        font-size: 17px;
        color: #fff;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        border: none;
        cursor: pointer;
        padding: 0;
        margin-top: 4px;
        box-shadow: 0 1px 4px rgba(102, 126, 234, 0.4);
    }

    .device-card-flight-toggle:active {
        opacity: 0.8;
    }

    .device-card-flight-add {
        font-size: 18px;
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        box-shadow: 0 1px 4px rgba(16, 185, 129, 0.4);
    }

    .device-card-flight-add:active {
        opacity: 0.8;
    }

    .device-card-flight .flight-binding-row {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 2px 4px;
        padding: 4px 6px;
        overflow: visible;
    }

    .device-card-flight .flight-binding-fn {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex: none;
        overflow: visible;
        font-size: 15px;
    }

    .device-card-flight .flight-binding-pending {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex: none;
        font-size: 15px;
    }

    .device-card-flight .flight-binding-route-badge {
        display: inline-block;
        font-size: 12px;
        font-weight: 600;
        color: #4338ca;
        background: #e0e7ff;
        border-radius: 4px;
        padding: 1px 6px;
        margin-left: 0;
        margin-top: 2px;
        white-space: nowrap;
        width: fit-content;
    }

    .device-card-flight .flight-binding-route-time {
        color: #047857;
        background: #d1fae5;
        display: inline-block;
        width: fit-content;
        margin-top: 2px;
    }

    .device-card-flight .flight-binding-route-detail {
        display: block;
        font-size: 12px;
        color: #6b7280;
        white-space: nowrap;
        margin-top: 2px;
    }

    .device-card-flight .flight-binding-sub {
        display: none;
    }

    .device-card-flight .flight-binding-city {
        display: block;
        width: 100%;
        font-size: 12px;
        font-weight: 600;
        color: #4b5563;
        background: #f3f4f6;
        border-radius: 4px;
        padding: 2px 8px;
        margin-top: 2px;
        text-align: left;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .device-card-flight .flight-binding-airline-badge {
        display: inline-block;
        font-size: 12px;
        font-weight: 600;
        color: #4338ca;
        background: #e0e7ff;
        border-radius: 4px;
        padding: 1px 6px;
        margin-right: 4px;
    }

    .device-card-actions {
        display: none;
    }

    /* --- History panel → bottom sheet --- */
    .history-panel {
        position: fixed;
        top: auto;
        right: auto;
        left: 0;
        bottom: 0;
        width: 100%;
        max-height: 70vh;
        border-radius: 16px 16px 0 0;
        border: 1px solid rgba(255, 255, 255, 0.4);
        border-bottom: none;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
        z-index: 1500;
        overflow-y: auto;
        padding: 0 14px 14px;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .history-panel[hidden] {
        display: block !important;
        pointer-events: none;
    }

    .history-panel.is-visible {
        transform: translateY(0);
    }

    .history-panel::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        margin: 8px auto 12px;
    }

    .history-header {
        padding: 0;
        margin-bottom: 8px;
    }

    .history-header h3 {
        font-size: 15px;
    }

    .history-panel.compact {
        max-height: auto;
        padding: 0 14px 14px;
    }

    .quick-range {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 4px;
        padding-bottom: 4px;
    }

    .quick-range::-webkit-scrollbar {
        display: none;
    }

    .quick-range .chip {
        flex-shrink: 0;
        padding: 6px 12px;
        font-size: 14px;
        min-height: 36px;
    }

    .quick-range .flight-combine-toggle {
        margin-left: auto;
    }

    .history-form {
        gap: 6px;
    }

    .history-form label {
        font-size: 14px;
    }

    .history-form input {
        padding: 8px 10px;
        font-size: 15px;
        min-height: 40px;
    }

    .history-form .btn {
        min-height: 40px;
    }

    /* --- Replay controls mobile --- */
    .replay-controls {
        padding: 8px;
        gap: 6px;
    }

    .replay-toolbar {
        display: flex;
        align-items: center;
        gap: 4px;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .replay-toolbar::-webkit-scrollbar {
        display: none;
    }

    .replay-buttons {
        display: flex;
        gap: 3px;
        flex-shrink: 0;
    }

    .replay-buttons .btn {
        padding: 5px 8px;
        font-size: 13px;
        min-height: 32px;
    }

    .replay-speed {
        display: flex;
        gap: 2px;
        flex-shrink: 0;
        margin-left: auto;
    }

    .replay-speed-chip {
        padding: 4px 6px;
        font-size: 12px;
        min-height: 28px;
    }

    .flight-combine-toggle {
        font-size: 13px;
        flex-shrink: 0;
    }

    .replay-progress {
        width: 100%;
    }

    .replay-progress-track {
        height: 6px;
    }

    .replay-progress-handle {
        width: 16px;
        height: 16px;
    }

    .replay-time {
        font-size: 14px;
    }

    /* --- Login mobile --- */
    .login-view {
        padding: 16px;
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
        align-items: center;
        justify-content: center;
    }

    .login-card {
        padding: 28px 20px;
        border-radius: 12px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    }

    .login-logo {
        width: 64px;
        height: 64px;
    }

    .login-header {
        gap: 12px;
    }

    .login-card h1 {
        font-size: 28px;
    }

    .login-card .subtitle {
        font-size: 15px;
        margin-bottom: 16px;
    }

    .form-group label {
        font-size: 14px;
    }

    .form-group input {
        padding: 12px 14px;
        font-size: 16px;
        min-height: 48px;
    }

    #loginForm .btn-primary {
        padding: 14px;
        font-size: 16px;
        min-height: 50px;
    }

    .auth-links {
        display: none;
    }

    .link-btn {
        font-size: 14px;
        padding: 4px 0;
    }

    /* --- Modals → bottom sheet --- */
    .modal-card {
        position: absolute;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, 0.4);
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    #flightBindModal .modal-card {
        top: 0;
        bottom: 0;
        max-height: 100%;
        border-radius: 0;
        border-top: none;
    }

    .modal.is-open .modal-card {
        transform: translateY(0);
    }

    .modal-card::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        margin: 8px auto 0;
        flex-shrink: 0;
    }

    .modal-header {
        padding: 10px 16px 12px;
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
        background: rgba(255, 255, 255, 0.7);
    }

    .modal-header h3 {
        font-size: 17px;
    }

    .modal-body {
        padding: 14px 16px;
    }

    .modal-footer {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .modal-footer .btn {
        padding: 10px 16px;
        font-size: 16px;
        min-height: 44px;
    }

    /* Flight search suggestions mobile */
    .flight-suggestions {
        max-height: 50vh;
    }

    #flightSearchInput {
        font-size: 16px;
        min-height: 48px;
    }

    .flight-preview {
        padding: 12px;
    }

    .flight-preview-number {
        font-size: 18px;
    }

    /* Device form modal mobile */
    #deviceFormModal input[type="text"] {
        font-size: 16px;
        min-height: 48px;
    }

    .delete-device-btn {
        min-height: 44px;
        font-size: 14px;
    }

    /* --- Better touch targets --- */
    .btn-sm {
        min-height: 36px;
    }

    .chip {
        min-height: 36px;
    }

    .history-btn {
        min-height: 36px;
        padding: 6px 10px;
    }

    .bind-btn,
    .unbind-btn {
        height: 20px;
        font-size: 10px;
        padding: 0 6px;
        border-radius: 4px;
        border: 1px solid #d1d5db;
        color: #6b7280;
        background: transparent;
        margin-left: auto;
    }

    .unbind-btn:active {
        border-color: #ef4444;
        color: #fff;
        background: #ef4444;
    }

    .bind-btn {
        width: 23px;
        height: 23px;
        padding: 0;
        border-radius: 50%;
        font-size: 18px;
        font-weight: 700;
        border: none;
        color: #fff;
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        box-shadow: 0 1px 4px rgba(16, 185, 129, 0.4);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    .action-btn {
        min-height: 36px;
        padding: 6px 10px;
    }

    /* --- Map adjustments --- */
    .map-pane {
        height: calc(100vh - 44px);
    }

    #map {
        height: 100%;
    }

    /* Leaflet popup mobile */
    .leaflet-popup-content {
        font-size: 14px;
        min-width: 160px;
        margin: 8px 10px;
    }

    .leaflet-popup-content .popup-line {
        font-size: 13px;
    }

    /* Toast mobile */
    .toast {
        bottom: 16px;
        left: 12px;
        right: 12px;
        transform: none;
        font-size: 14px;
        padding: 12px 16px;
        border-radius: 10px;
        text-align: center;
    }

    @keyframes slideIn {
        from { opacity: 0; transform: translateY(8px); }
        to { opacity: 1; transform: translateY(0); }
    }

    /* --- Meta stats/endpoints mobile --- */
    .meta-stats {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .meta-stat {
        padding: 6px 8px;
    }

    .meta-stat-value {
        font-size: 17px;
    }

    .meta-endpoints {
        grid-template-columns: 1fr;
    }

    .endpoint {
        padding: 8px;
    }

    /* --- Misc mobile --- */
    .info-box {
        font-size: 14px;
        padding: 10px 12px;
    }
}

.share-expiry-section {
    margin-bottom: 14px;
}
.share-expiry-section label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 6px;
}
.share-expiry-section .quick-range {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.share-link-row {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    align-items: center;
}
.share-link-input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 12px;
    font-family: monospace;
    background: #f9fafb;
    color: #374151;
    min-width: 0;
}
.share-qr-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 14px;
}
.share-qr-row #shareQR {
    flex-shrink: 0;
}
.share-tokens-list {
    margin-top: 14px;
}
.share-list-label {
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.share-empty {
    font-size: 13px;
    color: #9ca3af;
    padding: 10px 0;
}
.share-token-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
    gap: 10px;
}
.share-token-row:last-child {
    border-bottom: none;
}
.share-token-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.share-delete-btn { color: #dc2626; }
.share-delete-btn:hover { background: #fef2f2; }
.share-token-meta {
    font-size: 11px;
    color: #9ca3af;
    white-space: nowrap;
}
.share-token-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.share-token-expiry {
    font-size: 12px;
    color: #6b7280;
}
.share-token-accessed {
    font-size: 11px;
    color: #9ca3af;
}
#shareGenerateBtn {
    width: 100%;
}
.popup-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}
.popup-actions .history-btn,
.popup-actions .share-btn {
    flex: 1;
    padding: 5px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    font-size: 11px;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    transition: background 0.15s;
}
.popup-actions .history-btn:hover,
.popup-actions .share-btn:hover {
    background: #f3f4f6;
}
.popup-actions .share-btn {
    color: #667eea;
    border-color: #667eea;
}
.popup-actions .share-btn:hover {
    background: #eef2ff;
}
