/* ============================================================================
   PlayMSX — EPG Dynamic Guide 2.0
   Guia eletrônico de programação: categorias | canais | programação horizontal
   Tokens do tema PlayMSX via :root (--accent, --bg-0, etc.)
   ========================================================================= */
:root {
  --epg-bg: var(--bg-0, #080d17);
  --epg-surface: var(--bg-2, #111b2b);
  --epg-program: #172438;
  --epg-focus: var(--accent, #398bff);
  --epg-focus-light: var(--accent-2, #80bcff);
  --epg-text: var(--text, #f4f7fc);
  --epg-muted: var(--muted, #91a2bb);
  --epg-border: rgba(120, 160, 255, 0.14);
  --epg-now: #ff4757;

  --epg-cat-w: clamp(180px, 16vw, 240px);
  --epg-ch-w: clamp(200px, 17vw, 250px);
  --epg-row-h: 70px;
  --epg-logo-w: 64px;
  --epg-radius: 10px;
  --epg-gap: 5px;
  --epg-focus-scale: 1.045;
  --epg-neighbor-scale: 1.012;
  --epg-dur: 180ms;
  --epg-min-w: 5px;
}

.epg-guide, .epg-guide * { box-sizing: border-box; }

.epg-guide {
  display: flex;
  width: 100%; height: 100%;
  min-height: 0; overflow: hidden;
  background:
    radial-gradient(ellipse at top right, rgba(19, 39, 73, .55) 0%, transparent 55%),
    var(--epg-bg);
  color: var(--epg-text);
  border-radius: calc(var(--radius, 14px) * 1.2);
  animation: epg-in .35s var(--ease, cubic-bezier(.22,.9,.3,1)) both;
}
@keyframes epg-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ── Coluna 1 — Categorias ────────────────────────────────────────────── */
.epg-cats {
  flex: 0 0 var(--epg-cat-w);
  display: flex; flex-direction: column;
  min-height: 0; padding: 16px 12px;
  border-right: 1px solid var(--epg-border);
  background: rgba(9, 15, 26, .72);
}
.epg-cats-head {
  font-size: 10.5px; letter-spacing: .28em; text-transform: uppercase;
  color: var(--epg-muted); font-weight: 700; padding: 2px 8px 14px;
}
.epg-cats-list { flex: 1; overflow-y: auto; min-height: 0; scrollbar-width: none; }
.epg-cats-list::-webkit-scrollbar { display: none; }

.epg-cat {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 12px 14px; margin-bottom: 5px;
  color: var(--epg-muted); background: rgba(255,255,255,.035);
  border: 1.5px solid transparent; border-radius: var(--epg-radius);
  font-size: 14px; font-weight: 600; text-align: left; cursor: pointer;
  transition: all var(--epg-dur) cubic-bezier(.22,.9,.3,1);
  position: relative;
}
.epg-cat .epg-cat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.epg-cat .epg-cat-count {
  flex: 0 0 auto; font-size: 11px; font-weight: 700; opacity: .55;
  background: rgba(255,255,255,.08); padding: 2px 8px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.epg-cat.focused, .epg-cat.is-active {
  color: var(--epg-text);
  border-color: var(--epg-focus);
  background: linear-gradient(90deg, color-mix(in srgb, var(--epg-focus) 24%, transparent), color-mix(in srgb, var(--epg-focus) 6%, transparent));
  box-shadow: 0 8px 26px color-mix(in srgb, var(--epg-focus) 28%, transparent);
  transform: translateX(5px) scale(1.02);
}
.epg-cat.focused .epg-cat-count, .epg-cat.is-active .epg-cat-count {
  opacity: 1; background: color-mix(in srgb, var(--epg-focus) 45%, transparent); color: #fff;
}
.epg-cat.focused::before, .epg-cat.is-active::before {
  content: ''; position: absolute; left: 0; top: 14%; bottom: 14%; width: 3px;
  border-radius: 3px; background: var(--epg-focus-light);
  box-shadow: 0 0 12px var(--epg-focus-light);
}

/* ── Área principal ───────────────────────────────────────────────────── */
.epg-main {
  display: flex; flex-direction: column;
  flex: 1; min-width: 0; min-height: 0;
  padding: 16px 18px 12px; overflow: hidden;
}

/* Hero do canal selecionado */
.epg-hero {
  display: flex; align-items: center; flex-shrink: 0; gap: 20px;
  min-height: 118px; padding: 16px 20px; margin-bottom: 14px;
  border: 1px solid var(--epg-border); border-radius: 16px;
  background: linear-gradient(110deg, #101b2d, #14294b, #0a1221);
}
.epg-hero-logo {
  width: 110px; height: 74px; object-fit: contain; flex-shrink: 0;
  background: #0a1322; border-radius: 8px; padding: 6px;
}
.epg-hero-body { flex: 1; min-width: 0; }
.epg-live-badge {
  display: inline-block; color: #ff6471; font-size: 10.5px;
  font-weight: 800; letter-spacing: .14em;
}
.epg-live-badge::before { content: '● '; }
.epg-hero h2 {
  font-size: clamp(19px, 2vw, 26px); font-weight: 800;
  letter-spacing: -.02em; margin: 5px 0; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.epg-hero-prog { margin: 4px 0; color: var(--epg-muted); font-size: 13.5px; }
.epg-hero-bar {
  height: 4px; max-width: 320px; overflow: hidden; margin: 8px 0 5px;
  border-radius: 8px; background: #293b55;
}
.epg-hero-bar i { display: block; height: 100%; background: var(--epg-focus); border-radius: 8px; transition: width .4s ease; }
.epg-hero-time { font-size: 12px; color: var(--epg-muted); font-variant-numeric: tabular-nums; }

/* ── Tabela EPG ───────────────────────────────────────────────────────── */
.epg-table {
  display: flex; flex-direction: column; flex: 1;
  min-height: 0; min-width: 0; overflow: hidden;
  border: 1px solid var(--epg-border); border-radius: 12px;
}
.epg-table-head {
  display: flex; flex-shrink: 0; height: 42px; overflow: hidden;
  background: #101a2a;
}
.epg-ch-heading {
  flex: 0 0 var(--epg-ch-w); display: flex; align-items: center;
  padding-left: 16px; font-weight: 700; font-size: 13px; color: var(--epg-muted);
  letter-spacing: .12em; text-transform: uppercase;
  position: sticky; left: 0; z-index: 5; background: #101a2a;
}
.epg-timeline { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.epg-timeline-track { position: relative; height: 100%; }
.epg-hour {
  position: absolute; top: 0; height: 100%; padding: 12px 10px;
  font-size: 13px; border-left: 1px solid var(--epg-border);
  color: var(--epg-muted); font-variant-numeric: tabular-nums; font-weight: 600;
}

.epg-viewport {
  flex: 1; min-height: 0; overflow: auto; position: relative;
  padding: 5px 0; scrollbar-width: none;
}
.epg-viewport::-webkit-scrollbar { display: none; }
.epg-rows { position: relative; }

/* ── Linhas de canais ─────────────────────────────────────────────────── */
.epg-row {
  display: flex; align-items: stretch; position: relative;
  min-height: var(--epg-row-h); margin-bottom: var(--epg-gap);
  transition: min-height var(--epg-dur) ease;
}
.epg-row.is-focused { min-height: calc(var(--epg-row-h) * var(--epg-focus-scale)); z-index: 2; }
.epg-row.is-neighbor { min-height: calc(var(--epg-row-h) * var(--epg-neighbor-scale)); }

.epg-ch {
  position: sticky; left: 0; z-index: 4;
  flex: 0 0 var(--epg-ch-w);
  display: flex; align-items: center; gap: 11px;
  min-width: 0; padding: 7px 12px;
  background: var(--epg-surface); color: var(--epg-text);
  border: 1.5px solid var(--epg-border); border-radius: var(--epg-radius);
  cursor: pointer;
  transition: background var(--epg-dur), box-shadow var(--epg-dur), border-color var(--epg-dur);
}
.epg-row.is-focused .epg-ch {
  background: #18375f;
  border-color: var(--epg-focus);
  box-shadow: inset 0 0 14px rgba(57, 139, 255, .18), 0 4px 20px rgba(57, 139, 255, .22);
}
.epg-ch-num {
  flex: 0 0 auto; font-size: 11px; font-weight: 700; color: var(--epg-muted);
  font-variant-numeric: tabular-nums; min-width: 26px;
}
.epg-ch-logo {
  width: var(--epg-logo-w); height: 40px; flex-shrink: 0;
  object-fit: contain; background: #0a1322; border-radius: 6px; padding: 3px;
}
.epg-ch-info { flex: 1; min-width: 0; }
.epg-ch-name {
  display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 14.5px; font-weight: 700;
}
.epg-ch-quality { font-size: 10.5px; color: var(--epg-muted); }
.epg-ch-fav {
  flex: 0 0 auto; font-size: 15px; opacity: .45;
  transition: opacity .2s;
}
.epg-ch-fav.is-on { opacity: 1; color: var(--epg-focus-light); }

/* ── Programas ────────────────────────────────────────────────────────── */
.epg-programs { position: relative; flex-shrink: 0; min-height: var(--epg-row-h); }
.epg-prog {
  position: absolute; top: 2px; bottom: 2px;
  display: flex; flex-direction: column; justify-content: center;
  padding: 6px 12px; overflow: hidden;
  background: var(--epg-program); border: 1px solid var(--epg-border);
  border-radius: 8px; color: var(--epg-text); text-align: left; cursor: pointer;
  transition: background var(--epg-dur), box-shadow var(--epg-dur), border-color var(--epg-dur);
}
.epg-prog.is-current { background: #172c48; }
.epg-prog-title {
  font-size: 13px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; line-height: 1.3;
}
.epg-prog-time {
  margin-top: 3px; font-size: 11px; color: var(--epg-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.epg-prog-bar {
  height: 3px; margin-top: 5px; border-radius: 3px;
  background: rgba(255,255,255,.12); overflow: hidden;
}
.epg-prog-bar i { display: block; height: 100%; background: var(--epg-focus); border-radius: 3px; }
.epg-prog-left {
  margin-top: 3px; font-size: 10px; color: var(--epg-muted);
  font-variant-numeric: tabular-nums; text-align: right;
}

.epg-prog.focused, .epg-ch.focused {
  z-index: 3; border-color: var(--epg-focus-light) !important;
  box-shadow: 0 0 0 2px var(--epg-focus-light), 0 0 16px rgba(57, 139, 255, .35) !important;
}

/* Sem programação */
.epg-prog-empty {
  position: absolute; top: 2px; bottom: 2px; left: 0; width: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--epg-program); border: 1px solid var(--epg-border);
  border-radius: 8px; color: var(--epg-muted); font-size: 12.5px;
}

/* ── Linha do horário atual ───────────────────────────────────────────── */
.epg-now-line {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--epg-now); z-index: 3; pointer-events: none;
  box-shadow: 0 0 8px rgba(255, 71, 87, .5);
}
.epg-now-badge {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  padding: 3px 10px; border-radius: 6px; background: var(--epg-now);
  color: #fff; font-size: 11px; font-weight: 800;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(255, 71, 87, .4);
}

/* ── Rodapé ───────────────────────────────────────────────────────────── */
.epg-footer {
  display: flex; justify-content: space-between; flex-shrink: 0;
  gap: 12px; padding: 12px 4px 0;
  color: var(--epg-muted); font-size: 11.5px;
}
.epg-footer span b {
  display: inline-grid; place-items: center; min-width: 22px; height: 20px;
  padding: 0 5px; margin-right: 4px; border-radius: 5px;
  background: rgba(255,255,255,.1); color: var(--epg-focus-light);
  font-size: 11px; font-weight: 800;
}

/* ── Modo performance / TVs antigas ───────────────────────────────────── */
.epg-guide.perf-lite * {
  transition: none !important; animation: none !important;
}
@media (prefers-reduced-motion: reduce) {
  .epg-guide * { transition: none !important; animation: none !important; }
}

/* ── HD 720p ──────────────────────────────────────────────────────────── */
@media (max-width: 1280px) {
  :root {
    --epg-cat-w: 170px; --epg-ch-w: 190px;
    --epg-row-h: 58px; --epg-logo-w: 48px; --epg-min-w: 3.5px;
  }
  .epg-main { padding: 10px 12px 8px; }
  .epg-hero { min-height: 95px; padding: 12px 14px; gap: 14px; }
  .epg-hero h2 { font-size: 18px; }
  .epg-hero-logo { width: 80px; height: 54px; }
  .epg-ch-name { font-size: 12.5px; }
  .epg-prog-title { font-size: 12px; }
}
