/* ============================================================
   看电视TV - Web Version Styles
   Responsive: PC (>=768px) + Mobile (<768px)
   ============================================================ */

:root {
    --bg: #f5f5f5;
    --bg-card: #ffffff;
    --bg-sidebar: #1e1e2e;
    --text: #1a1a2e;
    --text-secondary: #666;
    --text-sidebar: #cdd6f4;
    --accent: #2196f3;
    --accent-light: #e3f2fd;
    --border: #e0e0e0;
    --shadow: rgba(0,0,0,0.08);
    --radius: 12px;
    --sidebar-width: 220px;
    --topbar-height: 48px;
    --ad-height: 70px;
}

[data-theme="dark"] {
    --bg: #121212;
    --bg-card: #1e1e1e;
    --bg-sidebar: #0d0d1a;
    --text: #e0e0e0;
    --text-secondary: #999;
    --text-sidebar: #cdd6f4;
    --border: #333;
    --shadow: rgba(0,0,0,0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 100;
    flex-shrink: 0;
    flex-grow: 0;
}

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.sidebar-header h2 { font-size: 18px; white-space: nowrap; }

.sidebar-search {
    padding: 8px 12px;
    flex-shrink: 0;
}

.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
    color: var(--text-sidebar);
    font-size: 14px;
    outline: none;
}

.sidebar-search input::placeholder { color: rgba(255,255,255,0.4); }

.sidebar-tabs {
    display: flex;
    padding: 0 8px;
    gap: 4px;
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    border-radius: 8px 8px 0 0;
    font-size: 13px;
    transition: all 0.2s;
}

.tab-btn.active {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.sidebar-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0;
    min-height: 0;
}

.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

.country-group-title {
    padding: 8px 16px 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.4);
    font-weight: 600;
    position: sticky;
    top: 0;
    background: var(--bg-sidebar);
    z-index: 1;
}

.country-item {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    cursor: pointer;
    transition: background 0.15s;
    gap: 8px;
}

.country-item:hover { background: rgba(255,255,255,0.08); }
.country-item.active { background: var(--accent); color: #fff; }
.country-item.active .count { color: #fff; background: rgba(255,255,255,0.2); }

.country-item .flag { font-size: 16px; flex-shrink: 0; }
.country-item .name { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.country-item .count {
    font-size: 11px;
    color: rgba(255,255,255,0.5);
    background: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 10px;
    flex-shrink: 0;
}

.country-item.has-channels .count {
    color: var(--accent);
    background: rgba(33,150,243,0.2);
}

.country-item.has-channels .name { font-weight: 600; }

.country-item .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
}

/* Favorite items */
.fav-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    cursor: pointer;
    gap: 8px;
    transition: background 0.15s;
}

.fav-item:hover { background: rgba(255,255,255,0.08); }
.fav-item .flag { font-size: 18px; }
.fav-item .name { flex: 1; font-size: 14px; }
.fav-item .remove { cursor: pointer; opacity: 0.5; }
.fav-item .remove:hover { opacity: 1; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    max-width: calc(100vw - var(--sidebar-width));
}

/* ---- Top Bar ---- */
.top-bar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-shrink: 0;
}

.top-bar-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 16px;
    min-width: 0;
}

.badge {
    background: var(--accent);
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

.top-bar-actions { display: flex; gap: 4px; flex-shrink: 0; }

.btn-icon {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: background 0.15s;
    color: var(--text);
    line-height: 1;
}

.btn-icon:hover { background: var(--accent-light); }

[data-theme="dark"] .btn-icon:hover { background: rgba(255,255,255,0.1); }

/* ---- Search Bar ---- */
.search-bar {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    gap: 8px;
    flex-shrink: 0;
}

.search-bar input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    outline: none;
}

.search-bar input:focus { border-color: var(--accent); }

/* ---- Loading ---- */
.loading {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px;
    min-height: 0;
}

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

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

.progress-bar {
    width: 200px;
    max-width: 80%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s;
    width: 0%;
}

#progress-text { font-size: 13px; color: var(--text-secondary); }

/* ---- Error State ---- */
.error-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    min-height: 0;
}

.error-icon { font-size: 48px; }

.btn-primary {
    padding: 10px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.85; }

/* ============================================================
   CHANNEL GRID
   ============================================================ */
.channel-grid {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(auto-fill, 180px);
    gap: 12px;
    justify-content: center;
    align-content: start;
    min-height: 0;
}

@media (max-width: 767px) {
    .channel-grid {
        grid-template-columns: repeat(auto-fill, 150px);
        gap: 8px;
        padding: 8px;
    }
}

.channel-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 2px 8px var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    width: 180px;
    height: 120px;
    display: flex;
    flex-direction: column;
}

.channel-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px var(--shadow);
}

.channel-card .logo-area {
    height: 70px;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-light);
    position: relative;
    overflow: hidden;
}

[data-theme="dark"] .channel-card .logo-area { background: rgba(255,255,255,0.05); }

.channel-card .logo-area img {
    max-height: 48px;
    max-width: 85%;
    object-fit: contain;
}

.channel-card .logo-area .placeholder {
    font-size: 28px;
    opacity: 0.4;
}

.channel-card .fav-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0,0,0,0.4);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.channel-card .info {
    padding: 6px 8px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.channel-card .info .ch-name {
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.channel-card .info .ch-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    font-size: 10px;
    color: var(--text-secondary);
}

/* ============================================================
   PLAYER MODAL
   ============================================================ */
.player-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.player-container {
    width: 100%;
    max-width: 960px;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
}

.player-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.player-header #player-channel-name {
    flex: 1;
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.video-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
}

.video-wrapper video {
    width: 100%;
    height: 100%;
    display: block;
}

.video-loading, .video-error {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(0,0,0,0.7);
    color: #fff;
}

.player-info {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ============================================================
   BOTTOM BAR: Ad (left) + Download (right 80px)
   ============================================================ */
.bottom-bar {
    height: 80px;
    min-height: 80px;
    display: flex;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    overflow: hidden;
}

.ad-banner {
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.download-btn {
    width: 80px;
    min-width: 80px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    cursor: pointer;
    transition: background 0.2s;
    padding: 0;
}

.download-btn:hover { background: #1976d2; }

.download-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden { display: none !important; }
.mobile-only { display: none; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

/* ============================================================
   RESPONSIVE - Mobile (< 768px)
   ============================================================ */
@media (max-width: 767px) {
    .mobile-only { display: flex; }
    .desktop-only { display: none; }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 85vw;
        max-width: 320px;
        min-width: 0;
    }

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

    .sidebar-overlay.show { display: block; }

    .channel-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 8px;
    }

    .channel-card { width: 150px; height: 105px; }
    .channel-card .logo-area { height: 56px; min-height: 56px; }
    .channel-card .logo-area img { max-height: 38px; }
    .channel-card .logo-area .placeholder { font-size: 22px; }
    .channel-card .info .ch-name { font-size: 11px; }
    .channel-card .info .ch-meta { font-size: 9px; }

    .player-modal { padding: 0; }
    .player-container {
        max-width: 100%;
        border-radius: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
    }
    .video-wrapper { flex: 1; aspect-ratio: auto; min-height: 0; }

    .top-bar-title { font-size: 14px; }
    .top-bar { padding: 0 10px; gap: 8px; }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #999; }
