:root {
  --bg:        #0c0d11;
  --bg-2:      #14161c;
  --panel:     #191c24;
  --panel-2:   #1f232d;
  --line:      #2a2f3a;
  --text:      #e9ecf2;
  --muted:     #8a91a0;
  --gold:      #d4af37;
  --gold-2:    #f0c674;
  --gold-soft: rgba(212,175,55,.14);
  --danger:    #ff5c5c;
  --live:      #35d07f;
  --radius:    16px;
  --shadow:    0 18px 50px rgba(0,0,0,.55);
  --mono:      ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1100px 700px at 50% -10%, #1a1e27 0%, var(--bg) 60%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 12px; color: var(--gold); }
.brand h1 {
  margin: 0; font-size: 1.6rem; letter-spacing: .5px; font-weight: 800;
  color: var(--text);
}
.brand h1 span { color: var(--gold); }
.brand.small h1 { font-size: 1.15rem; }
.brand-mark {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px;
  background: var(--gold-soft); color: var(--gold-2);
  border: 1px solid rgba(212,175,55,.35);
}
.brand.small .brand-mark { width: 34px; height: 34px; border-radius: 9px; }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 34px 30px 24px;
  text-align: center;
}
.login-card .brand { justify-content: center; margin-bottom: 4px; }
.tagline { margin: 6px 0 26px; color: var(--muted); font-size: .92rem; }

.field { display: block; text-align: left; margin-bottom: 14px; }
.field span { display: block; font-size: .78rem; color: var(--muted); margin-bottom: 7px; letter-spacing: .3px; }
.field input {
  width: 100%; padding: 13px 14px; border-radius: 11px;
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text); font-size: 1rem; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }

.btn-gold {
  width: 100%; padding: 13px 16px; border: none; border-radius: 11px; cursor: pointer;
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: #241d05; font-weight: 800; font-size: 1rem; letter-spacing: .3px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  transition: filter .15s, transform .05s;
}
.btn-gold:hover { filter: brightness(1.06); }
.btn-gold:active { transform: translateY(1px); }
.btn-gold:disabled { filter: grayscale(.3) brightness(.9); cursor: default; }

.error { color: var(--danger); font-size: .85rem; margin: -4px 0 12px; text-align: left; }
.secure-note {
  margin: 20px 0 2px; color: var(--muted); font-size: .74rem;
  display: inline-flex; align-items: center; gap: 6px;
}

.spinner {
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid rgba(36,29,5,.35); border-top-color: #241d05;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- App / grid ---------- */
.app-body { padding: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 12px 18px;
  background: rgba(12,13,17,.82); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-actions { display: flex; align-items: center; gap: 14px; }

.livefeed {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: .68rem; font-weight: 700; letter-spacing: .12em;
  color: var(--gold-2);
}
.livefeed .d { width: 8px; height: 8px; border-radius: 50%; background: var(--live); box-shadow: 0 0 8px var(--live); animation: pulse 1.6s infinite; }
.clock {
  font-family: var(--mono); font-size: .82rem; color: var(--text); letter-spacing: .05em;
  font-variant-numeric: tabular-nums; opacity: .9;
}
@media (max-width: 620px) { .livefeed, .clock { display: none; } }

.layout-toggle { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.lt-btn {
  border: none; background: transparent; color: var(--muted);
  width: 34px; height: 30px; border-radius: 7px; cursor: pointer; font-size: 1rem;
}
.lt-btn.is-active { background: var(--gold-soft); color: var(--gold-2); }

.btn-ghost {
  background: transparent; color: var(--text); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: .88rem;
}
.btn-ghost:hover { border-color: var(--gold); color: var(--gold-2); }
.btn-ghost.icon { padding: 8px; display: inline-grid; place-items: center; }

/* ---- Settings modal ---- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: rgba(4,5,7,.72); backdrop-filter: blur(4px);
}
.overlay[hidden] { display: none; }
.modal {
  width: 100%; max-width: 420px; max-height: 90dvh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 22px 24px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.modal-head h2 { margin: 0; font-size: 1.2rem; color: var(--text); }
.modal-x { background: transparent; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; padding: 6px; border-radius: 8px; }
.modal-x:hover { color: var(--gold-2); background: var(--gold-soft); }
.modal-meta { margin: 0 0 16px; font-family: var(--mono); font-size: .7rem; color: var(--muted); }
.modal-sep { border: none; border-top: 1px solid var(--line); margin: 20px 0; }
.settings-form h3 { margin: 0 0 12px; font-size: .95rem; color: var(--gold-2); font-weight: 700; }
.settings-form h3 .muted { color: var(--muted); font-weight: 400; font-size: .78rem; }
.settings-form .field { margin-bottom: 12px; }
.btn-gold.sm { width: auto; padding: 10px 16px; font-size: .9rem; }
.form-msg { font-size: .82rem; margin: 4px 0 12px; }
.form-msg.good { color: var(--live); }
.form-msg.bad { color: var(--danger); }

.grid { display: grid; gap: 10px; padding: 12px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 820px)  { .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px)  { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

.grid-loading { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 0; }

.tile {
  position: relative; aspect-ratio: 16 / 9; background: #000;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.tile:hover { border-color: rgba(212,175,55,.5); }
.tile:fullscreen { border-radius: 0; aspect-ratio: auto; }
.tile iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }

/* Top overlay: monospace timestamp + camera name (left), LIVE pill (right) */
.tile-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: 8px 10px; pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,.55), transparent);
}
.tile-osd { display: flex; flex-direction: column; gap: 1px; }
.tile-osd .ts {
  font-family: var(--mono); font-size: .64rem; letter-spacing: .02em;
  color: #eafff2; text-shadow: 0 1px 2px #000; font-variant-numeric: tabular-nums;
}
.tile-osd .tile-name {
  font-family: var(--mono); font-size: .64rem; letter-spacing: .04em;
  color: var(--gold-2); text-shadow: 0 1px 2px #000;
}
.live {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 7px; border-radius: 5px;
  background: rgba(0,0,0,.5); border: 1px solid rgba(53,208,127,.35);
  font-family: var(--mono); font-size: .58rem; font-weight: 700; letter-spacing: .1em; color: #eafff2;
}
.live .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--live); box-shadow: 0 0 7px var(--live); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* Bottom bar: NVR label (left) + fullscreen control (right) — appears on hover */
.tile-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 10px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.72));
  opacity: 0; transition: opacity .15s;
}
.tile:hover .tile-bar, .tile:focus-within .tile-bar { opacity: 1; }
.tile-nvr { font-family: var(--mono); font-size: .6rem; letter-spacing: .04em; color: var(--muted); }
.fs-btn {
  border: none; background: rgba(255,255,255,.14); color: #fff;
  width: 30px; height: 26px; border-radius: 7px; cursor: pointer; font-size: .9rem;
}
.fs-btn:hover { background: var(--gold); color: #241d05; }

/* Bottom status bar */
.statusbar {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 18px; font-family: var(--mono); font-size: .68rem; letter-spacing: .08em;
  color: var(--muted); background: rgba(12,13,17,.85); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.statusbar .d { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--live); box-shadow: 0 0 7px var(--live); margin-right: 7px; vertical-align: middle; }
.statusbar .sb-left { color: var(--live); }
.statusbar .sb-right { color: var(--gold-2); font-variant-numeric: tabular-nums; }
