:root {
  --bg: #0f1419;
  --panel: #1a2129;
  --panel2: #232c37;
  --border: #2e3945;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #2f81f7;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button {
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
}
button.ghost { background: var(--panel2); }
input, select {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }
.error { color: var(--red); min-height: 18px; }

.login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 32px;
  border-radius: 12px;
  display: flex; flex-direction: column; gap: 12px;
  width: 320px;
}
.login-card h1 { font-size: 20px; text-align: center; margin: 0 0 8px; }

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; }
.tabs { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.tabs button { background: transparent; color: var(--muted); }
.tabs button.active { background: var(--panel2); color: var(--text); }
.badge {
  background: var(--red); color: #fff; border-radius: 10px;
  padding: 0 6px; font-size: 11px; margin-left: 4px;
}
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-menu #logout { background: var(--panel2); }

main { padding: 16px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

.grid { display: grid; gap: 8px; }
.grid-1 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
.grid-9 { grid-template-columns: repeat(3, 1fr); }
.grid-16 { grid-template-columns: repeat(4, 1fr); }
.cell {
  position: relative; aspect-ratio: 16/9;
  background: #000; border: 1px solid var(--border);
  border-radius: 6px; overflow: hidden;
}
.cell iframe { width: 100%; height: 100%; border: 0; }
.cell .label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.6); padding: 3px 8px; font-size: 12px;
  display: flex; justify-content: space-between; align-items: center;
}
.cell .empty { display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.online { background: var(--green); }
.dot.offline { background: var(--muted); }
.dot.alarm { background: var(--red); }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.data-table th { color: var(--muted); font-weight: 500; }
.pill { padding: 2px 8px; border-radius: 10px; font-size: 12px; }
.pill.new { background: rgba(248,81,73,.2); color: var(--red); }
.pill.acknowledged { background: rgba(210,153,34,.2); color: var(--yellow); }
.pill.completed { background: rgba(63,185,80,.2); color: var(--green); }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px; margin-bottom: 16px;
}
.panel h3 { margin-top: 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.list { list-style: none; padding: 0; margin: 0; }
.list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border); gap: 8px;
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.card .big { font-size: 28px; font-weight: 600; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; }
.modal-body { background: var(--panel); border-radius: 10px; padding: 20px; width: min(90vw, 900px); position: relative; }
.modal-close { position: absolute; top: 8px; right: 10px; background: transparent; font-size: 24px; }
.modal-body iframe { width: 100%; aspect-ratio: 16/9; border: 0; border-radius: 6px; }
.modal-body video { width: 100%; border-radius: 6px; background: #000; }

.ptz-panel { display: flex; gap: 20px; margin-top: 12px; align-items: flex-start; flex-wrap: wrap; }
.ptz-pad {
  display: grid; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px);
  gap: 4px; user-select: none;
}
.ptz-pad button { padding: 0; font-size: 17px; touch-action: none; }
.ptz-pad .ptz-center { background: var(--panel2) !important; cursor: default; opacity: .6; }
.ptz-zoom { display: flex; flex-direction: column; gap: 8px; min-width: 140px; }
.ptz-zoom button { touch-action: none; }
.ptz-zoom input[type="range"] { width: 100%; vertical-align: middle; margin-left: 6px; }

.sep { width: 1px; background: var(--border); margin: 0 4px; }
.calendar { display: flex; flex-direction: column; gap: 4px; }
.calendar .day {
  display: flex; justify-content: space-between; padding: 6px 10px;
  background: var(--panel2); border-radius: 6px; cursor: pointer;
}
.calendar .day:hover { outline: 1px solid var(--accent); }

.map-canvas {
  position: relative; width: 100%; max-width: 1100px; background: #000;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  min-height: 300px; background-size: contain; background-repeat: no-repeat;
  background-position: center;
}
.marker {
  position: absolute; width: 26px; height: 26px; border-radius: 50%;
  transform: translate(-50%, -50%); cursor: pointer; border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.marker.online { background: var(--green); }
.marker.offline { background: var(--muted); }
.marker.alarm { background: var(--red); }
.map-palette { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.map-palette button { background: var(--panel2); }
.rep-mini { font-size: 13px; }
.rep-mini div { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px solid var(--border); }

@media (max-width: 720px) {
  .cols { grid-template-columns: 1fr; }
  .grid-9, .grid-16 { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-wrap: wrap; }
}
