/* =========================================================================
   Dawud TV - Styles
   A dark, TV-like interface for the video streaming app
   ========================================================================= */

/* --- Reset & Base ------------------------------------------------------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary:     #0a0a12;
    --bg-secondary:   #12121e;
    --bg-surface:     #1a1a2e;
    --bg-surface-hov: #252545;
    --bg-card:        #16213e;
    --bg-overlay:     rgba(0, 0, 0, 0.85);

    --accent-primary: #e94560;
    --accent-glow:    rgba(233, 69, 96, 0.3);
    --accent-hover:   #ff6b81;
    --accent-secondary: #0f3460;

    --text-primary:   #f0f0f0;
    --text-secondary: #a0a0b8;
    --text-muted:     #6c6c80;

    --border-color:   #2a2a45;
    --border-radius:  12px;
    --border-radius-sm: 8px;

    --shadow:         0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-sm:      0 4px 16px rgba(0, 0, 0, 0.3);
    --transition:     0.2s ease;

    --font-family:    'Segoe UI', system-ui, -apple-system, sans-serif;
    --sidebar-width:  240px;
    --header-height:  64px;
}

html, body {
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a { color: var(--accent-primary); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* --- Scrollbar ---------------------------------------------------------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb {
    background: var(--bg-surface);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--bg-surface-hov); }

/* =========================================================================
   APP SHELL
   ========================================================================= */
#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* =========================================================================
   LOGIN SCREEN
   ========================================================================= */
#login-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(233, 69, 96, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 50%, rgba(15, 52, 96, 0.1) 0%, transparent 60%);
}

.login-box {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 48px 40px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow);
    animation: loginFadeIn 0.5s ease;
}

@keyframes loginFadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.login-logo {
    font-size: 48px;
    margin-bottom: 8px;
}

.login-box h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.login-box p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 32px;
}

.login-box .input-group {
    position: relative;
    margin-bottom: 20px;
}

.login-box input[type="password"] {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-size: 16px;
    font-family: var(--font-family);
    transition: border-color var(--transition);
    outline: none;
}

.login-box input[type="password"]:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-box input[type="password"]::placeholder {
    color: var(--text-muted);
}

.btn-login {
    width: 100%;
    padding: 14px;
    background: var(--accent-primary);
    color: #fff;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    font-family: var(--font-family);
}

.btn-login:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-login:active {
    transform: translateY(0);
}

.login-error {
    color: var(--accent-primary);
    font-size: 13px;
    margin-top: 12px;
    min-height: 20px;
}

/* =========================================================================
   MAIN APP LAYOUT
   ========================================================================= */
#main-app {
    display: none;
    height: 100%;
    flex-direction: column;
}

#main-app.active {
    display: flex;
}

/* --- Header ------------------------------------------------------------- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    z-index: 100;
}

.app-header .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.app-header .brand-icon {
    font-size: 28px;
}

.app-header .header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.btn-logout {
    padding: 8px 16px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-family);
}

.btn-logout:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    background: rgba(233, 69, 96, 0.1);
}

/* --- Content Area ------------------------------------------------------- */
.app-content {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    padding-bottom: 100px;
}

/* =========================================================================
   CATEGORIES
   ========================================================================= */
.section {
    margin-bottom: 40px;
}

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

.section-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.section-description {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 2px;
}

.btn-play-all {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    background: var(--accent-primary);
    color: #fff;
    border: none;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-family);
    white-space: nowrap;
}

.btn-play-all:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-glow);
}

/* --- Video Scroller ----------------------------------------------------- */
.video-scroller {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 8px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.video-scroller::-webkit-scrollbar {
    height: 4px;
}

/* --- Video Card --------------------------------------------------------- */
.video-card {
    flex: 0 0 240px;
    scroll-snap-align: start;
    background: var(--bg-surface);
    border-radius: var(--border-radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    position: relative;
}

.video-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.video-card-thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: var(--bg-secondary);
    overflow: hidden;
}

.video-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition);
}

.video-card:hover .video-card-thumb img {
    transform: scale(1.05);
}

.video-card-thumb .play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    transition: opacity var(--transition);
}

.video-card:hover .play-overlay {
    opacity: 1;
}

.play-overlay .play-icon {
    width: 56px;
    height: 56px;
    background: var(--accent-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 4px 20px rgba(233, 69, 96, 0.4);
    transition: transform var(--transition);
}

.video-card:hover .play-overlay .play-icon {
    transform: scale(1.1);
}

.video-card-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.video-card-body {
    padding: 12px 14px 14px;
}

.video-card-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.video-card-badge {
    display: inline-block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Empty state */
.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 60px 20px;
    font-size: 15px;
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* =========================================================================
   PLAYER MODAL
   ========================================================================= */
#player-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: var(--bg-overlay);
    backdrop-filter: blur(8px);
    animation: playerFadeIn 0.3s ease;
}

#player-modal.active {
    display: flex;
    flex-direction: column;
}

@keyframes playerFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.player-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* --- Player Toolbar ----------------------------------------------------- */
.player-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    flex-shrink: 0;
}

.player-toolbar .player-title {
    font-size: 16px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin: 0 16px;
}

.btn-close-player {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    transition: background var(--transition);
    flex-shrink: 0;
}

.btn-close-player:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* --- Player Main Area --------------------------------------------------- */
.player-main {
    flex: 1;
    display: flex;
    overflow: hidden;
    padding: 0 24px 24px;
    gap: 20px;
}

.player-video-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.player-video-wrapper video {
    width: 100%;
    height: 100%;
    max-height: 70vh;
    background: #000;
    border-radius: var(--border-radius);
    object-fit: contain;
    box-shadow: var(--shadow);
}

/* Custom video controls overlay */
.video-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    flex-wrap: wrap;
}

.video-controls button {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-controls button:hover {
    background: rgba(255, 255, 255, 0.1);
}

.video-controls .progress-bar {
    flex: 1;
    min-width: 100px;
    height: 4px;
    background: var(--bg-surface);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
    transition: height var(--transition);
}

.video-controls .progress-bar:hover {
    height: 6px;
}

.video-controls .progress-bar .progress-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s linear;
}

.video-controls .progress-bar .progress-handle {
    display: none;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    background: var(--accent-primary);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent-glow);
}

.video-controls .progress-bar:hover .progress-handle {
    display: block;
}

.video-controls .time-display {
    font-size: 13px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.video-controls .volume-control {
    display: flex;
    align-items: center;
    gap: 6px;
}

.video-controls .volume-slider {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-surface);
    border-radius: 2px;
    outline: none;
}

.video-controls .volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
}

/* Autoplay toggle */
.autoplay-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background var(--transition);
}

.autoplay-toggle:hover {
    background: rgba(255, 255, 255, 0.05);
}

.autoplay-toggle input[type="checkbox"] {
    width: 38px;
    height: 20px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-surface);
    border-radius: 10px;
    position: relative;
    cursor: pointer;
    transition: background var(--transition);
    flex-shrink: 0;
}

.autoplay-toggle input[type="checkbox"]::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: transform var(--transition), background var(--transition);
}

.autoplay-toggle input[type="checkbox"]:checked {
    background: var(--accent-primary);
}

.autoplay-toggle input[type="checkbox"]:checked::before {
    transform: translateX(18px);
    background: #fff;
}

/* --- Playlist Sidebar --------------------------------------------------- */
.playlist-sidebar {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.playlist-sidebar .playlist-header {
    padding: 16px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.playlist-sidebar .playlist-items {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.playlist-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}

.playlist-item:hover {
    background: var(--bg-surface-hov);
}

.playlist-item.active {
    background: rgba(233, 69, 96, 0.15);
    border-left: 3px solid var(--accent-primary);
}

.playlist-item-thumb {
    width: 80px;
    flex-shrink: 0;
    aspect-ratio: 16 / 9;
    border-radius: 4px;
    overflow: hidden;
    background: var(--bg-secondary);
}

.playlist-item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.playlist-item-info {
    flex: 1;
    min-width: 0;
}

.playlist-item-title {
    font-size: 13px;
    font-weight: 500;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.playlist-item-duration {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.playlist-item-index {
    font-size: 12px;
    color: var(--text-muted);
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.playlist-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 40px 20px;
    font-size: 13px;
}

/* =========================================================================
   ERROR / LOADING STATES
   ========================================================================= */
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-muted);
}

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

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

.error-message {
    text-align: center;
    padding: 40px;
    color: var(--accent-primary);
}

/* =========================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 1024px) {
    .playlist-sidebar {
        width: 260px;
    }
}

@media (max-width: 768px) {
    .app-header {
        padding: 0 16px;
    }

    .app-content {
        padding: 20px 16px;
    }

    .section-title {
        font-size: 18px;
    }

    .video-card {
        flex: 0 0 180px;
    }

    .video-card-body {
        padding: 10px 12px;
    }

    .video-card-title {
        font-size: 13px;
    }

    .player-main {
        flex-direction: column;
        padding: 0 12px 12px;
    }

    .playlist-sidebar {
        width: 100%;
        max-height: 200px;
    }

    .player-toolbar {
        padding: 12px 16px;
    }

    .player-toolbar .player-title {
        font-size: 14px;
    }

    .video-controls {
        gap: 8px;
    }

    .video-controls .volume-slider {
        width: 50px;
    }

    .login-box {
        margin: 20px;
        padding: 32px 24px;
    }

    .btn-play-all {
        font-size: 12px;
        padding: 6px 14px;
    }
}

@media (max-width: 480px) {
    .video-card {
        flex: 0 0 150px;
    }

    .play-overlay .play-icon {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
}
