/* =====================================================================
   IPTV Player Pro — thème sombre moderne, mobile-first.
   ===================================================================== */
:root {
    --bg:           #0b0f17;
    --bg-elev:      #131826;
    --bg-elev2:     #1a2030;
    --border:       #232a3a;
    --text:         #e6eaf2;
    --text-dim:     #9aa3b7;
    --accent:       #4f46e5;
    --accent-hov:   #6366f1;
    --accent-soft:  rgba(79, 70, 229, .15);
    --success:      #10b981;
    --warning:      #f59e0b;
    --danger:       #ef4444;
    --radius:       12px;
    --radius-sm:    8px;
    --shadow:       0 6px 24px rgba(0,0,0,.35);
    --transition:   .18s cubic-bezier(.4,0,.2,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow-x: hidden;
}
button, input, select, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }

/* ---------- TOPBAR ---------- */
.topbar {
    position: sticky; top: 0; z-index: 100;
    display: flex; align-items: center; gap: 1rem;
    background: rgba(11, 15, 23, .92);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    padding: .6rem 1rem;
}
.brand { display: flex; align-items: center; gap: .6rem; }
.brand .logo {
    width: 36px; height: 36px; border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: .9rem; box-shadow: 0 4px 14px rgba(79,70,229,.4);
}
.brand h1 { margin: 0; font-size: 1.15rem; font-weight: 700; letter-spacing: .2px; }
.brand h1 span { background: linear-gradient(135deg, var(--accent), #ec4899); -webkit-background-clip: text; background-clip: text; color: transparent; }

.tabs { margin-left: auto; display: flex; gap: .25rem; flex-wrap: wrap; }
.tab {
    background: transparent; border: 1px solid transparent;
    color: var(--text-dim); padding: .55rem .9rem;
    border-radius: var(--radius-sm); font-weight: 500; font-size: .9rem;
    display: inline-flex; align-items: center; gap: .45rem;
    transition: var(--transition);
}
.tab:hover { background: var(--bg-elev); color: var(--text); }
.tab.active { background: var(--accent-soft); color: #c7d2fe; border-color: rgba(79,70,229,.35); }

@media (max-width: 640px) {
    .tab span { display: none; }
    .tab { padding: .55rem .75rem; }
    .brand h1 { font-size: 1rem; }
}

/* ---------- VIEWS ---------- */
.app { padding: 1rem; max-width: 1600px; margin: 0 auto; }
.view { display: none; animation: fadeIn .25s ease-out; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity:0; transform: translateY(6px); } to { opacity:1; transform: translateY(0); } }

.page-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem; flex-wrap: wrap; gap: .75rem;
}
.page-head h2 { margin: 0; font-size: 1.4rem; font-weight: 700; display: flex; align-items: center; gap: .6rem; }

/* ---------- LAYOUT LECTEUR ---------- */
.player-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1rem;
}
@media (max-width: 900px) {
    .player-layout { grid-template-columns: 1fr; }
}

/* SIDEBAR */
.sidebar {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex; flex-direction: column;
    max-height: calc(100vh - 90px);
    position: sticky; top: 78px;
}
@media (max-width: 900px) {
    .sidebar { position: static; max-height: none; }
}
.sidebar-head { padding: .75rem; border-bottom: 1px solid var(--border); }
.search-box {
    padding: .5rem .75rem; border-bottom: 1px solid var(--border);
    position: relative;
}
.search-box i { position: absolute; left: 1.4rem; top: 50%; transform: translateY(-50%); color: var(--text-dim); pointer-events: none; }
.search-box input {
    width: 100%; padding: .55rem .75rem .55rem 2.2rem;
    background: var(--bg-elev2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: .9rem;
    transition: var(--transition);
}
.search-box input:focus { outline: none; border-color: var(--accent); background: var(--bg); }

.groups-list { overflow-y: auto; flex: 1; padding: .5rem 0; }
.group-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: .6rem .9rem; cursor: pointer;
    color: var(--text-dim); font-size: .9rem; border-left: 3px solid transparent;
    transition: var(--transition);
}
.group-item:hover { background: var(--bg-elev2); color: var(--text); }
.group-item.active { background: var(--accent-soft); color: #c7d2fe; border-left-color: var(--accent); }
.group-item .count { font-size: .75rem; background: var(--bg-elev2); padding: .15rem .5rem; border-radius: 999px; color: var(--text-dim); }
.group-item.active .count { background: var(--accent); color: #fff; }

/* SELECT global */
.select {
    width: 100%; padding: .55rem .75rem;
    background: var(--bg-elev2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: .9rem;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%239aa3b7' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right .75rem center; padding-right: 2rem;
}
.select:focus { outline: none; border-color: var(--accent); }

/* MAIN PLAYER */
.player-main { display: flex; flex-direction: column; gap: 1rem; }

.video-wrap {
    position: relative; background: #000;
    border-radius: var(--radius); overflow: hidden;
    aspect-ratio: 16 / 9; box-shadow: var(--shadow);
}
#video { width: 100%; height: 100%; display: block; background: #000; object-fit: contain; }
.video-overlay {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    color: var(--text-dim); pointer-events: none;
    background: linear-gradient(135deg, #0a0e16, #131826);
}
.video-overlay.hidden { display: none; }
.overlay-msg { text-align: center; }
.overlay-msg i { font-size: 3rem; opacity: .4; display: block; margin-bottom: .75rem; }

.video-loading {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: .75rem;
    background: rgba(0,0,0,.6); color: #fff; font-size: .85rem;
    pointer-events: none;
}
.spinner {
    width: 36px; height: 36px; border: 3px solid rgba(255,255,255,.2);
    border-top-color: var(--accent); border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* NOW PLAYING */
.now-playing:empty { display: none; }
.now-playing {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius); padding: .9rem 1rem;
    display: flex; align-items: center; gap: 1rem;
}
.now-playing .ch-logo {
    width: 48px; height: 48px; border-radius: 8px; object-fit: cover;
    background: var(--bg-elev2); flex-shrink: 0;
}
.now-playing .ch-meta { flex: 1; min-width: 0; }
.now-playing .ch-name { font-weight: 600; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-playing .ch-group { color: var(--text-dim); font-size: .82rem; margin-top: .15rem; }
.now-playing .ch-actions button {
    background: var(--bg-elev2); border: 1px solid var(--border); color: var(--text);
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    display: inline-flex; align-items: center; justify-content: center;
    margin-left: .35rem; transition: var(--transition);
}
.now-playing .ch-actions button:hover { background: var(--accent); border-color: var(--accent); }
.now-playing .ch-actions .fa-star.fav { color: #fbbf24; }

/* CHANNELS TOOLBAR */
.channels-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: .25rem .25rem;
}
.result-info { color: var(--text-dim); font-size: .85rem; }
.view-modes { display: flex; gap: .25rem; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .2rem; }
.vm {
    background: transparent; border: 0; color: var(--text-dim);
    width: 32px; height: 28px; border-radius: 6px; transition: var(--transition);
}
.vm:hover { color: var(--text); }
.vm.active { background: var(--accent); color: #fff; }

/* CHANNEL VIRTUAL LIST */
.channels-virtual {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    height: 60vh;
    min-height: 380px;
    overflow-y: auto;
    overflow-x: hidden;
    contain: strict;
    position: relative;
}
.channels-virtual::-webkit-scrollbar { width: 8px; }
.channels-virtual::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.channels-virtual::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.virtual-spacer { width: 100%; position: relative; }
.virtual-window { position: absolute; left: 0; right: 0; top: 0; pointer-events: auto; }

/* CHANNEL ITEM (mode liste) */
.ch-item {
    display: flex; align-items: center; gap: .8rem;
    padding: .55rem .8rem; cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
    height: 60px;
}
.ch-item:hover { background: var(--bg-elev2); }
.ch-item.active { background: var(--accent-soft); border-left: 3px solid var(--accent); padding-left: calc(.8rem - 3px); }
.ch-item .ch-logo {
    width: 44px; height: 44px; border-radius: 6px; object-fit: cover;
    background: var(--bg-elev2); flex-shrink: 0;
}
.ch-item .ch-info { flex: 1; min-width: 0; }
.ch-item .ch-name { font-size: .9rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.ch-item .ch-group { font-size: .75rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-item .ch-status i { color: var(--success); font-size: .75rem; }

/* GRID MODE */
.channels-virtual.grid { padding: 1rem; }
.channels-virtual.grid .virtual-window {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: .75rem;
}
.channels-virtual.grid .ch-item {
    flex-direction: column; height: auto; padding: .8rem .5rem; text-align: center;
    border: 1px solid var(--border); border-radius: var(--radius-sm); border-bottom-width: 1px;
    background: var(--bg-elev2);
}
.channels-virtual.grid .ch-item:hover { transform: translateY(-2px); border-color: var(--accent); }
.channels-virtual.grid .ch-item.active { padding-left: .5rem; border-color: var(--accent); }
.channels-virtual.grid .ch-logo { width: 64px; height: 64px; border-radius: 10px; }
.channels-virtual.grid .ch-info { width: 100%; }
.channels-virtual.grid .ch-name { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.channels-virtual.grid .ch-status { display: none; }

/* ---------- PLAYLISTS GRID ---------- */
.playlists-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}
.playlist-card {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem; transition: var(--transition);
    display: flex; flex-direction: column; gap: .75rem;
}
.playlist-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.playlist-card .pc-head { display: flex; align-items: start; gap: .75rem; }
.playlist-card .pc-icon {
    width: 48px; height: 48px; border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex; align-items: center; justify-content: center; color: #fff;
    flex-shrink: 0;
}
.playlist-card .pc-icon.xtream { background: linear-gradient(135deg, var(--success), #06b6d4); }
.playlist-card h3 { margin: 0; font-size: 1rem; word-break: break-word; }
.playlist-card .pc-meta { color: var(--text-dim); font-size: .8rem; margin-top: .25rem; }
.playlist-card .pc-stats { display: flex; gap: 1rem; padding: .5rem 0; color: var(--text-dim); font-size: .82rem; border-top: 1px solid var(--border); }
.playlist-card .pc-stats b { color: var(--text); }
.playlist-card .pc-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.playlist-card .pc-actions .btn { flex: 1; min-width: 0; padding: .5rem .6rem; font-size: .85rem; }

/* ---------- ADD VIEW ---------- */
.add-tabs {
    display: flex; gap: .25rem; padding: .25rem;
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 1rem; flex-wrap: wrap;
}
.add-tab {
    flex: 1; min-width: 110px;
    background: transparent; border: 0; color: var(--text-dim);
    padding: .65rem .75rem; border-radius: var(--radius-sm);
    transition: var(--transition); font-weight: 500; font-size: .9rem;
}
.add-tab:hover { color: var(--text); background: var(--bg-elev2); }
.add-tab.active { background: var(--accent); color: #fff; }

.add-panels { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.add-panel { display: none; flex-direction: column; gap: .75rem; }
.add-panel.active { display: flex; }
.row { display: flex; gap: .75rem; }
.row.two > * { flex: 1; }
@media (max-width: 600px) { .row.two { flex-direction: column; } }

.input {
    width: 100%; padding: .65rem .85rem;
    background: var(--bg-elev2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: .92rem;
    transition: var(--transition);
}
.input:focus { outline: none; border-color: var(--accent); background: var(--bg); }
textarea.input { resize: vertical; min-height: 160px; font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: .85rem; }

.dropzone {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 2.5rem 1rem;
    background: var(--bg-elev2); border: 2px dashed var(--border);
    border-radius: var(--radius); cursor: pointer;
    transition: var(--transition); color: var(--text-dim);
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone i { color: var(--accent); margin-bottom: .75rem; }
.dropzone h3 { margin: 0 0 .25rem; color: var(--text); }
.dropzone .file-name { display: block; margin-top: .75rem; color: var(--accent); font-weight: 500; }

.hint { color: var(--text-dim); font-size: .82rem; margin: 0; padding: .6rem .8rem; background: var(--bg-elev2); border-radius: var(--radius-sm); }

/* ---------- BUTTONS ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .6rem 1rem; border: 1px solid var(--border);
    background: var(--bg-elev2); color: var(--text);
    border-radius: var(--radius-sm); font-weight: 500; font-size: .9rem;
    transition: var(--transition); white-space: nowrap;
}
.btn:hover { background: var(--bg-elev); border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hov); border-color: var(--accent-hov); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-block { width: 100%; padding: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- STATES ---------- */
.empty, .loading {
    text-align: center; padding: 3rem 1rem; color: var(--text-dim);
}
.empty i { color: var(--border); margin-bottom: 1rem; }
.empty h3 { margin: 0 0 .25rem; color: var(--text); }

.muted { color: var(--text-dim); }
.small { font-size: .85rem; }
.pad { padding: 1rem; }

/* ---------- TOASTS ---------- */
.toasts { position: fixed; top: 80px; right: 1rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; max-width: calc(100vw - 2rem); }
.toast {
    min-width: 250px; max-width: 360px;
    padding: .85rem 1rem; border-radius: var(--radius-sm);
    background: var(--bg-elev); border: 1px solid var(--border);
    box-shadow: var(--shadow); color: var(--text);
    display: flex; align-items: center; gap: .6rem;
    animation: toastIn .3s cubic-bezier(.4,0,.2,1);
    border-left: 4px solid var(--accent);
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger);  }
.toast.warning { border-left-color: var(--warning); }
.toast i { font-size: 1.1rem; flex-shrink: 0; }
.toast.success i { color: var(--success); }
.toast.error i   { color: var(--danger);  }
.toast.warning i { color: var(--warning); }
.toast.info i    { color: var(--accent);  }
@keyframes toastIn { from { opacity:0; transform: translateX(100%);} to { opacity:1; transform: translateX(0);} }
@keyframes toastOut { to { opacity:0; transform: translateX(100%);} }

/* ---------- FULLSCREEN ---------- */
.video-wrap:fullscreen { aspect-ratio: auto; }
.video-wrap:fullscreen #video