/* === Cloud Camera PWA — Mobile Dark Theme === */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg: #1a1a2e;
    --card: #16213e;
    --accent: #e94560;
    --accent2: #0f3460;
    --text: #eee;
    --text-dim: #888;
    --green: #00d09c;
    --red: #e94560;
    --radius: 12px;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    user-select: none;
    -webkit-user-select: none;
}

/* === Screens === */
.screen {
    display: none;
    height: 100%;
    flex-direction: column;
}
.screen.active {
    display: flex;
}

/* === Login === */
#loginScreen {
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.login-card {
    background: var(--card);
    border-radius: 20px;
    padding: 40px 30px;
    width: 100%;
    max-width: 360px;
    text-align: center;
}
.logo { font-size: 64px; margin-bottom: 10px; }
.login-card h1 { font-size: 24px; margin-bottom: 5px; }
.subtitle { color: var(--text-dim); font-size: 14px; margin-bottom: 30px; }
.login-card input {
    width: 100%;
    padding: 14px 16px;
    margin-bottom: 12px;
    border: 1px solid #ffffff15;
    border-radius: 10px;
    background: #ffffff08;
    color: var(--text);
    font-size: 16px;
    outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card input::placeholder { color: var(--text-dim); }
.btn-primary {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}
.btn-primary:active { opacity: 0.7; }
.error-msg { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* === Top Bar === */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--card);
    font-size: 16px;
    font-weight: 600;
    padding-top: max(12px, env(safe-area-inset-top));
}
.dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.dot.online { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.offline { background: var(--text-dim); }

/* === Tab Content === */
.tab-content {
    flex: 1;
    overflow-y: auto;
    display: none;
    -webkit-overflow-scrolling: touch;
}
.tab-content.active { display: flex; flex-direction: column; }

/* === Video === */
.video-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    position: relative;
    min-height: 200px;
}
.video-feed {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}
/* Canvas keeps previous frame until new one drawn — no flicker */
#liveCanvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
}
.placeholder {
    position: absolute;
    text-align: center;
    color: var(--text-dim);
}
.placeholder span { font-size: 48px; display: block; margin-bottom: 10px; }

/* === Live Bar === */
.live-bar, .playback-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: var(--card);
    padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.fps-badge {
    background: #ffffff10;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-family: monospace;
}
.btn-icon {
    background: #ffffff10;
    border: none;
    color: var(--text);
    width: 40px; height: 40px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.btn-icon:active { background: #ffffff20; }

/* === File List === */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 8px;
}
.section-header h2 { font-size: 18px; }
.file-list { padding: 0 16px 80px; }
.file-item {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.file-info { flex: 1; }
.file-name { font-size: 14px; font-weight: 500; }
.file-meta { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.file-actions { display: flex; gap: 8px; }
.file-actions button {
    background: #ffffff10;
    border: none;
    color: var(--text);
    width: 36px; height: 36px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
}
.file-actions button:active { background: #ffffff20; }
.file-actions .btn-delete { color: var(--red); }
.empty-hint { color: var(--text-dim); text-align: center; padding: 30px; font-size: 14px; }

/* === Settings === */
.card {
    background: var(--card);
    border-radius: var(--radius);
    margin: 16px;
    padding: 20px;
}
.card h2 { font-size: 16px; margin-bottom: 16px; }
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #ffffff08;
}
.setting-row:last-child { border-bottom: none; }
.setting-row label { font-size: 15px; }
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type="range"] { width: 120px; accent-color: var(--accent); }
.val-badge {
    background: #ffffff10;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 13px;
    font-family: monospace;
    min-width: 30px;
    text-align: center;
}

/* === Toggle Switch === */
.switch {
    position: relative;
    display: inline-block;
    width: 44px; height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #ffffff20;
    border-radius: 24px;
    transition: 0.3s;
}
.slider::before {
    content: "";
    position: absolute;
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* === Status Grid === */
.status-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.status-item {
    background: #ffffff08;
    padding: 10px 12px;
    border-radius: 8px;
}
.status-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; }
.status-value { font-size: 16px; font-weight: 600; margin-top: 2px; }

/* === Tab Bar === */
.tab-bar {
    display: flex;
    background: var(--card);
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid #ffffff10;
}
.tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 8px 0;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: color 0.2s;
}
.tab.active { color: var(--accent); }
.tab-icon { font-size: 22px; }

/* === Utility === */
.hidden { display: none !important; }

/* === Snapshot flash === */
@keyframes flash {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}
.flash-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: white;
    pointer-events: none;
    z-index: 999;
    animation: flash 0.3s ease-out;
}
