:root {
  --bg: #0f1419;
  --bg-elev: #1a222c;
  --bg-tile: #121820;
  --text: #e8e2d8;
  --muted: #8b949e;
  --accent: #c45c26;
  --accent-soft: rgba(196, 92, 38, 0.18);
  --ok: #3d9a6a;
  --danger: #c44;
  --border: #2a3440;
  --font: "Segoe UI", "IBM Plex Sans", system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #1c2836 0%, transparent 55%),
    radial-gradient(800px 400px at 100% 0%, #2a1a12 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100dvh; }

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(72px + var(--safe-bottom));
}

.view { padding: 16px; }
.view[hidden], .panel[hidden], [hidden] { display: none !important; }

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.top h1 {
  flex: 1;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.brand {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.lede { color: var(--muted); margin: 0 0 1.25rem; }

.login-card {
  margin-top: 12vh;
  padding: 1.5rem;
  background: linear-gradient(160deg, var(--bg-elev), var(--bg-tile));
  border: 1px solid var(--border);
  border-radius: 12px;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.85rem;
}
label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  color: var(--text);
}
label.check input { width: auto; margin: 0; }
input {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b1015;
  color: var(--text);
  font-size: 1rem;
}
button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.45rem 0.7rem;
  font-weight: 500;
}
button.danger-ghost {
  background: transparent;
  color: #ff8a8a;
  border: 1px solid rgba(196, 68, 68, 0.45);
  padding: 0.4rem 0.65rem;
  font-weight: 500;
}
#login-form button[type="submit"] { width: 100%; margin-top: 0.5rem; }

.error { color: #ff8a8a; font-size: 0.9rem; }
.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; }
.hint { color: var(--muted); font-size: 0.8rem; align-self: center; }

.site-list, .alert-list, .user-list { list-style: none; margin: 0; padding: 0; }
.site-list li, .alert-item, .user-item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
}
.site-list button.site-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 1rem;
  border-radius: 10px;
}
.site-list .name { flex: 1; font-weight: 600; }

.pill {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.pill.online { color: var(--ok); border-color: rgba(61, 154, 106, 0.45); background: rgba(61, 154, 106, 0.12); }
.pill.offline { color: var(--muted); }
.pill.admin { color: var(--accent); border-color: rgba(196, 92, 38, 0.45); background: var(--accent-soft); }

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  background: var(--bg-tile);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
  padding: 0.55rem 0.4rem;
  font-weight: 600;
}
.tab.active {
  background: var(--accent-soft);
  color: var(--text);
}

.panel-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.alert-item {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 0;
  cursor: pointer;
}
.alert-item img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  background: #000;
  display: block;
}
.alert-item .meta { padding: 0.65rem 0.75rem; }
.alert-item .meta .type { font-weight: 650; margin: 0 0 0.2rem; }
.alert-item .meta .sub { margin: 0; color: var(--muted); font-size: 0.8rem; }

.cam-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.cam-tile {
  background: #000;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  aspect-ratio: 4 / 3;
}
.cam-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #111;
}
.cam-tile .label {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.75rem;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
}

.mode-current { color: var(--muted); }
.mode-current strong { color: var(--text); }
.mode-buttons {
  display: grid;
  gap: 8px;
}
.mode-buttons button {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  text-align: left;
}
.mode-buttons button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.admin-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.admin-card h2 {
  margin: 0 0 0.85rem;
  font-size: 1rem;
}
.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 0.5rem;
}
.user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.85rem 1rem;
}
.user-item .meta { flex: 1; min-width: 0; }
.user-item .name { font-weight: 650; margin: 0 0 0.15rem; }
.user-item .sub { margin: 0; color: var(--muted); font-size: 0.78rem; }
.user-item .actions { display: flex; gap: 6px; flex-shrink: 0; }

.home-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(15, 20, 25, 0.92) 35%, rgba(15, 20, 25, 0.98));
  pointer-events: none;
}
.home-bar[hidden] { display: none !important; }
.home-btn {
  pointer-events: auto;
  min-width: 140px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

#img-dialog {
  border: 1px solid var(--border);
  background: #000;
  color: var(--text);
  padding: 0;
  max-width: min(96vw, 900px);
  width: 96vw;
}
#img-dialog::backdrop { background: rgba(0,0,0,0.75); }
#img-dialog img { width: 100%; display: block; max-height: 80vh; object-fit: contain; }
.dialog-close { margin: 8px; }

@media (min-width: 640px) {
  .cam-grid { grid-template-columns: 1fr 1fr 1fr; }
}
