:root {
  --bg: #0b0f17;
  --surface: #141a26;
  --surface-2: #1c2434;
  --border: #273247;
  --text: #eef2ff;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.stack { display: flex; flex-direction: column; gap: 0.9rem; }

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 100;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.7rem 1rem;
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
}

.brand-row { display: flex; align-items: center; gap: 0.65rem; }
.brand-row h1 { margin: 0; font-size: 1.35rem; }
.brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  display: inline-block;
}

.field { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; }
.field input, textarea, .search-input, .inline-form input {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
.field input:focus, textarea:focus, .search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.alert-warn {
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid var(--warn);
  color: #fde68a;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  margin-bottom: 0.9rem;
  font-size: 0.88rem;
}
.error-text { color: #fca5a5; font-size: 0.88rem; margin: 0; }

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.58rem 0.95rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
}
.btn-primary { background: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: rgba(239, 68, 68, 0.18); border-color: var(--danger); color: #fecaca; }
.btn-sm { padding: 0.38rem 0.7rem; font-size: 0.82rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

.app-shell { max-width: 1220px; margin: 0 auto; padding: 1rem; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.topbar-left, .topbar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }

.pill {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.pill-muted { background: var(--surface-2); color: var(--muted); }
.pill-ok { background: rgba(34, 197, 94, 0.15); border-color: var(--ok); color: #86efac; }
.pill-warn { background: rgba(245, 158, 11, 0.15); border-color: var(--warn); color: #fde68a; }

.tab-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0; }
.tab {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.52rem 0.95rem;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 600;
}
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.card, .player-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.player-card { margin-bottom: 1rem; }
.player-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.player-header h2 { margin: 0; font-size: 1.15rem; }
.player-controls { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.seg-btn {
  background: var(--bg);
  color: var(--muted);
  border: none;
  padding: 0.38rem 0.68rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}
.seg-btn.active { background: var(--accent); color: #fff; }

.video-wrap {
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}
.video-wrap video { width: 100%; height: 100%; display: block; }

.toolbar { display: flex; flex-direction: column; gap: 0.7rem; margin-bottom: 1rem; }
.group-pills { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.group-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.84rem;
}
.group-pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.85rem;
}
.channel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
}
.channel-card.playing { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.ch-top { display: flex; align-items: center; gap: 0.7rem; }
.ch-logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--bg);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.ch-fallback {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}
.ch-name { font-weight: 700; font-size: 0.98rem; word-break: break-word; }

.panel-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.85rem;
}
.panel-header h2, .panel-header h3 { margin: 0; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
.checkbox { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; cursor: pointer; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1rem; }
.inline-form input { flex: 1; min-width: 220px; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td {
  text-align: left;
  padding: 0.65rem 0.55rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }
