html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
        sans-serif;
}

body {
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
}

/* ---------- Header ---------- */
.header {
    padding: 8px 16px;
    background: #111827;
    color: #f9fafb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid #0b1120;
}

.header h1 {
    font-size: 18px;
    margin: 0;
    letter-spacing: 0.03em;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #e5e7eb;
    background: rgba(15, 23, 42, 0.8);
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
    color: #cbd5f5;
    opacity: 0.9;
}

.meta-label {
    opacity: 0.8;
}

.meta-value {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.live-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(16, 185, 129, 0.12);
    color: #bbf7d0;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.9);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.header-group--auto {
    padding-left: 12px;
    margin-left: 4px;
    border-left: 1px solid rgba(148, 163, 184, 0.6);
}

/* Switch */
.switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

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

.switch-slider {
    position: relative;
    width: 36px;
    height: 20px;
    background: #e5e7eb;
    border-radius: 999px;
    transition: background 0.15s ease;
}

.switch-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s ease;
}

.switch input:checked + .switch-slider {
    background: #22c55e;
}

.switch input:checked + .switch-slider::after {
    transform: translateX(16px);
}

.switch input:disabled + .switch-slider {
    opacity: 0.55;
    cursor: not-allowed;
}

.switch-label {
    font-weight: 600;
}

.switch-window {
    font-size: 11px;
    opacity: 0.85;
}

.header .switch,
.header .switch-window {
    color: #e5e7eb;
}

.header-btn {
    border: 1px solid #374151;
    background: #020617;
    color: #e5e7eb;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease,
        transform 0.08s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.header-btn:hover {
    background: #111827;
    border-color: #4b5563;
    color: #fff;
    transform: translateY(-1px);
}

.header-btn:active {
    transform: translateY(0);
}

.header-btn--primary {
    background: #22c55e;
    border-color: #22c55e;
    color: #022c22;
    font-weight: 500;
}

.header-btn--primary:disabled,
.header-btn--primary.is-disabled,
.header-btn.is-disabled,
.header-btn:disabled {
    opacity: 0.55;
    background: #6b7280;
    border-color: #6b7280;
    color: #e5e7eb;
    cursor: not-allowed;
}

.header-btn--secondary {
    background: #020617;
    border-color: #374151;
    color: #e5e7eb;
}

/* Icon eye */
.icon-eye {
    width: 14px;
    height: 14px;
    display: inline-block;
    background: center / contain no-repeat
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M2 12s4-7 10-7 10 7 10 7-4 7-10 7-10-7-10-7Z'/%3E%3C/svg%3E");
}

.header-btn.is-off .icon-eye {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m2 2 20 20'/%3E%3Cpath d='M10.8 10.9a3 3 0 0 0 3.3 3.3'/%3E%3Cpath d='M9.5 5.1A9.5 9.5 0 0 1 12 5c6 0 10 7 10 7a15 15 0 0 1-2.4 3.1'/%3E%3Cpath d='M6.7 6.7C3.3 8.3 2 12 2 12a15 15 0 0 0 6.1 5.5'/%3E%3C/svg%3E");
}

/* ---------- Layout & Map ---------- */
.layout {
    position: relative;
    padding: 12px;
    box-sizing: border-box;
    height: calc(100vh - 40px);
}

#map {
    width: 100%;
    height: 100%;
    min-height: 320px;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

/* ---------- Overlay bus panel ---------- */
.bus-panel {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 1100;
    width: 280px;
    min-width: 240px;
    max-height: 70vh;
    background: #f8fafc;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bus-panel.collapsed {
    display: none;
}

.bus-panel__header {
    padding: 12px 14px;
    font-weight: 600;
    border-bottom: 1px solid #e5e7eb;
    background: #f1f5f9;
}

.bus-list {
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-y: auto;
}

.bus-list__empty {
    padding: 14px;
    font-size: 13px;
    color: #6b7280;
}

.bus-item {
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    background: transparent;
    border: none;
    border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
    transition: background 0.1s ease, transform 0.1s ease;
}

.bus-item:hover {
    background: #e5e7eb;
    transform: translateY(-1px);
}

.bus-item:active {
    transform: translateY(0);
}

.bus-item__title {
    font-weight: 600;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.bus-item__meta {
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
}

/* ---------- Tooltip ---------- */
.leaflet-tooltip.bus-tooltip {
    background: rgba(17, 24, 39, 0.92);
    color: #f9fafb;
    border: none;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.4;
}

.leaflet-tooltip.bus-tooltip:before {
    display: none;
}

.bus-tooltip__content strong {
    font-size: 13px;
}

.bus-tooltip__title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

/* Global hide tooltip */
.tooltips-hidden .leaflet-tooltip.bus-tooltip {
    opacity: 0 !important;
    pointer-events: none;
}

/* Override: show temporarily when global hide */
.tooltips-hidden .leaflet-tooltip.bus-tooltip.force-show {
    opacity: 0.95 !important;
    pointer-events: auto;
}

/* Override: hide temporarily when global show */
body:not(.tooltips-hidden) .leaflet-tooltip.bus-tooltip.force-hide {
    opacity: 0 !important;
    pointer-events: none;
}

/* ---------- Status badge ---------- */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.2px;
    border: 1px solid #e5e7eb;
    background: #e5e7eb;
    color: #0f172a;
}

.status-badge--online {
    background: #dcfce7;
    border-color: #bbf7d0;
    color: #166534;
}

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

.status-badge--lost-signal {
    background: #f8ff90;
    border-color: #f8ff90;
    color: #166534;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
        align-items: flex-start;
        gap: 8px;
    }

    .header-group--auto {
        border-left: none;
        padding-left: 0;
        margin-left: 0;
        border-top: 1px solid rgba(148, 163, 184, 0.6);
        padding-top: 4px;
        margin-top: 4px;
    }

    .bus-panel {
        top: 8px;
        left: 8px;
        right: 8px;
        width: auto;
        min-width: 0;
        max-height: 60vh;
    }
}
