/* ==========================================================================
   CamerasTVE - CENTRAL DE MONITORAMENTO
   Design System: Sala de Controle / CCTV Video Wall Studio
   ========================================================================== */

:root {
  --bg-darkest: #070709;
  --bg-panel: #0e0f12;
  --bg-surface: #14151a;
  --bg-hover: #1c1e24;

  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-focus: rgba(240, 156, 35, 0.5);

  --text-primary: #f8fafc;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  /* Identidade Visual Catve Oficial */
  --catve-gradient: linear-gradient(90deg, rgb(240, 156, 35) 0%, rgb(165, 29, 64) 20%, rgb(105, 47, 135) 40%, rgb(50, 83, 157) 60%, rgb(18, 83, 41) 80%, rgb(145, 188, 62) 100%);
  --accent-amber: #f09c23;
  --accent-red: #ef4444;
  --accent-red-glow: rgba(239, 68, 68, 0.5);
  --accent-cyan: #38bdf8;
  --accent-emerald: #10b981;

  --header-height: 52px;
  --footer-height: 32px;
  --sidebar-width: 290px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Outfit', 'Inter', sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-darkest);
  color: var(--text-primary);
  font-family: var(--font-sans);
  overflow: hidden;
  user-select: none;
}

/* ==========================================================================
   BARRA SUPERIOR COM AS OPÇÕES
   ========================================================================== */

.app-header {
  height: var(--header-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
  z-index: 50;
  position: relative;
}

.header-left, .header-center, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: #fff;
}

.live-dot {
  width: 8px;
  height: 8px;
  background-color: var(--accent-red);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-red-glow);
  animation: pulse-live 1.8s infinite;
}

.stats-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.control-select {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.control-select:focus {
  border-color: var(--accent-blue);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--bg-surface);
  color: #fff;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-action:hover {
  background: var(--bg-hover);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-highlight {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.18);
  font-weight: 600;
}

.btn-highlight:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: var(--accent-amber);
  box-shadow: 0 0 12px rgba(240, 156, 35, 0.3);
}

/* ==========================================================================
   SELETOR INTERATIVO DE GRADE (POPOVER ESTILO CRIAÇÃO DE TABELA)
   ========================================================================== */

.grid-picker-wrapper {
  position: relative;
}

.grid-picker-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-focus);
  border-radius: 8px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.8), 0 0 15px rgba(59, 130, 246, 0.15);
  padding: 12px;
  width: 290px;
  z-index: 100;
  display: none;
  flex-direction: column;
  gap: 10px;
}

.grid-picker-popover.active {
  display: flex;
}

.picker-top-option {
  width: 100%;
}

.btn-picker-option {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.btn-picker-option:hover {
  background: var(--bg-hover);
  border-color: var(--accent-cyan);
}

.btn-picker-option.active {
  background: rgba(6, 182, 212, 0.15);
  border-color: var(--accent-cyan);
}

.btn-picker-option .opt-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
}

.btn-picker-option .opt-desc {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.picker-divider {
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-align: center;
  position: relative;
}

.picker-divider::before, .picker-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 20%;
  height: 1px;
  background: var(--border-subtle);
}

.picker-divider::before { left: 0; }
.picker-divider::after { right: 0; }

.picker-matrix-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 4px;
  background: var(--bg-darkest);
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
}


.picker-cell {
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.1s ease, border-color 0.1s ease;
}

.picker-cell.highlighted {
  background: rgba(59, 130, 246, 0.5);
  border-color: #3b82f6;
  box-shadow: 0 0 4px rgba(59, 130, 246, 0.4);
}

.picker-preview-bar {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-cyan);
  padding: 2px 0;
}

/* ==========================================================================
   LAYOUT GERAL: SIDEBAR + ÁREA DE CÂMERAS
   ========================================================================== */

.app-layout {
  display: flex;
  height: calc(100vh - var(--header-height) - var(--footer-height));
  width: 100vw;
  overflow: hidden;
}

/* ==========================================================================
   BARRA LATERAL DE SELEÇÃO DE CÂMERAS
   ========================================================================== */

.cameras-sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), margin-left 0.25s ease;
  overflow: hidden;
}

.cameras-sidebar.collapsed {
  width: 0;
  margin-left: 0;
  border-right: none;
}

.sidebar-header {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-title {
  font-size: 0.88rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.sidebar-quick-actions {
  display: flex;
  gap: 6px;
}

.btn-xs {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.btn-xs:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

.sidebar-search {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-search input {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: #fff;
  font-size: 0.8rem;
  outline: none;
}

.sidebar-search input:focus {
  border-color: var(--accent-amber);
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.city-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.city-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  user-select: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.city-group-header:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
}

.city-group-title {
  display: flex;
  align-items: center;
  gap: 7px;
}

.city-chevron {
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--text-muted);
  flex-shrink: 0;
}

.city-group-header:hover .city-chevron {
  color: var(--accent-cyan);
}

.city-group.collapsed .city-chevron {
  transform: rotate(-90deg);
}

.city-cams-container {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-left: 4px;
}

.city-group.collapsed .city-cams-container {
  display: none;
}

.camera-check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: grab;
  font-size: 0.82rem;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease, transform 0.1s ease;
  user-select: none;
}

.camera-check-item:hover {
  background: var(--bg-hover);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.08);
}

.camera-check-item:active {
  cursor: grabbing;
}

.camera-check-item.dragging {
  opacity: 0.35;
  background: rgba(59, 130, 246, 0.25);
  border-color: var(--accent-blue);
  transform: scale(0.98);
}

.camera-check-item.drag-over {
  border-top: 2px solid var(--accent-cyan);
  background: rgba(6, 182, 212, 0.18);
  box-shadow: 0 -2px 8px rgba(6, 182, 212, 0.3);
}

/* NÚMERO DE ORDEM NA LISTA */
.camera-order-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 18px;
  text-align: center;
  background: rgba(255, 255, 255, 0.05);
  padding: 1px 4px;
  border-radius: 3px;
}

/* TAG DE CIDADE NA LISTA */
.camera-city-tag {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.12);
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.drag-handle-sidebar {
  cursor: grab;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 2px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  opacity: 0.6;
  transition: opacity 0.12s ease, color 0.12s ease, background 0.12s ease;
  user-select: none;
}

.drag-handle-sidebar:hover {
  opacity: 1;
  color: var(--accent-cyan);
  background: rgba(255, 255, 255, 0.08);
}

.drag-handle-sidebar:active {
  cursor: grabbing;
}

/* QUANDO QUALQUER ELEMENTO ESTIVER SENDO ARRASTADO, DESATIVE EVENTOS INTERNOS PARA EVITAR CONFLITOS DE DRAGLEAVE */
body.is-dragging .camera-card *,
body.is-dragging .camera-check-item * {
  pointer-events: none !important;
}

body.is-dragging .camera-card,
body.is-dragging .camera-check-item {
  pointer-events: auto !important;
}

.camera-check-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.checkbox-custom {
  appearance: none;
  width: 16px;
  height: 16px;

  border: 1.5px solid var(--text-muted);
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.checkbox-custom:checked {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
}

.checkbox-custom:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ==========================================================================
   ÁREA DAS CÂMERAS (TELA DE MONITORAMENTO)
   ========================================================================== */

.cameras-screen {
  flex: 1;
  height: 100%;
  background-color: var(--bg-darkest);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  padding: 4px;
}

/* MODO DE PREENCHIMENTO NA TELA */
.cameras-screen.fit-mode {
  overflow: hidden;
}

.cameras-screen.scroll-mode {
  overflow-y: auto;
}

/* QUANDO ENTRA EM TELA CHEIA: OCUPA 100% DA TELA SEM NADA AO REDOR */
.cameras-screen:fullscreen {
  width: 100vw;
  height: 100vh;
  padding: 2px;
  background: #000;
}

/* ==========================================================================
   GRADE DAS CÂMERAS (SEMPRE EM 16:9, ESPAÇAMENTO OTIMIZADO)
   ========================================================================== */

.cameras-grid {
  display: grid;
  gap: 4px;
  width: 100%;
  height: 100%;
  align-content: center;
  justify-content: center;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* RÓTULOS PERMANENTES DE NOME E CIDADE */
.camera-permanent-label {
  position: absolute;
  bottom: 6px;
  left: 6px;
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(7, 10, 18, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  color: #f1f5f9;
  pointer-events: none;
  z-index: 6;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  transition: opacity 0.15s ease;
}

.camera-permanent-label .label-city {
  color: var(--accent-cyan);
  font-weight: 700;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.camera-permanent-label .label-name {
  font-weight: 600;
  color: #fff;
}

.show-labels .camera-permanent-label {
  display: inline-flex;
}

.camera-card:hover .camera-permanent-label {
  opacity: 0;
}

/* MATRIZ CONFIGURÁVEL POR VARIÁVEIS CSS */
.cameras-grid[style*="--matrix-cols"] {
  grid-template-columns: repeat(var(--matrix-cols, 2), 1fr);
  grid-template-rows: repeat(var(--matrix-rows, 2), 1fr);
}


/* PRESETS DE MATRIZ MANUAL */
.cameras-grid.matrix-1x1 {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}
.cameras-grid.matrix-2x1 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: 1fr;
}
.cameras-grid.matrix-3x1 {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: 1fr;
}
.cameras-grid.matrix-2x2 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
.cameras-grid.matrix-3x2 {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
.cameras-grid.matrix-3x3 {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.cameras-grid.matrix-4x2 {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
.cameras-grid.matrix-4x3 {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.cameras-grid.matrix-4x4 {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}
.cameras-grid.matrix-5x3 {
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.cameras-grid.matrix-5x4 {
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(4, 1fr);
}
.cameras-grid.matrix-6x4 {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(4, 1fr);
}
.cameras-grid.matrix-6x5 {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(5, 1fr);
}

/* ==========================================================================
   FORMATOS DINÂMICOS INTELIGENTES
   ========================================================================== */

/* 5 Câmeras: Linha de 3 + Linha de 2 */
.cameras-grid.matrix-dynamic-5 {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
.cameras-grid.matrix-dynamic-5 > .camera-card:nth-child(1),
.cameras-grid.matrix-dynamic-5 > .camera-card:nth-child(2),
.cameras-grid.matrix-dynamic-5 > .camera-card:nth-child(3) {
  grid-column: span 2; /* 3 x 2 = 6 frações */
}
.cameras-grid.matrix-dynamic-5 > .camera-card:nth-child(4),
.cameras-grid.matrix-dynamic-5 > .camera-card:nth-child(5) {
  grid-column: span 3; /* 2 x 3 = 6 frações */
}

/* 7 Câmeras: Linha de 4 + Linha de 3 */
.cameras-grid.matrix-dynamic-7 {
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
.cameras-grid.matrix-dynamic-7 > .camera-card:nth-child(1),
.cameras-grid.matrix-dynamic-7 > .camera-card:nth-child(2),
.cameras-grid.matrix-dynamic-7 > .camera-card:nth-child(3),
.cameras-grid.matrix-dynamic-7 > .camera-card:nth-child(4) {
  grid-column: span 3; /* 4 x 3 = 12 frações */
}
.cameras-grid.matrix-dynamic-7 > .camera-card:nth-child(5),
.cameras-grid.matrix-dynamic-7 > .camera-card:nth-child(6),
.cameras-grid.matrix-dynamic-7 > .camera-card:nth-child(7) {
  grid-column: span 4; /* 3 x 4 = 12 frações */
}

/* 10 Câmeras: 5 colunas x 2 linhas */
.cameras-grid.matrix-dynamic-10 {
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

/* 11 Câmeras: Linha de 4 + Linha de 4 + Linha de 3 (3 Linhas 100% preenchidas) */
.cameras-grid.matrix-dynamic-11 {
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.cameras-grid.matrix-dynamic-11 > .camera-card:nth-child(-n+8) {
  grid-column: span 3; /* 4 câmeras por linha x 3 = 12 frações */
}
.cameras-grid.matrix-dynamic-11 > .camera-card:nth-child(n+9) {
  grid-column: span 4; /* 3 câmeras x 4 = 12 frações */
}

/* 13 Câmeras: Linha de 5 + Linha de 4 + Linha de 4 (3 Linhas 100% preenchidas sem deixar 1 câmera isolada) */
.cameras-grid.matrix-dynamic-13 {
  grid-template-columns: repeat(20, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.cameras-grid.matrix-dynamic-13 > .camera-card:nth-child(-n+5) {
  grid-column: span 4; /* 5 câmeras x 4 = 20 frações */
}
.cameras-grid.matrix-dynamic-13 > .camera-card:nth-child(n+6) {
  grid-column: span 5; /* 4 câmeras x 5 = 20 frações */
}

/* 14 Câmeras: Linha de 5 + Linha de 5 + Linha de 4 (3 Linhas balanceadas) */
.cameras-grid.matrix-dynamic-14 {
  grid-template-columns: repeat(20, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.cameras-grid.matrix-dynamic-14 > .camera-card:nth-child(-n+10) {
  grid-column: span 4; /* 5 câmeras por linha x 4 = 20 frações */
}
.cameras-grid.matrix-dynamic-14 > .camera-card:nth-child(n+11) {
  grid-column: span 5; /* 4 câmeras x 5 = 20 frações */
}

/* 15 Câmeras: 5 colunas x 3 linhas */
.cameras-grid.matrix-dynamic-15 {
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

/* ==========================================================================
   CARD DA CÂMERA (SEMPRE EM 16x9, LIMPO, COM OPÇÕES NO HOVER)
   ========================================================================== */

.camera-card {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9; /* SEMPRE 16x9 */
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.camera-card:active {
  cursor: grabbing;
}

.camera-card.dragging {
  opacity: 0.35;
  transform: scale(0.95);
  border-color: var(--accent-blue);
}

.camera-card.drag-over {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 16px rgba(6, 182, 212, 0.6);
  transform: scale(1.02);
}


.camera-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  user-select: none;
}

.card-drag-handle {
  cursor: grab;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.95rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  transition: all 0.15s ease;
  user-select: none;
}

.card-drag-handle:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.card-drag-handle:active {
  cursor: grabbing;
}


/* SPINNER DE CARREGAMENTO */
.camera-loading {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 5;
  pointer-events: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ==========================================================================
   HOVER OVERLAY: AO PASSAR O MOUSE EM CIMA, MOSTRAR NOME E OPÇÕES
   ========================================================================== */

.camera-hover-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 12px;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.75) 0%,
    rgba(0, 0, 0, 0) 40%,
    rgba(0, 0, 0, 0) 60%,
    rgba(0, 0, 0, 0.85) 100%
  );
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10;
}

.camera-card:hover .camera-hover-overlay {
  opacity: 1;
  pointer-events: auto;
}

.hover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hover-info {
  display: flex;
  flex-direction: column;
}

.hover-camera-name {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

.hover-camera-city {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-cyan);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

.hover-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.status-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-indicator.live {
  background: var(--accent-red);
  box-shadow: 0 0 6px var(--accent-red);
}

.status-indicator.connecting {
  background: #f59e0b;
}

.status-indicator.paused {
  background: var(--text-muted);
}

.status-indicator.error {
  background: #f43f5e;
}

.hover-actions-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.action-chip-btn {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #cbd5e1;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.action-chip-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  transform: scale(1.08);
}

.action-chip-btn.favorited {
  color: #fbbf24;
}

.action-chip-btn.btn-remove:hover {
  color: #f43f5e;
  background: rgba(244, 63, 94, 0.25);
  border-color: rgba(244, 63, 94, 0.5);
}


/* ==========================================================================
   RODAPÉ FIXO COM DEGRADÊ OFICIAL CATVE CITANDO A FONTE DAS IMAGENS
   ========================================================================== */

.app-footer {
  height: var(--footer-height);
  background: var(--catve-gradient);
  border-top: 1px solid rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.5);
  z-index: 40;
}

.footer-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #ffffff;
  text-decoration: none;
  font-size: 0.77rem;
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  transition: opacity 0.15s ease, transform 0.12s ease;
  text-align: center;
}

.footer-link strong {
  font-weight: 800;
  color: #ffffff;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.footer-link svg {
  flex-shrink: 0;
  opacity: 0.9;
}

.footer-link:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

/* ==========================================================================
   ESTADO VAZIO / MODAL DE FOCO / TOASTS
   ========================================================================== */

.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.empty-state.active {
  display: flex;
}

.empty-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.empty-subtitle {
  font-size: 0.85rem;
}

/* Modal de Foco / Cinema */
.focus-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.94);
  backdrop-filter: blur(16px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.focus-modal.active {
  display: flex;
}

.focus-content {
  width: 100%;
  max-width: 1280px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow: hidden;
}

.focus-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.focus-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.focus-body {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

.focus-body video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 40px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: #fff;
  font-size: 0.82rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  animation: toast-in 0.25s ease;
}

/* Animações */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse-live {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.85); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   RESPONSIVIDADE MOBILE (LAYOUT CONFORME MOCKUP:
   TOPO FIXO + GRID FIXO NO MEIO + LISTA DE CÂMERAS SCROLLÁVEL EMBAIXO)
   ========================================================================== */

@media (max-width: 768px) {
  :root {
    --header-height: auto;
    --footer-height: 30px;
    --sidebar-width: 100%;
  }

  /* 1. NOME E BOTÃO PARA OPÇÕES (FIXO NO TOPO) */
  .app-header {
    height: auto;
    min-height: 48px;
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
  }

  .header-left {
    flex: 1;
    justify-content: flex-start;
  }

  /* No mobile, a lista de câmeras já fica visível embaixo, botão de toggle da sidebar desktop não é necessário */
  #btn-toggle-sidebar {
    display: none;
  }

  .header-right {
    gap: 6px;
  }

  .header-center {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .header-center::-webkit-scrollbar {
    display: none;
  }

  .brand-text {
    font-size: 0.95rem;
  }

  .stats-text {
    font-size: 0.72rem;
  }

  .btn-action {
    padding: 4px 8px;
    font-size: 0.74rem;
  }

  .control-select {
    padding: 4px 8px;
    font-size: 0.74rem;
  }

  .control-label {
    font-size: 0.68rem;
  }



/* TELA CHEIA EMULADA PARA IOS SAFARI (IPHONE / IPAD) */
body.ios-fullscreen-active {
  overflow: hidden !important;
}

body.ios-fullscreen-active #cameras-screen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  aspect-ratio: unset !important;
  padding: env(safe-area-inset-top, 6px) env(safe-area-inset-right, 6px) env(safe-area-inset-bottom, 6px) env(safe-area-inset-left, 6px) !important;
  background: #000 !important;
  z-index: 99999 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

body.ios-fullscreen-active #cameras-screen .cameras-grid {
  width: 100% !important;
  height: 100% !important;
  max-width: 100vw !important;
  max-height: 100dvh !important;
  aspect-ratio: 16 / 9;
}

  /* LAYOUT VERTICAL MOBILE */
  .app-layout {
    flex-direction: column;
    height: calc(100dvh - 86px - var(--footer-height));
    min-height: 0;
    overflow: hidden;
  }

  /* 2. GRID DAS TELAS (FIXO NO MEIO SUPERIOR COM PROPORÇÃO RIGOROSAMENTE 16:9) */
  .cameras-screen {
    order: 1;
    width: 100%;
    aspect-ratio: 16 / 9;
    height: auto;
    max-height: calc(100vw * 9 / 16);
    flex: none;
    flex-shrink: 0;
    padding: 2px;
    background: #000;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
  }

  .cameras-grid {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 16 / 9;
  }

  /* QUANDO ENTRA EM TELA CHEIA NATIVA NO CELULAR */
  .cameras-screen:fullscreen {
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    aspect-ratio: unset !important;
    padding: env(safe-area-inset-top, 4px) env(safe-area-inset-right, 4px) env(safe-area-inset-bottom, 4px) env(safe-area-inset-left, 4px) !important;
    background: #000 !important;
    z-index: 99999 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .cameras-screen:fullscreen .cameras-grid {
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: 16 / 9;
  }

  /* 3. LISTA DE CÂMERAS (SCROLLÁVEL EMBAIXO) */
  .cameras-sidebar {
    order: 2;
    width: 100% !important;
    margin-left: 0 !important;
    flex: 1;
    min-height: 0;
    border-right: none;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .cameras-sidebar.collapsed {
    width: 100% !important;
    display: flex !important;
  }

  .sidebar-header {
    padding: 8px 12px;
  }

  .sidebar-search {
    padding: 8px 12px;
  }

  .sidebar-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 10px;
  }

  .camera-check-item {
    padding: 8px 10px;
    font-size: 0.85rem;
  }

  /* 4. BARRA FIXA NO RODAPÉ */
  .app-footer {
    height: var(--footer-height);
    padding: 0 8px;
    flex-shrink: 0;
  }

  .footer-link {
    font-size: 0.68rem;
    gap: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Popover do Seletor de Grade em telas pequenas */
  .grid-picker-popover {
    left: 0;
    width: calc(100vw - 24px);
    max-width: 300px;
  }
}
