:root {
    --bg: #111113;
    --bg2: #1a1a1e;
    --bg3: #222228;
    --border: #2a2a30;
    --text: #eee;
    --text2: #999;
    --text3: #666;
    --accent: #6366f1;
    --radius: 8px;
    --transition: 150ms ease;
}

[data-theme="light"] {
    --bg: #f5f5f5;
    --bg2: #fff;
    --bg3: #eee;
    --border: #ddd;
    --text: #111;
    --text2: #555;
    --text3: #999;
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }
img { max-width: 100%; display: block; }

/* Header */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 52px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 100;
    gap: 12px;
}

.header-left, .header-right { display: flex; align-items: center; gap: 8px; }

.brand {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.icon-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    color: var(--text2);
    transition: var(--transition);
}
.icon-btn:hover { background: var(--bg3); color: var(--text); }

.header-center { flex: 1; max-width: 360px; }

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    height: 34px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: var(--transition);
}
.search-box:focus-within { border-color: var(--accent); }
.search-box svg { color: var(--text3); flex-shrink: 0; }
.search-box input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 0.85rem;
}
.search-box input::placeholder { color: var(--text3); }

/* Layout */
.layout {
    display: flex;
    padding-top: 52px;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 220px;
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 50;
}

.sidebar-section { padding: 12px; }

.sidebar-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text3);
    padding: 0 8px 8px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text2);
    transition: var(--transition);
    width: 100%;
    text-align: left;
}
.sidebar-item:hover { background: var(--bg3); color: var(--text); }
.sidebar-item.active { background: var(--accent); color: #fff; }

.badge {
    font-size: 0.7rem;
    padding: 1px 6px;
    background: var(--bg3);
    border-radius: 10px;
    color: var(--text3);
}
.sidebar-item.active .badge { background: rgba(255,255,255,0.2); color: #fff; }

.sidebar-group { display: flex; flex-direction: column; }

.sidebar-group-header { cursor: pointer; }

.group-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.group-arrow {
    transition: transform 0.2s ease;
    opacity: 0.5;
}

.sidebar-group.expanded .group-arrow {
    transform: rotate(90deg);
}

.sidebar-channels {
    display: none;
    flex-direction: column;
    padding-left: 12px;
    gap: 1px;
}

.sidebar-group.expanded > .sidebar-channels,
.sidebar-subgroup.expanded > .sidebar-channels {
    display: flex;
}

.sidebar-subgroup {
    display: flex;
    flex-direction: column;
}

.sidebar-subgroup-header {
    padding-left: 8px !important;
    font-size: 0.8rem !important;
}

.sidebar-subgroup .sidebar-channels {
    padding-left: 16px;
}

.sidebar-channel {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text2);
    transition: var(--transition);
    text-align: left;
    width: 100%;
}
.sidebar-channel:hover { background: var(--bg3); color: var(--text); }

.channel-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text3);
    flex-shrink: 0;
}

.sidebar-channel:hover .channel-dot { background: var(--accent); }

.channel-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Content */
.content {
    flex: 1;
    margin-left: 220px;
    padding: 16px 20px;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.content-header h2 { font-size: 1rem; font-weight: 600; }
.text-muted { font-size: 0.8rem; color: var(--text3); }

/* Channel Grid */
.channel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.channel-card {
    position: relative;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    gap: 8px;
}
.channel-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.channel-logo {
    width: 56px;
    height: 56px;
    border-radius: 6px;
    background: var(--bg3);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.channel-logo img { width: 100%; height: 100%; object-fit: contain; }
.channel-logo svg { width: 24px; height: 24px; color: var(--text3); }

.channel-name {
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Player Modal */
.player-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
}
.player-modal.active { display: flex; }

.player-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.92);
    backdrop-filter: blur(8px);
}

.player-box {
    position: relative;
    width: 100%;
    max-width: 1000px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,0.6);
    animation: playerIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes playerIn {
    from { opacity: 0; transform: scale(0.95) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.player-screen {
    position: relative;
    aspect-ratio: 16/9;
    background: #000;
}
.player-screen video {
    width: 100%;
    height: 100%;
    outline: none;
}

/* Gradient overlays - auto hide */
.player-gtop, .player-gbot {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 10;
    padding: 16px 18px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.player-screen.controls-visible .player-gtop,
.player-screen.controls-visible .player-gbot {
    opacity: 1;
    pointer-events: auto;
}

.player-gtop {
    top: 0;
    background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.player-gbot {
    bottom: 0;
    background: linear-gradient(0deg, rgba(0,0,0,0.7) 0%, transparent 100%);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.player-top-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.player-top-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.player-action-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(4px);
    color: #fff;
    transition: var(--transition);
}
.player-action-btn:hover { background: rgba(255,255,255,0.25); }

/* Fullscreen mode */
.player-box:fullscreen,
.player-box:-webkit-full-screen {
    max-width: none;
    border-radius: 0;
}
.player-box:fullscreen .player-screen,
.player-box:-webkit-full-screen .player-screen {
    aspect-ratio: unset;
    height: 100vh;
}

/* Center play/pause button */
.player-center-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    z-index: 15;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(6px);
    border: 2px solid rgba(255,255,255,0.2);
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease, background 0.2s ease;
}
.player-center-play.show {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}
.player-center-play:hover {
    background: rgba(0,0,0,0.7);
    border-color: rgba(255,255,255,0.4);
}

.player-logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: contain;
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(4px);
    padding: 2px;
}

.player-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.player-group {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.6);
    margin-top: 1px;
}

.player-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(4px);
    color: #fff;
    transition: var(--transition);
}
.player-close:hover { background: rgba(231,76,60,0.8); }

/* Loading spinner - modern */
.player-loading, .player-error {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    z-index: 5;
}

.loader-ring {
    display: inline-block;
    position: relative;
    width: 48px;
    height: 48px;
}
.loader-ring div {
    box-sizing: border-box;
    display: block;
    position: absolute;
    width: 40px;
    height: 40px;
    margin: 4px;
    border: 3px solid transparent;
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: loaderSpin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}
.loader-ring div:nth-child(1) { animation-delay: -0.45s; }
.loader-ring div:nth-child(2) { animation-delay: -0.3s; }
.loader-ring div:nth-child(3) { animation-delay: -0.15s; }
@keyframes loaderSpin { to { transform: rotate(360deg); } }

.player-error svg { color: rgba(255,255,255,0.4); }
.player-error span { font-size: 0.9rem; color: rgba(255,255,255,0.7); }

.btn-retry {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    font-size: 0.85rem;
    font-weight: 500;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    transition: var(--transition);
}
.btn-retry:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* Source pills */
.player-sources-bar {
    display: flex;
    gap: 8px;
    padding: 10px 4px;
    overflow-x: auto;
    pointer-events: auto;
    scrollbar-width: none;
}
.player-sources-bar::-webkit-scrollbar { display: none; }

.source-btn {
    flex-shrink: 0;
    padding: 6px 16px;
    font-size: 0.78rem;
    font-weight: 500;
    background: rgba(255,255,255,0.12);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 20px;
    color: rgba(255,255,255,0.8);
    transition: var(--transition);
}
.source-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }
.source-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.active { display: flex; }

.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.7); }

.modal-box {
    position: relative;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    animation: fadeUp 0.2s ease;
}
.modal-sm { max-width: 380px; }

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 0.95rem; font-weight: 600; }
.modal-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 1.2rem;
    color: var(--text3);
    transition: var(--transition);
}
.modal-close:hover { background: var(--bg3); color: var(--text); }

.modal-body { padding: 16px; overflow-y: auto; max-height: calc(80vh - 50px); }
.modal-body label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--text2); margin-bottom: 4px; margin-top: 12px; }
.modal-body label:first-child { margin-top: 0; }
.modal-body input[type="text"],
.modal-body input[type="url"] {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
    transition: var(--transition);
}
.modal-body input:focus { border-color: var(--accent); }

.modal-actions { display: flex; gap: 8px; margin-top: 16px; }

.btn {
    padding: 7px 14px;
    font-size: 0.85rem;
    font-weight: 500;
    background: var(--accent);
    color: #fff;
    border-radius: 6px;
    transition: var(--transition);
}
.btn:hover { opacity: 0.9; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text2); }
.btn-outline:hover { border-color: var(--text3); color: var(--text); }

.modal-actions { justify-content: flex-end; }

/* Sources List */
.source-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    background: var(--bg3);
    border-radius: 6px;
    margin-bottom: 8px;
}
.source-info { flex: 1; min-width: 0; }
.source-name { font-size: 0.85rem; font-weight: 500; }
.source-url { font-size: 0.7rem; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-meta { font-size: 0.7rem; color: var(--text3); margin-top: 2px; }

.source-actions { display: flex; gap: 4px; margin-left: 8px; }
.source-action-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: var(--text3);
    transition: var(--transition);
}
.source-action-btn:hover { background: var(--border); color: var(--text); }
.source-action-btn svg { width: 14px; height: 14px; }
.source-action-btn.delete:hover { background: #e74c3c; color: #fff; }

/* Toast */
.toast-container {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 8px 16px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: fadeUp 0.2s ease;
    pointer-events: auto;
}
.toast-success { border-color: #27ae60; }
.toast-error { border-color: #e74c3c; }

/* Fetch Overlay */
.fetch-overlay {
    position: fixed;
    inset: 0;
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.5);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text3);
}
.empty-state svg { margin: 0 auto 12px; }
.empty-state p { font-size: 0.9rem; }

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

/* Responsive */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: 280px; transition: transform 0.25s ease; }
    .sidebar.open { transform: translateX(0); }
    .content { margin-left: 0; }
    .channel-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .channel-card { padding: 12px 8px; }
    .channel-logo { width: 44px; height: 44px; }
    .header-center { max-width: none; }
    .player-box { border-radius: 0; max-width: none; }
    .sidebar-channels { padding-left: 8px; }
    .sidebar-subgroup .sidebar-channels { padding-left: 10px; }
    .player-gtop, .player-gbot { padding: 10px 12px; }
    .player-logo { width: 32px; height: 32px; }
    .player-title { font-size: 0.85rem; }
    .source-btn { padding: 5px 12px; font-size: 0.72rem; }
}

@media (max-width: 480px) {
    .channel-grid { grid-template-columns: repeat(2, 1fr); }
    .header-center { max-width: none; }
    .header-left .brand { display: none; }
}

@media (hover: none) {
    .channel-card:hover { transform: none; }
    .channel-card:active { background: var(--bg3); }
}
