:root {
  --bg: #090c10;
  --surface: #11161d;
  --surface-2: #171e28;
  --surface-3: #1f2835;
  --line: #222d3b;
  --text: #e8eef6;
  --muted: #8796a8;
  --accent: #5eead4;
  --accent-ink: #04201c;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --live: #ef4444;
  --radius: 16px;
  --radius-sm: 11px;
  --glass: rgb(8 11 15 / 0.62);
  --glass-line: rgb(255 255 255 / 0.09);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html {
  background: radial-gradient(1000px 460px at 50% -160px, rgb(94 234 212 / 0.075), transparent 70%), var(--bg);
  background-color: var(--bg);
  color: var(--text);
}
body {
  margin: 0;
  background: transparent;
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; }
h1 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; }
button, a.ghost, a.primary { font: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 20px calc(32px + env(safe-area-inset-bottom));
}

/* topo */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0 14px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  flex: none; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--accent);
}
.brand-text { display: grid; gap: 3px; min-width: 0; }
.brand-text h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); min-width: 0; }
.pill #pillText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px rgb(74 222 128 / 0.16); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 4px rgb(251 191 36 / 0.14); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 4px rgb(248 113 113 / 0.14); }

/* botões */
.ghost, .primary, .icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 8px 13px; border-radius: var(--radius-sm); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 8px; line-height: 1.2;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.ghost:hover, .icon-btn:hover { background: var(--surface-2); border-color: #2b384a; }
.ghost:active, .icon-btn:active, .primary:active { transform: scale(0.97); }
.ghost:disabled, .icon-btn:disabled, .primary:disabled { opacity: 0.4; cursor: default; transform: none; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; justify-content: center; padding: 10px 16px; }
.primary:hover { filter: brightness(1.07); }
.primary:disabled { background: var(--surface-3); color: var(--muted); opacity: 1; }
.icon-btn { width: 38px; height: 38px; padding: 0; justify-content: center; flex: none; }

/* abas */
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; width: fit-content; margin: 2px 0 18px; }
.tabs button {
  appearance: none; border: 0; background: transparent; color: var(--muted); padding: 8px 16px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; font: inherit; font-weight: 500; transition: background 0.12s, color 0.12s;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { background: var(--surface-3); color: var(--text); }
.tabs button[aria-selected="true"] svg { color: var(--accent); }

/* estrutura dos painéis */
.panel { display: grid; gap: 18px; align-items: start; }
.stage { min-width: 0; }
.card, .rec-layout .side { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 12px; }
.card-title small { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 8px; font-size: 12.5px; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 2px 0; }

/* player */
.player {
  position: relative; background: #000; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; aspect-ratio: 16 / 9; box-shadow: 0 14px 44px -22px rgb(0 0 0 / 0.9);
}
.live-layout .player { max-height: 76dvh; }
.player video, .player video-stream { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }
.player video-stream { position: relative; }
.player:fullscreen { aspect-ratio: auto; max-height: none; border-radius: 0; border: 0; }
.player:-webkit-full-screen { aspect-ratio: auto; max-height: none; border-radius: 0; border: 0; }

.overlay { position: absolute; z-index: 3; display: flex; align-items: center; gap: 8px; pointer-events: none; }
.overlay > * { pointer-events: auto; }
.overlay-tl { top: 12px; left: 12px; }
.overlay-tr { top: 12px; right: 12px; }
.overlay .icon-btn { width: 34px; height: 34px; background: var(--glass); border-color: var(--glass-line); color: #fff; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.overlay .icon-btn:hover { background: rgb(8 11 15 / 0.8); }

.badge {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px 5px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #fff;
  background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.badge-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge[data-state="live"] .badge-dot { background: var(--live); animation: pulse 1.8s ease-out infinite; }
.badge[data-state="connecting"] .badge-dot { background: var(--warn); }
.badge[data-state="offline"] .badge-dot { background: var(--bad); }

.loading {
  position: absolute; inset: 0; z-index: 2; display: grid; place-content: center; justify-items: center; gap: 12px;
  color: var(--muted); font-size: 13.5px; pointer-events: none; text-align: center; padding: 16px;
}
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 2.5px solid rgb(255 255 255 / 0.12); border-top-color: var(--accent); animation: spin 0.85s linear infinite; }

.empty {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px;
  color: var(--muted); text-align: center; padding: 16px; pointer-events: none;
}
.empty svg { opacity: 0.7; }
.empty p { margin: 0; max-width: 32ch; }
.empty .primary { pointer-events: auto; margin-top: 4px; }

/* qualidade */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.seg button { appearance: none; border: 0; background: transparent; color: var(--muted); padding: 5px 13px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.seg-glass { background: var(--glass); border-color: var(--glass-line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.seg-glass button { color: rgb(255 255 255 / 0.68); }
.seg-glass button[aria-pressed="true"] { background: rgb(255 255 255 / 0.18); color: #fff; }

/* controle da câmera */
.ptz-wrap { display: grid; justify-items: center; }
.ptz-wrap .card-title { justify-self: start; }
.ptz {
  width: 188px; height: 188px; padding: 9px; border-radius: 50%;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  grid-template-areas: ". up ." "left stop right" ". down .";
  background: var(--surface-2); border: 1px solid var(--line); box-shadow: inset 0 3px 14px rgb(0 0 0 / 0.35);
}
.ptz button {
  appearance: none; border: 0; background: transparent; color: var(--text); border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: background 0.12s, transform 0.08s;
}
.ptz button svg { pointer-events: none; }
.ptz button:hover { background: var(--surface-3); }
.ptz button:active, .ptz button.is-held { background: var(--accent); color: var(--accent-ink); transform: scale(0.94); }
.ptz [data-dir="up"] { grid-area: up; }
.ptz [data-dir="left"] { grid-area: left; }
.ptz [data-dir="stop"] { grid-area: stop; background: var(--surface-3); color: var(--muted); }
.ptz [data-dir="right"] { grid-area: right; }
.ptz [data-dir="down"] { grid-area: down; }
.ptz-wrap .hint { text-align: center; margin-top: 12px; }

/* gravações */
.clip-bar { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.clip-title { flex: 1; min-width: 0; text-align: center; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clip-actions { display: flex; gap: 8px; margin-left: auto; }

.side-head { margin-bottom: 14px; }
.side-head .hint { margin: 4px 0 0; }
.side-head .card-title { margin-bottom: 0; }
.rec-list { display: grid; gap: 18px; }
.hour-group h3 { display: flex; align-items: baseline; gap: 8px; margin: 0 0 8px; font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.hour-group .hday { font-size: 12.5px; font-weight: 400; color: var(--muted); }
.hour-group .hmeta { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--muted); }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.chip {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: 8px 10px; border-radius: 10px; cursor: pointer; font-variant-numeric: tabular-nums; font-size: 13.5px; font-weight: 600;
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left; transition: background 0.12s, border-color 0.12s;
}
.chip small { color: var(--muted); font-size: 11.5px; font-weight: 400; margin: 0; }
.chip:hover { background: var(--surface-3); border-color: #2b384a; }
.chip[aria-current="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip[aria-current="true"] small { color: inherit; opacity: 0.72; }

.saved-block { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.saved-list { display: grid; gap: 8px; }
.saved-item { display: flex; align-items: stretch; gap: 8px; }
.saved-item .chip { flex: 1; flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
.saved-item .del {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  border-radius: 10px; padding: 0 12px; cursor: pointer; font: inherit; font-size: 13px;
}
.saved-item .del:hover { color: var(--bad); border-color: var(--bad); }

/* login */
.login-body { display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 30px 26px 26px; margin-bottom: 6vh; box-shadow: 0 24px 70px -30px rgb(0 0 0 / 0.9);
}
.login-mark { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 15px; background: var(--surface-2); border: 1px solid var(--line); color: var(--accent); margin-bottom: 16px; }
.login-card h1 { font-size: 21px; }
.login-card p { margin: 6px 0 20px; }
.login-card form { display: grid; gap: 12px; }
.login-card input {
  width: 100%; padding: 13px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit;
}
.login-card input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgb(94 234 212 / 0.14); }
.error { color: var(--bad); font-size: 13.5px; margin: 0 !important; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgb(239 68 68 / 0.55); }
  70%, 100% { box-shadow: 0 0 0 7px rgb(239 68 68 / 0); }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .badge[data-state="live"] .badge-dot { animation: none; }
  * { transition: none !important; }
}

/* telas largas: ao vivo com painel ao lado, gravações com lista ao lado */
@media (min-width: 960px) {
  .live-layout.has-ptz { grid-template-columns: minmax(0, 1fr) 290px; }
  .rec-layout { grid-template-columns: minmax(0, 1fr) 360px; }
  .rec-layout .side { position: sticky; top: 16px; max-height: calc(100dvh - 32px); overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
}

/* celular: abas na parte de baixo, ao alcance do polegar */
@media (max-width: 720px) {
  .app { padding-left: 14px; padding-right: 14px; padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
  .top { padding-top: 14px; }
  .pill { align-items: flex-start; }
  .pill #pillText { white-space: normal; overflow: visible; }
  .pill .dot { margin-top: 5px; }
  .top .ghost .label { display: none; }
  .top .ghost { width: 38px; height: 38px; padding: 0; justify-content: center; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; width: auto; margin: 0; gap: 6px;
    border-radius: 0; border-width: 1px 0 0; padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
    background: rgb(13 18 25 / 0.9); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  }
  .tabs button { flex: 1; flex-direction: column; gap: 3px; padding: 7px 4px; font-size: 11.5px; border-radius: 11px; }
  .player { border-radius: 14px; }
  .clip-actions { flex-basis: 100%; margin-left: 0; }
  .clip-actions > * { flex: 1; justify-content: center; }
  .ptz { width: 200px; height: 200px; }
}
