* {
    box-sizing: border-box;
}

/* ─── Thème clair (défaut) ─────────────────────────────────────── */

:root {
    --bg: #ffffff;
    --bg-secondary: #f5f5f5;
    --ink: #111111;
    --muted: #888888;
    --border: #dddddd;
    --hover: #f0f0f0;
    --accent: #222222;
    --accent-text: #ffffff;
    --topbar-bg: rgba(30, 30, 30, 0.95);
    --topbar-text: #ffffff;
    --player-bg: #000000;
    --shadow: rgba(0, 0, 0, 0.12);
}

/* ─── Thème sombre ─────────────────────────────────────────────── */

body.tv-dark {
    --bg: #111111;
    --bg-secondary: #1c1c1c;
    --ink: #f0f0f0;
    --muted: #777777;
    --border: #2e2e2e;
    --hover: #1e1e1e;
    --accent: #e0e0e0;
    --accent-text: #111111;
    --topbar-bg: rgba(0, 0, 0, 0.95);
    --topbar-text: #f0f0f0;
    --player-bg: #000000;
    --shadow: rgba(0, 0, 0, 0.5);
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    transition: background 0.2s, color 0.2s;
}

#tv-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ──────────────────────────────────────────────────── */

#tv-sidebar {
    width: 320px;
    min-width: 160px;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg);
    overflow: hidden;
    flex-shrink: 0;
    transition: width 0.2s ease;
}

#tv-sidebar.collapsed {
    width: 0 !important;
    min-width: 0;
    border-right: none;
}

#tv-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

#tv-back-link {
    font-size: 12px;
    color: var(--muted);
    text-decoration: none;
    transition: color 0.15s;
}

#tv-back-link:hover {
    color: var(--ink);
}

#tv-sidebar-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

#tv-filters {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#tv-filters input,
#tv-filters select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--ink);
    font-size: 13px;
}

#tv-channel-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

.tv-channel-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    position: relative;
}

.tv-channel-item:hover {
    background: var(--hover);
}

.tv-channel-item.active {
    background: var(--accent);
    color: var(--accent-text);
}

.tv-channel-number {
    font-size: 11px;
    color: var(--muted);
    min-width: 24px;
    text-align: right;
    flex-shrink: 0;
}

.tv-channel-item.active .tv-channel-number {
    color: var(--accent-text);
    opacity: 0.75;
}

.tv-channel-item img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    flex-shrink: 0;
}

.tv-channel-name {
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Barre de redimensionnement ───────────────────────────────── */

#tv-resizer {
    width: 5px;
    cursor: col-resize;
    background: var(--border);
    flex-shrink: 0;
    position: relative;
    transition: background 0.15s;
    z-index: 10;
}

#tv-resizer:hover,
#tv-resizer.dragging {
    background: var(--accent);
}

#tv-resizer::after {
    content: '⋮';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--muted);
    font-size: 14px;
    pointer-events: none;
    line-height: 1;
}

#tv-resizer:hover::after,
#tv-resizer.dragging::after {
    color: var(--accent-text);
}

/* ─── Player principal ─────────────────────────────────────────── */

#tv-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #000;
    overflow: hidden;
    min-width: 0;
}

#tv-player-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#tv-player-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--topbar-bg);
    flex-shrink: 0;
    gap: 8px;
}

#tv-now-playing {
    font-size: 14px;
    color: var(--topbar-text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#tv-player-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

#tv-player-actions button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

#tv-player-actions button:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

#tv-player-area {
    position: relative;
    flex: 1;
    display: flex;
    min-height: 0;
}

#player {
    width: 100%;
    flex: 1;
    background: #000;
    display: block;
    min-height: 0;
}

#tv-error-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: #000;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 5;
}

#tv-error-overlay.visible {
    display: flex;
}

#tv-error-icon {
    font-size: 40px;
    color: #888888;
}

#tv-error-message {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.7);
}

/* ─── Bouton charger plus ──────────────────────────────────────── */

#tv-load-more-wrapper {
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#tv-load-more {
    width: 100%;
    padding: 7px 12px;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: opacity 0.15s;
}

#tv-load-more:hover {
    opacity: 0.85;
}

#tv-load-more:disabled {
    background: var(--muted);
    cursor: default;
    opacity: 0.6;
}

#tv-channel-count {
    font-size: 11px;
    color: var(--muted);
}

/* ─── Mini-player flottant ─────────────────────────────────────── */

#tv-mini-player {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 280px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 32px var(--shadow);
    z-index: 1000;
    display: none;
    flex-direction: column;
}

#tv-mini-player.visible {
    display: flex;
}

#tv-mini-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.8);
    flex-shrink: 0;
}

#tv-mini-name {
    font-size: 12px;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

#tv-mini-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

#tv-mini-actions button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 5px;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

#tv-mini-actions button:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
}

#mini-video {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    display: block;
}

#tv-mini-loading {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    top: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    pointer-events: none;
    background: #000;
}

#tv-mini-player.ready #tv-mini-loading {
    display: none;
}

/* ─── Responsive mobile — tab bar ──────────────────────────────── */

#tv-tab-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    z-index: 200;
    flex-direction: row;
}

.tv-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    padding: 6px 4px;
    transition: color 0.15s;
}

.tv-tab.active {
    color: var(--ink);
}

.tv-tab-icon {
    font-size: 16px;
    line-height: 1;
}

.tv-tab-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ─── Mode mobile actif ────────────────────────────────────────── */

body.tv-mobile-mode {
    overflow: hidden;
}

body.tv-mobile-mode #tv-tab-bar {
    display: flex;
}

body.tv-mobile-mode #tv-resizer {
    display: none;
}

body.tv-mobile-mode #tv-mini-player {
    display: none !important;
}

body.tv-mobile-mode #tv-app {
    height: calc(100vh - 56px);
    flex-direction: column;
    position: relative;
}

body.tv-mobile-mode #tv-main {
    position: absolute;
    inset: 0;
    z-index: 0;
}

/* ─── Drawer mobile ────────────────────────────────────────────── */

body.tv-mobile-mode #tv-sidebar {
    display: none;
    position: fixed;
    bottom: 56px;
    left: 0;
    right: 0;
    width: 100% !important;
    max-width: 100%;
    height: 40%;
    min-height: 20%;
    max-height: 80%;
    border-right: none;
    border-top: 2px solid var(--accent);
    border-radius: 12px 12px 0 0;
    z-index: 100;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
    box-shadow: 0 -4px 24px var(--shadow);
}

body.tv-mobile-mode #tv-sidebar.drawer-open {
    display: flex;
}

/* Handle drag du drawer */
#tv-drawer-handle {
    display: none;
    width: 100%;
    height: 24px;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    cursor: ns-resize;
    background: var(--bg);
    touch-action: none;
}

body.tv-mobile-mode #tv-drawer-handle {
    display: flex;
}

#tv-drawer-handle::before {
    content: '';
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
}

/* Filtres dans le drawer */
body.tv-mobile-mode #tv-filters {
    display: flex;
    flex-shrink: 0;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

/* Swipe zones player */
#tv-swipe-prev,
#tv-swipe-next {
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    width: 60px;
    z-index: 50;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

body.tv-mobile-mode #tv-swipe-prev,
body.tv-mobile-mode #tv-swipe-next {
    display: flex;
    pointer-events: auto;
}

#tv-swipe-prev {
    left: 0;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.3), transparent);
}

#tv-swipe-next {
    right: 0;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.3), transparent);
}

#tv-swipe-prev.flash,
#tv-swipe-next.flash {
    opacity: 1;
}

/* ─── Panneau EPG Programme ────────────────────────────────────── */

#tv-epg-panel {
    display: none;
    position: fixed;
    inset: 0 0 56px 0;
    background: var(--bg);
    z-index: 100;
    overflow-y: auto;
    flex-direction: column;
}

body.tv-mobile-mode #tv-epg-panel.tab-visible {
    display: flex;
}

#tv-epg-inner {
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
}

#tv-epg-search-bar {
    display: flex;
    gap: 8px;
}

#tv-epg-input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
}

#tv-epg-input:focus {
    outline: none;
    border-color: var(--ink);
}

#tv-epg-submit {
    padding: 9px 14px;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

#tv-epg-submit:hover {
    opacity: 0.85;
}

#tv-epg-status {
    font-size: 12px;
    color: var(--muted);
    min-height: 16px;
}

#tv-epg-results {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tv-epg-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: var(--bg);
}

.tv-epg-item:hover {
    border-color: var(--accent);
    background: var(--hover);
}

.tv-epg-item.no-stream {
    opacity: 0.5;
    cursor: default;
}

.tv-epg-item img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 4px;
}

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

.tv-epg-channel {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tv-epg-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 2px;
}

.tv-epg-time {
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
}

.tv-epg-play {
    font-size: 18px;
    color: var(--ink);
    flex-shrink: 0;
}

.tv-epg-item.no-stream .tv-epg-play {
    display: none;
}