/* =================================================================
   IPTVIZION — Theme & Layout
   Brand accent: #c11c1f
   Approach: CSS custom properties so SSH edits to config can later
   inject overrides without rebuilding.
   ================================================================= */

:root {
  --brand: #c11c1f;
  --brand-hover: #d92327;
  --brand-soft: rgba(193, 28, 31, 0.15);

  --bg-0: #08080a;
  --bg-1: #101013;
  --bg-2: #17171c;
  --bg-3: #1f1f26;
  --bg-hover: #25252e;

  --border: #2a2a33;
  --border-strong: #3a3a45;

  --text-1: #f5f5f7;
  --text-2: #b8b8c2;
  --text-3: #7a7a85;

  --ok: #2ecc71;
  --warn: #f4a261;
  --err: #ef4444;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;

  --shadow-1: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 8px 32px rgba(0, 0, 0, 0.6);

  --font-display: "Bebas Neue", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg-0);
  color: var(--text-1);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; }
button { font-family: inherit; }
img { display: block; max-width: 100%; }

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- BOOT ---------- */
.boot {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 24px;
  background: radial-gradient(circle at 50% 30%, #1a0608, var(--bg-0) 60%);
}
.boot__logo, .login__logo, .topbar__brand {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  font-size: 2.4rem;
  line-height: 1;
}
.boot__logo span, .login__logo span, .topbar__brand span { color: var(--brand); }
.boot__status { color: var(--text-2); margin: 0; font-size: 0.95rem; }

/* ---------- SPINNERS ---------- */
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}
.spinner--sm { width: 16px; height: 16px; border-width: 2px; }
.spinner--lg { width: 56px; height: 56px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- LOGIN ---------- */
.login {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(193,28,31,0.18), transparent 60%),
    radial-gradient(800px 400px at -10% 110%, rgba(193,28,31,0.08), transparent 60%),
    var(--bg-0);
}
.login__panel {
  width: 100%; max-width: 440px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-2);
}
.login__header { text-align: center; margin-bottom: 24px; }
.login__tagline { color: var(--text-2); margin: 6px 0 0; font-size: 0.95rem; }
.login__fields { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.login__footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 18px; font-size: 0.85rem;
}

/* ---------- FIELDS ---------- */
.field { display: flex; flex-direction: column; gap: 6px; border: none; padding: 0; margin: 0; }
.field__label { font-size: 0.8rem; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.field__row { display: flex; gap: 8px; align-items: stretch; }
.field input[type="text"], .field input[type="password"], .field input[type="search"],
.search, .setting select, .setting input[type="text"] {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 12px; color: var(--text-1);
  font-size: 0.95rem; outline: none; transition: border-color 0.15s, background 0.15s;
}
.field input:focus, .search:focus, .setting select:focus { border-color: var(--brand); background: var(--bg-3); }
.field input:invalid:not(:placeholder-shown) { border-color: var(--err); }

.field--packages { gap: 10px; }
.packages { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pkg {
  display: flex; flex-direction: column; gap: 2px; padding: 12px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; transition: all 0.15s;
  text-align: left;
}
.pkg input { position: absolute; opacity: 0; pointer-events: none; }
.pkg__label { font-weight: 600; font-size: 0.95rem; }
.pkg__desc { color: var(--text-3); font-size: 0.78rem; }
.pkg:hover { background: var(--bg-3); border-color: var(--border-strong); }
.pkg--selected { border-color: var(--brand); background: var(--brand-soft); }
.pkg--selected .pkg__label { color: #fff; }

.checkbox { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text-2); cursor: pointer; }
.checkbox input { accent-color: var(--brand); }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--bg-2); color: var(--text-1); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: var(--radius-sm); cursor: pointer;
  font-weight: 500; font-size: 0.92rem; transition: all 0.15s;
  user-select: none;
}
.btn:hover { background: var(--bg-3); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--bg-3); }
.btn--block { width: 100%; }
.btn--icon { width: 40px; padding: 0; }
.btn--sm { padding: 6px 10px; font-size: 0.85rem; }
.btn__spinner { margin-left: 6px; }

/* ---------- BANNERS / TOASTS ---------- */
.banner { padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 0.9rem; }
.banner--hidden { display: none; }
.banner--err { background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.4); color: #ffd5d5; }
.banner--info { background: var(--brand-soft); border: 1px solid var(--brand); color: #fff; }

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; pointer-events: none; }
.toast {
  background: var(--bg-2); border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  padding: 10px 14px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-1); min-width: 220px; pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}
.toast--err { border-left-color: var(--err); }
.toast--ok { border-left-color: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---------- MAIN APP / TOPBAR ---------- */
.main { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  height: var(--topbar-h); padding: 0 20px;
  background: var(--bg-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar__menu { display: none; }
.topbar__nav { display: flex; gap: 4px; flex: 1; }
.navbtn {
  background: transparent; border: none; color: var(--text-2);
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 0.92rem; font-weight: 500;
}
.navbtn:hover { color: var(--text-1); background: var(--bg-2); }
.navbtn--active { color: #fff; background: var(--brand); }
.topbar__right { display: flex; align-items: center; gap: 8px; }
.search { width: 220px; padding: 8px 12px; font-size: 0.88rem; }

/* ---------- VIEWS ---------- */
.view { padding: 24px; flex: 1; }
.view__title {
  font-family: var(--font-display);
  font-size: 2rem; letter-spacing: 0.04em;
  margin: 0 0 20px;
}
.view__subtitle { font-size: 1.1rem; margin: 24px 0 12px; color: var(--text-2); }

/* ---------- CARDS ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card__label { font-size: 0.78rem; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.card__value { font-size: 1.2rem; font-weight: 600; word-break: break-word; }
.card--action {
  text-align: left; cursor: pointer; transition: all 0.15s;
  color: var(--text-1); font-size: 1.05rem; font-weight: 500;
  border-color: var(--border);
}
.card--action:hover { background: var(--bg-2); border-color: var(--brand); transform: translateY(-2px); }

/* ---------- SPLIT (sidebar + content) ---------- */
.split { display: grid; grid-template-columns: 260px 1fr; gap: 20px; }
.sidebar {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px; max-height: 70vh; overflow-y: auto;
}
.sidebar__item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 12px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 0.9rem; color: var(--text-2);
}
.sidebar__item:hover { background: var(--bg-2); color: var(--text-1); }
.sidebar__item--active { background: var(--brand-soft); color: #fff; }
.sidebar__count { font-size: 0.75rem; color: var(--text-3); }

/* ---------- GRIDS ---------- */
.grid--channels { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.channel {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px; cursor: pointer;
  transition: all 0.15s;
}
.channel:hover { border-color: var(--brand); transform: translateY(-1px); }
.channel__logo { width: 40px; height: 40px; object-fit: contain; background: var(--bg-2); border-radius: 4px; flex-shrink: 0; }
.channel__num { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-3); }
.channel__name { font-size: 0.9rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.grid--posters { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.poster {
  display: flex; flex-direction: column; gap: 6px; cursor: pointer;
  background: transparent; border: none; padding: 0; text-align: left;
  color: inherit;
}
.poster__img {
  aspect-ratio: 2 / 3; background: var(--bg-2);
  border-radius: var(--radius-sm); overflow: hidden; position: relative;
  transition: transform 0.15s;
}
.poster:hover .poster__img { transform: scale(1.03); box-shadow: var(--shadow-2); }
.poster__img img { width: 100%; height: 100%; object-fit: cover; }
.poster__title { font-size: 0.85rem; font-weight: 500; line-height: 1.3;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.poster__meta { font-size: 0.75rem; color: var(--text-3); }

/* ---------- SKELETONS ---------- */
.skel { background: linear-gradient(90deg, var(--bg-2), var(--bg-3), var(--bg-2));
  background-size: 200% 100%; animation: skel 1.2s ease-in-out infinite; border-radius: var(--radius-sm); }
@keyframes skel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skel--poster { aspect-ratio: 2/3; }
.skel--line { height: 14px; margin-top: 6px; }

/* ---------- EMPTY STATES ---------- */
.empty { padding: 40px 20px; text-align: center; color: var(--text-3); font-size: 0.95rem; }

/* ---------- EPG ---------- */
.epg {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; overflow-x: auto;
}
.epg__row { display: grid; grid-template-columns: 200px 1fr; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); padding: 8px 0; }
.epg__row:last-child { border-bottom: none; }
.epg__channel { font-weight: 500; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.epg__programs { display: flex; gap: 4px; overflow-x: auto; }
.epg__prog {
  flex-shrink: 0; min-width: 180px; padding: 6px 10px;
  background: var(--bg-2); border-radius: 4px; border-left: 3px solid var(--border);
  cursor: pointer; transition: background 0.15s;
}
.epg__prog:hover { background: var(--bg-3); }
.epg__prog--now { border-left-color: var(--brand); background: var(--brand-soft); }
.epg__prog-time { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-3); }
.epg__prog-title { font-size: 0.85rem; font-weight: 500; line-height: 1.2;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------- MODAL / PLAYER ---------- */
/*
 * Many elements below use `display: flex`. The HTML `hidden` attribute normally
 * applies `display: none`, but any explicit `display` declaration outranks the
 * user-agent `[hidden]` rule. Without this override, hidden=true is ignored and
 * modals/overlays remain visible at boot.
 */
[hidden] { display: none !important; }
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.85); backdrop-filter: blur(6px); }
.modal__panel {
  position: relative; background: var(--bg-1); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2); overflow: hidden;
  width: min(1100px, 96vw); max-height: 92vh; display: flex; flex-direction: column;
}
.modal__panel--player { width: min(1200px, 96vw); }

.player__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg-2); border-bottom: 1px solid var(--border);
}
.player__title { font-size: 1rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player__controls-extra { display: flex; gap: 6px; }
.player__stage { position: relative; background: #000; aspect-ratio: 16/9; }
.video-js { width: 100% !important; height: 100% !important; }
.player__error, .player__loading {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  background: rgba(0,0,0,0.85); color: #fff; text-align: center; padding: 20px;
}
.player__error-icon { font-size: 3rem; color: var(--warn); }
.player__error-msg { font-size: 1rem; max-width: 480px; }
.player__error-actions { display: flex; gap: 8px; margin-top: 8px; }

.drawer { background: var(--bg-2); padding: 16px; max-height: 50vh; overflow-y: auto;
  border-top: 1px solid var(--border); }
.drawer h3, .drawer h4 { margin: 0 0 12px; font-size: 0.95rem; }
.drawer h4 { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--border); }
.setting { display: grid; grid-template-columns: 140px 1fr auto; gap: 10px; align-items: center; margin-bottom: 10px; }
.setting label { font-size: 0.85rem; color: var(--text-2); }
.setting--inline { display: flex; }
.setting select, .setting input[type="range"] { width: 100%; }

/* Tighter Video.js theming to match brand */
.video-js .vjs-big-play-button { background-color: rgba(193,28,31,0.85); border-color: var(--brand); }
.video-js .vjs-control-bar { background-color: rgba(0,0,0,0.6); }
.video-js .vjs-slider-bar, .video-js .vjs-volume-level { background-color: var(--brand); }

/* Subtitle styling — controlled via CSS variables set by JS */
.video-js .vjs-text-track-cue {
  font-size: calc(1em * var(--sub-scale, 1)) !important;
  color: var(--sub-color, #fff) !important;
  background-color: rgba(0, 0, 0, var(--sub-bg, 0.5)) !important;
}

.muted { color: var(--text-3); }
.hidden { display: none !important; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 900px) {
  .topbar__menu { display: inline-flex; }
  .topbar__nav {
    position: fixed; top: var(--topbar-h); left: 0; right: 0;
    flex-direction: column; background: var(--bg-1); border-bottom: 1px solid var(--border);
    padding: 8px; gap: 2px; display: none;
  }
  .topbar__nav.open { display: flex; }
  .search { width: 140px; }
  .split { grid-template-columns: 1fr; }
  .sidebar { max-height: none; }
}
@media (max-width: 560px) {
  .packages { grid-template-columns: 1fr; }
  .view { padding: 16px; }
  .view__title { font-size: 1.6rem; }
  .setting { grid-template-columns: 1fr; }
  .search { display: none; }
}
