/* ===== CSS Variables ===== */
:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-hover: #0f3460;
  --accent: #e94560;
  --accent-hover: #c73652;
  --accent-secondary: #533483;
  --text-primary: #ffffff;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  --border: #2d3748;
  --success: #48bb78;
  --warning: #ed8936;
  --error: #fc8181;
  --sidebar-width: 320px;
  --header-height: 60px;
  --radius: 8px;
  --transition: 0.2s ease;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
}

[data-theme="light"] {
  --bg-primary: #f7fafc;
  --bg-secondary: #edf2f7;
  --bg-card: #ffffff;
  --bg-hover: #e2e8f0;
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --border: #e2e8f0;
  --shadow: 0 4px 20px rgba(0,0,0,0.1);
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
.header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon { font-size: 24px; }

.logo-text {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-controls { display: flex; gap: 8px; }

/* ===== App Container ===== */
.app-container {
  display: flex;
  margin-top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition), transform var(--transition);
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: 50px;
}

.sidebar.collapsed .sidebar-header h2,
.sidebar.collapsed .source-section,
.sidebar.collapsed .filter-section,
.sidebar.collapsed .stats-bar,
.sidebar.collapsed .channel-list,
.sidebar.collapsed .pagination {
  display: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 { font-size: 16px; font-weight: 600; }

/* ===== Source Section ===== */
.source-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.custom-url-wrapper {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group {
  display: flex;
  gap: 6px;
}

/* ===== Filter Section ===== */
.filter-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  font-size: 14px;
}

.search-input {
  width: 100%;
  padding: 8px 30px 8px 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}

.search-input:focus { border-color: var(--accent); }

.clear-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px;
}

.filter-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.filter-row .select-input { flex: 1; }

/* ===== Stats ===== */
.stats-bar {
  padding: 6px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-text { font-size: 12px; color: var(--text-muted); }
.loading-text { font-size: 12px; color: var(--accent); animation: pulse 1s infinite; }

/* ===== Channel List ===== */
.channel-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.channel-list::-webkit-scrollbar { width: 4px; }
.channel-list::-webkit-scrollbar-track { background: transparent; }
.channel-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.channel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  border: 1px solid transparent;
  margin-bottom: 4px;
}

.channel-item:hover { background: var(--bg-hover); }

.channel-item.active {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.channel-thumb {
  width: 40px;
  height: 30px;
  border-radius: 4px;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.channel-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.channel-thumb-placeholder {
  font-size: 18px;
}

.channel-meta { flex: 1; min-width: 0; }

.channel-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.channel-group {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.channel-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.channel-status.online { background: var(--success); }
.channel-status.offline { background: var(--error); }

/* ===== Pagination ===== */
.pagination {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-top: 1px solid var(--border);
}

.page-info { font-size: 13px; color: var(--text-secondary); }

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ===== Player Section ===== */
.player-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.player-wrapper {
  flex: 1;
  background: #000;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#videoPlayer {
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ===== Placeholder ===== */
.player-placeholder {
  text-align: center;
  padding: 40px;
}

.placeholder-icon { font-size: 64px; margin-bottom: 16px; }

.player-placeholder h3 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.player-placeholder p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.feature-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.feature-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===== Player Error ===== */
.player-error {
  text-align: center;
  padding: 40px;
}

.error-icon { font-size: 48px; margin-bottom: 16px; }

.player-error p {
  color: var(--error);
  margin-bottom: 20px;
  font-size: 15px;
}

.error-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== Now Playing ===== */
.now-playing {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.channel-info { display: flex; align-items: center; gap: 12px; }

.channel-logo {
  width: 48px;
  height: 36px;
  object-fit: contain;
  border-radius: 4px;
  background: var(--bg-card);
}

.channel-name-big { font-size: 16px; font-weight: 600; }
.channel-group-tag {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-block;
  margin-top: 4px;
}

.player-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Bottom Section ===== */
.bottom-section {
  height: 200px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.tab-nav {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all var(--transition);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { flex: 1; overflow: hidden; }

.tab-panel {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding: 12px;
}

.tab-panel.active { display: block; }

/* ===== Mini Channel Grid ===== */
.mini-channel-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mini-channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 13px;
}

.mini-channel-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.empty-mini { color: var(--text-muted); font-size: 13px; padding: 20px; }

/* ===== Sources Grid ===== */
.sources-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.source-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

/* ===== Buttons ===== */
.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition);
  font-weight: 500;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-action {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-action:hover { border-color: var(--accent); color: var(--accent); }
.btn-action.active { background: var(--accent); color: white; border-color: var(--accent); }

.btn-icon {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition);
  font-family: inherit;
}

.btn-icon:hover { border-color: var(--accent); background: var(--bg-hover); }

.btn-page {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
  transition: all var(--transition);
}

.btn-page:hover:not(:disabled) { border-color: var(--accent); }
.btn-page:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-sm { padding: 6px 10px; font-size: 12px; }

/* ===== Form Elements ===== */
.select-input {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
  width: 100%;
}

.select-input:focus { border-color: var(--accent); }
.select-sm { padding: 6px 8px; font-size: 12px; }

.text-input {
  flex: 1;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
  min-width: 0;
}

.text-input:focus { border-color: var(--accent); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; line-height: 1.6; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 13px;
  z-index: 1000;
  box-shadow: var(--shadow);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  max-width: 300px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--error); }
.toast.info { border-left: 3px solid var(--accent); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; }

/* ===== EPG ===== */
.epg-info {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== Animations ===== */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    z-index: 50;
    transform: translateX(-100%);
    width: 90vw;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .app-container { flex-direction: column; }
  .main-content { width: 100%; }

  .now-playing {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .bottom-section { height: 160px; }

  .player-placeholder { padding: 20px; }
  .placeholder-icon { font-size: 40px; }
  .player-placeholder h3 { font-size: 18px; }
}

@media (max-width: 480px) {
  .header-content { padding: 0 12px; }
  .error-actions { flex-direction: column; }
  .btn-primary, .btn-secondary { width: 100%; text-align: center; }
}
