/* ============================================================================
   MEZZ, app do cliente final (câmeras). Mesma identidade do login unificado:
   azul-aço da marca (#5980a6 / #416180), neutros frios, fontes do sistema
   (nada externo: o app abre rápido, funciona instalado e empacotado).
   Claro em html[data-theme="light"], escuro em html[data-theme="dark"].
   ========================================================================= */

:root, html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --line: rgba(15, 23, 42, .09);
  --line-strong: rgba(15, 23, 42, .16);
  --ink: #111827;
  --ink-2: #3f4a5f;
  --muted: #667085;
  --brand: #416180;
  --brand-soft: #5980a6;
  --brand-dim: rgba(65, 97, 128, .1);
  --on-brand: #ffffff;
  --ok: #2f7a52;
  --bad: #b42318;
  --bad-dim: rgba(180, 35, 24, .08);
  --stage: #0b0f16;
  --shadow: 0 10px 30px -18px rgba(15, 23, 42, .35);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f16;
  --surface: #131a24;
  --surface-2: #19212d;
  --line: rgba(255, 255, 255, .07);
  --line-strong: rgba(255, 255, 255, .13);
  --ink: #e8edf5;
  --ink-2: #b3bfd1;
  --muted: #8a95a8;
  --brand: #94bce3;
  --brand-soft: #7e9cb8;
  --brand-dim: rgba(148, 188, 227, .12);
  --on-brand: #0b1622;
  --ok: #7fd6a2;
  --bad: #ff8a7a;
  --bad-dim: rgba(255, 138, 122, .1);
  --stage: #05080c;
  --shadow: 0 14px 34px -20px rgba(0, 0, 0, .9);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.micro { color: var(--muted); font-size: .82rem; margin: 16px 0 0; }

/* ---------------------------------------------------------------- marca */
.brand { display: inline-flex; align-items: center; color: var(--ink); }
.mark { height: 18px; width: auto; }
.brand--lg .mark { height: 26px; }
.mark__m { stroke: var(--brand-soft); }
.mark__dot { fill: var(--brand-soft); }

/* ---------------------------------------------------------------- botões e campos */
.btn {
  appearance: none; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer;
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { border-color: var(--brand-soft); }
.btn:disabled { opacity: .55; cursor: default; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn--ghost { background: transparent; border-color: rgba(255,255,255,.25); color: #fff; }
.btn--block { width: 100%; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: inherit; width: 44px; height: 44px;
  border-radius: 10px; display: inline-grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--brand-dim); }
.icon-btn svg { width: 22px; height: 22px; }

input, select {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
label { display: block; font-weight: 600; font-size: .88rem; color: var(--ink-2); margin: 14px 0 6px; }
.form-err { color: var(--bad); min-height: 1.2em; font-size: .9rem; margin: 10px 0; }

/* ---------------------------------------------------------------- login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login__card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px 24px 22px; box-shadow: var(--shadow);
}
.login h1 { font-size: 1.5rem; margin: 18px 0 2px; }
.login .muted { margin: 0 0 6px; }

/* ---------------------------------------------------------------- casca */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.site-pick { margin: 0; flex: 1; min-width: 0; }
.site-pick select { min-height: 38px; padding: 6px 10px; font-weight: 600; }
.site-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top__acts { display: flex; gap: 2px; margin-left: auto; }

.tabs { display: flex; gap: 4px; padding: 8px 16px 0; background: var(--surface); border-bottom: 1px solid var(--line); }
.tabs button {
  appearance: none; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted);
  padding: 10px 12px 12px; border-bottom: 2px solid transparent; cursor: pointer; min-height: 44px;
}
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }

main { padding: 16px 16px calc(env(safe-area-inset-bottom) + 24px); max-width: 1400px; margin: 0 auto; }
.hint { color: var(--muted); font-size: .88rem; margin: 0 0 12px; min-height: 1.2em; }

/* ---------------------------------------------------------------- grade ao vivo */
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
@media (max-width: 640px) { .grid { grid-template-columns: 1fr; } }

.tile {
  position: relative; aspect-ratio: 16 / 9; background: var(--stage); border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line); cursor: pointer;
}
.tile video, .stage video { width: 100%; height: 100%; object-fit: contain; background: var(--stage); display: block; }
.tile__name {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 12px 8px; color: #fff; font-weight: 600; font-size: .9rem;
  background: linear-gradient(transparent, rgba(0,0,0,.65)); pointer-events: none; display: flex; justify-content: space-between; gap: 8px;
}
.tile__state { font-weight: 500; opacity: .85; font-size: .8rem; }
.tile__msg {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px 16px 40px;
  color: #cfd7e3; font-size: .9rem; pointer-events: none;
}
.tile__msg svg { width: 28px; height: 28px; display: block; margin: 0 auto 6px; opacity: .8; }
.tile--err .tile__msg { color: #ffb4a8; }

.spinner {
  width: 26px; height: 26px; border-radius: 50%; border: 3px solid rgba(255,255,255,.18); border-top-color: #fff;
  animation: spin 0.9s linear infinite; margin: 0 auto 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- vazio */
.empty {
  text-align: center; padding: 48px 20px; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-strong);
  border-radius: 14px; grid-column: 1 / -1;
}
.empty svg { width: 36px; height: 36px; color: var(--brand-soft); }
.empty b { display: block; color: var(--ink); font-size: 1.05rem; margin: 8px 0 4px; }

/* ---------------------------------------------------------------- tela cheia */
.full { position: fixed; inset: 0; z-index: 20; background: #000; display: flex; flex-direction: column; }
.full__bar {
  display: flex; align-items: center; gap: 10px; color: #fff; padding: calc(env(safe-area-inset-top) + 6px) 8px 6px 16px;
  background: rgba(0,0,0,.6);
}
.full__bar b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.full__acts { display: flex; align-items: center; gap: 6px; }
.full .icon-btn { color: #fff; }
.stage { position: relative; background: var(--stage); border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9; }
.stage--full { flex: 1; border-radius: 0; aspect-ratio: auto; padding-bottom: env(safe-area-inset-bottom); }

/* ---------------------------------------------------------------- gravações */
.rec-form { display: grid; gap: 10px; grid-template-columns: 2fr 1fr 1fr auto; align-items: end; }
.rec-form .field { margin: 0; }
.rec-form .field span { display: block; margin-bottom: 6px; }
@media (max-width: 720px) {
  .rec-form { grid-template-columns: 1fr 1fr; }
  .rec-form .field:first-child { grid-column: 1 / -1; }
  .rec-form .btn { grid-column: 1 / -1; }
}
.hours { display: flex; gap: 6px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: thin; }
.hours button {
  flex: 0 0 auto; appearance: none; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .85rem; cursor: pointer; min-height: 36px;
}
.hours button[aria-pressed="true"] { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.hours button:disabled { opacity: .4; cursor: default; }
.rec-player { margin-top: 14px; }
.rec-bar { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 10px; }
.rec-clock { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 9ch; text-align: center; }
#recEmpty { margin-top: 14px; }

/* ---------------------------------------------------------------- avisos */
.ios-hint {
  position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px); z-index: 30;
  display: flex; align-items: center; gap: 8px; background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong);
  border-radius: 14px; padding: 10px 6px 10px 14px; box-shadow: var(--shadow);
}
.ios-hint p { margin: 0; font-size: .9rem; flex: 1; }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: .2s; z-index: 40; max-width: calc(100% - 32px); font-size: .9rem;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
