:root {
    --primary-blue: #1e40af;
    --dark-blue: #0f172a;
    --darker-blue: #020617;
    --light-blue: #3b82f6;
    --white: #ffffff;
    --gray: #64748b;
    --green: #10b981;
    --yellow: #f59e0b;
    --red: #ef4444;
    --offline-gray: #475569;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--darker-blue);
    color: var(--white);
    height: 100vh;
    overflow: hidden;
}

.header {
    background: var(--dark-blue);
    border-bottom: 2px solid var(--primary-blue);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    color: var(--gray);
    font-size: 20px;
    text-decoration: none;
    transition: color 0.2s;
    flex-shrink: 0;
    margin-right: 8px;
    background: transparent;
    line-height: 1;
}
.back-btn:hover {
    color: var(--white);
}

.logo {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-icon img {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    object-fit: cover;
}

.logo-text h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--white);
}

.logo-text p {
    font-size: 12px;
    color: var(--gray);
}

.system-badge {
    background: var(--green);
    padding: 6px 15px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: 600;
}

.main-layout {
    display: flex;
    height: calc(100vh - 70px);
}

.sidebar {
    width: 280px;
    background: var(--dark-blue);
    border-right: 2px solid var(--primary-blue);
    overflow-y: auto;
    padding: 20px;
}

.sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 20px;
}

.vehicle-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.vehicle-item {
    background: var(--darker-blue);
    border: 2px solid transparent;
    border-radius: 10px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.vehicle-item:hover {
    border-color: var(--light-blue);
}

.vehicle-item.online {
    border-left: 4px solid var(--green);
}

.vehicle-item.offline {
    opacity: 0.4;
    border-left: 4px solid var(--offline-gray);
}

.vehicle-item.offline:hover {
    border-color: var(--light-blue);
}
.vehicle-item.shutting-down {
    border-left: 4px solid #f59e0b;
}
.vehicle-item.shutting-down:hover {
    border-color: var(--light-blue);
}

.vehicle-item.selected {
    background: var(--primary-blue);
    border-color: var(--light-blue);
}

.vehicle-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    font-size: 28px;
}

.vehicle-item-info {
    flex: 1;
}

.vehicle-item-plate {
    font-size: 16px;
    font-weight: 700;
    color: var(--white);
}

.vehicle-item-status {
    font-size: 11px;
    color: var(--gray);
}

.vehicle-item-indicator {
    font-size: 12px;
}

.vehicle-item-indicator.online {
    color: var(--green);
}

.vehicle-item-indicator.offline {
    color: var(--offline-gray);
}
.vehicle-item-indicator.shutting-down {
    color: #f59e0b;
    animation: indicator-pulse 2s ease-in-out infinite;
}
.vehicle-countdown {
    font-size: 10px;
    color: #f59e0b;
    margin-top: 1px;
    font-weight: 500;
    letter-spacing: 0.3px;
}
@keyframes indicator-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

.content {
    position: relative;
    flex: 1;
    overflow-y: auto;
    padding: 30px;
}

.content-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--white);
    margin-bottom: 20px;
}

.selected-count {
    color: var(--gray);
    font-size: 14px;
    font-weight: 400;
}

.empty-state {
    text-align: center;
    padding: 0 20px;
    color: var(--gray);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
}

.empty-state-icon {
    font-size: 80px;
    margin-bottom: 20px;
    opacity: 0.3;
}

.selected-panel {
    background: var(--dark-blue);
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 25px;
    position: relative;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.panel-title {
    font-size: 20px;
    color: var(--white);
    font-weight: 600;
}

.close-btn {
    background: transparent;
    border: 2px solid var(--gray);
    color: var(--gray);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.3s;
}

.close-btn:hover {
    border-color: var(--white);
    color: var(--white);
}

.cameras-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.camera-box {
    background: black;
    border: 2px solid var(--primary-blue);
    border-radius: 10px;
    aspect-ratio: 4/3;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s;
}

.camera-box:hover {
    border-color: var(--light-blue);
    transform: scale(1.02);
}

.camera-box.active {
    border-color: var(--green);
    border-width: 3px;
}

.camera-box.loading {
    border-color: var(--light-blue);
    animation: pulse 1.5s ease-in-out infinite;
    cursor: wait;
    pointer-events: none;
}

.camera-box video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.camera-label {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.8);
    padding: 5px 12px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    z-index: 10;
}

.camera-status {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 11px;
    z-index: 10;
}

.camera-status.loading {
    color: var(--light-blue);
}

.camera-status.active {
    color: var(--green);
}

.camera-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--gray);
    font-size: 14px;
}

.camera-placeholder-icon {
    font-size: 40px;
    margin-bottom: 10px;
    opacity: 0.3;
}

.expanded-section {
    background: var(--dark-blue);
    border-radius: 12px;
    margin-top: 20px;
    overflow: hidden;
    animation: fadeIn 0.3s ease-in;
}

.expanded-header {
    background: var(--primary-blue);
    padding: 15px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.expanded-info {
    font-size: 16px;
    font-weight: 600;
}

.expanded-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.close-expanded-btn,
.popup-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: var(--white);
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    font-weight: 600;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-expanded-btn:hover,
.popup-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.05);
}

.close-expanded-btn:active,
.popup-btn:active {
    transform: scale(0.95);
}

.expanded-video-container {
    background: black;
    position: relative;
    width: 100%;
    aspect-ratio: 3/2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.expanded-video-container video {
    width: 100%;
    height: 100%;
    object-fit: fill;
    display: block;
}

.expanded-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--gray);
}

.expanded-placeholder-icon {
    font-size: 80px;
    margin-bottom: 20px;
    opacity: 0.3;
}

.expanded-placeholder-text {
    font-size: 18px;
    color: var(--gray);
}

.expanded-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    padding: 20px;
}

.metric-card {
    text-align: center;
    padding: 15px;
    background: var(--darker-blue);
    border-radius: 8px;
}

.metric-card h4 {
    font-size: 11px;
    color: var(--gray);
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.metric-card .value {
    font-size: 20px;
    font-weight: 700;
    color: var(--light-blue);
}

.metric-card .unit {
    font-size: 11px;
    color: var(--gray);
}

.hidden {
    display: none !important;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--darker-blue);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-blue);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--light-blue);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Voice button */
.vehicle-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.voice-btn {
    background: transparent;
    border: 1.5px solid var(--gray);
    color: var(--gray);
    width: 32px;
    height: 32px;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.voice-btn svg {
    width: 16px;
    height: 16px;
    transition: all 0.2s;
}

.voice-btn:hover {
    border-color: var(--green);
    color: var(--green);
}

.voice-btn:hover svg {
    color: var(--green);
}

.voice-btn.active {
    border-color: var(--green);
    background: var(--green);
    color: #fff;
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.45);
}

.voice-btn.active svg {
    color: #fff;
}

.voice-btn.connecting {
    border-color: var(--green);
    color: var(--green);
    animation: voicePulse 0.9s ease-in-out infinite;
    pointer-events: none;
}

.voice-btn.connecting svg {
    color: var(--green);
}

@keyframes voicePulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5);
        border-color: var(--green);
    }

    50% {
        box-shadow: 0 0 0 5px rgba(16, 185, 129, 0);
        border-color: #34d399;
    }
}

/* Mobile menu */
.mobile-menu-btn {
    position: fixed;
    top: 12px;
    left: 10px;
    z-index: 1001;
    background: var(--primary-blue);
    border: none;
    color: var(--white);
    width: 44px;
    height: 44px;
    border-radius: 8px;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s;
    display: none;
}

.mobile-menu-btn:active {
    transform: scale(0.95);
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-close-btn {
    display: none;
}

@media (max-width: 768px) {
    .header {
        position: sticky;
        top: 0;
        z-index: 3001;
    }

    .sidebar-overlay {
        z-index: 3000;
    }

    .sidebar {
        z-index: 3002;
    }

    .logo-text h1 {
        font-size: 20px;
    }

    .logo-text p {
        font-size: 10px;
    }

    .system-badge {
        font-size: 10px;
        padding: 4px 10px;
    }

    .mobile-menu-btn {
        display: block;
    }

    .main-layout {
        position: relative;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        border-right: none;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
        padding: 0;
        display: flex;
        flex-direction: column;
    }

    .sidebar-title {
        margin-top: 0;
        padding: 10px 12px;
        min-height: 56px;
        display: grid;
        grid-template-columns: 52px 1fr;
        align-items: center;
        gap: 10px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar-title::before {
        content: none;
        display: none;
    }

    .sidebar-title span {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar-close-btn {
        width: 40px;
        height: 40px;
        border: none;
        background: rgba(255, 255, 255, 0.06);
        color: inherit;
        border-radius: 10px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        cursor: pointer;
    }

    .vehicle-list {
        flex: 1;
        overflow-y: auto;
        padding: 20px;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .sidebar.active {
        left: 0;
    }

    .content {
        width: 100%;
        padding: 20px;
    }

    .cameras-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .expanded-metrics {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .popup-btn {
        display: none;
    }
}

@media (max-width: 480px) {
    .header {
        position: sticky;
        top: 0;
        z-index: 3001;
        padding: 10px 12px;
        display: grid;
        grid-template-columns: 52px 1fr auto;
        align-items: center;
        gap: 10px;
    }

    .mobile-menu-btn {
        position: static;
        width: 40px;
        height: 40px;
        justify-self: center;
        align-self: center;
        z-index: auto;
    }

    .logo {
        width: auto;
        display: flex;
        flex: 1 1 auto;
        min-width: 0;
        gap: 8px;
        align-items: center;
    }

    .logo-icon img {
        width: 32px;
        height: 32px;
    }

    .logo-text {
        flex: 1;
        min-width: 0;
    }

    .logo-text h1 {
        font-size: 14px;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .logo-text p {
        display: none;
    }

    .system-badge {
        align-self: center;
        margin-left: 0;
        padding: 6px 10px;
        font-size: 12px;
        white-space: nowrap;
        flex: 0 0 auto;
    }

    .sidebar-overlay {
        z-index: 3000;
    }

    .sidebar {
        z-index: 3002;
        padding-top: 0;
    }

    .sidebar-title {
        position: sticky;
        top: 0;
        z-index: 3003;
        margin-top: 0;
        padding: 10px 12px;
        min-height: 56px;
        display: grid;
        grid-template-columns: 44px 1fr;
        align-items: center;
        gap: 6px;
        background: inherit;
        border-bottom: 1px solid rgba(255, 255, 255, 0.04);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar-title::before {
        content: none;
        display: none;
    }

    .sidebar-title span {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar-close-btn {
        width: 40px;
        height: 40px;
        border: none;
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.06);
        color: inherit;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        cursor: pointer;
    }

    .sidebar-close-btn:hover {
        background: rgba(255, 255, 255, 0.10);
    }

    body.sidebar-open .system-badge {
        visibility: hidden;
    }

    .vehicle-list {
        flex: 1;
        overflow-y: auto;
        padding: 10px;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .content {
        padding: 15px;
    }

    .content-title {
        font-size: 16px;
    }

    .selected-panel {
        padding: 15px;
    }

    .panel-title {
        font-size: 16px;
    }

    .close-btn {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .cameras-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .camera-box {
        min-height: 200px;
    }

    .camera-label,
    .camera-status {
        font-size: 10px;
        padding: 4px 8px;
    }

    .expanded-section {
        margin-top: 15px;
    }

    .expanded-header {
        padding: 12px 15px;
    }

    .expanded-info {
        font-size: 14px;
    }

    .close-expanded-btn {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .expanded-video-container {
        aspect-ratio: 3/2;
    }

    .expanded-metrics {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 15px;
    }

    .metric-card {
        padding: 12px;
    }

    .metric-card h4 {
        font-size: 10px;
    }

    .metric-card .value {
        font-size: 16px;
    }

    .empty-state {
        padding: 60px 15px;
    }

    .empty-state-icon {
        font-size: 60px;
    }

    .empty-state h3 {
        font-size: 16px;
    }

    .empty-state p {
        font-size: 13px;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .expanded-video-container {
        height: 85vh;
        aspect-ratio: auto;
    }

    .expanded-metrics {
        grid-template-columns: repeat(4, 1fr);
        padding: 10px;
    }

    .metric-card {
        padding: 8px;
    }

    .metric-card h4 {
        font-size: 9px;
    }

    .metric-card .value {
        font-size: 14px;
    }
}

/* ── Skeleton de cámara — visible mientras el stream arranca ── */

.camera-skeleton {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    background-size: 200% 200%;
    animation: skeletonShimmer 2s ease-in-out infinite, pulse 1.5s ease-in-out infinite;
    gap: 10px;
    z-index: 1;
}

.skeleton-icon {
    font-size: 36px;
    opacity: 0.25;
}

.skeleton-text {
    font-size: 12px;
    color: var(--gray);
    letter-spacing: 0.5px;
}

@keyframes skeletonShimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Estado de error en cámara */
.camera-status.error {
    color: var(--red);
}
/* ── Overlay de reconexión — último frame visible debajo ── */
.camera-box .reconnect-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    z-index: 5;
    backdrop-filter: blur(2px);
}

.reconnect-overlay .reconnect-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.reconnect-overlay .reconnect-text {
    font-size: 11px;
    color: rgba(255,255,255,0.85);
    letter-spacing: 0.5px;
}

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