:root {
  --bg: #0d0f12;
  --panel: #15181d;
  --panel-2: #1c2027;
  --border: #262b33;
  --text: #e6e8eb;
  --text-dim: #8a919c;
  --accent: #3b82f6;
  --red: #ef4444;
  --green: #22c55e;
  --gray: #4b5563;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.brand-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: .3px;
}
.badge-ok { background: rgba(34,197,94,.15); color: var(--green); }
.badge-error { background: rgba(239,68,68,.15); color: var(--red); }
.badge-unknown { background: rgba(139,146,156,.15); color: var(--text-dim); }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  padding: 20px 24px;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

.player-panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.player-wrap {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-wrap img { width: 100%; height: 100%; object-fit: contain; display: block; }

.error-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13,15,18,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}
.error-overlay.hidden { display: none; }
.error-box strong { color: var(--red); display: block; margin-bottom: 6px; font-size: 15px; }
.error-box p { color: var(--text-dim); font-size: 13px; margin: 0; word-break: break-word; }

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
}

.led-group { display: flex; align-items: center; gap: 10px; }
.led {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--gray);
  box-shadow: 0 0 0 rgba(239,68,68,0);
  transition: all .2s ease;
}
.led.on {
  background: var(--red);
  box-shadow: 0 0 10px 2px rgba(239,68,68,.7);
  animation: pulse 1.1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}
.led-text { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.led-text.on { color: var(--red); }
.rec-file { font-size: 12px; color: var(--text-dim); }

.sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.sidebar-header h2 { font-size: 14px; margin: 0; color: var(--text); }
.sidebar-header button {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; width: 28px; height: 28px; cursor: pointer; font-size: 14px;
}
.sidebar-header button:hover { background: var(--border); }

.recordings-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; max-height: 70vh; }
.recordings-list li {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  background: var(--panel-2);
  border: 1px solid transparent;
  font-size: 13px;
}
.recordings-list li:hover { border-color: var(--accent); }
.recordings-list li .rec-name { display: block; font-weight: 600; margin-bottom: 2px; word-break: break-all; }
.recordings-list li .rec-meta { display: block; color: var(--text-dim); font-size: 11px; }
.recordings-list li.empty { color: var(--text-dim); cursor: default; text-align: center; }
.recordings-list li.empty:hover { border-color: transparent; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; width: min(900px, 92vw);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.modal-header button {
  background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer;
}
.modal-content video { width: 100%; display: block; background: #000; max-height: 75vh; }

/* ===================== Navbar (paginas autenticadas) ===================== */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.navbar .nav-links { display: flex; align-items: center; gap: 8px; }
.navbar .nav-links a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
}
.navbar .nav-links a:hover { color: var(--text); background: var(--panel-2); }
.navbar .nav-links a.active { color: var(--text); background: var(--panel-2); }
.navbar .nav-user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-dim); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* ===================== Botoes ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 9px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--red); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }

/* ===================== Formularios ===================== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.form-group input, .form-group select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font-size: 14px;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--accent); }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-hint { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.form-error {
  background: rgba(239,68,68,.12); color: var(--red); border: 1px solid rgba(239,68,68,.3);
  border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px;
}
.form-error.hidden { display: none; }
details.advanced { margin: 6px 0 16px; }
details.advanced summary { cursor: pointer; font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }

/* ===================== Paginas de auth (login/cadastro) ===================== */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px;
}
.auth-card .brand { justify-content: center; margin-bottom: 6px; font-size: 17px; }
.auth-subtitle { text-align: center; color: var(--text-dim); font-size: 13px; margin: 0 0 24px; }
.auth-footer { text-align: center; font-size: 13px; color: var(--text-dim); margin-top: 16px; }
.auth-footer a { color: var(--accent); text-decoration: none; font-weight: 600; }

/* ===================== Cards / Accordion (dashboard) ===================== */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-header h1 { font-size: 18px; margin: 0; }
.section-header h2 { font-size: 15px; margin: 0; }

.empty-state { color: var(--text-dim); font-size: 13px; padding: 24px; text-align: center; background: var(--panel); border: 1px dashed var(--border); border-radius: 12px; }

.card-list { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; cursor: pointer;
}
.card-head:hover { background: var(--panel-2); }
.card-title { font-weight: 600; font-size: 14px; }
.card-subtitle { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.card-meta { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 10px; }
.card-body { border-top: 1px solid var(--border); padding: 16px 18px; display: none; }
.card-body.open { display: block; }
.chevron { transition: transform .15s ease; color: var(--text-dim); }
.chevron.open { transform: rotate(90deg); }

.sub-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.sub-item {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
}
.sub-item-head { display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.sub-item-body { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 12px; display: none; }
.sub-item-body.open { display: block; }

.camera-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border);
  margin-bottom: 8px; font-size: 13px;
}
.camera-row .camera-info { min-width: 0; }
.camera-row .camera-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.camera-row .camera-rtsp { color: var(--text-dim); font-size: 11px; word-break: break-all; }
.camera-row .camera-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gray); display: inline-block; }
.status-dot.enabled { background: var(--green); }
.status-dot.disabled { background: var(--gray); }

/* ===================== Monitor ao vivo (mosaico) ===================== */
.mosaic {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.tile {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  display: flex; flex-direction: column;
}
.tile-video {
  position: relative; background: #000; aspect-ratio: 16/9; cursor: pointer;
}
.tile-video img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile-footer {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; gap: 8px;
}
.tile-label { min-width: 0; }
.tile-label .tile-camera { font-size: 13px; font-weight: 600; }
.tile-label .tile-path { font-size: 11px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-led-group { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.tile-led-group .led-text { font-size: 11px; }
