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

:root {
  --header-h: 45px;
}

html { -webkit-text-size-adjust: 100%; }

body {
  background: #0d0d0d;
  color: #e0e0e0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  overscroll-behavior: none;
}

header {
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid #1e1e1e;
  display: flex;
  align-items: center;
  gap: 1.2rem;
  background: #111;
  height: var(--header-h);
}
header h1 { font-size: 1rem; font-weight: 600; color: #fff; white-space: nowrap; }
header .spacer { flex: 1; }
header span { font-size: 0.78rem; color: #666; white-space: nowrap; }
header .hdr-sep { color: #333; }
header .hdr-status { display: inline-flex; align-items: center; }
header .play-btn {
  background: #1a2d44;
  border: 1px solid #3a6ea8;
  color: #7bb8f0;
  border-radius: 5px;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s;
}
header .play-btn:hover:not(:disabled) { background: #1c3e54; }
header .play-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Botón de menú: solo en móvil */
.menu-btn {
  display: none;
  background: #161616;
  border: 1px solid #2a2a2a;
  color: #ccc;
  border-radius: 5px;
  width: 34px;
  height: 30px;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.main {
  display: flex;
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: 210px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #1e1e1e;
  background: #111;
  overflow: hidden;
}

.drawer-backdrop { display: none; }

.card {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid #1e1e1e;
  flex-shrink: 0;
}
.card h3 {
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #555;
  margin-bottom: 0.55rem;
}

/* Selector de producto */
.mode-btns { display: flex; flex-direction: column; gap: 0.3rem; }
.mode-btns button {
  background: #161616;
  border: 1px solid #2a2a2a;
  color: #aaa;
  border-radius: 5px;
  padding: 0.38rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.mode-btns button:disabled   { opacity: 0.3; cursor: not-allowed; }
.mode-btns button.active     { background: #1c2e44; border-color: #3a6ea8; color: #7bb8f0; }
.mode-btns button:not(:disabled):not(.active):hover {
  background: #1e1e1e; border-color: #444; color: #ddd;
}

/* Timeline */
.timeline-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0.8rem 1rem 0.5rem;
}
.timeline-wrap h3 {
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #555;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}
.timeline {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.timeline::-webkit-scrollbar { width: 4px; }
.timeline::-webkit-scrollbar-thumb { background: #222; border-radius: 2px; }

.tl-item {
  background: #161616;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.3rem 0.55rem;
  font-size: 0.76rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  transition: background 0.1s;
}
.tl-item:hover  { background: #1c1c1c; border-color: #2a2a2a; }
.tl-item.active { background: #1a2d44; border-color: #3a6ea8; color: #7bb8f0; }

.tl-badge {
  font-size: 0.62rem;
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
}
.badge-day   { background: #1e2e10; color: #7ab648; }
.badge-night { background: #12203a; color: #4d8fcf; }

.no-data-tl {
  font-size: 0.78rem;
  color: #3a3a3a;
  text-align: center;
  padding: 2rem 0;
}

/* ── Visor ────────────────────────────────────────────────── */
.viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0d0d0d;
  min-width: 0;
}

.viewer-bar {
  padding: 0.55rem 1.2rem;
  border-bottom: 1px solid #1a1a1a;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.78rem;
  color: #666;
  background: #111;
  flex-shrink: 0;
  min-height: 38px;
}
.viewer-bar strong { color: #bbb; white-space: nowrap; }
.viewer-bar .spacer { flex: 1; }
.viewer-bar .sep { color: #2a2a2a; }
.viewer-bar .prod-id { color: #444; font-size: 0.72rem; }

.live-pill {
  font-size: 0.68rem;
  color: #6fbf73;
  border: 1px solid #234a26;
  background: #12200f;
  border-radius: 20px;
  padding: 2px 9px;
  white-space: nowrap;
}
.golive-btn {
  font-size: 0.68rem;
  color: #7bb8f0;
  background: #14243a;
  border: 1px solid #2c4d75;
  border-radius: 20px;
  padding: 2px 9px;
  cursor: pointer;
  white-space: nowrap;
}
.golive-btn:hover { background: #1a3050; }

.zoom-btn {
  background: #161616;
  border: 1px solid #2a2a2a;
  color: #999;
  border-radius: 5px;
  width: 28px;
  height: 24px;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.zoom-btn:hover { background: #1e1e1e; color: #ddd; }

.availability { display: flex; gap: 0.5rem; }
.avail-pill {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid transparent;
  opacity: 0.3;
  transition: opacity 0.15s;
}
.avail-pill.ok { opacity: 1; }
.avail-pill.day-p   { background: #1a2a0e; border-color: #3a5a1a; color: #8bc34a; }
.avail-pill.night-p { background: #0e1a2a; border-color: #1a3a5a; color: #5b9bd5; }

.img-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 1rem;
  min-height: 0;
}
.img-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

/* Tamaño completo: el contenedor pasa a scroll y el pellizco funciona nativo */
.img-wrap.zoomed {
  align-items: flex-start;
  justify-content: flex-start;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
  padding: 0;
}
.img-wrap.zoomed img {
  max-width: none;
  max-height: none;
  object-fit: none;
  border-radius: 0;
}

.no-data-viewer {
  color: #2e2e2e;
  font-size: 0.9rem;
  text-align: center;
}
.no-data-viewer p {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: #252525;
}

/* Status dot */
.status-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4caf50;
  margin-right: 4px;
  flex-shrink: 0;
}
.status-dot.stale   { background: #ff9800; }
.status-dot.offline { background: #f44336; }
.status-dot.connecting { background: #607d8b; }

/* ── Transporte (slider) ──────────────────────────────────── */
.transport {
  flex-shrink: 0;
  background: #111;
  border-top: 1px solid #1a1a1a;
  padding: 0.45rem 1.2rem 0.55rem;
  padding-bottom: calc(0.55rem + env(safe-area-inset-bottom, 0px));
}

.tl-strip {
  display: flex;
  gap: 1px;
  height: 6px;
  margin-bottom: 0.45rem;
  border-radius: 2px;
  overflow: hidden;
}
.strip-cell {
  flex: 1 1 0;
  min-width: 1px;
  cursor: pointer;
  transition: filter 0.1s;
}
.strip-cell.d { background: #33501c; }
.strip-cell.n { background: #1b3352; }
.strip-cell:hover { filter: brightness(1.7); }
.strip-cell.cur  { background: #e0e0e0; }

.transport-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.icon-btn {
  background: #161616;
  border: 1px solid #2a2a2a;
  color: #aaa;
  border-radius: 5px;
  width: 30px;
  height: 26px;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, border-color 0.12s;
}
.icon-btn:hover:not(:disabled) { background: #1e1e1e; border-color: #444; color: #ddd; }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.icon-btn.primary { background: #1a2d44; border-color: #3a6ea8; color: #7bb8f0; }
.icon-btn.primary:hover:not(:disabled) { background: #23406a; }

.scrubber {
  flex: 1;
  min-width: 80px;
  height: 20px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.scrubber::-webkit-slider-runnable-track {
  height: 4px;
  background: #262626;
  border-radius: 2px;
}
.scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px; height: 13px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: #7bb8f0;
  border: 1px solid #0d0d0d;
}
.scrubber::-moz-range-track {
  height: 4px;
  background: #262626;
  border-radius: 2px;
}
.scrubber::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #7bb8f0;
  border: 1px solid #0d0d0d;
}
.scrubber:disabled { opacity: 0.35; cursor: not-allowed; }
.scrubber:focus-visible { outline: 1px solid #3a6ea8; outline-offset: 3px; }

.tr-time {
  font-size: 0.76rem;
  color: #bbb;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tr-count {
  font-size: 0.7rem;
  color: #555;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.transport-row .speed-select {
  background: #161616;
  border: 1px solid #2a2a2a;
  color: #aaa;
  border-radius: 5px;
  padding: 0.2rem 0.4rem;
  font-size: 0.72rem;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Modal de exportación ─────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal {
  width: 100%;
  max-width: 470px;
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  background: #131313;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid #1e1e1e;
}
.modal-head h2 { font-size: 0.92rem; font-weight: 600; color: #fff; }
.modal-body {
  padding: 0.9rem 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  padding-bottom: calc(0.7rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #1e1e1e;
  background: #111;
}

.btn-primary {
  background: #1a2d44;
  border: 1px solid #3a6ea8;
  color: #7bb8f0;
  border-radius: 5px;
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-primary:hover:not(:disabled) { background: #23406a; }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-ghost {
  background: #161616;
  border: 1px solid #2a2a2a;
  color: #999;
  border-radius: 5px;
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-ghost:hover { background: #1e1e1e; color: #ddd; }

.exp-block { margin-bottom: 1.1rem; }
.exp-block h3 {
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #555;
  margin-bottom: 0.55rem;
}

.exp-presets { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.7rem; }
.exp-presets button {
  background: #161616;
  border: 1px solid #2a2a2a;
  color: #999;
  border-radius: 5px;
  padding: 0.25rem 0.6rem;
  font-size: 0.74rem;
  cursor: pointer;
}
.exp-presets button:hover:not(:disabled) { background: #1e1e1e; border-color: #444; color: #ddd; }
.exp-presets button:disabled { opacity: 0.35; cursor: not-allowed; }

.exp-range {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.45rem;
}
.exp-range > label {
  font-size: 0.74rem;
  color: #777;
  width: 44px;
  flex-shrink: 0;
}
.exp-range input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 18px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.exp-range input[type="range"]::-webkit-slider-runnable-track {
  height: 3px; background: #262626; border-radius: 2px;
}
.exp-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 12px; height: 12px; margin-top: -4.5px;
  border-radius: 50%; background: #7bb8f0; border: 1px solid #0d0d0d;
}
.exp-range input[type="range"]::-moz-range-track {
  height: 3px; background: #262626; border-radius: 2px;
}
.exp-range input[type="range"]::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%;
  background: #7bb8f0; border: 1px solid #0d0d0d;
}
.exp-range-val {
  font-size: 0.72rem;
  color: #bbb;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  width: 128px;
  text-align: right;
  flex-shrink: 0;
}

.exp-note { font-size: 0.73rem; color: #666; margin-top: 0.4rem; }

.exp-grid { display: flex; gap: 0.7rem; }
.exp-grid > label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.74rem;
  color: #777;
}
.exp-grid select {
  background: #161616;
  border: 1px solid #2a2a2a;
  color: #ccc;
  border-radius: 5px;
  padding: 0.3rem 0.4rem;
  font-size: 0.76rem;
  cursor: pointer;
}

.exp-checks { display: flex; flex-wrap: wrap; gap: 1.2rem; margin-top: 0.7rem; }
.exp-checks label {
  font-size: 0.76rem;
  color: #999;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.exp-progress { margin-top: 0.4rem; }
.exp-progress .bar {
  height: 5px;
  background: #1e1e1e;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}
.exp-progress .bar-fill {
  height: 100%;
  background: #3a6ea8;
  transition: width 0.15s linear;
}
.exp-progress span { font-size: 0.73rem; color: #7bb8f0; }

.exp-error {
  margin-top: 0.6rem;
  font-size: 0.75rem;
  color: #e57373;
  background: #2a1414;
  border: 1px solid #4a1f1f;
  border-radius: 5px;
  padding: 0.45rem 0.6rem;
}
.exp-warn {
  margin-top: 0.2rem;
  margin-bottom: 0.6rem;
  font-size: 0.74rem;
  color: #d9a441;
  background: #241c0c;
  border: 1px solid #4a3a17;
  border-radius: 5px;
  padding: 0.45rem 0.6rem;
}
.exp-ok {
  margin-top: 0.6rem;
  font-size: 0.75rem;
  color: #8bc34a;
  background: #16220e;
  border: 1px solid #2c451a;
  border-radius: 5px;
  padding: 0.45rem 0.6rem;
}

/* ═════════════════════════════════════════════════════════
   MÓVIL Y TABLET ESTRECHA
   ═════════════════════════════════════════════════════════ */
@media (max-width: 820px) {

  header {
    padding: 0.5rem 0.7rem;
    gap: 0.55rem;
  }
  header h1 { font-size: 0.85rem; }
  .h1-long { display: none; }
  .hdr-sep, .hdr-refresh { display: none; }
  .hdr-status-txt { display: none; }
  .btn-long { display: none; }
  header .play-btn { padding: 0.3rem 0.55rem; font-size: 0.85rem; }
  .menu-btn { display: block; }

  /* La barra lateral pasa a cajón deslizante */
  .sidebar {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    width: min(78vw, 280px);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
  }
  .sidebar.open { transform: translateX(0); }

  .drawer-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 55;
  }

  .hide-sm { display: none !important; }

  .viewer-bar {
    padding: 0.45rem 0.7rem;
    gap: 0.5rem;
    font-size: 0.72rem;
  }
  .viewer-bar strong { font-size: 0.74rem; }

  .img-wrap { padding: 0.4rem; }

  .transport { padding: 0.5rem 0.7rem 0.6rem; }
  .tl-strip { height: 10px; margin-bottom: 0.55rem; }

  /* El slider ocupa su propia fila, encima de los botones */
  .transport-row { gap: 0.4rem; row-gap: 0.55rem; }
  .scrubber { order: -1; flex: 0 0 100%; height: 30px; }
  .scrubber::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -8px; }
  .scrubber::-moz-range-thumb { width: 19px; height: 19px; }

  .icon-btn { width: 44px; height: 38px; font-size: 0.95rem; }
  .zoom-btn { width: 34px; height: 30px; }
  .tr-time { margin-left: auto; font-size: 0.74rem; }
  .tr-count { display: none; }
  .transport-row .speed-select { padding: 0.35rem 0.4rem; font-size: 0.76rem; }

  /* Modal como hoja inferior a pantalla casi completa */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    max-width: none;
    max-height: 92dvh;
    border-radius: 12px 12px 0 0;
    border-bottom: none;
  }
  .exp-range { flex-wrap: wrap; row-gap: 0.15rem; }
  .exp-range > label { width: auto; flex: 0 0 auto; }
  .exp-range-val { width: auto; margin-left: auto; }
  .exp-range input[type="range"] { flex: 0 0 100%; height: 30px; order: 3; }
  .exp-range input[type="range"]::-webkit-slider-thumb { width: 19px; height: 19px; margin-top: -8px; }
  .exp-range input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; }
  .exp-presets button { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
  .exp-grid { flex-direction: column; gap: 0.6rem; }
  .exp-grid select { padding: 0.45rem 0.4rem; font-size: 0.85rem; }
  .exp-checks input[type="checkbox"] { width: 17px; height: 17px; }
  .modal-foot { justify-content: space-between; }
  .btn-primary, .btn-ghost { padding: 0.5rem 1rem; font-size: 0.85rem; }
}

/* Móvil en horizontal: la cabecera roba demasiada altura */
@media (max-width: 820px) and (orientation: landscape) {
  :root { --header-h: 38px; }
  header { height: 38px; }
  .tl-strip { height: 7px; margin-bottom: 0.35rem; }
  .icon-btn { height: 32px; }
  .scrubber { flex: 1 1 auto; order: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
