/* multistream: sistema visual compartilhado (painel, convidado e login do admin). */

:root {
  color-scheme: light dark;
  --bg: #f4f5fb;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #6d5efc22, transparent 60%),
             radial-gradient(900px 500px at 110% 0%, #22d3ee1f, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f1f3fa;
  --fg: #14162b;
  --muted: #5d6280;
  --line: #14162b14;
  --accent: #5b4cf0;
  --accent-fg: #ffffff;
  --accent-soft: #5b4cf01a;
  --cyan: #0ea5c6;
  --ok: #0f9d58;
  --ok-soft: #0f9d5820;
  --danger: #d6336c;
  --danger-soft: #d6336c1a;
  --warn: #b45309;
  --warn-soft: #f59e0b22;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px #0000000d, 0 8px 24px -12px #14162b26;
  --focus: 0 0 0 3px #5b4cf055;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0e18;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, #6d5efc26, transparent 60%),
               radial-gradient(900px 500px at 110% 0%, #22d3ee18, transparent 55%);
    --surface: #161829;
    --surface-2: #1d2034;
    --fg: #eef0ff;
    --muted: #9aa0c3;
    --line: #ffffff14;
    --accent: #8b7dff;
    --accent-fg: #0c0e18;
    --accent-soft: #8b7dff22;
    --cyan: #5fd6ef;
    --ok: #4ade80;
    --ok-soft: #4ade8022;
    --danger: #ff6b8b;
    --danger-soft: #ff6b8b22;
    --warn: #fbbf24;
    --warn-soft: #fbbf2422;
    --shadow: 0 1px 2px #00000040, 0 12px 32px -14px #000000aa;
    --focus: 0 0 0 3px #8b7dff66;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0e18;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #6d5efc26, transparent 60%),
             radial-gradient(900px 500px at 110% 0%, #22d3ee18, transparent 55%);
  --surface: #161829;
  --surface-2: #1d2034;
  --fg: #eef0ff;
  --muted: #9aa0c3;
  --line: #ffffff14;
  --accent: #8b7dff;
  --accent-fg: #0c0e18;
  --accent-soft: #8b7dff22;
  --cyan: #5fd6ef;
  --ok: #4ade80;
  --ok-soft: #4ade8022;
  --danger: #ff6b8b;
  --danger-soft: #ff6b8b22;
  --warn: #fbbf24;
  --warn-soft: #fbbf2422;
  --shadow: 0 1px 2px #00000040, 0 12px 32px -14px #000000aa;
  --focus: 0 0 0 3px #8b7dff66;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-grad), var(--bg);
  background-color: var(--bg);
  color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.35rem, 2.4vw, 1.75rem); }
h2 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0; }
code { font-size: .85em; overflow-wrap: anywhere; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: .92rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }

/* Cabeçalho */
.topbar {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; color: var(--fg); text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  display: grid; place-items: center; color: var(--accent-fg); font-size: .9rem; font-weight: 800;
}
.topbar nav { display: flex; gap: 6px; flex-wrap: wrap; }
.topbar nav a {
  color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: .92rem; font-weight: 550;
}
.topbar nav a:hover { color: var(--fg); background: var(--surface-2); }

/* Layout */
.page { max-width: 1080px; margin: 0 auto; padding: 24px 20px 56px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .muted { margin-top: 4px; }
.grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid.two { grid-template-columns: 1.1fr .9fr; align-items: start; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }

/* Pílulas de estado */
.pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px;
  font-size: .82rem; font-weight: 650; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.live { background: var(--ok-soft); color: var(--ok); }
.pill.live::before { box-shadow: 0 0 0 0 var(--ok); animation: ping 1.8s ease-out infinite; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--danger-soft); color: var(--danger); }
@keyframes ping { 0% { box-shadow: 0 0 0 0 #0f9d5866; } 100% { box-shadow: 0 0 0 9px #0f9d5800; } }
@media (prefers-reduced-motion: reduce) { .pill.live::before { animation: none; } }

/* Botões e campos */
.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 650; font-size: .95rem;
  padding: 11px 18px; min-height: 44px; border-radius: 12px;
  background: var(--accent); color: var(--accent-fg);
  transition: transform .08s ease, filter .15s ease, opacity .15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; filter: none; transform: none; }
.btn.secondary { background: var(--surface-2); color: var(--fg); box-shadow: inset 0 0 0 1px var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: var(--accent); padding-left: 10px; padding-right: 10px; }
.btn.sm { min-height: 36px; padding: 7px 12px; font-size: .86rem; border-radius: 10px; }
.btn.is-busy::after {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.field { position: relative; display: flex; flex: 1 1 280px; min-width: 0; }
.input {
  width: 100%; min-width: 0; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--fg); font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }
.field .toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; color: var(--accent); border: 0; font: inherit; font-size: .85rem; font-weight: 650;
  padding: 6px 8px; cursor: pointer; border-radius: 8px;
}
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: stretch; }
.help { margin-top: 10px; font-size: .86rem; color: var(--muted); }

/* Mensagens e avisos */
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 12px; font-size: .94rem; margin-top: 14px;
  background: var(--surface-2); color: var(--fg);
}
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.success { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: grid; gap: 8px; width: min(360px, calc(100vw - 32px)); }
.toast {
  background: var(--surface); color: var(--fg); border: 1px solid var(--line); box-shadow: var(--shadow);
  border-left: 4px solid var(--accent); border-radius: 12px; padding: 12px 14px; font-size: .93rem;
  animation: rise .2s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Tabelas (viram cartões no celular) */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 650; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; }
tbody tr:hover { background: var(--surface-2); }
td.err { color: var(--danger); max-width: 280px; overflow-wrap: anywhere; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: .84rem; font-weight: 600; color: var(--muted); }
.chip.on { color: var(--ok); }
.chip.off { color: var(--muted); }
.chip.screen { color: var(--cyan); }
.acoes { white-space: nowrap; }
.acoes .btn + .btn { margin-left: 6px; }
.empty { text-align: center; padding: 26px 8px; color: var(--muted); }

@media (max-width: 720px) {
  .page { padding: 16px 14px 48px; }
  .card { padding: 16px; }
  .topbar-inner { padding: 10px 14px; }
  .row .btn { width: 100%; }
  .field { flex-basis: 100%; }
  .field .toggle { position: static; transform: none; margin-top: 6px; display: block; margin-left: auto; }
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; background: var(--surface); }
  table.responsive td { border: 0; padding: 6px 0; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
  table.responsive td.acoes { display: block; }
  table.responsive td.acoes::before { display: block; margin-bottom: 6px; }
  table.responsive td.acoes .btn { width: 100%; margin: 4px 0 0; }
  table.responsive td.acoes .btn + .btn { margin-left: 0; }
  table.responsive td.err { display: block; }
}

/* Tela de login (admin) */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(420px, 100%); }
.login-card .brand { margin-bottom: 18px; }
.login-card h1 { margin-bottom: 6px; }
.login-form { display: grid; gap: 14px; margin-top: 18px; }
.login-form label { display: grid; gap: 6px; font-size: .9rem; font-weight: 600; color: var(--muted); }
.login-form .btn { width: 100%; margin-top: 4px; }
.login-foot { margin-top: 18px; text-align: center; font-size: .86rem; }

/* Grade de vídeos (convidado) */
.stage { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); margin-top: 16px; }
.stage:empty { display: none; }
.tile { position: relative; background: #05060c; border-radius: 14px; overflow: hidden; aspect-ratio: 16 / 9; box-shadow: var(--shadow); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .nome {
  position: absolute; left: 10px; bottom: 10px; max-width: calc(100% - 20px);
  background: #000a; color: #fff; padding: 3px 9px; border-radius: 8px; font-size: .8rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile.screen { outline: 2px solid var(--cyan); }

.control-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.control-bar .btn { flex: 1 1 150px; }
.control-bar[hidden] { display: none; }
[hidden] { display: none !important; }

/* Admin do Django (ajustes leves para combinar com o painel) */
:root {
  --header-bg: #14162b;
  --primary: #5b4cf0;
  --link-fg: #5b4cf0;
}
#header { background: #14162b; }
.module h2, .module caption { border-radius: 10px 10px 0 0; }
