* { box-sizing: border-box; }
body {
  --iptv-bg: #f4f4f4;
  --iptv-surface: #ffffff;
  --iptv-surface-muted: #f8fafc;
  --iptv-border: #dbe3ea;
  --iptv-text: #222222;
  --iptv-muted: #64748b;
  --iptv-accent: #0077b5;
  --iptv-panel: #ffffff;
  --iptv-summary: #e8f0f5;
  --iptv-hover: #e8f4fb;
  --iptv-logo: #eef2f5;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--iptv-bg);
  color: var(--iptv-text);
  margin: 0;
  transition: background .2s ease, color .2s ease;
}

body.dark-mode {
  --iptv-bg: #121212;
  --iptv-surface: #181818;
  --iptv-surface-muted: #242424;
  --iptv-border: #333333;
  --iptv-text: #ffffff;
  --iptv-muted: #a1a1aa;
  --iptv-accent: #38a9df;
  --iptv-panel: #222222;
  --iptv-summary: #2a2a2a;
  --iptv-hover: #333333;
  --iptv-logo: #1a1a1a;
  --bg: #121212;
  --card: #181818;
  --text: #ffffff;
  --muted: #a1a1aa;
}

body.dark-mode > header,
body.dark-mode > footer { border-color: var(--iptv-border); }
body.dark-mode > header { background: var(--iptv-surface); }
body.dark-mode > footer { background: var(--iptv-surface); }

.iptv-app { display: flex; height: calc(100vh - 145px); min-height: 520px; padding: 0; }
body.site-chrome-hidden > header,
body.site-chrome-hidden > footer { display: none; }
body.site-chrome-hidden .iptv-app { height: 100vh; min-height: 100vh; }

#sidebar { width: 350px; border-right: 1px solid var(--iptv-border); display: flex; flex-direction: column; background: var(--iptv-surface); }
.sidebar-header { padding: 15px; border-bottom: 1px solid var(--iptv-border); }
.header-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.header-title h2 { margin: 0; font-size: 1.2rem; color: var(--iptv-text); }
.theme-button { color: var(--iptv-muted); font-size: 1.1rem; background: transparent; border: 0; cursor: pointer; padding: 2px 4px; }
.theme-button:hover { color: var(--iptv-accent); }
.help-icon { color: var(--iptv-muted); font-size: 1.2rem; text-decoration: none; transition: color 0.2s ease; }
.help-icon:hover { color: var(--iptv-accent); }

#searchInput {
  width: 100%;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--iptv-border);
  background: var(--iptv-surface-muted);
  color: var(--iptv-text);
  font-size: 0.95rem;
  outline: none;
}
#searchInput:focus { border-color: var(--iptv-accent); }
#channel-container { flex: 1; overflow-y: auto; padding: 10px; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; }
#main h1, #main h2 { color: var(--iptv-text); }
.player-stage { position: relative; width: 100%; max-width: 1100px; aspect-ratio: 16 / 9; }
video { width: 100%; height: 100%; display: block; aspect-ratio: 16 / 9; object-fit: contain; background: #000; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.5); }
.fullscreen-button { position: absolute; top: 12px; right: 12px; z-index: 2; color: #fff; background: rgba(0, 0, 0, 0.65); border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 6px; cursor: pointer; padding: 8px 10px; opacity: 0; transition: opacity .2s ease, background .2s ease; }
.player-stage:hover .fullscreen-button,
.player-stage:focus-within .fullscreen-button { opacity: 1; }
.fullscreen-button:hover { background: var(--iptv-accent); }
@media (hover: none) {
  .fullscreen-button { opacity: .9; }
}

details { margin-bottom: 8px; background: var(--iptv-panel); border-radius: 4px; overflow: hidden; }
summary { padding: 10px 12px; font-weight: 600; cursor: pointer; background: var(--iptv-summary); user-select: none; display: flex; align-items: center; gap: 8px; }
summary:hover { background: var(--iptv-hover); }
.channel-item { padding: 8px 12px; font-size: 0.9em; border-bottom: 1px solid var(--iptv-border); cursor: pointer; display: flex; align-items: center; gap: 10px; }
.channel-item:hover { background: var(--iptv-hover); color: var(--iptv-accent); }
.logo-container { width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; background: var(--iptv-logo); border-radius: 4px; flex-shrink: 0; overflow: hidden; }
.channel-logo { width: 100%; height: 100%; object-fit: contain; }
.fallback-logo { font-size: 14px; }
.status { color: var(--iptv-muted); font-size: 0.85rem; margin-top: 5px; }

@media (max-width: 700px) {
  .iptv-app,
  body.site-chrome-hidden .iptv-app { height: auto; min-height: 100vh; flex-direction: column; }
  #sidebar { display: contents; }
  .sidebar-header { display: contents; }
  .header-title { order: 1; width: 100%; padding: 15px; margin: 0; background: var(--iptv-surface); border-bottom: 1px solid var(--iptv-border); }
  #main { order: 2; min-height: 0; padding: 8px 12px 10px; }
  #main h1 { margin: 0 0 8px; }
  #main h2 { margin: 8px 0 0; }
  #searchInput { order: 3; width: calc(100% - 24px); margin: 8px 12px 0; }
  #status { order: 4; margin: 6px 16px 0; }
  #channel-container { order: 5; width: 100%; min-height: 260px; max-height: 42vh; background: var(--iptv-surface); border-bottom: 1px solid var(--iptv-border); }
  .player-stage { max-width: 100%; }
  #main h1 { font-size: 1.5rem; }
  #main h2 { font-size: 1rem; text-align: center; }
}
