﻿  :root {
    color-scheme: dark;
    --bg: #0c0c0c;
    --surface: #141414;
    --card: #1a1a1a;
    --border: #2a2a2a;
    --accent: #c4a574;
    --accent2: #c45c5c;
    --text: #e8e4df;
    --muted: #8a8580;
    --live: #7a9e7e;
    --header-bg: rgba(12, 12, 12, 0.95);
    --overlay-bg: rgba(12, 12, 12, 0.95);
    --accent-subtle: rgba(196, 165, 116, 0.08);
    --accent-muted: rgba(196, 165, 116, 0.1);
    --accent-border: rgba(196, 165, 116, 0.25);
    --accent-focus: rgba(196, 165, 116, 0.3);
    --accent-badge-bg: rgba(196, 165, 116, 0.06);
    --live-bg: rgba(122, 158, 126, 0.1);
    --live-border: rgba(122, 158, 126, 0.25);
    --error-bg: rgba(196, 92, 92, 0.06);
    --error-border: rgba(196, 92, 92, 0.3);
    --error-toast-border: rgba(196, 92, 92, 0.4);
    --btn-on-accent: #0c0c0c;
    --mono: 'Space Mono', Consolas, monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  }

  html[data-theme="light"] {
    color-scheme: light;
    --bg: #f4f3ef;
    --surface: #eae9e4;
    --card: #ffffff;
    --border: #d8d6d0;
    --accent: #00c45f;
    --accent2: #c45c5c;
    --text: #141412;
    --muted: #5c5b56;
    --live: #4a7a4e;
    --header-bg: rgba(255, 255, 255, 0.92);
    --overlay-bg: rgba(244, 243, 239, 0.95);
    --accent-subtle: rgba(0, 196, 95, 0.08);
    --accent-muted: rgba(0, 196, 95, 0.12);
    --accent-border: rgba(0, 196, 95, 0.28);
    --accent-focus: rgba(0, 196, 95, 0.4);
    --accent-badge-bg: rgba(0, 196, 95, 0.1);
    --live-bg: rgba(74, 122, 78, 0.12);
    --live-border: rgba(74, 122, 78, 0.28);
    --error-bg: rgba(196, 92, 92, 0.08);
    --error-border: rgba(196, 92, 92, 0.35);
    --error-toast-border: rgba(196, 92, 92, 0.45);
    --btn-on-accent: #0a0a0a;
  }

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

  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    min-height: 100vh;
    overflow-x: hidden;
  }

  header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    border-bottom: 1px solid var(--border);
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    position: sticky; top: 0; z-index: 100;
  }
  .theme-toggle {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    background: transparent;
    border: none;
    padding: 4px 0;
    cursor: pointer;
    transition: color .2s;
    white-space: nowrap;
  }
  .theme-toggle:hover { color: var(--accent); }
  .logo {
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: .08em;
    color: var(--text);
  }

  .header-right { display: flex; align-items: center; gap: 12px; }
  .app {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: calc(100vh - 56px);
  }

  /* SIDEBAR */
  .sidebar {
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    overflow: hidden;
    background: var(--surface);
  }
  .sidebar-top {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 10px;
    overflow-y: auto;
    max-height: 45vh;
    flex-shrink: 0;
  }

  .search-box {
    width: 100%;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
    transition: border-color .2s;
    outline: none;
  }
  .search-box::placeholder { color: var(--muted); }
  .search-box:focus { border-color: var(--accent); }

  select.filter-select {
    width: 100%;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 28px 7px 10px;
    color: var(--text);
    font-family: var(--sans);
    font-size: 12px;
    cursor: pointer;
    outline: none;
    transition: border-color .2s;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8580' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
  }
  html[data-theme="light"] select.filter-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235c5b56' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  }
  select.filter-select:focus { border-color: var(--accent); }

  .btn {
    background: var(--accent); color: var(--btn-on-accent);
    border: none; border-radius: 6px;
    padding: 8px 14px;
    font-family: var(--mono); font-size: 11px; font-weight: 700;
    letter-spacing: .06em; cursor: pointer;
    transition: opacity .2s, transform .1s;
    white-space: nowrap;
  }
  .btn:hover { opacity: .85; }
  .btn:active { transform: scale(.97); }
  .btn:disabled { opacity: .4; cursor: not-allowed; }
  .btn-sm { padding: 6px 10px; font-size: 10px; }

  .add-playlist-toggle {
    width: 100%;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .04em;
    cursor: pointer;
    text-align: left;
    transition: border-color .2s, color .2s;
  }
  .add-playlist-toggle:hover { border-color: var(--accent); color: var(--text); }
  .add-playlist-toggle.open { border-color: var(--accent); color: var(--accent); }

  .add-playlist-panel {
    display: none;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
  }
  .add-playlist-panel.open { display: flex; }

  .source-tabs {
    display: flex;
    gap: 4px;
  }
  .source-tab {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 8px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .04em;
    cursor: pointer;
    transition: all .2s;
  }
  .source-tab:hover { color: var(--text); }
  .source-tab.active {
    background: var(--accent-muted);
    border-color: var(--accent-focus);
    color: var(--accent);
  }

  .source-tab-panel { display: none; flex-direction: column; gap: 8px; }
  .source-tab-panel.active { display: flex; }

  .source-input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    font-family: var(--sans);
    font-size: 12px;
    outline: none;
    transition: border-color .2s;
  }
  .source-input:focus { border-color: var(--accent); }
  .source-textarea {
    min-height: 80px;
    resize: vertical;
    font-family: var(--mono);
    font-size: 11px;
    line-height: 1.4;
  }

  .custom-sources { display: flex; flex-direction: column; gap: 4px; }
  .custom-sources:empty { display: none; }

  .custom-source-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
  }
  .custom-source-label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
  }
  .custom-source-type {
    font-family: var(--mono);
    font-size: 9px;
    color: var(--muted);
    background: var(--border);
    padding: 1px 5px;
    border-radius: 2px;
    flex-shrink: 0;
  }
  .custom-source-remove {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 3px;
    transition: color .2s;
    flex-shrink: 0;
  }
  .custom-source-remove:hover { color: var(--accent2); }

  .channel-list {
    flex: 1; overflow-y: auto; padding: 8px;
  }
  .channel-list::-webkit-scrollbar { width: 4px; }
  .channel-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

  .channel-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 6px;
    cursor: pointer; transition: background .15s;
    border: 1px solid transparent; margin-bottom: 2px;
  }
  .channel-item:hover { background: var(--card); }
  .channel-item.active {
    background: var(--accent-subtle);
    border-color: var(--accent-border);
  }

  .ch-logo {
    width: 40px; height: 28px; border-radius: 4px;
    object-fit: contain; background: var(--border);
    flex-shrink: 0;
  }
  .ch-logo-placeholder {
    width: 40px; height: 28px; border-radius: 4px;
    background: var(--border); flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--mono); font-size: 9px; color: var(--muted);
  }

  .ch-info { flex: 1; min-width: 0; }
  .ch-name {
    font-size: 13px; font-weight: 500; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .channel-item.active .ch-name { color: var(--text); font-weight: 600; }
  .ch-meta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin-top: 2px; flex-wrap: wrap; }
  .ch-tag {
    font-family: var(--mono); font-size: 9px;
    background: var(--border); padding: 1px 5px; border-radius: 2px;
  }
  .ch-source {
    font-family: var(--mono); font-size: 9px;
    color: var(--accent);
    background: var(--accent-muted);
    padding: 1px 5px; border-radius: 2px;
  }

  .empty-state { text-align: center; padding: 48px 24px; color: var(--muted); font-size: 13px; }
  .empty-state p { line-height: 1.6; }

  /* PLAYER */
  .player-panel { display: flex; flex-direction: column; overflow: hidden; height: 100%; }

  .video-wrap {
    position: relative; background: #000;
    flex: 1; min-height: 0;
    display: flex; align-items: center; justify-content: center;
  }
  video { width: 100%; height: 100%; object-fit: contain; display: block; }

  .video-placeholder {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
    color: var(--muted);
  }
  .video-placeholder svg { opacity: .12; stroke: currentColor; }
  .video-placeholder p { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: .06em; }

  .now-playing-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px; border-top: 1px solid var(--border);
    background: var(--surface); min-height: 58px;
    flex-shrink: 0;
  }
  .now-playing-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
  .live-pill {
    font-family: var(--mono); font-size: 9px; font-weight: 700;
    letter-spacing: .1em; color: var(--live);
    background: var(--live-bg); border: 1px solid var(--live-border);
    padding: 3px 8px; border-radius: 3px; flex-shrink: 0;
  }
  .np-title { font-size: 15px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .np-subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .np-right { display: flex; gap: 8px; flex-shrink: 0; }

  .icon-btn {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 6px; padding: 7px 10px;
    color: var(--muted); cursor: pointer;
    font-family: var(--mono); font-size: 10px; letter-spacing: .04em;
    transition: all .2s; display: flex; align-items: center; gap: 5px;
  }
  .icon-btn:hover { border-color: var(--accent); color: var(--accent); }
  .icon-btn.favorited { border-color: var(--accent-focus); color: var(--accent); }

  .favorites-toggle {
    width: 100%;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .04em;
    cursor: pointer;
    text-align: left;
    transition: border-color .2s, color .2s, background .2s;
  }
  .favorites-toggle:hover { border-color: var(--accent); color: var(--text); }
  .favorites-toggle.active {
    background: var(--accent-subtle);
    border-color: var(--accent-focus);
    color: var(--accent);
  }

  .ch-fav-mark {
    font-size: 11px;
    color: var(--accent);
    flex-shrink: 0;
    line-height: 1;
  }

  /* Loading */
  #loading-overlay {
    position: fixed; inset: 0;
    background: var(--overlay-bg);
    display: none; align-items: center; justify-content: center;
    z-index: 200; flex-direction: column; gap: 16px;
  }
  .loader-bar { width: 240px; height: 2px; background: var(--border); border-radius: 1px; overflow: hidden; }
  .loader-bar-fill { height: 100%; background: var(--accent); border-radius: 1px; animation: loading-anim 1.4s ease-in-out infinite; }
  @keyframes loading-anim {
    0% { width: 0; margin-left: 0; }
    50% { width: 60%; margin-left: 20%; }
    100% { width: 0; margin-left: 100%; }
  }
  .loader-text { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: .06em; }

  /* Toast */
  #toast {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--card); border: 1px solid var(--border);
    border-radius: 8px; padding: 12px 16px;
    font-size: 12px; color: var(--text);
    font-family: var(--mono); letter-spacing: .04em;
    z-index: 300; transform: translateY(80px);
    transition: transform .3s; pointer-events: none;
    max-width: 300px; line-height: 1.5;
  }
  #toast.show { transform: translateY(0); }
  #toast.err { border-color: var(--error-toast-border); color: var(--accent2); }

  @media (max-width: 768px) {
    .app { grid-template-columns: 1fr; grid-template-rows: 50vh 1fr; height: auto; }
    .sidebar { height: 50vh; border-right: none; border-bottom: 1px solid var(--border); }
    .sidebar-top { max-height: 35vh; }
    .player-panel { min-height: 50vh; }
  }
