/* TV Agent PWA — "Cinematic Slate" dark theme (port of iptv/ui_styles.py MODERN_QSS). */

:root {
  --bg-main: #0d0f15;
  --bg-sidebar: #131620;
  --bg-card: #171a26;
  --bg-card-hover: #1f2434;
  --bg-card-sel: #1c2a44;
  --bg-card-playing: #142721;
  --bg-input: #1a1e2b;
  --border: #252b3d;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --sidebar-width: 340px;
  --statusbar-height: 26px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

.hidden { display: none !important; }
.spacer { flex: 1 1 auto; }

/* ---------------------------- Layout ---------------------------- */
#app {
  display: flex;
  height: calc(100% - var(--statusbar-height));
  min-height: 0;
}

#sidebar {
  width: var(--sidebar-width);
  min-width: 240px;
  max-width: 60vw;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.splitter {
  width: 3px;
  flex: 0 0 auto;
  background: var(--border);
  cursor: col-resize;
  transition: background .15s;
}
.splitter:hover, .splitter.dragging { background: var(--accent); }

.player-area {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
}

/* ---------------------------- Sidebar ---------------------------- */
.side-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 0;
}
.side-title { font-size: 15px; font-weight: 700; color: var(--text-primary); white-space: nowrap; }
.badge {
  background: #1e2434;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}

.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #181c28;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
}
.icon-btn:hover { background: #262c3e; border-color: var(--accent); color: var(--accent-hover); }
.icon-btn.spinning { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* The sidebar chrome must keep its height: only .list-wrap may shrink, otherwise a
 * long playlist (thousands of cards) crushes the categories/search row to nothing. */
.side-head, .search-wrap, .tabs, .side-foot { flex: 0 0 auto; }

.search-wrap { padding: 8px 10px 6px; }
#search {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  outline: none;
}
#search:hover { border-color: #3b455f; }
#search:focus { border-color: var(--accent); background: #1e2434; }
#search::placeholder { color: #5a6579; }

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 10px 8px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  background: #171b26;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 5px 13px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.tab:hover { background: #212737; color: #e2e8f0; border-color: #37425b; }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

.list-wrap {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 6px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: #2a3144 transparent;
}
.list-wrap::-webkit-scrollbar { width: 7px; }
.list-wrap::-webkit-scrollbar-thumb { background: #2a3144; border-radius: 3px; }
.list-wrap::-webkit-scrollbar-thumb:hover { background: #404b66; }
.list-wrap::-webkit-scrollbar-track { background: transparent; }

.channel-list { outline: none; }
.list-sentinel { height: 1px; }

.card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 3px 4px;
  padding: 6px 8px 6px 10px;
  height: 58px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  position: relative;
  cursor: default;
  user-select: none;
}
.card:hover { background: var(--bg-card-hover); border-color: #2e384e; }
.card.selected { background: var(--bg-card-sel); border-color: var(--accent); }
.card.playing { background: var(--bg-card-playing); border-color: var(--success); }
.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3.5px;
  border-radius: 2px;
  background: transparent;
}
.card.selected::before { background: var(--accent); }
.card.playing::before { background: var(--success); }

.avatar {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .3px;
}
.avatar .playing-glyph { color: var(--success); font-size: 13px; }

.card-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card.selected .card-name, .card.playing .card-name { color: #fff; }
.card-sub {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  gap: 4px;
  min-width: 0;
}
.card-sub .prog-time { color: var(--accent-hover); flex: 0 0 auto; }
.card-sub .prog-title { overflow: hidden; text-overflow: ellipsis; }
.card-sub.muted { color: var(--text-muted); }

.star {
  flex: 0 0 auto;
  width: 30px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  color: transparent;
  background: none;
  border: none;
  padding: 0;
  border-radius: 6px;
}
.card:hover .star, .card.selected .star { color: #475569; }
.star.on { color: var(--warning); }
.star:hover { color: var(--warning); }

.empty-state {
  margin: 18px 12px;
  padding: 18px;
  border: 1px dashed #2a3144;
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
}
.empty-state b { color: var(--text-secondary); }

.side-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-top: 1px solid #1b2030;
  flex-wrap: wrap;
}
.side-status { color: var(--text-muted); font-size: 11px; }
.subtle-btn, .clear-btn, .recents-btn {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #282f42;
  background: #1a1e2b;
  color: #cbd5e1;
}
.subtle-btn:hover, .recents-btn:hover { background: #242a3d; border-color: #3b4663; color: #fff; }
.subtle-btn:disabled { background: transparent; border-color: var(--border); color: #4b5563; cursor: default; }
.clear-btn { background: rgba(239, 68, 68, .10); border-color: rgba(239, 68, 68, .30); color: #fca5a5; }
.clear-btn:hover { background: rgba(239, 68, 68, .22); border-color: var(--danger); color: #fff; }
.clear-btn:disabled { background: transparent; border-color: var(--border); color: #4b5563; cursor: default; }
.recents-btn.active { background: #1d335a; border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------------------------- Video ---------------------------- */
.video-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#video { width: 100%; height: 100%; background: #000; display: block; }
#video:not([src]) { visibility: hidden; }

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
  pointer-events: none;
}
.vp-icon { font-size: 42px; opacity: .55; }
.vp-title { font-size: 16px; color: var(--text-secondary); }
.vp-hint { font-size: 12px; }

.spinner {
  position: absolute;
  top: 50%; left: 50%;
  width: 46px; height: 46px;
  margin: -23px 0 0 -23px;
  border: 3px solid rgba(148, 163, 184, .25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
  pointer-events: none;
}

/* ---------------------------- Player bar ---------------------------- */
.player-bar {
  flex: 0 0 auto;
  min-height: 74px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
}
.bar-avatar {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  border: 1px solid #2a344d;
  background: #1e2638;
  color: var(--accent-hover);
  font-size: 13px;
  font-weight: 700;
}
.bar-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.bar-title-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-epg {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-epg b { color: var(--text-primary); }

.pill {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}
.pill.live {
  background: rgba(16, 185, 129, .2);
  color: #34d399;
  font-weight: 700;
  border: 1px solid rgba(16, 185, 129, .4);
}
.pill.group {
  background: #1e2536;
  color: var(--text-secondary);
  border: 1px solid #283248;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill.proxy {
  background: rgba(16, 185, 129, .15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, .35);
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 12px;
}

.bar-controls { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }

.fav-btn {
  width: 34px; height: 34px;
  background: #1b202e;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 15px;
}
.fav-btn:hover { background: #242b3d; border-color: var(--warning); color: var(--warning); }
.fav-btn.active { background: rgba(245, 158, 11, .15); border-color: var(--warning); color: var(--warning); }

.btn {
  background: #1b202e;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
}
.btn:hover { background: #242b3d; border-color: #3b4663; color: #fff; }
.btn:disabled { background: #141721; color: #4b5563; border-color: #1c212e; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #2563eb; border-color: var(--accent-hover); }
.btn.small { padding: 5px 11px; font-size: 11px; }

.stop-btn {
  background: rgba(239, 68, 68, .12);
  border: 1px solid rgba(239, 68, 68, .35);
  color: #fca5a5;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
}
.stop-btn:hover { background: rgba(239, 68, 68, .25); border-color: var(--danger); color: #fff; }

.fs-btn {
  background: #1b202e;
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 8px;
}
.fs-btn:hover { background: #242b3d; border-color: #3b4663; color: #fff; }

/* Fullscreen: hide the chrome, keep only the video */
body.fs #sidebar, body.fs .splitter, body.fs .player-bar, body.fs .statusbar { display: none; }
body.fs #app { height: 100%; }
body.fs:fullscreen #app, #app:fullscreen { height: 100%; }

/* ---------------------------- Status bar ---------------------------- */
.statusbar {
  height: var(--statusbar-height);
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: #0b0d13;
  border-top: 1px solid #181b26;
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------------------- Context menu ---------------------------- */
.menu {
  position: fixed;
  z-index: 60;
  min-width: 210px;
  background: #181b28;
  border: 1px solid #283044;
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .55);
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 12px;
  padding: 7px 12px;
  border-radius: 5px;
}
.menu-item:hover { background: var(--accent); color: #fff; }
.menu-sep { height: 1px; background: #252d3f; margin: 4px 6px; }

/* ---------------------------- Dialog ---------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5, 7, 12, .7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.dialog {
  width: min(720px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
  overflow: hidden;
}
.dialog h2 { margin: 0; padding: 16px 20px 10px; font-size: 17px; }
.dialog-body { padding: 0 20px 6px; overflow-y: auto; }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid #1b2030;
}

.field-group { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; border-bottom: 1px solid #191d29; }
.field-group:last-child { border-bottom: none; }
.group-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }

/* Collapsible section (proxy block) */
details.collapsible { overflow: hidden; }
details.collapsible > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  outline: none;
}
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::before {
  content: '▶';
  font-size: 9px;
  color: var(--text-secondary);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
details.collapsible[open] > summary::before { transform: rotate(90deg); }
details.collapsible > summary:hover { color: var(--text-primary); }
details.collapsible > summary:hover::before { color: var(--text-primary); }
.collapse-hint { text-transform: none; font-weight: 400; letter-spacing: 0; opacity: 0.7; }
.row { display: flex; gap: 8px; align-items: center; }
.row input[type="text"], .row input[type="password"], .row input[type="number"], .row textarea {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.row textarea { resize: vertical; min-height: 34px; max-height: 160px; line-height: 1.35; }
.row input:hover, .row textarea:hover { border-color: #3b455f; }
.row input:focus, .row textarea:focus { border-color: var(--accent); background: #1e2434; }
.row.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row.presets { flex-wrap: wrap; }
.chip {
  background: #171b26;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 12px;
  font-size: 11px;
}
.chip:hover { background: #212737; color: #fff; border-color: #37425b; }
.chip.active { background: #1d335a; border-color: var(--accent); color: #fff; }

.hint { font-size: 11px; color: var(--text-muted); line-height: 1.5; }
.hint.warn { color: #f0b35a; }
.hint.ok { color: var(--success); }
.hint.err { color: #f87171; }

.pl-list { list-style: none; margin: 0; padding: 0; max-height: 150px; overflow-y: auto; background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; }
.pl-list:empty { display: none; }
.pl-list li { padding: 7px 12px; font-size: 12px; color: var(--text-primary); border-bottom: 1px solid #1d2231; cursor: pointer; word-break: break-all; }
.pl-list li:last-child { border-bottom: none; }
.pl-list li.selected { background: #1d335a; }
.pl-list li .kind { color: var(--text-muted); font-size: 11px; margin-right: 6px; }

.check { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-primary); }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------------------------- Toasts ---------------------------- */
.toast-wrap {
  position: fixed;
  right: 16px;
  bottom: calc(var(--statusbar-height) + 14px);
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, 80vw);
}
.toast {
  background: #1b202e;
  border: 1px solid #333d54;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-primary);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .5);
  animation: toastIn .18s ease-out;
}
.toast.warn { border-left-color: var(--warning); }
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------------------------- Small screens ---------------------------- */
@media (max-width: 820px) {
  #app { flex-direction: column; }
  #sidebar { width: 100% !important; max-width: none; flex: 1 1 auto; min-height: 0; border-right: none; border-bottom: 1px solid var(--border); }
  .splitter { display: none; }
  /* The player keeps a fixed compact height; the list may shrink but never disappears. */
  .player-area { flex: 0 0 auto; }
  .video-frame { height: 30vh; min-height: 96px; }
  .list-wrap { min-height: 84px; }
  .player-bar { flex-wrap: wrap; min-height: 0; padding: 10px 12px; }
  .bar-controls { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
}
