:root {
  --bg: #0a0e17;
  --panel: #121826;
  --panel2: #1a2234;
  --text: #eef2ff;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent2: #60a5fa;
  --ok: #34d399;
  --err: #f87171;
  --border: #ffffff14;
  --radius: 14px;
  --touch: 52px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  height: 100%;
}
body { display: flex; flex-direction: column; min-height: 100dvh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font-size: clamp(16px, 3vw, 20px); font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent2); box-shadow: 0 0 12px var(--accent2); flex-shrink: 0; }
.brand-tag { font-size: 11px; font-weight: 800; letter-spacing: .08em; color: var(--accent2); background: #3b82f622; padding: 4px 8px; border-radius: 999px; }
.top-actions { display: flex; gap: 8px; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.player-panel { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.player-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 16 / 9;
  max-height: min(56vh, 720px);
}
#player { width: 100%; height: 100%; display: block; background: #000; object-fit: contain; }

.status { margin: 0; font-size: 14px; color: var(--muted); min-height: 1.2em; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

.sidebar {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 0;
}
.filters { display: flex; flex-direction: column; gap: 8px; }
.filters input, .filters select {
  width: 100%; min-height: var(--touch);
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text);
  padding: 0 14px; font-size: 16px;
}
.channel-list { overflow: auto; flex: 1; min-height: 0; padding-right: 2px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }

.group-block + .group-block { margin-top: 12px; }
.group-title {
  margin: 0 0 8px; font-size: 13px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}
.group-title .count { opacity: .7; }

.channel-grid { display: grid; grid-template-columns: 1fr; gap: 6px; }
.channel-btn {
  display: grid; grid-template-columns: 44px 1fr 36px; align-items: center; gap: 10px;
  min-height: var(--touch);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.channel-btn:hover, .channel-btn.active {
  border-color: #3b82f666;
  background: #1e293b;
}
.channel-btn.active { box-shadow: inset 0 0 0 1px #3b82f6; }
.ch-logo {
  width: 44px; height: 44px; border-radius: 8px;
  background: #0005; display: grid; place-items: center; overflow: hidden; font-size: 20px;
}
.ch-logo img { width: 100%; height: 100%; object-fit: contain; }
.ch-name { font-weight: 700; font-size: 15px; line-height: 1.2; word-break: break-word; }
.ch-fav { font-size: 22px; line-height: 1; opacity: .5; padding: 4px; }
.ch-fav.on { opacity: 1; color: #fbbf24; }

.btn {
  min-height: 44px; min-width: 44px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text);
  font: inherit; font-weight: 700; cursor: pointer; padding: 0 14px;
}
.btn.icon { font-size: 20px; padding: 0; width: 44px; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn:hover { filter: brightness(1.08); }

.modal {
  position: fixed; inset: 0; display: none; place-items: center;
  background: #000a; z-index: 50; padding: 16px;
}
.modal.open { display: grid; }
.modal-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.modal-card h2 { margin: 0 0 8px; }
.source-picker {
  max-width: min(42vw, 200px);
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  padding: 0 10px;
  font-size: 14px;
}
.source-list-wrap { margin-bottom: 10px; }
.source-list {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 8px; max-height: 120px; overflow: auto;
}
.source-chip {
  min-height: 40px; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text);
  font: inherit; font-weight: 700; font-size: 13px; cursor: pointer;
}
.source-chip.active { background: var(--accent); border-color: transparent; color: #fff; }
.source-chip .type { opacity: .75; font-weight: 600; font-size: 11px; margin-left: 4px; }
.source-add { width: 100%; min-height: 40px; }
.btn.danger { color: #f87171; border-color: #f8717144; }
.modal-card label { display: block; margin: 10px 0 6px; font-weight: 700; }
.modal-card input[type=url] {
  width: 100%; min-height: var(--touch);
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text);
  padding: 0 14px; font-size: 16px;
}
.tabs { display: flex; gap: 6px; margin: 12px 0 6px; }
.tab {
  flex: 1; min-height: 44px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel2); color: var(--muted);
  font: inherit; font-weight: 700; cursor: pointer;
}
.tab.active { background: var(--accent); border-color: transparent; color: #fff; }
.tab-panel { margin-top: 6px; }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 14px 0 4px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel2); cursor: pointer;
}
.toggle-label { display: flex; flex-direction: column; gap: 4px; text-align: left; }
.toggle-label b { font-size: 15px; }
.toggle-label .muted { font-size: 12px; line-height: 1.3; }
.toggle-row input[type=checkbox] {
  width: 22px; height: 22px; flex-shrink: 0; accent-color: var(--accent);
}

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.muted { color: var(--muted); font-size: 14px; }
.hint { margin: 14px 0 0; font-size: 12px; color: var(--muted); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .player-wrap { max-height: 42vh; }
  .sidebar { max-height: 46vh; }
}

@media (max-width: 600px) {
  .topbar { padding: 8px 10px; }
  .layout { padding: 8px; gap: 8px; }
}
