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

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --border: #2a2a4a;
    --drawer-w: 280px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

.app-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ===== HEADER ===== */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 50;
    padding-top: var(--safe-top);
    flex-shrink: 0;
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    height: 56px;
}

.menu-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}

.menu-btn:active {
    background: rgba(255,255,255,0.1);
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.install-btn {
    background: var(--accent);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

/* ===== DRAWER ===== */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.drawer-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--drawer-w);
    max-width: 80vw;
    background: var(--bg-secondary);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
    padding-top: var(--safe-top);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.drawer.open {
    transform: translateX(0);
}

.drawer-header {
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.drawer-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
}

.drawer-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.drawer-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 20px;
    cursor: pointer;
    transition: background 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
}

.drawer-item:active {
    background: rgba(255,255,255,0.05);
}

.drawer-item.active {
    background: rgba(233, 69, 96, 0.15);
    color: var(--accent);
}

.drawer-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.drawer-item.active svg {
    opacity: 1;
}

.drawer-item-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.drawer-item-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: rgba(255,255,255,0.08);
    padding: 2px 8px;
    border-radius: 10px;
    flex-shrink: 0;
}

.drawer-item.active .drawer-item-count {
    background: var(--accent);
    color: #fff;
}

.drawer-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 20px;
}

/* ===== CONTENT ===== */
.content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 8px;
    padding-bottom: calc(8px + var(--safe-bottom));
}

.camera-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

/* ===== CARD ===== */
.cam-card {
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.12s;
}

.cam-card:active {
    transform: scale(0.98);
}

.cam-preview {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.cam-preview-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cam-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #111;
    transition: opacity 0.4s;
}

.cam-preview.has-thumb .cam-loading {
    opacity: 0;
    pointer-events: none;
}

.cam-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255,255,255,0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.play-icon {
    position: absolute;
    width: 48px;
    height: 48px;
    background: rgba(233, 69, 96, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
    z-index: 2;
}

.cam-card:active .play-icon {
    transform: scale(0.9);
}

.play-icon svg {
    margin-left: 3px;
}

.cam-status {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    z-index: 3;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: none;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cam-status.online {
    background: rgba(46, 204, 113, 0.85);
    color: #fff;
}

.cam-status.online .status-dot {
    background: #fff;
    box-shadow: 0 0 6px 2px rgba(255,255,255,0.5);
}

.cam-info {
    padding: 10px 12px;
}

.cam-name {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.3;
}

.cam-source {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.cam-live {
    display: inline-block;
    background: #e74c3c;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
    animation: pulse 2s infinite;
}

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

.street-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 12px 4px 6px;
    grid-column: 1 / -1;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2px;
}

/* ===== PLAYER ===== */
.player-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.95);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.player-overlay.hidden {
    display: none;
}

.player-container {
    width: 100%;
    max-width: 600px;
    position: relative;
}

.close-btn {
    position: absolute;
    top: -44px;
    right: 0;
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    z-index: 210;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.active-player {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
}

.active-player iframe,
.active-player video {
    width: 100%;
    height: 100%;
    border: none;
}

.player-name {
    text-align: center;
    padding: 12px;
    font-size: 15px;
    font-weight: 500;
}

/* ===== FOOTER ===== */
.footer {
    text-align: center;
    padding: 16px;
    color: var(--text-secondary);
    font-size: 12px;
}

/* ===== GRID 2 COL ===== */
@media (min-width: 520px) {
    .camera-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
}

/* ===== iOS STANDALONE ===== */
@supports (-webkit-touch-callout: none) {
    .header {
        padding-top: env(safe-area-inset-top, 20px);
    }
    .content {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .drawer {
        padding-top: env(safe-area-inset-top, 20px);
    }
}

/* ===== LIGHT MODE ===== */
@media (prefers-color-scheme: light) {
    :root {
        --bg-primary: #f0f2f5;
        --bg-secondary: #fff;
        --bg-card: #fff;
        --text-primary: #1a1a2e;
        --text-secondary: #666;
        --border: #e0e0e0;
    }
    .drawer {
        box-shadow: 4px 0 24px rgba(0,0,0,0.15);
    }
    .drawer-overlay.open {
        background: rgba(0,0,0,0.3);
    }
}
