:root {
  color-scheme: dark;
  --bg: #11151b;
  --panel: #181e27;
  --panel2: #202836;
  --line: #2d3949;
  --text: #e7edf5;
  --muted: #93a1b5;
  --accent: #55d6a5;
  --accent2: #4aa8ff;
  --danger: #ff6b6b;
  --warn: #ffc857;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 20% -10%, #1d2b3a 0%, var(--bg) 55%);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, Segoe UI, sans-serif;
}
button, input, textarea { font: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent2); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: #174b3a; border-color: #2b8a65; }
button.danger { border-color: #71343a; color: #ffb4b4; }
button.ghost { background: transparent; }
button.small { padding: 5px 9px; font-size: 12px; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #0e131a;
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
}
textarea { min-height: 76px; resize: vertical; font-family: ui-monospace, monospace; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.5em; }
.hint { color: var(--muted); font-size: 12px; margin-top: 18px; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(440px, 100%);
  background: rgba(24, 30, 39, .92);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-card h1 { margin: 0 0 8px; font-size: 24px; }
.login-card form { display: grid; gap: 10px; margin-top: 20px; }
.login-card button { width: 100%; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 21, 27, .8);
  backdrop-filter: blur(8px);
}
.brand { font-weight: 700; letter-spacing: .2px; }
.top-actions { display: flex; align-items: center; gap: 14px; }

.layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: calc(100vh - 76px);
}
.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px;
  min-width: 0;
}
.content { padding: 22px; min-width: 0; }
.section-head { display: flex; justify-content: space-between; align-items: center; }
.section-head h2 { font-size: 15px; margin: 0; }
.device-list { display: grid; gap: 8px; margin-top: 14px; }
.device {
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.device.active { border-color: var(--accent2); box-shadow: 0 0 0 1px #1e5f9c inset; }
.device .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.new-device { display: grid; gap: 7px; margin-top: 10px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.online { background: var(--accent); box-shadow: 0 0 8px #2ddb9b; }
.dot.offline { background: #667181; }

.empty {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}

.grid { display: grid; gap: 14px; grid-template-columns: repeat(12, 1fr); }
.card {
  background: rgba(24, 30, 39, .88);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  min-width: 0;
}
.card h3 { margin: 0 0 10px; font-size: 14px; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .span-4, .span-6, .span-8 { grid-column: span 12; }
}

.device-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.device-head h1 { font-size: 22px; margin: 0; }
.badge { border: 1px solid var(--line); padding: 3px 8px; border-radius: 999px; font-size: 12px; color: var(--muted); }
.badge.online { color: var(--accent); border-color: #2b8a65; }
.badge.offline { color: var(--muted); }
.kv { display: grid; grid-template-columns: 150px minmax(0,1fr); gap: 6px 12px; }
.kv .k { color: var(--muted); }
.kv .v { overflow-wrap: anywhere; }
.big { font-size: 24px; font-weight: 700; }
.temps { display: flex; gap: 22px; flex-wrap: wrap; }
.temps div { min-width: 90px; }
.temps .label { color: var(--muted); font-size: 12px; }
.temps .value { font-size: 22px; font-weight: 700; }
.progress { height: 8px; border-radius: 99px; background: #0e131a; overflow: hidden; margin: 10px 0; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); width: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; }
.row > button { flex: 0 0 auto; }
.camera {
  width: 100%;
  min-height: 180px;
  max-height: 360px;
  object-fit: contain;
  border-radius: 10px;
  background: #0b0f14;
  border: 1px solid var(--line);
}
.video-mount {
  min-height: 220px;
  background: #06090d;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.video-stream {
  display: block;
  width: 100%;
  min-height: 220px;
  max-height: 480px;
  object-fit: contain;
  background: #06090d;
}
.cfs { display: grid; gap: 7px; }
.slot { display: grid; grid-template-columns: 34px 16px minmax(0,1fr) 60px; gap: 8px; align-items: center; font-size: 13px; }
.swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid #000; }
.log { max-height: 220px; overflow: auto; font-family: ui-monospace, monospace; font-size: 12px; }
.log div { padding: 3px 0; border-bottom: 1px solid #232c39; overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, monospace; font-size: 12px; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: grid; place-items: center; padding: 24px; z-index: 20;
}
.modal-card {
  width: min(620px, 100%); background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 22px;
}
.modal-card pre {
  white-space: pre-wrap; overflow-wrap: anywhere; background: #0e131a;
  border: 1px solid var(--line); border-radius: 8px; padding: 12px;
}
.toast {
  position: fixed; right: 18px; bottom: 18px; max-width: 420px;
  background: #1c2835; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 14px; opacity: 0; transform: translateY(8px);
  transition: .2s; pointer-events: none; z-index: 30;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: #71343a; color: #ffb4b4; }
