/* BREEZE TV 样式表 — 暗色主题，左侧频道 + 右侧播放器布局 */

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-hover: #1f2b47;
    --text-primary: #e8e8f0;
    --text-secondary: #9898b0;
    --text-muted: #6c6c88;
    --accent: #4fc3f7;
    --accent-hover: #29b6f6;
    --accent-dim: #1a3a5c;
    --green: #66bb6a;
    --red: #ef5350;
    --yellow: #ffca28;
    --border: #2a2a4a;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ─── 顶部栏 ─── */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    backdrop-filter: blur(10px);
}

.top-bar h1 {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, #4fc3f7, #81d4fa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
}

.search-box {
    flex: 1;
    max-width: 400px;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 10px 16px 10px 40px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
}

.search-box::before {
    content: "🔍";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    opacity: 0.5;
}

.filter-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-bar select, .filter-bar button {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}

.filter-bar select:hover, .filter-bar button:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.filter-bar .stats {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ─── 国家选择器 ─── */
.country-bar {
    padding: 10px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
}

.country-bar::-webkit-scrollbar { height: 4px; }
.country-bar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.country-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    margin: 0 4px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.country-chip:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.country-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    font-weight: 600;
}

.country-chip .count {
    font-size: 11px;
    opacity: 0.6;
}

/* ─── 主布局：左侧频道 + 右侧播放器 ─── */
.main-layout {
    display: flex;
    height: calc(100vh - 100px); /* 减去顶部栏 + 国家栏高度 */
    overflow: hidden;
}

.left-panel {
    flex: 1;
    min-width: 280px;
    overflow-y: auto;
    overflow-x: hidden;
}

.left-panel::-webkit-scrollbar { width: 6px; }
.left-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* 分隔条 */
.resizer {
    width: 6px;
    cursor: col-resize;
    background: var(--border);
    flex-shrink: 0;
    position: relative;
    transition: background 0.15s;
    z-index: 10;
}

.resizer:hover,
.resizer.active {
    background: var(--accent);
}

.resizer::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 32px;
    background: var(--text-muted);
    border-radius: 2px;
    opacity: 0.5;
}

.resizer:hover::after,
.resizer.active::after {
    opacity: 1;
    background: var(--accent);
}

.right-panel {
    width: 420px;
    min-width: 320px;
    max-width: 60vw;
    background: var(--bg-secondary);
    border-left: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

/* ─── 频道网格 ─── */
.channels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
    padding: 12px 16px;
}

.channel-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}

.channel-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.channel-card.playing {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), var(--shadow);
}

.channel-card .card-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.channel-card .channel-logo {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    background: rgba(255,255,255,0.05);
    flex-shrink: 0;
}

.channel-card .channel-logo.loading {
    background: linear-gradient(90deg, var(--bg-hover) 25%, var(--border) 50%, var(--bg-hover) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.channel-card .channel-info {
    flex: 1;
    min-width: 0;
}

.channel-card .channel-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.channel-card .channel-meta {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.channel-card .channel-meta .country-tag {
    background: var(--accent-dim);
    color: var(--accent);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
}

.channel-card .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.channel-card .status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.channel-card .status-dot.offline { background: var(--red); }
.channel-card .status-dot.unknown { background: var(--text-muted); }

/* 延迟标识 */
.channel-card .delay-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.channel-card .delay-badge.fast {
    background: rgba(102, 187, 106, 0.2);
    color: var(--green);
}

.channel-card .delay-badge.medium {
    background: rgba(255, 202, 40, 0.2);
    color: var(--yellow);
}

.channel-card .delay-badge.slow {
    background: rgba(239, 83, 80, 0.2);
    color: var(--red);
}

.channel-card .delay-badge.unknown {
    display: none;
}

.channel-card .card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
}

.channel-card .fav-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 15px;
    padding: 2px;
    transition: var(--transition);
}

.channel-card .fav-btn:hover { color: var(--yellow); }
.channel-card .fav-btn.favorited { color: var(--yellow); }

.channel-card .url-type-badge {
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-muted);
    text-transform: uppercase;
}

/* ─── 加载中 ─── */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── 空状态 ─── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text-secondary); }

/* ─── 右侧播放器面板 ─── */
#video-container {
    width: 100%;
    background: #000;
    position: relative;
    aspect-ratio: 16 / 9;
    flex-shrink: 0;
    display: none;
}

#video-container.visible {
    display: block;
}

#video-container video {
    width: 100%;
    height: 100%;
    display: block;
    background: #000;
    object-fit: contain;
}

#video-container .tv-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: none;
    position: absolute;
    top: 0;
    left: 0;
}

#video-container .tv-iframe.visible {
    display: block;
}

/* 频道信息栏 */
.player-info {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.player-info.visible { display: flex; }

.player-info .player-logo {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: contain;
    flex-shrink: 0;
}

.player-info .player-meta {
    flex: 1;
    min-width: 0;
}

.player-info .player-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-info .player-delay {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.player-info .player-delay .delay-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
}

.player-info .player-delay .delay-dot.online { background: var(--green); }
.player-info .player-delay .delay-dot.offline { background: var(--red); }

.player-info .close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 6px;
    border-radius: 50%;
    transition: var(--transition);
    flex-shrink: 0;
}

.player-info .close-btn:hover {
    background: var(--bg-hover);
    color: var(--red);
}

/* ─── EPG 节目单面板 ─── */
.epg-panel {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.epg-panel.visible { display: flex; }

.epg-header {
    padding: 10px 14px 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.epg-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0 14px 14px;
}

.epg-scroll::-webkit-scrollbar { width: 4px; }
.epg-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.epg-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.epg-item {
    display: flex;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    cursor: default;
}

.epg-item:hover {
    background: var(--bg-hover);
}

.epg-item.now {
    background: var(--accent-dim);
    border-left: 3px solid var(--accent);
}

.epg-item .epg-time {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 80px;
    padding-top: 1px;
}

.epg-item .epg-content {
    flex: 1;
    min-width: 0;
}

.epg-item .epg-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.epg-item.now .epg-title {
    color: var(--accent);
    font-weight: 600;
}

.epg-item .epg-desc {
    font-size: 11px;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 2px;
}

.epg-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ─── 播放器占位（未选择频道） ─── */
.player-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-muted);
}

.player-placeholder .placeholder-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.player-placeholder .placeholder-text {
    font-size: 15px;
    opacity: 0.5;
}

/* ─── 响应式 ─── */
@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
        height: auto;
    }

    .right-panel {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    #video-container {
        aspect-ratio: 16 / 9;
        max-height: 50vh;
    }

    .left-panel {
        max-height: 50vh;
    }

    .channels-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 8px;
        padding: 10px 12px;
    }
}

@media (max-width: 768px) {
    .top-bar {
        flex-wrap: wrap;
        padding: 10px 12px;
    }

    .top-bar h1 { font-size: 16px; }
    .search-box { max-width: 100%; order: 3; flex-basis: 100%; }

    .channels-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 8px;
        padding: 8px 10px;
    }

    .channel-card { padding: 10px; }
    .channel-card .channel-logo { width: 32px; height: 32px; }
    .channel-card .channel-name { font-size: 12px; }

    .filter-bar select, .filter-bar button { font-size: 12px; padding: 6px 10px; }

    .left-panel {
        max-height: 40vh;
    }
}

/* ─── Toast ─── */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 999;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 14px;
    box-shadow: var(--shadow);
    transform: translateY(-20px);
    opacity: 0;
    transition: var(--transition);
}

.toast.visible {
    transform: translateY(0);
    opacity: 1;
}

.toast.error { border-color: var(--red); }
.toast.success { border-color: var(--green); }