:root {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #18233b;
  --line: #24314d;
  --ink: #e8edf6;
  --ink-2: #a9b4c8;
  --ink-3: #7a869c;
  --accent: #22c55e;
  --accent-ink: #04130a;
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; text-wrap: balance; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
[hidden] { display: none !important; }

/* Barra de topo */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  min-height: 52px; flex-shrink: 0;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; margin-right: auto; min-width: 0; }
.topbar .brand img { height: 28px; width: auto; }
.topbar .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.topbar nav a, .btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 6px; font: inherit; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.topbar nav a:hover, .btn:hover { background: #22304f; }
.topbar nav a[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn:focus-visible, .topbar nav a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: #16a34a; }
.btn.danger { border-color: #6b2a2a; color: #f3b4b4; }
.btn.danger:hover { background: #3a1a1e; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.topbar .who { color: var(--ink-3); font-size: 12px; margin: 0 6px; }

input[type=text], input[type=password], input[type=search], select {
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 10px; font: inherit; min-width: 0;
}

/* Indicadores de estado: sempre ponto + texto, nunca só cor */
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex-shrink: 0; }
.status.live::before { background: var(--good); box-shadow: 0 0 0 3px rgba(12, 163, 12, .2); }
.status.warn::before { background: var(--warning); }
.status.bad::before { background: var(--critical); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #475569; flex-shrink: 0; display: inline-block; }
.dot.live { background: var(--good); box-shadow: 0 0 0 3px rgba(12, 163, 12, .2); }

/* Páginas de reprodução */
.page { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.split { flex: 1; min-height: 0; display: flex; }
.side { width: 250px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side h2 { padding: 12px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); border-bottom: 1px solid var(--line); }
.side .list { flex: 1; overflow-y: auto; }
.stream-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 11px 14px; background: none; border: 0; border-bottom: 1px solid var(--line);
  color: var(--ink); font: inherit; cursor: pointer;
}
.stream-item:hover { background: var(--surface-2); }
.stream-item[aria-pressed="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.stream-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.stream-item .tag { font-size: 11px; color: var(--ink-3); }
.stage { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #000; position: relative; }
.stage video { flex: 1; min-height: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.stage .now { position: absolute; top: 10px; left: 10px; background: rgba(0, 0, 0, .65); padding: 4px 10px; border-radius: 6px; font-size: 13px; pointer-events: none; }
.notice { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; color: var(--ink-2); pointer-events: none; }
.empty { padding: 24px 14px; color: var(--ink-3); text-align: center; }

.thumb { position: relative; width: 100%; aspect-ratio: 16/9; background: #000; border-radius: 6px; overflow: hidden; cursor: pointer; border: 2px solid transparent; padding: 0; display: block; }
.thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb[aria-pressed="true"] { border-color: var(--accent); }
.thumb .label, .tile .label { position: absolute; left: 6px; bottom: 6px; background: rgba(0, 0, 0, .7); color: #fff; padding: 2px 7px; border-radius: 4px; font-size: 12px; display: flex; gap: 6px; align-items: center; }
.thumb .off { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--ink-3); font-size: 12px; }

.picker { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); max-height: 30vh; overflow: auto; flex-shrink: 0; }
.picker label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.picker .actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.grid { flex: 1; min-height: 0; display: grid; gap: 6px; padding: 6px; background: #000; }
.tile { position: relative; background: #05070c; border-radius: 6px; overflow: hidden; cursor: pointer; min-height: 0; min-width: 0; border: 2px solid transparent; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile.audio { border-color: var(--accent); }

@media (max-width: 720px) {
  .split { flex-direction: column; }
  .side { width: auto; max-height: 32vh; border-right: 0; border-bottom: 1px solid var(--line); }
}

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { width: 100%; max-width: 320px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login img { width: 96px; margin: 0 auto 4px; }
.login h1 { font-size: 16px; color: var(--ink-2); font-weight: 500; margin-bottom: 6px; }
.login label { text-align: left; font-size: 12px; color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; }
.login .error { color: #f3a0a0; font-size: 13px; min-height: 18px; }

/* Dashboard de administração */
.admin { max-width: 1400px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.banner { padding: 10px 14px; border-radius: var(--radius); background: #3a1a1e; border: 1px solid #6b2a2a; color: #f6c9c9; }
.headline { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; color: var(--ink-2); font-size: 13px; }
.headline strong { color: var(--ink); font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile-kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.tile-kpi .k { font-size: 12px; color: var(--ink-2); }
.tile-kpi .v { font-size: 26px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile-kpi .v small { font-size: 13px; font-weight: 400; color: var(--ink-2); margin-left: 3px; }
.tile-kpi .s { font-size: 12px; color: var(--ink-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--series-1); border-radius: 3px; width: 0; transition: width .4s; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.card > header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.card > header h2 { font-size: 14px; margin-right: auto; }
.card > header .sub { font-size: 12px; color: var(--ink-3); }
.card .body { padding: 14px; }
.card .scroll { overflow-x: auto; }
.card .tall { max-height: 420px; overflow-y: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--ink-3); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 220px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, .02); }
td .actions { display: flex; gap: 6px; }
.mono { font-family: var(--mono); font-size: 12px; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 170px; overflow: visible; }
.chart .legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.chart .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart .tip { position: absolute; top: 0; pointer-events: none; background: #060a14; border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; font-size: 12px; white-space: nowrap; z-index: 2; }
.chart .tip b { font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.chart text { fill: var(--ink-3); font-size: 11px; font-family: var(--font); }

.log { font-family: var(--mono); font-size: 12px; max-height: 360px; overflow: auto; padding: 8px 14px; }
.log div { padding: 2px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.log .lv { display: inline-block; min-width: 44px; color: var(--ink-3); }
.log .WARN .lv { color: var(--warning); }
.log .FAIL .lv, .log .ERROR .lv { color: #f08a8a; }
.log time { color: var(--ink-3); margin-right: 8px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; color: var(--ink-2); }
.toast { position: fixed; right: 16px; bottom: 16px; background: #060a14; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; z-index: 10; max-width: 360px; }
.toast.err { border-color: #6b2a2a; color: #f6c9c9; }
dialog { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(360px, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
