:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a26;
  --accent-color: #6366f1;
  --accent-hover: #4f46e5;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --danger-color: #ef4444;
  --focus-glow: 0 0 0 3px #6366f1, 0 0 20px rgba(99, 102, 241, 0.6);
  --border-radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body.dark-theme {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  overflow-x: hidden;
}

/* ECRÃS */
.screen {
  display: none;
  min-height: 100vh;
}
.screen.active {
  display: flex;
}

/* FOCO E NAVEGAÇÃO D-PAD / ANDROID TV */
.focusable {
  outline: none;
  transition: all 0.2s ease;
}
.focusable:focus, .focusable.focused {
  box-shadow: var(--focus-glow) !important;
  transform: scale(1.03);
  z-index: 10;
}

/* LOGIN CARD */
#login-screen {
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at center, #1a1a2e 0%, #0a0a0f 100%);
}

.login-card {
  background: var(--bg-card);
  padding: 40px;
  border-radius: 20px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.05);
}

.brand h1 {
  font-size: 2.5rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 5px;
}
.brand h1 span { color: var(--accent-color); }
.brand p { text-align: center; color: var(--text-secondary); margin-bottom: 30px; font-size: 0.9rem; }

.input-group {
  margin-bottom: 20px;
}
.input-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.input-group input {
  width: 100%;
  padding: 14px;
  background: var(--bg-secondary);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--border-radius);
  color: #fff;
  font-size: 1rem;
}

.btn {
  padding: 12px 24px;
  border-radius: var(--border-radius);
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-size: 1rem;
}
.btn-primary {
  width: 100%;
  background: var(--accent-color);
  color: #fff;
}
.btn-logout {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
}
.btn-icon {
  background: var(--bg-card);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.1);
}

.error-message {
  color: var(--danger-color);
  font-size: 0.85rem;
  margin-bottom: 15px;
  text-align: center;
}

/* APP LAYOUT */
#app-screen {
  flex-direction: column;
}

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  background: var(--bg-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.brand-small { font-size: 1.5rem; font-weight: 800; }
.brand-small span { color: var(--accent-color); }

.search-box input {
  padding: 10px 20px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  color: #fff;
  width: 300px;
}

.main-layout {
  display: flex;
  flex: 1;
}

/* SIDEBAR */
.sidebar {
  width: 250px;
  background: var(--bg-secondary);
  padding: 20px;
  border-right: 1px solid rgba(255,255,255,0.05);
}
.sidebar h3 { color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; margin-bottom: 15px; }
.sidebar ul { list-style: none; }
.category-item {
  padding: 12px 16px;
  border-radius: var(--border-radius);
  margin-bottom: 8px;
  cursor: pointer;
  color: var(--text-secondary);
}
.category-item.active {
  background: var(--accent-color);
  color: #fff;
}

/* CONTENT AREA */
.content-area {
  flex: 1;
  padding: 25px;
  display: flex;
  flex-direction: column;
  gap: 25px;
  overflow-y: auto;
}

.player-container {
  background: var(--bg-card);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.05);
}

.video-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  max-height: 500px;
  background: #000;
}
video { width: 100%; height: 100%; object-fit: contain; }

.player-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 15px;
}
.spinner {
  width: 40px; height: 40px;
  border: 4px solid rgba(255,255,255,0.1);
  border-left-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.now-playing-bar {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.channel-logo-large {
  width: 60px; height: 60px;
  object-fit: contain;
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 5px;
}
.channel-meta { flex: 1; }
.epg-info { margin-top: 5px; }
.epg-title { font-size: 0.9rem; color: var(--accent-color); font-weight: 600; }
.epg-next { font-size: 0.8rem; color: var(--text-secondary); display: block; margin-top: 4px; }

.progress-bar-bg {
  width: 100%; max-width: 400px; height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px; margin: 6px 0;
}
.progress-bar-fill { height: 100%; width: 0%; background: var(--accent-color); border-radius: 2px; }

/* CHANNELS GRID */
.channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 15px;
  margin-top: 15px;
}

.channel-card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.05);
}
.channel-card img {
  width: 50px; height: 50px;
  object-fit: contain;
  margin-bottom: 10px;
}
.channel-card .title { font-size: 0.95rem; font-weight: 600; }
.channel-card .group-badge { font-size: 0.7rem; color: var(--text-secondary); margin-top: 4px; }

/* RESPONSIVO */
@media (max-width: 768px) {
  .main-layout { flex-direction: column; }
  .sidebar { width: 100%; }
  .search-box input { width: 100%; }
}