/* ===========================
   Reset & Base Styles
   =========================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

/* ===========================
   Layout
   =========================== */
#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow-md);
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    max-width: 1600px;
    margin: 0 auto;
}

.header-title {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.header-search-container {
    flex: 1;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
}

.header-search-box {
    position: relative;
    display: flex;
    align-items: center;
    background: white;
    border-radius: 24px;
    padding: 0.5rem 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    transition: all 0.2s ease;
    width: 100%;
}

.header-search-box:focus-within {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    transform: translateY(-1px);
}

.search-icon {
    color: var(--text-secondary);
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.header-search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 0.9375rem;
    color: var(--text-primary);
    background: transparent;
}

.header-search-input::placeholder {
    color: var(--text-secondary);
}

.header-stats {
    display: flex;
    gap: 2rem;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.stat-label {
    font-size: 0.625rem;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1rem;
    font-weight: 700;
}

.stat-value.live {
    color: var(--success-color);
}

.desktop-stats {
    display: flex;
}

.mobile-only {
    display: none;
}

/* ===========================
   Bottom Bar (Mobile)
   =========================== */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 0.75rem 1rem;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
    z-index: 100;
}

.bottom-bar-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 100%;
}

.bottom-bar-title {
    font-size: 0.625rem;
    font-weight: 600;
    color: white;
    margin: 0;
    opacity: 0.95;
    line-height: 1.3;
    text-align: center;
}

.bottom-bar-stats {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    max-width: 100%;
    margin: 0;
}

.bottom-bar .stat {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.bottom-bar .stat-label {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    margin: 0;
}

.bottom-bar .stat-value {
    font-size: 1rem;
    font-weight: 700;
    color: white;
}

.bottom-bar .stat-value.live {
    color: var(--success-color);
}

.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ===========================
   Sidebar
   =========================== */
.sidebar {
    width: 350px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn-close-sidebar {
    background: var(--bg-tertiary);
    border: none;
    border-radius: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: none;
    align-items: center;
    justify-content: center;
}

.btn-close-sidebar:hover {
    background: var(--danger-color);
    color: white;
}

@media (max-width: 768px) {
    .btn-close-sidebar {
        display: flex;
    }
}

.sidebar-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.btn-refresh {
    background: var(--bg-tertiary);
    border: none;
    border-radius: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-refresh:hover {
    background: var(--primary-color);
    color: white;
    transform: rotate(90deg);
}

.search-box {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.desktop-search {
    display: block;
}

.search-box input {
    width: 100%;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.camera-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.camera-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.camera-item:hover {
    background: var(--bg-primary);
    box-shadow: var(--shadow-md);
    transform: translateX(4px);
    border-color: var(--primary-color);
}

.camera-item.active {
    background: var(--bg-primary);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
}

.camera-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.camera-name {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.camera-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success-color);
    animation: pulse 2s infinite;
}

.camera-status.offline {
    background: var(--danger-color);
    animation: none;
}

.camera-item.offline {
    opacity: 0.6;
    background: #fee;
}

.camera-location {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.camera-location::before {
    content: "📍";
}

.camera-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.btn-action {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background: white;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-action:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ===========================
   Map
   =========================== */
.map-container {
    flex: 1;
    position: relative;
}

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

.map-controls {
    position: absolute;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 10;
}

/* Map credit (bottom left, near Google logo) */
.map-credit {
    position: absolute;
    left: 0.5rem;
    bottom: 1.8rem; /* slightly above Google logo strip */
    padding: 0.1rem 0.3rem;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.35); /* lighter, more transparent */
    color: #cbd5f5;
    font-size: 0.55rem; /* smaller text */
    font-weight: 400;
    z-index: 9; /* below controls but above map */
    pointer-events: none;
}

/* Mobile map toolbar */
.mobile-map-toolbar {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    right: 0.75rem;
    display: none;
    justify-content: flex-start;
    z-index: 15;
    pointer-events: none;
}

.btn-mobile-primary {
    pointer-events: auto;
    background: rgba(15, 23, 42, 0.9);
    color: #e5e7eb;
    border: none;
    border-radius: 999px;
    padding: 0.55rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.35);
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.btn-mobile-primary:hover {
    background: rgba(15, 23, 42, 1);
}

.btn-control {
    background: white;
    border: none;
    border-radius: 0.5rem;
    width: 48px;
    height: 48px;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-control:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

/* Custom Info Window */
.camera-info-window {
    max-width: 300px;
}

.info-header {
    margin-bottom: 0.75rem;
}

.info-location {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.info-title {
    font-weight: 400;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* 16:9 frame so 4:3 / square substreams (e.g. 704×504) look normal in widescreen preview */
.info-preview {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    overflow: hidden;
}

.info-preview video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.info-details {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.info-detail {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
}

.info-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-info-action {
    flex: 1;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-info-action:hover {
    background: var(--primary-dark);
}

.btn-info-action.secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-info-action.secondary:hover {
    background: var(--border-color);
}

/* ===========================
   Fullscreen Modal
   =========================== */
.fullscreen-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    display: none;
    flex-direction: column;
}

.fullscreen-modal.active {
    display: flex;
}

.fullscreen-header {
    padding: 1.5rem 2rem;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.fullscreen-info h2 {
    color: white;
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
}

.fullscreen-info p {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.875rem;
}

.btn-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 0.5rem;
    padding: 0.75rem;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-close:hover {
    background: var(--danger-color);
}

.fullscreen-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

/* 16:9 frame for fullscreen so substreams (e.g. 704×504) display as normal widescreen */
#fullscreenPlayer {
    width: 100%;
    max-width: min(96vw, (100vh - 120px) * 16 / 9);
    aspect-ratio: 16 / 9;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

#fullscreenPlayer video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

/* ===========================
   Loading
   =========================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    z-index: 2000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-overlay p {
    margin-top: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===========================
   Animations
   =========================== */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 1024px) {
    .sidebar {
        width: 300px;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 0.5rem 0.75rem;
    }
    
    .header-title {
        font-size: 0.75rem;
        display: none;
    }
    
    .header-search-container {
        max-width: none;
        flex: 1;
    }
    
    .header-search-box {
        padding: 0.625rem 1rem;
        border-radius: 28px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    }
    
    .header-search-input {
        font-size: 0.9375rem;
        padding: 0;
    }
    
    .header-search-input::placeholder {
        color: #9ca3af;
    }
    
    .search-icon {
        width: 20px;
        height: 20px;
        margin-right: 0.75rem;
        color: #6b7280;
        flex-shrink: 0;
    }
    
    .desktop-stats {
        display: none;
    }
    
    .desktop-search {
        display: none;
    }
    
    .mobile-only {
        display: block;
    }
    
    /* Override bottom bar styles for mobile */
    .bottom-bar {
        display: block;
    }
    
    /* Mobile slide-over sidebar */
    .sidebar {
        position: fixed;
        top: 56px; /* below header */
        left: 0;
        right: 0;
        bottom: 60px; /* above bottom bar */
        width: auto;
        max-width: 100%;
        z-index: 200;
        background: var(--bg-primary);
        box-shadow: var(--shadow-xl);
        border-right: none;
        border-top: 1px solid var(--border-color);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .header-content {
        flex-direction: row;
        gap: 0.5rem;
        align-items: center;
    }
    
    .map-container {
        height: calc(100vh - 60px - 60px); /* Account for header and bottom bar */
        padding-bottom: 60px; /* Space for bottom bar */
    }
    
    .bottom-bar {
        display: block;
    }
    
    .map-controls {
        bottom: 5rem; /* Above bottom bar */
    }
    
    .mobile-map-toolbar {
        display: flex;
    }
    
    /* Fullscreen modal optimizations for mobile */
    .fullscreen-header {
        padding: 1rem;
    }
    
    .fullscreen-info h2 {
        font-size: 1rem;
    }
    
    .fullscreen-info p {
        font-size: 0.75rem;
    }
    
    .fullscreen-content {
        padding: 0.25rem;
    }
    
    #fullscreenPlayer {
        max-width: min(96vw, (100vh - 80px) * 16 / 9);
    }
}

/* ===========================
   Scrollbar
   =========================== */
.camera-list::-webkit-scrollbar {
    width: 8px;
}

.camera-list::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.camera-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.camera-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
