/* LibreCam — estilo minimalista oscuro, inspirado en Agent DVR */
:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c2230;
  --border: #2a313c;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #3b82f6;
  --local: #22c55e;
  --cloud: #38bdf8;
  --alarm: #ef4444;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.muted { color: var(--muted); }

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand small { font-weight: 400; margin-left: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--local);
       box-shadow: 0 0 8px var(--local); }
.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  padding: 7px 14px; border-radius: var(--radius); cursor: pointer; font-size: 14px;
}
.tab.active { color: var(--text); background: var(--panel-2); border-color: var(--border); }

/* ---- vistas ---- */
.view { display: none; }
.view.active { display: flex; }
#view-cameras.active { flex-direction: column; gap: 18px; padding: 18px; }

/* ---- timeline layout ---- */
#view-timeline { height: calc(100vh - 55px); }
.sidebar {
  width: 210px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border); padding: 16px; overflow-y: auto;
}
.sidebar h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; color: var(--muted); }
.cam-list { list-style: none; margin: 0 0 20px; padding: 0; }
.cam-list li {
  padding: 9px 11px; border-radius: 8px; cursor: pointer; margin-bottom: 4px;
  display: flex; align-items: center; gap: 8px; border: 1px solid transparent;
}
.cam-list li:hover { background: var(--panel-2); }
.cam-list li.active { background: var(--panel-2); border-color: var(--accent); }
.cam-list li .st { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.cam-list li.online .st { background: var(--local); }

.alarm-list { list-style: none; margin: 0 0 20px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.alarm-list li { display: flex; gap: 9px; align-items: center; cursor: pointer; padding: 4px; border-radius: 8px; }
.alarm-list li:hover { background: var(--panel-2); }
.alarm-list img { width: 52px; height: 32px; object-fit: cover; border-radius: 5px; background: #000; flex-shrink: 0; border: 1px solid var(--border); }
.alarm-list .noimg { width: 52px; height: 32px; border-radius: 5px; background: var(--panel-2); display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 16px; flex-shrink: 0; }
.alarm-list .meta { font-size: 11px; line-height: 1.3; overflow: hidden; }
.alarm-list .meta b { display: block; color: var(--text); font-weight: 500; }
.alarm-list .meta span { color: var(--muted); font-family: ui-monospace, monospace; }
.legend { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw.local { background: var(--local); } .sw.cloud { background: var(--cloud); } .sw.alarm { background: var(--alarm); }

.player-area { flex: 1; display: flex; flex-direction: column; padding: 16px; min-width: 0; }
.video-wrap { position: relative; background: #000; border-radius: var(--radius);
  overflow: hidden; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#player, #mjpeg { width: 100%; height: 100%; object-fit: contain; }
.mode-badge {
  position: absolute; top: 12px; right: 12px; font-family: ui-monospace, monospace;
  font-size: 10px; letter-spacing: 1px; padding: 3px 8px; border-radius: 5px;
  background: rgba(59,130,246,.18); color: var(--accent); border: 1px solid rgba(59,130,246,.4);
}
.mode-badge.mjpeg { background: rgba(56,189,248,.15); color: var(--cloud); border-color: rgba(56,189,248,.4); }
.mode-badge.err { background: rgba(239,68,68,.15); color: var(--alarm); border-color: rgba(239,68,68,.4); }
.ts-overlay {
  position: absolute; top: 12px; left: 12px; font-variant-numeric: tabular-nums;
  background: rgba(0,0,0,.6); padding: 4px 10px; border-radius: 6px; font-size: 13px;
  letter-spacing: .5px;
}

.timeline-controls { display: flex; align-items: center; gap: 12px; margin: 14px 0 8px; }
.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.live { color: var(--alarm); font-weight: 600; }
.cursor-time { font-variant-numeric: tabular-nums; color: var(--muted); }
.spacer { flex: 1; }
.mirror-toggle { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---- la línea de tiempo ---- */
.timeline {
  position: relative; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 0 26px; user-select: none; cursor: crosshair;
}
.track { position: relative; height: 34px; margin: 6px 12px; background: var(--panel-2);
  border-radius: 6px; overflow: hidden; }
.track-label { position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  font-size: 10px; color: var(--muted); z-index: 3; letter-spacing: 1px; }
.ranges, .alarms { position: absolute; inset: 0; }
.range { position: absolute; top: 4px; bottom: 4px; border-radius: 3px; }
.track[data-source="local"] .range { background: var(--local); opacity: .8; }
.track[data-source="cloud"] .range { background: var(--cloud); opacity: .8; }
.alarm-mark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--alarm);
  box-shadow: 0 0 6px var(--alarm); cursor: pointer; }
.alarm-mark::after { content: ''; position: absolute; top: -3px; left: -3px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--alarm); }

.ticks { position: relative; height: 18px; margin: 0 12px; }
.tick { position: absolute; top: 0; font-size: 10px; color: var(--muted);
  transform: translateX(-50%); border-left: 1px solid var(--border); padding-left: 3px; height: 12px; }
.tick span { position: absolute; top: 12px; left: -8px; }
.playhead { position: absolute; top: 6px; bottom: 20px; width: 2px; background: #fff;
  left: 100%; pointer-events: none; box-shadow: 0 0 6px rgba(255,255,255,.7); }
.playhead::before { content: ''; position: absolute; top: -5px; left: -4px;
  border: 5px solid transparent; border-top-color: #fff; }

.hint { margin-top: 10px; font-size: 12px; }

/* ---- vista cámaras ---- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.panel h2 { margin: 0 0 6px; font-size: 17px; }
.discover-form { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.discover-form input { flex: 1; min-width: 160px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; }
.grid { width: 100%; border-collapse: collapse; margin-top: 12px; }
.grid th, .grid td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.grid th { color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 11px; }
.grid td.rtsp { font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { padding: 2px 8px; border-radius: 20px; font-size: 11px; }
.badge.onvif { background: rgba(34,197,94,.15); color: var(--local); }
.badge.scan { background: rgba(56,189,248,.15); color: var(--cloud); }
.badge.online { background: rgba(34,197,94,.15); color: var(--local); }
.badge.offline { background: rgba(239,68,68,.15); color: var(--alarm); }

/* ============ RESPONSIVE / MÓVIL ============ */
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; }
  .brand { font-size: 15px; }
  .tabs { width: 100%; }
  .tab { flex: 1; text-align: center; }

  /* apilar vertical: barra compacta arriba, video grande */
  #view-timeline { flex-direction: column; height: auto; min-height: calc(100vh - 60px); }

  .sidebar {
    width: 100%; border-right: none; border-bottom: 1px solid var(--border);
    padding: 10px 12px; overflow: visible;
  }
  .sidebar h3 { margin: 2px 0 8px; }
  /* cámaras como chips horizontales deslizables */
  .cam-list {
    display: flex; flex-direction: row; overflow-x: auto; gap: 8px;
    margin: 0; padding-bottom: 2px; -webkit-overflow-scrolling: touch;
  }
  .cam-list li { flex: 0 0 auto; margin: 0; white-space: nowrap; }
  /* ocultar secciones secundarias en movil para maximizar el video
     (las alarmas siguen visibles como marcas rojas en la linea de tiempo) */
  .sidebar h3:nth-of-type(2), #alarm-list, .sidebar .legend { display: none; }

  .player-area { padding: 12px; }
  .video-wrap { flex: none; height: 46vh; }         /* video ocupa buena parte */
  #player, #mjpeg { object-fit: contain; }

  .timeline-controls { flex-wrap: wrap; gap: 8px; }
  .timeline-controls .spacer { display: none; }
  .cursor-time { width: 100%; order: 5; }
  .mirror-toggle { order: 4; }

  /* linea de tiempo un poco mas compacta */
  .track { height: 30px; }
  .tick span { font-size: 9px; }
}

@media (max-width: 420px) {
  .video-wrap { height: 40vh; }
  .btn { padding: 7px 11px; font-size: 12px; }
}
