/* ═══════════════════════════════════════════════════════════════
   Cameras Uai Telecom — style.css
   Identidade visual baseada na Uai Telecom
   Cores: #020101 (fundo), #F36F21 (laranja/accent), #CA0000 (vermelho), #FFB709 (amarelo)
   Tipografia: Sen (Google Fonts)
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* Paleta Uai Telecom */
  --uai-orange:   #F36F21;
  --uai-red:      #CA0000;
  --uai-yellow:   #FFB709;
  --uai-black:    #020101;
  --uai-white:    #FFFFFF;
  --uai-gray:     #777777;

  /* Cores do sistema */
  --bg:           #020101;
  --bg-2:         #0e0d0d;
  --bg-3:         #1a1818;
  --bg-4:         #242222;
  --bg-5:         #2e2b2b;
  --border:       #2e2b2b;
  --border-2:     #3a3737;
  --text-1:       #f5f4f4;
  --text-2:       #c8c5c5;
  --text-3:       #8a8585;
  --text-4:       #5a5555;

  --accent:       #CA0000;
  --accent-dim:   rgba(202, 0, 0, 0.15);
  --accent-hover: #b00000;
  --green:        #22c55e;
  --red:          #CA0000;
  --red-dim:      rgba(202, 0, 0, 0.15);
  --yellow:       #FFB709;

  /* Sidebar */
  --sidebar-w:    220px;
  --sidebar-bg:   #0a0909;
  --topbar-h:     52px;

  /* Tipografia */
  --font:         'Sen', system-ui, -apple-system, sans-serif;

  /* Bordas */
  --radius:       8px;
  --radius-sm:    5px;
  --radius-lg:    12px;

  /* Sombras */
  --shadow:       0 2px 12px rgba(0,0,0,.5);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.7);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-1);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
input, select, button, textarea { font-family: inherit; }
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; display: block; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: var(--bg-5); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ══════════════════════════════════════════════════════
   LOGIN
   ══════════════════════════════════════════════════════ */

.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 9999;
  padding: 16px;
}

.login-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}
.login-logo-img {
  height: 72px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(243,111,33,.3));
}
.login-title {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}
.login-sub {
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 28px;
}

/* ══════════════════════════════════════════════════════
   LAYOUT APP
   ══════════════════════════════════════════════════════ */

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}
.app.hidden { display: none; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .25s ease, min-width .25s ease;
  z-index: 100;
}

.brand {
  padding: 16px 14px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.brand-logo {
  height: 52px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 1px 6px rgba(243,111,33,.25));
}
.brand-sub {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent);
  opacity: .9;
}

.menu {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.menu-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.menu-btn:hover { background: var(--bg-4); color: var(--text-1); }
.menu-btn.active { background: var(--accent-dim); color: var(--accent); }
.menu-btn.active .menu-icon { stroke: var(--accent); }
.menu-icon { width: 17px; height: 17px; flex-shrink: 0; stroke: var(--text-3); transition: stroke .15s; }
.menu-btn:hover .menu-icon { stroke: var(--text-1); }
.btn-danger.hidden { display: none !important; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  font-size: 12px;
  color: var(--text-2);
  min-width: 0;
}
.user-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.user-role {
  font-size: 10px;
  color: var(--text-4);
  margin-left: 2px;
  white-space: nowrap;
}

/* Sidebar colapsada */
body.sidebar-collapsed .sidebar {
  width: 0;
  min-width: 0;
  border-right-color: transparent;
}

/* ── Main ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  flex-shrink: 0;
  z-index: 50;
}
.left-tools  { display: flex; align-items: center; gap: 8px; min-width: 0; }
.center-tools { display: flex; align-items: center; gap: 8px; flex: 1; justify-content: center; }
.right-tools  { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.topbar-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Views ── */
.view {
  display: none;
  flex: 1;
  overflow: hidden;
}
.view.active {
  display: flex;
  flex-direction: column;
}

/* ══════════════════════════════════════════════════════
   BOTÕES
   ══════════════════════════════════════════════════════ */

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary.full-width { width: 100%; justify-content: center; padding: 12px; font-size: 14px; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--bg-4); color: var(--text-1); border-color: var(--text-4); }

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  background: var(--red-dim);
  color: #ff6b6b;
  border: 1px solid rgba(202,0,0,.3);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.btn-danger:hover { background: rgba(202,0,0,.3); color: #ff4444; }

.btn-rec-all {
  background: var(--red-dim);
  color: #ff6b6b;
  border: 1px solid rgba(202,0,0,.3);
}
.btn-rec-all.active {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
  animation: pulse-red 2s infinite;
}
@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(202, 0, 0, 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(202, 0, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(202, 0, 0, 0); }
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: transparent;
  color: var(--text-2);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-4); color: var(--text-1); }
.btn-icon svg { width: 18px; height: 18px; }

/* ══════════════════════════════════════════════════════
   FORMULÁRIOS
   ══════════════════════════════════════════════════════ */

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.field input, .field select, .field textarea {
  padding: 9px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 13.5px;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.field input::placeholder { color: var(--text-4); }
.field select option { background: var(--bg-3); }
.req { color: var(--accent); }

.field-row {
  display: flex;
  gap: 12px;
  margin-bottom: 0;
}
.field-row .field { flex: 1; margin-bottom: 14px; }

.transcode-opts { margin-bottom: 4px; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 14px;
  user-select: none;
}
.checkbox-label input[type="checkbox"] { display: none; }
.checkmark {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-2);
  border-radius: 4px;
  background: var(--bg-3);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
}
.checkbox-label input:checked + .checkmark {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox-label input:checked + .checkmark::after {
  content: '';
  width: 5px;
  height: 9px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
}
.checkbox-label.small { font-size: 12px; margin-bottom: 0; }

.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.search-input {
  padding: 7px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
  width: 160px;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-4); }

/* ── Mensagens inline ── */
.msg-inline {
  font-size: 12.5px;
  min-height: 18px;
  color: var(--text-3);
  margin-top: 4px;
}
.msg-inline.ok  { color: var(--green); }
.msg-inline.err { color: #ff6b6b; }
.msg-error {
  font-size: 13px;
  color: #ff6b6b;
  min-height: 18px;
  text-align: center;
  margin-top: 8px;
}

/* ── Tip box ── */
.tip-box {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--text-3);
  margin-top: 8px;
}
.tip-box strong { color: var(--accent); }

/* ── Permissões ── */
.permissions-grid {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.permissions-title {
  grid-column: 1 / -1;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.permissions-grid.disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ── Badge ── */
.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--bg-4);
  color: var(--text-3);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.ok  { background: rgba(34,197,94,.15); color: var(--green); border-color: rgba(34,197,94,.3); }
.badge.err { background: var(--red-dim); color: #ff6b6b; border-color: rgba(202,0,0,.3); }

.count-badge {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  background: var(--accent-dim);
  color: var(--accent);
  white-space: nowrap;
}

/* ══════════════════════════════════════════════════════
   PAINÉIS
   ══════════════════════════════════════════════════════ */

.panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  overflow: hidden;
}
.panel h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
}
.panel h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
}
.panel-subpanel {
  background: var(--bg-3);
  border-color: var(--border-2);
  padding: 14px;
  margin-bottom: 16px;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.panel-header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Cameras layout ── */
.cameras-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  align-content: start;
}

/* ── Camera list ── */
.camera-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 600px;
  overflow-y: auto;
}

.cam-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: border-color .15s;
}
.cam-card:hover { border-color: var(--border-2); }
.cam-card.editing { border-color: var(--accent); background: var(--accent-dim); }

.cam-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}
.cam-card-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-4);
  flex-shrink: 0;
}
.cam-card-dot.online { background: var(--green); box-shadow: 0 0 6px rgba(34,197,94,.5); }
.cam-card-dot.offline { background: var(--text-4); }

.cam-card-name {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-1);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cam-card-badges { display: flex; gap: 4px; flex-shrink: 0; }
.cam-badge {
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
}
.cam-badge.live { background: rgba(34,197,94,.15); color: var(--green); }
.cam-badge.rec  { background: var(--red-dim); color: #ff6b6b; animation: blink 1.2s infinite; }
.cam-badge.off  { background: var(--bg-4); color: var(--text-4); }

.cam-card-rtsp {
  font-size: 11px;
  color: var(--text-4);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 4px;
  font-family: monospace;
}
.cam-card-meta {
  font-size: 11.5px;
  color: var(--text-3);
  margin-bottom: 8px;
}
.cam-card-error {
  font-size: 11px;
  color: #ff9966;
  background: rgba(202,0,0,.1);
  border-radius: 4px;
  padding: 4px 8px;
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cam-card-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.cam-card-actions button {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-2);
  background: var(--bg-4);
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.cam-card-actions button:hover { background: var(--bg-5); color: var(--text-1); }
.cam-card-actions button.btn-danger { background: var(--red-dim); color: #ff6b6b; border-color: rgba(202,0,0,.3); }
.cam-card-actions button.btn-danger:hover { background: rgba(202,0,0,.3); }

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--text-4);
  text-align: center;
}
.empty-state-icon {
  font-size: 32px;
  opacity: .5;
}
.empty-state p { font-size: 13px; }

/* ══════════════════════════════════════════════════════
   MONITOR — GRID DE CÂMERAS
   ══════════════════════════════════════════════════════ */

#view-monitor {
  background: #000;
  overflow: hidden;
}

.camera-grid {
  flex: 1;
  display: grid;
  width: 100%;
  height: 100%;
  gap: 2px;
  background: #000;
  overflow: hidden;
}

/* Layouts */
.camera-grid.layout-1  { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.camera-grid.layout-4  { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
.camera-grid.layout-6  { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); }
.camera-grid.layout-9  { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.camera-grid.layout-12 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(3, 1fr); }
.camera-grid.layout-16 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }

/* Tile */
.camera-tile {
  position: relative;
  background: #0a0a0a;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.camera-tile:hover .camera-overlay { opacity: 1; }
.camera-tile.stream-playing .cam-loading-indicator { display: none; }

.empty-tile {
  background: #050505;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-4);
  cursor: default;
}

/* Media container */
.camera-media {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  will-change: transform;
  touch-action: none;
}
.camera-media video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.camera-tile.zoomed { cursor: grab; }
.camera-tile.zoomed:active { cursor: grabbing; }

/* Loading indicator */
.cam-loading-indicator {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0,0,0,.85);
  font-size: 11px;
  color: var(--text-3);
  z-index: 2;
}

/* Overlay */
.camera-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.85));
  padding: 24px 10px 8px;
  opacity: 0;
  transition: opacity .2s;
  z-index: 3;
  pointer-events: none;
}
.camera-tile:hover .camera-overlay,
.camera-tile:focus-within .camera-overlay { opacity: 1; }
.camera-overlay .cam-tile-actions { pointer-events: auto; }

.camera-tile-name {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
}
.camera-tile-meta {
  font-size: 10.5px;
  color: rgba(255,255,255,.7);
  margin-bottom: 6px;
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
}

.cam-tile-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.monitor-rec-btn {
  padding: 4px 9px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(0,0,0,.5);
  color: #fff;
  transition: background .15s;
  backdrop-filter: blur(4px);
}
.monitor-rec-btn:hover { background: rgba(255,255,255,.15); }
.monitor-rec-btn.btn-danger {
  background: rgba(202,0,0,.6);
  border-color: rgba(202,0,0,.5);
  animation: blink 1.2s infinite;
}

/* Botão solo (visualizar câmera individual) */
.monitor-solo-btn {
  padding: 4px 9px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(0,0,0,.5);
  color: #fff;
  transition: background .15s;
  backdrop-filter: blur(4px);
}
.monitor-solo-btn:hover { background: rgba(243,111,33,.5); border-color: rgba(243,111,33,.5); }

/* Status dot no tile */
.monitor-status-dot {
  position: absolute;
  top: 7px;
  left: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-4);
  z-index: 4;
  border: 1px solid rgba(0,0,0,.5);
}
.monitor-status-dot.live {
  background: var(--green);
  box-shadow: 0 0 6px rgba(34,197,94,.7);
  animation: pulse 2s infinite;
}

/* Badge REC no tile */
.monitor-rec-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(202,0,0,.85);
  color: #fff;
  z-index: 4;
  animation: blink 1.2s infinite;
}

/* ══════════════════════════════════════════════════════
   SPINNER
   ══════════════════════════════════════════════════════ */

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(243,111,33,.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ══════════════════════════════════════════════════════
   GRAVAÇÕES
   ══════════════════════════════════════════════════════ */

#view-recordings {
  overflow-y: auto;
  padding: 16px;
}
#view-recordings .panel { max-width: 100%; }

.rec-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.rec-stat {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  min-width: 100px;
  text-align: center;
}
.rec-stat-val   { font-size: 20px; font-weight: 800; color: var(--accent); }
.rec-stat-label { font-size: 11px; color: var(--text-4); margin-top: 2px; }

.rec-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.rec-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.rec-filters select {
  padding: 6px 10px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 12.5px;
  outline: none;
  cursor: pointer;
}

.recordings-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 500px;
  overflow-y: auto;
}

.rec-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s;
}
.rec-card:hover { border-color: var(--border-2); }
.rec-card.selected { border-color: var(--accent); background: var(--accent-dim); }

.rec-file-icon { font-size: 20px; flex-shrink: 0; }
.rec-card-info { flex: 1; min-width: 0; }
.rec-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rec-card-meta { font-size: 11.5px; color: var(--text-4); margin-top: 2px; }
.rec-card-actions { display: flex; gap: 5px; flex-shrink: 0; }
.rec-card-actions button {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-2);
  background: var(--bg-4);
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.rec-card-actions button:hover { background: var(--bg-5); color: var(--text-1); }
.rec-card-actions .btn-danger { background: var(--red-dim); color: #ff6b6b; border-color: rgba(202,0,0,.3); }
.rec-card-actions .btn-danger:hover { background: rgba(202,0,0,.3); }

/* ══════════════════════════════════════════════════════
   STATUS / HEALTH
   ══════════════════════════════════════════════════════ */

#view-settings {
  overflow-y: auto;
  padding: 16px;
}
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-content: start;
}

.health-box, .streams-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.health-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.health-row span:first-child { color: var(--text-3); }
.health-row span:last-child  { color: var(--text-1); font-weight: 600; }
.health-row .ok  { color: var(--green); }
.health-row .err { color: #ff6b6b; }

.stream-row {
  padding: 10px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.stream-row-name { font-weight: 700; color: var(--text-1); margin-bottom: 3px; }
.stream-row-meta { color: var(--text-4); font-size: 11.5px; }
.stream-row-err  { color: #ff9966; font-size: 11px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ══════════════════════════════════════════════════════
   USUÁRIOS
   ══════════════════════════════════════════════════════ */

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.user-row-info { flex: 1; min-width: 0; }
.user-row-name { font-size: 13px; font-weight: 700; color: var(--text-1); }
.user-row-meta { font-size: 11.5px; color: var(--text-4); }
.user-role-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
}
.user-role-badge.admin    { background: var(--accent-dim); color: var(--accent); }
.user-role-badge.operator { background: var(--bg-4); color: var(--text-3); }

/* ══════════════════════════════════════════════════════
   MODAIS
   ══════════════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 820px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-box.small { max-width: 400px; padding: 24px; }
.modal-box.small h3 { font-size: 16px; margin-bottom: 10px; }
.modal-box.small p  { font-size: 13.5px; color: var(--text-2); margin-bottom: 20px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 14px; font-weight: 700; color: var(--text-1); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

#modalVideo {
  width: 100%;
  max-height: 70vh;
  background: #000;
  display: block;
}

/* ══════════════════════════════════════════════════════
   SOLO VIEW — câmera individual em tela cheia
   ══════════════════════════════════════════════════════ */

.solo-overlay {
  z-index: 2000;
  padding: 0;
  background: rgba(0,0,0,.97);
}
.solo-box {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: #000;
}
.solo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(2,1,1,.95);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 10px;
}
.solo-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.solo-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.solo-rec-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--border-2);
  background: transparent;
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.solo-rec-btn:hover { background: var(--bg-4); color: var(--text-1); }
.solo-rec-btn.recording {
  background: var(--red-dim);
  color: #ff6b6b;
  border-color: rgba(202,0,0,.4);
  animation: blink 1.2s infinite;
}

.solo-video-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
}
.solo-video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.solo-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0,0,0,.8);
  color: var(--text-3);
  font-size: 13px;
}
.solo-loading.hidden { display: none; }

/* ══════════════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════════════ */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-4);
  color: var(--text-1);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid var(--border-2);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .3s;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.ok   { background: rgba(34,197,94,.2); border-color: rgba(34,197,94,.4); color: #4ade80; }
.toast.err  { background: var(--red-dim); border-color: rgba(202,0,0,.4); color: #ff6b6b; }

/* ══════════════════════════════════════════════════════
   FULLSCREEN
   ══════════════════════════════════════════════════════ */

body.fullscreen-grid .sidebar,
body.fullscreen-grid .topbar { display: none; }
body.fullscreen-grid .main { height: 100vh; }
body.fullscreen-grid #view-monitor {
  position: fixed;
  inset: 0;
  z-index: 500;
}
body.fullscreen-grid .camera-grid {
  height: 100vh;
}

/* ══════════════════════════════════════════════════════
   ANIMAÇÕES
   ══════════════════════════════════════════════════════ */

@keyframes spin  { to { transform: rotate(360deg); } }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 6px rgba(34,197,94,.7); }
  50%     { box-shadow: 0 0 12px rgba(34,197,94,.9); }
}

/* ══════════════════════════════════════════════════════
   RESPONSIVO — TABLET (≤ 1100px)
   ══════════════════════════════════════════════════════ */

@media (max-width: 1100px) {
  :root { --sidebar-w: 190px; }

  .cameras-layout {
    grid-template-columns: 320px 1fr;
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

/* ══════════════════════════════════════════════════════
   RESPONSIVO — MOBILE (≤ 768px)
   ══════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  :root {
    --sidebar-w: 240px;
    --topbar-h: 48px;
  }

  /* Sidebar vira drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s ease, width .25s ease;
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
    box-shadow: 4px 0 20px rgba(0,0,0,.6);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  /* Overlay escuro quando sidebar aberta */
  body.sidebar-open::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 199;
  }

  /* Main ocupa toda a largura */
  .main { width: 100%; }

  /* Topbar mobile */
  .topbar { padding: 0 10px; gap: 6px; }
  .center-tools { gap: 5px; }
  .btn-label { display: none; }
  #layoutSelect { font-size: 12px; padding: 5px 8px; }

  /* Grid mobile — 1 coluna por padrão, mas mantém o layout selecionado */
  .camera-grid.layout-9,
  .camera-grid.layout-12,
  .camera-grid.layout-16 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: auto;
  }
  .camera-grid.layout-6 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: auto;
  }
  .camera-grid.layout-4 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: auto;
  }
  .camera-grid.layout-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  /* Tiles com altura fixa no mobile */
  .camera-tile {
    height: 160px;
  }
  .camera-grid.layout-1 .camera-tile {
    height: calc(100vh - var(--topbar-h));
  }

  /* Overlay sempre visível no mobile */
  .camera-overlay { opacity: 1; }

  /* Cameras layout empilhado */
  .cameras-layout {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }

  /* Gravações */
  #view-recordings { padding: 10px; }
  .rec-stats { gap: 8px; }
  .rec-stat { padding: 8px 12px; min-width: 80px; }
  .rec-stat-val { font-size: 16px; }
  .rec-toolbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .rec-filters { width: 100%; }
  .rec-filters select { flex: 1; }
  .rec-card { flex-wrap: wrap; }
  .rec-card-actions { width: 100%; justify-content: flex-end; }

  /* Status */
  #view-settings { padding: 10px; }
  .settings-grid { grid-template-columns: 1fr; gap: 10px; }

  /* Painéis */
  .panel { padding: 14px; }
  .panel-header { flex-direction: column; align-items: flex-start; }
  .panel-header-tools { width: 100%; }
  .search-input { width: 100%; flex: 1; }

  /* Form */
  .field-row { flex-direction: column; gap: 0; }
  .form-actions { flex-direction: column; }
  .form-actions .btn-primary,
  .form-actions .btn-ghost { width: 100%; justify-content: center; }

  /* Login */
  .login-card { padding: 28px 20px; }

  /* Solo view */
  .solo-header { padding: 8px 12px; }
  .solo-title { font-size: 13px; }
}

/* ══════════════════════════════════════════════════════
   RESPONSIVO — MOBILE PEQUENO (≤ 480px)
   ══════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  .camera-tile { height: 130px; }
  .camera-grid.layout-1 .camera-tile { height: calc(100vh - var(--topbar-h)); }
  .camera-tile-name { font-size: 10px; }
  .camera-tile-meta { font-size: 9px; }
  .monitor-rec-btn, .monitor-solo-btn { font-size: 10px; padding: 3px 7px; }
}

/* ══════════════════════════════════════════════════════
   SELECT GLOBAL
   ══════════════════════════════════════════════════════ */

select {
  padding: 7px 10px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}
select:focus { border-color: var(--accent); }
select option { background: var(--bg-3); }
