/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3350;
  --accent: #4f8ef7;
  --accent-hover: #6ea6ff;
  --text: #e2e6f0;
  --text-muted: #7a82a0;
  --danger: #e05252;
  --active-bg: #1f3464;
  --radius: 6px;
  --topbar-h: 48px;
}

html, body { height: 100%; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

/* ── Login page ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 40px 36px;
  width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}

.login-card h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 28px;
  color: var(--accent);
  text-align: center;
  letter-spacing: .5px;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .6px;
}

input[type="text"],
input[type="url"],
input[type="password"],
input[type="search"] {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--accent); }

.error-msg {
  background: rgba(224,82,82,.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, opacity .15s;
}
button:disabled { opacity: .5; cursor: not-allowed; }

#login-btn {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  margin-top: 6px;
  font-size: 15px;
}
#login-btn:hover:not(:disabled) { background: var(--accent-hover); }

/* ── Player page layout ── */
.player-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-title {
  font-weight: 600;
  color: var(--accent);
  font-size: 15px;
  flex: 1;
}

.logout-btn {
  padding: 5px 14px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
}
.logout-btn:hover { border-color: var(--danger); color: var(--danger); }

/* 2×2 grid */
.grid {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 1fr 1fr;
  min-height: 0;
  gap: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  min-height: 0;
}

.panel-categories { grid-column: 1; grid-row: 1; }
.panel-channels   { grid-column: 1; grid-row: 2; }
.panel-player     { grid-column: 2; grid-row: 1; background: #000; }
.panel-epg        { grid-column: 2; grid-row: 2; }

.panel-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-muted);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Type tabs (Live / Movies / Series) */
.type-tabs { display: flex; gap: 4px; }
.tab-btn {
  padding: 3px 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  border-radius: 20px;
}
.tab-btn.active, .tab-btn:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Search input inside panel header */
#channel-search {
  padding: 4px 9px;
  font-size: 12px;
  width: 120px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}

/* Scrollable lists */
.scroll-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.scroll-list li {
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .1s;
}
.scroll-list li:hover { background: var(--surface2); }
.scroll-list li.active { background: var(--active-bg); color: var(--accent); }
.scroll-list li.placeholder { color: var(--text-muted); cursor: default; font-style: italic; font-size: 13px; }

.channel-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 3px;
  background: var(--surface2);
}
.channel-logo-placeholder {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  background: var(--surface2);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-muted);
}

.channel-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Video player ── */
.video-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
}

#video-player {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
}

.player-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.7);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
  transition: opacity .3s;
}
.player-overlay.hidden { opacity: 0; }

/* ── EPG ── */
.epg-content {
  overflow-y: auto;
  flex: 1;
  padding: 0;
}

.epg-program {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.epg-program.now { background: rgba(79,142,247,.08); }

.epg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.epg-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 3px;
}
.epg-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.epg-now-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 20px;
  margin-left: 6px;
  vertical-align: middle;
  font-weight: 600;
}

.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
}

/* ── Cast button & state label ── */
.now-playing-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cast-state-label {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  white-space: nowrap;
  flex-shrink: 0;
}
.cast-state-label:empty { display: none; }
.cast-unavailable { color: var(--text-muted); border-color: var(--border); }
.cast-ready       { color: #6dbf7e;           border-color: #6dbf7e44;    }
.cast-connecting  { color: #e0a44f;           border-color: #e0a44f44;    }
.cast-connected   { color: var(--accent);     border-color: var(--accent); font-weight: 600; }

.cast-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}
.cast-icon-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ── Mobile nav (desktop: hidden) ── */
.mobile-nav { display: none; }

/* ── Scrollbar styling ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive: mobile ── */
@media (max-width: 768px) {
  /* Login card: full-width on small screens */
  .login-card {
    width: calc(100% - 32px);
    padding: 28px 20px;
  }

  /* Switch grid → flex column; player sits at top */
  .player-page { overflow: hidden; }

  .grid {
    display: flex;
    flex-direction: column;
    grid-template-columns: unset;
    grid-template-rows: unset;
  }

  /* Player panel: shrink to 16:9, don't flex-grow */
  .panel-player {
    flex-shrink: 0;
    order: 1;
    background: #000;
  }

  .video-wrapper {
    aspect-ratio: 16 / 9;
    flex: none;
    width: 100%;
    height: auto;
  }

  #video-player { position: absolute; inset: 0; height: 100%; }

  /* Mobile tab bar */
  .mobile-nav {
    display: flex;
    flex-shrink: 0;
    order: 2;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  .mobile-tab {
    flex: 1;
    padding: 11px 4px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
  }

  .mobile-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
  }

  /* Side panels: hidden by default, shown when tab is active */
  .panel-categories,
  .panel-channels,
  .panel-epg {
    display: none;
    order: 3;
    flex: 1;
    min-height: 0;
  }

  .panel-categories.mobile-active,
  .panel-channels.mobile-active,
  .panel-epg.mobile-active {
    display: flex;
  }

  /* Tighter header on mobile */
  .panel-header { padding: 8px 10px; }
  #channel-search { width: 100px; }

  /* Cast state label: hide on mobile to save space */
  .cast-state-label { display: none; }
}
