/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  --s0: #0d0d0f;
  --s1: #18181b;
  --s2: #232329;
  --s3: #2e2e36;
  --border: #3a3a44;
  --accent: #6366f1;
  --accent-dim: rgba(99,102,241,0.14);
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --t1: #f4f4f5;
  --t2: #a1a1aa;
  --t3: #52525b;
  --sidebar-w: 224px;
  --topbar-h: 56px;
  --radius: 10px;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--s0);
  color: var(--t1);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ── Material Symbols ──────────────────────────────────────── */
.icon {
  font-family: 'Material Symbols Rounded';
  font-weight: normal;
  font-style: normal;
  font-size: 20px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
  vertical-align: middle;
  user-select: none;
}

/* ── App Shell (Admin) ─────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

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

.sidebar-logo {
  height: var(--topbar-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo-mark {
  width: 30px;
  height: 30px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.logo-mark .icon { font-size: 18px; }

.sidebar-logo span {
  font-size: 15px;
  font-weight: 700;
  color: var(--t1);
  letter-spacing: -0.01em;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--t2);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background 0.12s, color 0.12s;
  font-family: inherit;
  text-decoration: none;
}

.nav-item:hover { background: var(--s3); color: var(--t1); }

.nav-item.active {
  background: var(--accent-dim);
  color: #818cf8;
  box-shadow: inset 2px 0 0 var(--accent);
  padding-left: 8px;
}

.nav-item .icon { font-size: 20px; flex-shrink: 0; }

.sidebar-footer {
  padding: 10px 8px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  padding: 6px 10px 10px;
  font-size: 12px;
  color: var(--t3);
}

/* ── Content Area ──────────────────────────────────────────── */
.content-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  background: var(--s1);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--t3);
  background: var(--s2);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  transition: color 0.2s;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--t3);
  transition: background 0.2s;
}

.status-pill.online { color: var(--t1); }
.status-pill.online .status-dot {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

/* ── Pages / Tabs ──────────────────────────────────────────── */
.page {
  padding: 24px;
  display: none;
  flex: 1;
}
.page.active { display: block; }

/* ── Stat Cards ────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.stat-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon .icon { font-size: 18px; }

.si-indigo { background: rgba(99,102,241,0.12); color: #818cf8; }
.si-green  { background: rgba(34,197,94,0.12);  color: #4ade80; }
.si-amber  { background: rgba(245,158,11,0.12); color: #fbbf24; }
.si-cyan   { background: rgba(6,182,212,0.12);  color: #22d3ee; }
.si-rose   { background: rgba(244,63,94,0.12);  color: #fb7185; }
.si-violet { background: rgba(167,139,250,0.12);color: #a78bfa; }

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--t1);
  line-height: 1;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 12px;
  color: var(--t2);
  font-weight: 500;
}

/* ── Section ───────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--t1);
}

/* ── Panel ─────────────────────────────────────────────────── */
.panel {
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}

.panel-body { padding: 20px; }

/* ── Tables ────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 9px 14px;
  color: var(--t3);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  background: var(--s2);
  white-space: nowrap;
}

.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--t1);
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--s2); }

.cell-mono {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 12px;
  color: var(--t2);
}

.cell-truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--t2);
  font-size: 12px;
}

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green  { background: rgba(34,197,94,0.12);  color: #4ade80; }
.badge-gray   { background: var(--s3);              color: var(--t2); border: 1px solid var(--border); }
.badge-indigo { background: rgba(99,102,241,0.12);  color: #818cf8; }
.badge-amber  { background: rgba(245,158,11,0.12);  color: #fbbf24; }

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  display: inline-block;
}

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--t2);
  margin-bottom: 5px;
}

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

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  appearance: auto;
  -webkit-appearance: auto;
  accent-color: var(--accent);
  cursor: pointer;
  padding: 0;
  border: none;
  background: none;
}

input:not([type="checkbox"]), textarea, select {
  width: 100%;
  padding: 9px 12px;
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--t1);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

input:not([type="checkbox"]):focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

input::placeholder, textarea::placeholder { color: var(--t3); }
select option { background: var(--s2); color: var(--t1); }
textarea { resize: vertical; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  line-height: 1;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:not(:disabled):hover { opacity: 0.88; }
.btn:not(:disabled):active { opacity: 0.72; transform: translateY(1px); }

.btn .icon { font-size: 18px; }

.btn-primary   { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--s3); color: var(--t1); border: 1px solid var(--border); }
.btn-danger    { background: rgba(239,68,68,0.12); color: #f87171; border: 1px solid rgba(239,68,68,0.2); }
.btn-ghost     { background: transparent; color: var(--t2); border: 1px solid var(--border); }
.btn-ghost:not(:disabled):hover { color: var(--t1); background: var(--s2); opacity: 1; }
.btn-icon-only { padding: 7px; background: var(--s3); color: var(--t2); border: 1px solid var(--border); }
.btn-icon-only:not(:disabled):hover { color: var(--t1); opacity: 1; }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-sm .icon { font-size: 15px; }
.btn-full { width: 100%; }

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Auth Overlay ──────────────────────────────────────────── */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--s0);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.auth-card {
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.auth-logo h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.22);
  color: #f87171;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  margin-top: 12px;
  display: none;
}

.auth-error.visible { display: block; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 150;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 500px;
  animation: modal-in 0.18s ease;
  max-height: 90vh;
  overflow-y: auto;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(-6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title { font-size: 15px; font-weight: 600; }

/* ── Toasts ────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  color: var(--t1);
  min-width: 220px;
  max-width: 340px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: toast-in 0.18s ease;
}

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

.toast-icon .icon { font-size: 18px; }
.toast.success .toast-icon { color: var(--success); }
.toast.error   .toast-icon { color: var(--danger); }
.toast.info    .toast-icon { color: #818cf8; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(6px); }
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--t3); }

/* ── Player Shell ──────────────────────────────────────────── */
.player-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--s0);
}

.player-topbar {
  height: var(--topbar-h);
  background: var(--s1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}

.player-topbar .logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.player-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  gap: 16px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

/* Video */
.video-wrapper {
  width: 100%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border);
}

.video-wrapper video {
  width: 100%;
  height: 100%;
  display: block;
}

.video-idle {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--t3);
  background: var(--s1);
}

.video-idle .icon { font-size: 48px; }
.video-idle span { font-size: 13px; }

/* Source Panel */
.source-panel {
  width: 100%;
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.source-top {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.source-top select { flex: 1; }

.source-meta {
  font-size: 12px;
  color: var(--t2);
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 18px;
  margin-bottom: 14px;
}

.source-meta .meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.source-meta .icon { font-size: 14px; }

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

/* Log */
.log-section { width: 100%; }

.log-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--t3);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 2px 0;
  font-family: inherit;
  transition: color 0.12s;
}

.log-toggle:hover { color: var(--t2); }
.log-toggle .icon { font-size: 16px; transition: transform 0.15s; }
.log-toggle.open .icon { transform: rotate(90deg); }

.log-body {
  display: none;
  margin-top: 8px;
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
  font-size: 11.5px;
  color: var(--t2);
  height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
}

.log-body.open { display: block; }

.log-line-error { color: #f87171; }
.log-line-event { color: #818cf8; }

/* Landing page */
.landing-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 32px;
}

.landing-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.landing-logo .logo-mark {
  width: 56px;
  height: 56px;
  border-radius: 14px;
}

.landing-logo .logo-mark .icon { font-size: 30px; }

.landing-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--t1);
}

.landing-subtitle {
  font-size: 14px;
  color: var(--t2);
  margin-top: -8px;
}

.landing-links {
  display: flex;
  gap: 12px;
}

.landing-card {
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  min-width: 140px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-decoration: none;
  color: var(--t1);
}

.landing-card:hover {
  border-color: var(--accent);
  background: var(--s2);
}

.landing-card .icon { font-size: 28px; color: #818cf8; }
.landing-card-label { font-size: 14px; font-weight: 600; }
.landing-card-sub { font-size: 12px; color: var(--t2); }

.landing-api {
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  font-family: monospace;
  font-size: 12px;
  color: var(--t2);
  max-width: 420px;
  width: 100%;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .page { padding: 16px; }
  .topbar { padding: 0 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .player-main { padding: 12px; }
  .player-topbar { padding: 0 16px; }
  .landing-links { flex-direction: column; align-items: center; }
}
