/* OTTFOX player — design system & base layout */
:root {
  /* Accent + secondary come from the active theme (set by themes.js).
     OTTFOX brand: amber → orange, matching the marketing site's --brand pair. */
  --accent: #ffb23f;
  --accent-2: #ff6b35;
  --accent-contrast: #1a0f04;

  /* Dark palette (default) — OTTFOX site navy, from assets/css/styles.css. */
  --bg-0: #07111f;
  --bg-1: #0e1b2c;
  --bg-2: #101d31;
  --bg-3: #13233a;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-2: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.20);
  --text: #eef5ff;
  --text-dim: #9fb0c6;
  --text-faint: #6b7d95;
  --danger: #ff6b6b;
  --good: #45d483;
  --warn: #ffd166;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
  --sidebar-w: 250px;
  --header-h: 62px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

:root[data-mode='light'] {
  --bg-0: #eef1f6;
  --bg-1: #f6f8fb;
  --bg-2: #ffffff;
  --bg-3: #eaeef4;
  --surface: rgba(10, 15, 30, 0.03);
  --surface-2: rgba(10, 15, 30, 0.06);
  --border: rgba(10, 20, 40, 0.10);
  --border-strong: rgba(10, 20, 40, 0.18);
  --text: #1a1f2b;
  --text-dim: #55607a;
  --text-faint: #8b95ab;
  --shadow: 0 10px 30px rgba(20, 30, 60, 0.12);
  --shadow-lg: 0 24px 60px rgba(20, 30, 60, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
body::before {
  /* Subtle accent glow backdrop */
  content: '';
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60vw 60vh at 8% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
    radial-gradient(50vw 50vh at 100% 0%, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent 55%);
  opacity: 0.9;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--accent); text-decoration: none; }
img { display: block; max-width: 100%; }
::selection { background: color-mix(in srgb, var(--accent) 45%, transparent); }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 20px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

.icon { display: inline-flex; align-items: center; justify-content: center; }
.icon svg { display: block; }

/* ---- App shell ---- */
#app { height: 100vh; display: flex; flex-direction: column; }
.app-shell { flex: 1; display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 0; }

/* ---- Sidebar ---- */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 16px 18px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
}
.brand-logo svg { width: 20px; height: 20px; }
.brand-name { font-weight: 800; font-size: 19px; letter-spacing: -0.4px; }
.brand-name b { color: var(--accent); }

.playlist-switch {
  margin: 2px 12px 8px; padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; gap: 9px; cursor: pointer; transition: background .15s;
}
.playlist-switch:hover { background: var(--surface-2); }
.playlist-switch .ps-info { min-width: 0; flex: 1; }
.playlist-switch .ps-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.playlist-switch .ps-sub { font-size: 11.5px; color: var(--text-faint); }

.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 550; transition: all .14s var(--ease); position: relative;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); }
.nav-item.active::before { content:''; position:absolute; left:-10px; top:50%; transform:translateY(-50%); width:4px; height:20px; border-radius:4px; background:var(--accent); }
.nav-item .icon { color: var(--accent); }
.nav-item .count { margin-left: auto; font-size: 11px; color: var(--text-faint); background: var(--surface-2); padding: 1px 7px; border-radius: 10px; }

.nav-section-title { padding: 14px 16px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-faint); font-weight: 700; }

.groups { flex: 1; overflow-y: auto; padding: 4px 10px 16px; min-height: 0; }
.group-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 13.5px; transition: all .12s; cursor: pointer;
}
.group-item:hover { background: var(--surface); color: var(--text); }
.group-item.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.group-item .g-count { margin-left: auto; font-size: 11px; color: var(--text-faint); }
.group-item.blocked { opacity: .5; }

/* Unobtrusive links back to the main site, pinned to the sidebar bottom. */
.site-links { margin-top: auto; display: flex; flex-wrap: wrap; gap: 2px; padding: 8px 10px 12px; border-top: 1px solid var(--border); }
.site-link { display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: var(--radius-sm); color: var(--text-faint); font-size: 12px; font-weight: 550; text-decoration: none; transition: color .14s, background .14s; }
.site-link:hover { color: var(--text); background: var(--surface); }
.site-link .icon { color: inherit; }

/* ---- Main ---- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-0); }
.topbar {
  height: var(--header-h); flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 20px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg-1) 70%, transparent);
  backdrop-filter: blur(12px);
}
.topbar h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.topbar .sub { color: var(--text-faint); font-size: 12.5px; font-weight: 500; }
.spacer { flex: 1; }

.searchbox { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 7px 14px; min-width: 220px; color: var(--text-dim); transition: border .15s; }
.searchbox:focus-within { border-color: var(--accent); }
.searchbox input { border: none; background: none; outline: none; width: 100%; }
.searchbox .icon { color: var(--text-faint); }

.iconbtn {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  color: var(--text-dim); border: 1px solid transparent; transition: all .14s;
}
.iconbtn:hover { background: var(--surface); color: var(--text); }
.iconbtn.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }

.toolbar { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { width: 34px; height: 30px; border-radius: 7px; display: grid; place-items: center; color: var(--text-dim); }
.seg button.active { background: var(--surface-2); color: var(--accent); }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text-dim); font-size: 13px; font-weight: 550; transition: all .14s; }
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 55%, transparent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.chip .icon { color: inherit; }

.content { flex: 1; overflow-y: auto; padding: 18px 20px 40px; min-height: 0; }

/* ---- Channel list / grid ---- */
.list-view { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.ch-row {
  display: flex; align-items: center; gap: 14px; padding: 9px 12px; border-radius: var(--radius);
  cursor: pointer; transition: background .12s; border: 1px solid transparent;
}
.ch-row:hover { background: var(--surface); }
.ch-row.playing { background: color-mix(in srgb, var(--accent) 14%, transparent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.ch-row.blocked-row { opacity: .5; }
.pop.ctx-menu button .icon { color: var(--text-faint); }
.pop.ctx-menu button.danger { color: var(--danger); }
.ch-num { width: 34px; text-align: center; color: var(--text-faint); font-variant-numeric: tabular-nums; font-size: 13px; flex: none; }
.ch-logo { width: 52px; height: 52px; border-radius: 11px; background: var(--surface-2); object-fit: contain; flex: none; padding: 5px; }
.ch-logo.fallback { display: grid; place-items: center; color: var(--text-faint); font-weight: 700; padding: 0; }
.ch-main { flex: 1; min-width: 0; }
.ch-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px; }
.ch-now { color: var(--text-dim); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-progress { height: 3px; border-radius: 3px; background: var(--surface-2); margin-top: 6px; overflow: hidden; width: 100%; }
.ch-progress > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.ch-badges { display: flex; gap: 6px; flex: none; align-items: center; }
.badge { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; padding: 2px 7px; border-radius: 6px; }
.badge.live { background: color-mix(in srgb, var(--danger) 22%, transparent); color: var(--danger); }
.badge.archive { background: color-mix(in srgb, var(--accent-2) 22%, transparent); color: var(--accent-2); }
.fav-btn { color: var(--text-faint); padding: 6px; border-radius: 8px; flex: none; }
.fav-btn:hover { color: var(--warn); background: var(--surface-2); }
.fav-btn.on { color: var(--warn); }
.fav-btn.on .icon svg { fill: var(--warn); }

.grid-view { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.grid-view.tiles { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.grid-view.posters { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: transform .16s var(--ease), border-color .16s, box-shadow .16s; }
.card:hover { transform: translateY(-3px); border-color: var(--border-strong); box-shadow: var(--shadow); }
.card.playing { border-color: var(--accent); }
.card-thumb { aspect-ratio: 16/10; background: var(--bg-2); display: grid; place-items: center; position: relative; }
.grid-view.posters .card-thumb { aspect-ratio: 2/3; }
.card-thumb img { width: 100%; height: 100%; object-fit: contain; padding: 12px; }
.grid-view.posters .card-thumb img { object-fit: cover; padding: 0; }
.card-thumb .ph { color: var(--text-faint); font-weight: 800; font-size: 26px; }
.card-body { padding: 9px 11px; }
.card-title { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { color: var(--text-faint); font-size: 11.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-fav { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.4); border-radius: 8px; color: #fff; padding: 5px; opacity: 0; transition: opacity .15s; }
.card:hover .card-fav, .card-fav.on { opacity: 1; }
.card-fav.on { color: var(--warn); }
.card-badge { position: absolute; top: 8px; left: 8px; }

/* ---- Empty / states ---- */
.empty { display: grid; place-items: center; text-align: center; padding: 60px 20px; color: var(--text-dim); gap: 14px; }
.empty .icon { color: var(--text-faint); }
.empty h3 { color: var(--text); font-size: 18px; }
.empty p { max-width: 400px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg-0) 60%, transparent); z-index: 20; backdrop-filter: blur(2px); }
.app-loader { position: fixed; inset: 0; z-index: 350; display: grid; place-items: center; background: color-mix(in srgb, var(--bg-0) 72%, transparent); backdrop-filter: blur(4px); animation: fade .15s; }
.app-loader-box { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 28px 40px; background: var(--bg-1); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.app-loader-msg { font-weight: 600; font-size: 14px; color: var(--text-dim); text-align: center; max-width: 260px; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 11px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); transition: all .14s; }
.btn:hover { border-color: var(--border-strong); background: var(--surface); }
.btn.primary { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, var(--accent-2))); color: var(--accent-contrast); border: none; box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ---- Forms ---- */
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; }
.input, .select, textarea.input { width: 100%; padding: 11px 13px; border-radius: 11px; background: var(--surface); border: 1px solid var(--border); outline: none; transition: border .15s; color: var(--text); }
.input:focus, .select:focus, textarea.input:focus { border-color: var(--accent); }
.select { appearance: none; background-color: var(--bg-2); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
/* Native option popups otherwise render white-on-white in dark mode. */
.select option, .input option { background: var(--bg-2); color: var(--text); }
.select optgroup { background: var(--bg-1); color: var(--text-dim); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch .track { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 999px; transition: background .18s, border-color .18s; pointer-events: none; }
.switch .track::before { content: ''; position: absolute; width: 20px; height: 20px; left: 2px; top: 2px; background: var(--text-dim); border-radius: 50%; transition: transform .18s var(--ease), background .18s; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.switch input:checked + .track { background: var(--accent); border-color: transparent; }
.switch input:checked + .track::before { transform: translateX(20px); background: #fff; }

.setting-row { display: flex; align-items: center; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: none; }
.setting-row .sr-main { flex: 1; min-width: 0; }
.setting-row .sr-title { font-weight: 600; overflow-wrap: anywhere; }
/* Long EPG/playlist URLs must wrap instead of forcing the row wider than the panel. */
.setting-row .sr-desc { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; overflow-wrap: anywhere; word-break: break-word; }
.setting-row .sr-control { flex: none; max-width: 100%; }

.panel { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px 22px; margin-bottom: 18px; }
.panel h2 { font-size: 15px; margin-bottom: 4px; }
.panel .panel-sub { color: var(--text-faint); font-size: 12.5px; margin-bottom: 14px; }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(4px); z-index: 200; display: grid; place-items: center; padding: 20px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--bg-1); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); width: min(560px, 100%); max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: pop .22s var(--ease); }
.modal.wide { width: min(880px, 100%); }
@keyframes pop { from { transform: translateY(14px) scale(.98); opacity: 0; } }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-1); z-index: 2; }
.modal-head h2 { font-size: 17px; flex: 1; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 22px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--bg-1); }
.tabbar { display: flex; gap: 4px; padding: 4px; background: var(--surface); border-radius: 12px; margin-bottom: 18px; }
.tabbar button { flex: 1; padding: 9px; border-radius: 9px; color: var(--text-dim); font-weight: 600; font-size: 13.5px; }
.tabbar button.active { background: var(--bg-2); color: var(--text); box-shadow: var(--shadow); }

/* ---- Toast ---- */
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 400; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--bg-3); border: 1px solid var(--border-strong); color: var(--text); padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow-lg); font-size: 13.5px; font-weight: 550; animation: pop .2s var(--ease); max-width: 90vw; }
.toast.err { border-color: color-mix(in srgb, var(--danger) 55%, transparent); }
.toast.ok { border-color: color-mix(in srgb, var(--good) 55%, transparent); }

/* ---- Mobile ---- */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar h1 { font-size: 15.5px; }
  .topbar .sub { display: none; }
  .searchbox { min-width: 0; flex: 1 1 auto; padding: 7px 12px; }
  .iconbtn { width: 40px; height: 40px; }
  .toolbar { padding: 10px 12px; gap: 6px; }
  .content { padding: 12px 12px 44px; }
  .grid-view { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
  .grid-view.tiles { grid-template-columns: repeat(auto-fill, minmax(102px, 1fr)); }
  .grid-view.posters { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); }
  .ch-row { gap: 10px; padding: 8px; }
  .ch-logo { width: 44px; height: 44px; }
  .ch-num { width: 24px; font-size: 12px; }
  .ch-progress { max-width: none; }
  /* Give the channel name the full width — wrap to 2 lines instead of clipping,
     and drop the wide ARCHIVE badge (archive is still available in the player). */
  .ch-name { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; }
  .ch-row .ch-badges { display: none; }
  .panel { padding: 16px 15px; border-radius: 16px; }
  .modal-head, .modal-foot { padding: 14px 16px; }
  .modal-body { padding: 16px; }
  .row2 { grid-template-columns: 1fr; }
  /* Settings rows: let the control drop to its own full-width line so EPG /
     playlist rows and dropdowns don't overflow the panel on small screens. */
  .setting-row { gap: 10px 12px; padding: 12px 0; flex-wrap: wrap; }
  .setting-row .sr-main { flex: 1 1 60%; }
  .setting-row .sr-control { flex: 1 1 100%; }
  .setting-row .sr-control select,
  .setting-row .sr-control .select { width: 100% !important; }
  .ctx-menu { min-width: 200px; }
  /* Touch targets a touch larger. */
  .nav-item, .group-item { padding-top: 11px; padding-bottom: 11px; }
}
/* Hide the inline filter box on the narrowest screens (Search nav still works). */
@media (max-width: 420px) {
  .topbar .searchbox { display: none; }
}
