:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f2630;
  --line: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #2f81f7;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: #3d4654; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.icon { padding: 4px 10px; line-height: 1; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  background: rgba(13, 17, 23, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 18px; }
.actions { display: flex; gap: 8px; align-items: center; }

.segmented { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; background: transparent; color: var(--muted); }
.segmented button.active { background: var(--panel-2); color: var(--text); }

.grid {
  display: grid;
  gap: 16px;
  padding: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 560px), 1fr));
}
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.camera {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.cam-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; }
.cam-name { margin: 0; font-size: 15px; }
.cam-status { font-size: 12px; color: var(--muted); }
.cam-status::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); margin-right: 6px; vertical-align: 1px;
}
.cam-status.live::before { background: var(--ok); }
.cam-status.retry::before { background: var(--warn); }

.lenses { display: grid; gap: 2px; grid-template-columns: repeat(var(--lenses, 1), 1fr); background: #000; }
@media (max-width: 640px) { .lenses { grid-template-columns: 1fr; } }

.lens { position: relative; margin: 0; aspect-ratio: 16 / 9; background: #000; overflow: hidden; }
.lens img { width: 100%; height: 100%; object-fit: contain; display: block; }
.lens figcaption {
  position: absolute; left: 8px; bottom: 8px;
  font-size: 12px; padding: 2px 8px; border-radius: 6px;
  background: rgba(0, 0, 0, .55);
}
.lens .loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 13px; pointer-events: none;
}
.lens.has-image .loading { display: none; }
.lens .expand {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0, 0, 0, .5); border-color: transparent;
}

.ptz {
  position: absolute; right: 12px; bottom: 12px;
  display: grid; grid-template: repeat(3, 40px) / repeat(3, 40px);
}
.ptz[hidden] { display: none; }
.ptz button {
  padding: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .5); border-color: rgba(255, 255, 255, .15);
  font-size: 13px;
}
.ptz button:active, .ptz button.busy { background: var(--accent); }
.ptz .up { grid-area: 1 / 2; }
.ptz .left { grid-area: 2 / 1; }
.ptz .right { grid-area: 2 / 3; }
.ptz .down { grid-area: 3 / 2; }

.lens:fullscreen { aspect-ratio: auto; }
.lens:fullscreen .ptz { grid-template: repeat(3, 56px) / repeat(3, 56px); right: 24px; bottom: 24px; }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--text);
  padding: 0; width: min(440px, calc(100% - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.sheet { display: flex; flex-direction: column; gap: 12px; padding: 18px; }
.sheet h3 { margin: 0 0 4px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 10px; color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.spacer { flex: 1; }
.error { color: var(--bad); margin: 0; font-size: 13px; }
.muted { color: var(--muted); }

.found { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.found .row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.found ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.found li button { width: 100%; text-align: left; display: flex; justify-content: space-between; }
.found li small { color: var(--muted); }

.details { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-all; }

/* ---------- nuvem ---------- */
.lens canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.cam-status.off::before { background: var(--bad); }
.error { padding: 0 16px; }

/* ---------- painel ---------- */
a { color: var(--accent); }
.btn {
  display: inline-block; text-decoration: none; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px;
}
.flash { margin: 12px 16px 0; padding: 10px 14px; border-radius: 8px; background: rgba(63, 185, 80, .12); border: 1px solid rgba(63, 185, 80, .4); }
.flash.error { background: rgba(248, 81, 73, .12); border-color: rgba(248, 81, 73, .4); color: var(--text); }
.narrow { max-width: 420px; margin: 32px auto; padding: 0 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.narrow .card { padding: 4px; }
.panel { max-width: 960px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.panel .card { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.panel h2 { margin: 0; font-size: 16px; }
.panel h2 small { font-weight: normal; font-size: 12px; margin-left: 6px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline.wrap { flex-wrap: wrap; }
.inline input { min-width: 0; flex: 1; }
.grow { flex: 1; }
.item { border-top: 1px solid var(--line); padding-top: 10px; }
.item.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.item summary { cursor: pointer; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item[open] > *:not(summary) { margin-top: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); flex: none; }
.dot.on { background: var(--ok); }
.tag { font-size: 11px; padding: 1px 8px; border-radius: 10px; background: var(--panel-2); color: var(--muted); }
.tag.bad { color: var(--bad); }
.small { font-size: 12px; }
.copy { display: flex; gap: 8px; align-items: center; }
.copy code {
  flex: 1; overflow-x: auto; white-space: nowrap; padding: 8px 10px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--line); font-size: 12px;
}
.cams { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
code { font-size: 12px; }
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .inline:not(.wrap) { flex-wrap: wrap; }
}
