/* ==========================================
   BASE & RESET STYLES
   ========================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: #f4f7f6;
    color: #333;
    padding: 20px;
    overscroll-behavior-y: none;
}

/* ==========================================
   LOGIN CONTAINER
   ========================================== */
#login-container {
    width: 100%;
    max-width: 400px;
    margin: 10vh auto;
    background: #ffffff;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

#login-container h2 {
    margin-bottom: 25px;
    font-size: 24px;
    color: #111;
    text-align: center;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #444;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: #0070f3;
    outline: none;
}

#login-error {
    color: #dc2626;
    font-size: 14px;
    margin-bottom: 15px;
    display: none;
    text-align: center;
}

/* ==========================================
   BUTTONS
   ========================================== */
.btn {
    width: 100%;
    padding: 12px 15px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn:active { transform: scale(0.98); }

.primary-btn {
    background-color: #0070f3;
    color: #ffffff;
}
.primary-btn:hover { background-color: #005bb5; }

.danger-btn {
    background-color: #dc2626;
    color: #ffffff;
    width: auto;
    padding: 8px 16px;
    font-size: 14px;
}
.danger-btn:hover { background-color: #b91c1c; }

/* ==========================================
   APP CONTAINERS & HEADER
   ========================================== */
#app-container, #stream-view-container {
    max-width: 1200px;
    margin: 0 auto;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    gap: 10px;
}

.app-header h2 {
    font-size: 20px;
    font-weight: 600;
}

/* ==========================================
   CAMERA GRID & CARDS
   ========================================== */
#camera-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
    gap: 16px;
}

.camera-card {
    background: #ffffff;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
}

.cam-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    gap: 10px;
}

.cam-header h3 {
    font-size: 18px;
    color: #111;
    word-break: break-word;
}

.status-online, .status-offline {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    white-space: nowrap;
}

.status-online { background-color: #dcfce7; color: #16a34a; }
.status-offline { background-color: #fee2e2; color: #dc2626; }

/* Snapshot Styles */
.cam-snapshot-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 12px;
    position: relative;
}

.cam-snapshot {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cam-snapshot-fallback {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #64748b;
    font-size: 13px;
    font-weight: 500;
    background: #f1f5f9;
}

.cam-details {
    margin-bottom: 16px;
    font-size: 13px;
    color: #555;
    background: #f8fafc;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.cam-details p { margin-bottom: 4px; line-height: 1.4; }
.cam-details p:last-child { margin-bottom: 0; }
.cam-details strong { color: #333; font-weight: 600; margin-right: 4px; }

.mt-auto { margin-top: auto; }

.btn-group { display: flex; gap: 10px; }
.playback-btn { background-color: #4f46e5; }
.playback-btn:hover { background-color: #4338ca; }

/* ==========================================
   STREAM VIEW & RESPONSIVE PLAYER
   ========================================== */
.stream-header { justify-content: flex-start; }
.btn-back { width: auto; padding: 8px 16px; font-size: 14px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-grow: 1; }

#player-wrapper {
    position: relative !important;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 75vh;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    touch-action: none; 
}

#zoom-container {
    width: 100%;
    height: 100%;
    transform-origin: center center;
    will-change: transform;
    transition: transform 0.1s ease-out; 
}

#ws-player {
    width: 100%;
    height: 100%;
    background: #000;
    position: absolute;
    top: 0; left: 0;
}

#ws-stream-status {
    margin-top: 15px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: #555;
}

.start-btn-wrapper { margin-top: 20px; display: flex; justify-content: center; }
#start-stream-btn { max-width: 250px; padding: 14px 24px; font-size: 18px; }

/* Control Bar Overlay */
#control-bar {
    position: absolute;
    bottom: 0; left: 0;
    width: 100%;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
    padding: 20px 15px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
}

@media (hover: none) and (pointer: coarse) {
    #control-bar { opacity: 1; background: rgba(0, 0, 0, 0.65); }
}

#player-wrapper:hover #control-bar { opacity: 1; }

.ctrl-left, .ctrl-center, .ctrl-right { display: flex; align-items: center; gap: 10px; }
.ctrl-btn {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    backdrop-filter: blur(4px);
}
.ctrl-btn:active, .ctrl-btn:hover { background: rgba(255, 255, 255, 0.4); }

.ctrl-group { display: flex; align-items: center; gap: 6px; }
.ctrl-group label { color: #fff; font-size: 13px; font-weight: 500; }

/* ==========================================
   TIMELINE PLAYBACK LAYOUT
   ========================================== */
#timeline-layout {
    display: flex;
    gap: 20px;
    width: 100%;
    height: 70vh;
    max-height: 600px;
}

#timeline-player-wrapper {
    flex: 2;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#playback-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.timeline-sidebar {
    flex: 1;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 280px;
}

.sidebar-header {
    padding: 15px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}
.sidebar-header h3 { font-size: 15px; color: #1e293b; }

#recordings-list { flex-grow: 1; overflow-y: auto; padding: 10px; }

.event-item {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: all 0.2s;
}
.event-item:hover { background: #f1f5f9; border-color: #cbd5e1; }
.event-item.active { background: #eff6ff; border-color: #3b82f6; }

.event-time { font-size: 13px; font-weight: 600; color: #0f172a; margin-bottom: 4px; }
.event-meta { font-size: 11px; color: #64748b; display: flex; justify-content: space-between; }

/* Mobile Adaptations */
@media screen and (max-width: 850px) {
    #timeline-layout { flex-direction: column; height: auto; }
    #timeline-player-wrapper { aspect-ratio: 16 / 9; width: 100%; }
    .timeline-sidebar { height: 280px; }
    
    #control-bar { flex-wrap: wrap; padding: 10px; justify-content: center; }
    .ctrl-center { width: 100%; justify-content: center; order: 3; margin-top: 6px; }
    .vol-group label, .speed-group label { display: none; }
}