/* PulseTV — Lightweight Dark Cinema Stylesheet (zero heavy GPU blur filters) */

:root {
  --bg: #0b0e14;
  --surface: #121722;
  --surface-2: #182030;
  --surface-hover: #1f293d;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef2f7;
  --text-muted: #94a3b8;
  --accent: #22d3ee;
  --accent-bg: rgba(34, 211, 238, 0.14);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.16);
  --ok: #10b981;
  --ok-bg: rgba(16, 185, 129, 0.16);
  --warn: #f59e0b;
  --radius: 8px;
  --topbar-h: 52px;
  --sidebar-w: 320px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

.muted-sm {
  color: var(--text-muted);
  font-size: 12px;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 10px;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  letter-spacing: -0.02em;
  user-select: none;
}

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}

.brand-name {
  font-size: 15px;
}

.brand-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--danger-bg);
  color: #fca5a5;
  letter-spacing: 0.05em;
}

.account-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  max-width: 260px;
  font-size: 13px;
}

.account-pill:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.account-pill span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.pill-meta {
  color: var(--accent);
  font-size: 11px;
  white-space: nowrap;
}

/* Segmented Engine Control */
.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--accent-bg);
  color: var(--accent);
}

/* Buttons & Inputs */
button, select, input, textarea {
  font: inherit;
  color: inherit;
}

.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background-color 0.12s, border-color 0.12s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

.btn-primary {
  background: var(--accent);
  color: #06131a;
}
.btn-primary:hover:not(:disabled) { background: #38e2fa; }

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.btn-danger {
  background: var(--danger-bg);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}
.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.28);
}

.icon-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.select-compact, .select-full, .input-full {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
}

.select-compact:focus, .select-full:focus, .input-full:focus {
  border-color: var(--accent);
}

.select-full, .input-full {
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
}

/* Workspace Layout */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar.collapsed {
  display: none;
}

.sidebar-controls {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
}

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

.search-box svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box input {
  border: none;
  background: transparent;
  padding: 7px 0;
  width: 100%;
  font-size: 13px;
  outline: none;
}

.search-clear {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0 2px;
}

.view-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.tab-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 5px 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent-bg);
  border-color: rgba(34, 211, 238, 0.35);
  color: var(--accent);
}

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

/* Channel List */
.channel-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px;
  contain: content;
}

.channel-list::-webkit-scrollbar {
  width: 7px;
}
.channel-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 4px;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  user-select: none;
}

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

.channel-item.active {
  background: var(--accent-bg);
  border-color: rgba(34, 211, 238, 0.35);
}

.ch-logo-wrap {
  width: 34px;
  height: 26px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.ch-logo-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.ch-monogram {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.ch-info {
  flex: 1;
  min-width: 0;
}

.ch-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-item.active .ch-name {
  color: var(--accent);
  font-weight: 600;
}

.ch-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ch-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.ch-act-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.45;
}

.channel-item:hover .ch-act-btn,
.ch-act-btn.fav-on {
  opacity: 1;
}

.ch-act-btn.fav-on {
  color: var(--warn);
}

.ch-act-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.sidebar-footer {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
}

/* Main Stage */
.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #05070a;
}

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

.video-el {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  background: #070a0f;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 4;
}

.empty-card {
  text-align: center;
  max-width: 480px;
}

.empty-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 800;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(34, 211, 238, 0.3);
}

.empty-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.empty-actions {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.shortcut-hints {
  margin-top: 22px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

kbd {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  color: var(--text);
}

/* Status Banner */
.status-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  background: rgba(15, 20, 30, 0.94);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 90%;
}

.status-banner-main {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
}

.status-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(34, 211, 238, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Diagnostics HUD */
.stats-hud {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 7;
  background: rgba(11, 14, 20, 0.88);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 175px;
  font-size: 12px;
  pointer-events: none;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 0;
}

.stats-row span {
  color: var(--text-muted);
}

.stats-sep {
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.sidebar-backdrop {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(0, 0, 0, 0.58);
  z-index: 24;
}

/* mpv Native Control Deck */
.mpv-deck {
  position: absolute;
  inset: 0;
  background: #080b11;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 5;
}

.mpv-card {
  width: 100%;
  max-width: 680px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.mpv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.mpv-header h2 {
  margin: 8px 0 2px;
  font-size: 20px;
}

.mpv-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge-accent {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: rgba(34, 211, 238, 0.35);
}

.badge-ok {
  background: var(--ok-bg);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.35);
}

.mpv-telemetry {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.tele-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tele-label {
  font-size: 11px;
  color: var(--text-muted);
}

.tele-box strong {
  font-size: 13px;
  color: var(--text);
}

.mpv-controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mpv-volume-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mpv-volume-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

/* Bottom Control Bar */
.control-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.now-playing {
  min-width: 0;
  flex: 1;
}

.np-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.np-title-row h3 {
  margin: 0;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
}

.epg-line {
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stream-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-sm { max-width: 380px; }
.modal-md { max-width: 540px; }
.modal-lg { max-width: 680px; }

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

.modal-header h2 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.accounts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.acct-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.acct-card.is-active {
  border-color: rgba(34, 211, 238, 0.45);
}

.acct-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.acct-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.form-tabs {
  display: flex;
  gap: 6px;
}

.form-tabs .tab-btn {
  padding: 6px 12px;
}

.account-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.field input, .field select, .field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  outline: none;
}

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.feedback {
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
}

.feedback.ok {
  background: var(--ok-bg);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.feedback.err, .alert-error {
  background: var(--danger-bg);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* Category Manager */
.cat-manager-list {
  max-height: 52vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cat-row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.cat-row-item.is-hidden {
  opacity: 0.55;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 60;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

@media (max-width: 900px) {
  .sidebar {
    width: 268px;
    min-width: 268px;
  }
  .mpv-telemetry {
    grid-template-columns: repeat(2, 1fr);
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .topbar {
    height: auto;
    min-height: var(--topbar-h);
    flex-wrap: wrap;
    padding: 6px 10px;
  }
  .account-pill {
    max-width: 170px;
  }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: min(84vw, 320px);
    min-width: 0;
    z-index: 25;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.65);
  }
  .control-bar {
    padding: 8px 10px;
  }
  .stream-controls {
    width: 100%;
    justify-content: flex-start;
  }
}
