/* Admin panel theme: the same night-time control room as the public site,
   laid out as an app (sidebar + content). CSP allows only same-origin styles. */
:root {
  --bg: #070b14;
  --panel: rgba(17, 25, 42, .72);
  --panel-solid: #111a2b;
  --panel-hi: #172238;
  --text: #e7ecf5;
  --muted: #8d9ab0;
  --line: rgba(148, 163, 184, .14);
  --line-hi: rgba(148, 163, 184, .28);
  --brand: #f5b324;
  --brand-2: #ff7a3d;
  --brand-ink: #111827;
  --accent: #38bdf8;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, .7);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sidebar: 248px;
  color-scheme: dark;
  accent-color: var(--brand);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; color: var(--text); font-size: 15px; line-height: 1.5; min-height: 100vh;
  background-color: var(--bg);
  background-image:
    radial-gradient(1000px 520px at 90% -10%, rgba(245, 179, 36, .08), transparent 60%),
    radial-gradient(800px 480px at 10% 110%, rgba(56, 189, 248, .07), transparent 60%),
    linear-gradient(rgba(148, 163, 184, .03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, .03) 1px, transparent 1px);
  background-size: auto, auto, 48px 48px, 48px 48px;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(245, 179, 36, .35); }
a { color: var(--brand); text-underline-offset: 3px; }
a:hover { color: #ffd166; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
code, .mono { font-family: var(--mono); font-size: .86em; }
code { color: #fde68a; background: rgba(245, 179, 36, .08); border: 1px solid rgba(245, 179, 36, .15); padding: .05rem .35rem; border-radius: 6px; word-break: break-all; }
h1, h2, h3 { letter-spacing: -.015em; }
h1 { font-size: 1.65rem; line-height: 1.2; margin: .2rem 0 1.1rem; font-weight: 800; }
h2 { font-size: 1.05rem; margin: 2rem 0 .75rem; font-weight: 700; display: flex; align-items: center; gap: .55rem; }
h2::before { content: ""; width: 14px; height: 2px; border-radius: 2px; background: var(--brand); flex: none; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.nowrap { white-space: nowrap; }
.warn { color: #fcd34d; }
p.warn { padding: .65rem .9rem; border-radius: var(--radius); background: rgba(245, 158, 11, .1); border: 1px solid rgba(245, 158, 11, .3); }

/* ------------------------------------------------------------ app shell */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.topbar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1.25rem; padding: 1.25rem 1rem;
  background: rgba(7, 11, 20, .78); border-right: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: .65rem; padding: .25rem .5rem; color: var(--text); text-decoration: none; font-weight: 800; letter-spacing: -.01em; }
.brand:hover { color: #fff; }
.brand small { display: block; font-weight: 600; font-size: .68rem; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; }
.brand-mark {
  position: relative; width: 32px; height: 32px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 6px 18px -6px rgba(245, 179, 36, .7);
}
.brand-mark::before { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #4b5563, #0b1220 70%); box-shadow: 0 0 0 2px rgba(11, 18, 32, .85); }
.brand-mark::after { content: ""; position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); border: 2px solid var(--bg); animation: blink 1.6s ease-in-out infinite; }
.topbar nav { display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.nav-label { margin: .75rem .75rem .35rem; font-size: .68rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: #5f6b80; }
.topbar nav a {
  position: relative; display: flex; align-items: center; gap: .7rem; padding: .6rem .75rem; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-weight: 600; transition: color .2s, background .2s;
}
.topbar nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.topbar nav a:hover { color: var(--text); background: rgba(148, 163, 184, .08); }
.topbar nav a.active { color: var(--text); background: linear-gradient(90deg, rgba(245, 179, 36, .16), rgba(245, 179, 36, .03)); }
.topbar nav a.active svg { color: var(--brand); opacity: 1; }
.topbar nav a.active::before { content: ""; position: absolute; left: -1rem; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); box-shadow: 0 0 12px rgba(245, 179, 36, .8); }
.logout { display: flex; align-items: center; gap: .65rem; padding: .7rem; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 800; color: var(--brand-ink); background: linear-gradient(135deg, #7dd3fc, var(--accent)); }
.logout .who { flex: 1; min-width: 0; font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout button.link { color: var(--muted); text-decoration: none; font-size: .82rem; font-weight: 600; }
.logout button.link:hover { color: var(--danger); }
main { width: 100%; max-width: 1240px; padding: 1.75rem 2rem 4rem; animation: rise .35s both; }
@media (max-width: 1024px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .topbar { position: sticky; height: auto; z-index: 50; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .7rem 1rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar nav { order: 3; flex: 1 1 100%; flex-direction: row; overflow-x: auto; gap: .25rem; scrollbar-width: none; }
  .topbar nav a { flex: none; padding: .45rem .7rem; }
  .topbar nav a.active::before { display: none; }
  .nav-label { display: none; }
  .logout { margin-left: auto; padding: .35rem .5rem; }
  .avatar { width: 28px; height: 28px; font-size: .8rem; }
  .logout .who { max-width: 9rem; }
  main { padding: 1.25rem 1rem 3rem; }
}

/* ------------------------------------------------------------ page head */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .5rem; }
.page-head h1 { margin-bottom: .5rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.eyebrow { margin: 0 0 .25rem; font-size: .72rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }

/* --------------------------------------------------------------- buttons */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; font-size: .9rem;
  padding: .55rem 1rem; border: 1px solid var(--line-hi); background: rgba(148, 163, 184, .08); color: var(--text);
  border-radius: 10px; cursor: pointer; text-decoration: none; transition: background .2s, border-color .2s, transform .15s, box-shadow .2s, filter .2s;
}
button:hover, .button:hover { color: var(--text); background: rgba(148, 163, 184, .15); border-color: rgba(148, 163, 184, .45); }
button:active, .button:active { transform: translateY(1px); }
button.primary, .button.primary { color: var(--brand-ink); border-color: transparent; background: linear-gradient(135deg, var(--brand), #ffcf5c); box-shadow: 0 6px 18px -8px rgba(245, 179, 36, .9); }
button.primary:hover, .button.primary:hover { color: var(--brand-ink); filter: brightness(1.06); box-shadow: 0 10px 24px -8px rgba(245, 179, 36, .9); }
button.danger { color: #fff; border-color: transparent; background: linear-gradient(135deg, #dc2626, #f43f5e); box-shadow: 0 6px 18px -8px rgba(239, 68, 68, .9); }
button.danger:hover { filter: brightness(1.08); background: linear-gradient(135deg, #dc2626, #f43f5e); }
button.link { background: none; border: 0; padding: 0; color: var(--brand); text-decoration: underline; box-shadow: none; }
button.link:hover { background: none; }
button.link.danger { color: #fca5a5; background: none; box-shadow: none; text-decoration: none; font-weight: 600; }
button.link.danger:hover { color: var(--danger); filter: none; }
button:disabled { opacity: .6; cursor: wait; }

/* ----------------------------------------------------------------- forms */
input, select, textarea {
  font: inherit; color: var(--text); padding: .6rem .75rem; border: 1px solid var(--line-hi); border-radius: 10px;
  background: rgba(7, 11, 20, .55); width: 100%; transition: border-color .2s, box-shadow .2s;
}
input::placeholder, textarea::placeholder { color: #5f6b80; }
input:hover, select:hover, textarea:hover { border-color: rgba(148, 163, 184, .45); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(245, 179, 36, .2); }
select option { background: var(--panel-solid); color: var(--text); }
input[type=checkbox], input[type=radio] { width: 1.05rem; height: 1.05rem; padding: 0; margin: 0; flex: none; cursor: pointer; }
input[type=file] { padding: .5rem; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; margin-right: .75rem; padding: .4rem .8rem; border-radius: 8px; border: 1px solid var(--line-hi); background: var(--panel-hi); color: var(--text); cursor: pointer; }
input.readonly, input[readonly] { background: rgba(148, 163, 184, .06); color: var(--muted); border-style: dashed; }
select:disabled, input:disabled { opacity: .55; }
label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; font-size: .9rem; }
label.inline { display: inline-flex; flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; cursor: pointer; }
label small, .small { font-weight: 400; }
label small { color: var(--muted); }
.error { color: #fca5a5; font-size: .85em; font-weight: 500; }
.check { display: flex; align-items: center; gap: .5rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; max-width: 36rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.25rem 1.4rem; margin: 1.25rem 0; box-shadow: var(--shadow); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.panel > h2:first-child { margin-top: 0; }
.panel.danger { border-color: rgba(239, 68, 68, .35); background: linear-gradient(180deg, rgba(127, 29, 29, .18), var(--panel)); }
.panel.danger h2::before { background: var(--danger); }
.grid-form fieldset {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.25rem 1.4rem 1.4rem; margin: 0 0 1.1rem;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem 1.25rem; box-shadow: var(--shadow);
}
.grid-form legend { font-weight: 800; padding: .3rem .8rem; border-radius: 999px; background: var(--panel-hi); border: 1px solid var(--line-hi); font-size: .85rem; }
.grid-form .span2 { grid-column: 1 / -1; }
fieldset.inline-set { border: 0; padding: 0; margin: 0; display: flex; gap: 1.25rem; }
.radio-group { display: flex; flex-wrap: wrap; gap: .75rem; }
.radio-group label.inline { padding: .65rem .9rem; border: 1px solid var(--line-hi); border-radius: 10px; background: rgba(7, 11, 20, .4); transition: border-color .2s, background .2s; }
.radio-group label.inline:has(input:checked) { border-color: rgba(245, 179, 36, .6); background: rgba(245, 179, 36, .08); }
.form-actions { display: flex; gap: 1rem; align-items: center; }
.form-actions a { color: var(--muted); font-weight: 600; text-decoration: none; }
.form-actions a:hover { color: var(--text); }

/* ---------------------------------------------------------------- flash */
.flash { display: flex; align-items: center; gap: .6rem; padding: .8rem 1rem; border-radius: var(--radius); margin-bottom: 1.25rem; border: 1px solid; font-weight: 500; animation: rise .3s both; }
.flash::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex: none; background: currentColor; box-shadow: 0 0 10px currentColor; }
.flash-success { background: rgba(34, 197, 94, .1); border-color: rgba(34, 197, 94, .35); color: #86efac; }
.flash-error { background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .35); color: #fca5a5; }

/* ---------------------------------------------------------------- tables */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0 1rem; padding: .55rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.filters input[type=search] { flex: 2 1 220px; width: auto; }
.filters select { flex: 1 1 160px; width: auto; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .7rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { white-space: nowrap; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); background: rgba(11, 18, 32, .95); }
tbody tr { transition: background .15s; }
tbody tr:hover { background: rgba(148, 163, 184, .05); }
tr:last-child td { border-bottom: 0; }
td a { text-decoration: none; }
td a strong { color: var(--text); }
td a:hover strong { color: var(--brand); }
td code { display: inline-block; margin-top: .25rem; font-size: .78em; white-space: nowrap; word-break: normal; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions a, .row-actions form { margin-left: .5rem; }
.row-actions > a { display: inline-block; padding: .3rem .65rem; border-radius: 8px; border: 1px solid var(--line-hi); color: var(--text); font-size: .85rem; font-weight: 600; }
.row-actions > a:hover { border-color: var(--brand); color: var(--brand); }
form.inline { display: inline; }
.toggle { gap: .45rem; font-size: .78rem; font-weight: 700; padding: .3rem .7rem; border-radius: 999px; color: var(--muted); background: rgba(148, 163, 184, .06); }
.toggle::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #64748b; }
.toggle.on { color: #86efac; border-color: rgba(34, 197, 94, .45); background: rgba(34, 197, 94, .1); }
.toggle.on::before { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.toggle.on:hover { background: rgba(34, 197, 94, .18); border-color: rgba(34, 197, 94, .6); }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .45rem; background: #64748b; vertical-align: .02em; }
.dot.online { background: var(--ok); box-shadow: 0 0 0 0 rgba(34, 197, 94, .7); animation: pulse-green 1.8s infinite; }
.dot.starting { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.dot.reconnecting { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: blink 1s infinite; }
.dot.offline { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.dot.idle { background: #64748b; } .dot.disabled { background: #334155; } .dot.unknown { background: #94a3b8; }
.badge { display: inline-flex; align-items: center; gap: .35rem; font-size: .75rem; font-weight: 700; padding: .2rem .6rem; border-radius: 999px; border: 1px solid var(--line-hi); }
.badge.on { color: #86efac; border-color: rgba(34, 197, 94, .4); background: rgba(34, 197, 94, .08); }
.badge.off { color: var(--muted); }
.badge.warn { color: #fcd34d; border-color: rgba(245, 158, 11, .45); background: rgba(245, 158, 11, .08); }
.pager { display: flex; gap: .75rem; justify-content: center; align-items: center; margin: 1.5rem 0; }
.pager a, .pager span { padding: .45rem 1rem; border-radius: 999px; font-weight: 600; font-size: .88rem; text-decoration: none; }
.pager a { color: var(--text); border: 1px solid var(--line-hi); background: var(--panel); }
.pager a:hover { border-color: var(--brand); background: rgba(245, 179, 36, .1); }
.pager span { color: var(--muted); }

/* ------------------------------------------------------------- dashboard */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(140px, 45%), 1fr)); gap: .85rem; }
.tile {
  position: relative; overflow: hidden; display: flex; flex-direction: column; gap: .15rem; padding: 1rem 1.15rem 1.1rem; text-decoration: none; color: inherit;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  transition: transform .2s, border-color .2s; animation: rise .4s both;
}
.tile::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: linear-gradient(90deg, var(--tile, var(--brand)), transparent); }
.tile::after { content: ""; position: absolute; right: -40px; top: -40px; width: 120px; height: 120px; border-radius: 50%; background: radial-gradient(circle, var(--tile, var(--brand)), transparent 70%); opacity: .12; }
a.tile:hover { transform: translateY(-3px); border-color: var(--line-hi); color: inherit; }
.tile .num { font-size: 2.1rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tile .lbl { color: var(--muted); font-size: .85rem; font-weight: 600; text-transform: capitalize; }
.tiles .tile:nth-child(2) { animation-delay: .04s; } .tiles .tile:nth-child(3) { animation-delay: .08s; }
.tiles .tile:nth-child(4) { animation-delay: .12s; } .tiles .tile:nth-child(n+5) { animation-delay: .16s; }
.tile.kpi-total { --tile: var(--brand); } .tile.kpi-published { --tile: var(--accent); } .tile.kpi-enabled { --tile: #a78bfa; }
.tile.state-online { --tile: var(--ok); } .tile.state-starting { --tile: var(--accent); } .tile.state-reconnecting { --tile: var(--warn); }
.tile.state-offline { --tile: var(--danger); } .tile.state-idle { --tile: #64748b; } .tile.state-disabled { --tile: #334155; } .tile.state-unknown { --tile: #94a3b8; }
.generated { margin-top: 2rem; }

/* ------------------------------------------------------- probe & preview */
.probe { margin-top: 1rem; padding: 1rem 1.15rem; border-radius: var(--radius); border: 1px solid; animation: rise .3s both; }
.probe.ok { background: rgba(34, 197, 94, .07); border-color: rgba(34, 197, 94, .35); }
.probe.ok > strong { color: #86efac; }
.probe.fail { background: rgba(239, 68, 68, .08); border-color: rgba(239, 68, 68, .35); color: #fca5a5; }
.probe dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; margin: .75rem 0 .25rem; }
.probe dt { color: var(--muted); font-size: .85rem; }
.probe dd { margin: 0; font-variant-numeric: tabular-nums; }
.player-box { max-width: 980px; }
.player-box video {
  width: 100%; aspect-ratio: 16 / 9; display: block; background: #000; border-radius: var(--radius-lg);
  border: 8px solid rgba(148, 163, 184, .08); box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .9), 0 0 80px -40px rgba(56, 189, 248, .45);
}
#preview-status { display: inline-flex; align-items: center; gap: .5rem; margin-top: .75rem; }
#preview-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: blink 1.2s steps(2, start) infinite; }
pre.changes { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: .76rem; color: #cbd5e1; max-width: 36rem; max-height: 14rem; overflow: auto; padding: .5rem .65rem; border-radius: 8px; background: rgba(7, 11, 20, .6); border: 1px solid var(--line); }
ul.errors { color: #fca5a5; }

/* ----------------------------------------------------------------- login */
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 1rem; }
.login {
  position: relative; width: 100%; max-width: 25rem; padding: 2rem 1.75rem 1.75rem; animation: rise .45s both;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 40px 80px -30px rgba(0, 0, 0, .9), 0 0 100px -50px rgba(245, 179, 36, .5);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.login::before { content: ""; position: absolute; left: 1.5rem; right: 1.5rem; top: -1px; height: 1px; background: linear-gradient(90deg, transparent, var(--brand), var(--accent), transparent); }
.login .brand { padding: 0; margin-bottom: 1.5rem; }
.login h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
.login .lead { margin: 0 0 1.5rem; color: var(--muted); font-size: .92rem; }
.login .stack button { margin-top: .35rem; padding: .7rem; }
.login-foot { margin: 1.5rem 0 0; text-align: center; font-size: .78rem; color: #5f6b80; }

/* ------------------------------------------------------------ animations */
@keyframes blink { 50% { opacity: .3; } }
@keyframes pulse-green { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .7); } 70% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
@media (max-width: 640px) {
  th:nth-child(3), td:nth-child(3) { display: none; }
}
