:root {
  --bg: #0e0a12;
  --panel: #17111d;
  --panel2: #201828;
  --line: #2e2338;
  --text: #f4ede7;
  --muted: #a797aa;
  --orange: #ff8a1f;
  --purple: #b07cff;
  --green: #3fd9a0;
  --red: #ff5d6c;
  --yellow: #ffcc4d;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 0% -10%, #2a1630 0%, transparent 60%),
    radial-gradient(900px 480px at 100% -5%, #2c1a0b 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h2 { font-size: 1.05rem; margin: 0 0 .6rem; letter-spacing: .01em; }
h3 { font-size: .95rem; margin: 1.3rem 0 .5rem; color: var(--orange); }
code { background: var(--panel2); padding: 0 .3em; border-radius: 4px; }
.muted { color: var(--muted); }
.tiny { font-size: .78rem; }
.empty { color: var(--muted); text-align: center; padding: 1.4rem .5rem; margin: 0; }
.dim { opacity: .45; }

/* ---- header ---- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem;
  padding: .7rem 1.2rem;
  background: rgba(14, 10, 18, .86); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.15rem; white-space: nowrap; }
.grand { display: flex; align-items: baseline; gap: .5rem; justify-content: center; }
.grand b { font-size: 2.6rem; line-height: 1; color: var(--orange); font-variant-numeric: tabular-nums; text-shadow: 0 0 24px rgba(255, 138, 31, .35); }
.grand span { color: var(--muted); }
.grand em { color: var(--yellow); font-style: normal; font-size: .85rem; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.badge { font-size: .78rem; padding: .25rem .6rem; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge.ok { border-color: rgba(63, 217, 160, .4); }
.badge.warn { border-color: rgba(255, 204, 77, .5); color: var(--yellow); }
.badge.err { border-color: rgba(255, 93, 108, .6); color: var(--red); }
.offline { background: var(--red); color: #fff; text-align: center; padding: .35rem; font-weight: 600; }
.banner { background: rgba(255, 204, 77, .12); border-bottom: 1px solid rgba(255, 204, 77, .4); color: var(--yellow); text-align: center; padding: .45rem 1rem; font-weight: 600; }

/* ---- buttons ---- */
.btn {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  padding: .45rem .85rem; border-radius: 10px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--orange); }
.btn.small { padding: .3rem .6rem; font-size: .85rem; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #1a0d02; font-weight: 700; }
.btn.danger { border-color: rgba(255, 93, 108, .5); color: var(--red); }
.icon {
  width: 2rem; height: 2rem; border-radius: 50%; border: 1px solid var(--line); background: var(--panel2);
  color: var(--text); font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.icon:hover { border-color: var(--orange); color: var(--orange); }
.link { background: none; border: 0; color: var(--purple); cursor: pointer; font: inherit; padding: 0 .3rem; }
.link.danger { color: var(--red); }
.x { background: none; border: 0; color: var(--muted); font-size: 1.2rem; cursor: pointer; }

/* ---- layout ---- */
main { max-width: 1500px; margin: 0 auto; padding: 1rem 1.2rem 3rem; display: grid; gap: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; min-width: 0; }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ---- one column per house: live view, chart, costumes and log all stay separate ---- */
.houses { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); gap: 1rem; align-items: start; }
.house { display: grid; gap: 1rem; min-width: 0; }
.house > .card { border-top: 3px solid var(--accent); }
.house > .card > h2, .house .loghead h2 { color: var(--accent); }
.grand .ht { display: inline-flex; align-items: baseline; gap: .35rem; padding: 0 .7rem; }
.grand .ht b { font-size: 2.3rem; color: var(--accent); text-shadow: none; }
.grand .ht span { color: var(--muted); }
.grand .ht em { color: var(--yellow); font-style: normal; font-size: .8rem; }

/* ---- cameras ---- */
.cams { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 1rem; }
.cam {
  background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--accent);
  border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; min-width: 0;
}
.cam > header { display: flex; justify-content: space-between; align-items: center; padding: .7rem 1rem; }
.cam h2 { margin: 0; color: var(--accent); }
.video { position: relative; background: #000; aspect-ratio: 16 / 10; display: grid; place-items: center; }
.video img { width: 100%; height: 100%; object-fit: contain; display: block; }
.door {
  position: absolute; left: .6rem; bottom: .6rem; padding: .3rem .7rem; border-radius: 999px;
  background: rgba(255, 138, 31, .92); color: #1a0d02; font-weight: 700; font-size: .85rem;
  animation: glow 1.6s ease-in-out infinite;
}
@keyframes glow { 50% { box-shadow: 0 0 0 6px rgba(255, 138, 31, .25); } }
.stats { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: .5rem; padding: .8rem 1rem .4rem; }
.stat { display: flex; flex-direction: column; min-width: 0; }
.stat b { font-size: 1.5rem; font-variant-numeric: tabular-nums; line-height: 1.15; white-space: nowrap; }
.stat span { color: var(--muted); font-size: .8rem; }
.stat em { color: var(--yellow); font-style: normal; font-size: .75rem; }
.stat.big b { font-size: 2.6rem; color: var(--accent); }
.cam > footer { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .4rem 1rem .9rem; flex-wrap: wrap; }
.bump { animation: bump .7s ease-out; }
@keyframes bump { 30% { transform: scale(1.35); filter: brightness(1.6); } }

/* ---- pills ---- */
.pill { display: inline-block; font-size: .74rem; padding: .12rem .55rem; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.live { color: var(--green); border-color: rgba(63, 217, 160, .45); }
.pill.ok { color: var(--green); }
.pill.wait { color: var(--yellow); border-color: rgba(255, 204, 77, .4); }
.pill.warn { color: var(--yellow); }
.pill.err { color: var(--red); border-color: rgba(255, 93, 108, .5); }
.pill.edit { color: var(--purple); }
.pill.idle { color: var(--muted); }
.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* ---- timeline + costumes ---- */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart line { stroke: var(--line); }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.legend i { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.costumes { display: grid; gap: .35rem; max-height: 300px; overflow: auto; padding-right: .3rem; }
.crow { display: grid; grid-template-columns: minmax(0, 11rem) 1fr 2rem; align-items: center; gap: .6rem; font-size: .9rem; }
.cname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cbar { display: flex; height: .7rem; background: var(--panel2); border-radius: 999px; overflow: hidden; }
.cbar i { display: block; height: 100%; }
.crow b { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- log ---- */
.loghead { display: flex; justify-content: space-between; align-items: baseline; }
.log { display: grid; gap: .55rem; }
.visit {
  display: grid; grid-template-columns: 132px minmax(0, 1fr) auto; gap: .9rem; align-items: center;
  padding: .55rem; border-radius: 12px; background: var(--panel2); border-left: 3px solid var(--accent);
}
.thumb { padding: 0; border: 0; background: #000; border-radius: 8px; overflow: hidden; cursor: zoom-in; aspect-ratio: 4 / 3; width: 132px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nothumb { display: grid; place-items: center; height: 100%; font-size: 1.6rem; }
.vtop { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; font-size: .85rem; }
.house { color: var(--accent); font-weight: 700; }
.summary { margin: .25rem 0; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip { font-size: .8rem; padding: .12rem .55rem; border-radius: 999px; background: rgba(176, 124, 255, .14); border: 1px solid rgba(176, 124, 255, .3); }
.count { display: grid; grid-template-columns: auto auto auto; align-items: center; gap: .35rem; justify-items: center; }
.count b { font-size: 1.7rem; min-width: 2.2rem; text-align: center; font-variant-numeric: tabular-nums; }
.count b.pending { color: var(--yellow); }
.count small { grid-column: 1 / -1; color: var(--muted); margin-top: -.3rem; }

/* ---- dialogs ---- */
.dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 0; width: min(760px, calc(100vw - 1.5rem)); max-height: calc(100vh - 2rem); }
.dlg.wide { width: min(1100px, calc(100vw - 1.5rem)); }
.dlg::backdrop { background: rgba(5, 3, 8, .7); backdrop-filter: blur(3px); }
.dlg form, #visitBody { display: flex; flex-direction: column; max-height: calc(100vh - 2rem); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; }
.dlg-scroll { overflow: auto; padding: .4rem 1.1rem 1rem; }
.dlg-foot { display: flex; gap: .5rem; justify-content: flex-end; align-items: center; padding: .8rem 1.1rem; border-top: 1px solid var(--line); flex-wrap: wrap; }
.dlg-foot .muted { margin-right: auto; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); margin: .45rem 0; }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
input, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: .45rem .6rem; min-width: 0;
}
input:focus, select:focus { outline: 2px solid rgba(255, 138, 31, .5); border-color: var(--orange); }
input[type="range"] { padding: 0; accent-color: var(--orange); }
input[type="checkbox"] { accent-color: var(--orange); width: 1.05rem; height: 1.05rem; }
output { color: var(--orange); font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 .8rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: .4rem 0; }
.camset { border: 1px solid var(--line); border-radius: 12px; padding: .4rem .9rem .7rem; margin: 0 0 .9rem; }
.camset legend { color: var(--orange); font-weight: 700; padding: 0 .4rem; }
.zone-pic { position: relative; margin: .5rem 0; border-radius: 8px; overflow: hidden; }
.zone-pic img { display: block; width: 100%; }
.zone-pic canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.k-person { color: var(--orange); } .k-far { color: #aaa; } .k-static { color: var(--purple); }
.frames { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .6rem; }
.frames figure { margin: 0; }
.frames img { width: 100%; border-radius: 8px; display: block; cursor: zoom-in; }
.frames figcaption { font-size: .75rem; color: var(--muted); margin-top: .2rem; }
.kids { list-style: none; padding: 0; margin: 0; display: grid; gap: .3rem; }
.kids li { display: flex; justify-content: space-between; gap: .6rem; padding: .35rem .5rem; background: var(--panel2); border-radius: 8px; }
.err-text { color: var(--red); }
.zoomed { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .92); display: grid; place-items: center; cursor: zoom-out; }
.zoomed img { max-width: 96vw; max-height: 94vh; }

.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--panel2); border: 1px solid var(--orange); padding: .55rem 1rem; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
.toast.bad { border-color: var(--red); }

/* ---- small screens ---- */
@media (max-width: 900px) {
  .top { grid-template-columns: 1fr auto; padding: .6rem .8rem; }
  .grand { grid-column: 1 / -1; grid-row: 2; }
  .badge { display: none; }
  main { padding: .8rem .8rem 2rem; }
  .duo { grid-template-columns: 1fr; }
  .cams { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .brand span { display: none; }
  .stats { grid-template-columns: 1.3fr 1fr 1fr; }
  .stats .stat:last-child { display: none; }
  .visit { grid-template-columns: 88px minmax(0, 1fr); }
  .thumb { width: 88px; }
  .count { grid-column: 1 / -1; grid-template-columns: auto auto auto auto; justify-content: end; }
  .count small { grid-column: auto; margin: 0; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .bump, .door, .pulse { animation: none; }
}
