/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tema oscuro (default) ────────────────────────────────────────────────── */
:root {
  --bg-dark:    #1a1a2e;
  --bg-card:    #16213e;
  --bg-surface: #0f3460;
  --accent:     #e94560;
  --accent-h:   #c73652;
  --text:       #eaeaea;
  --text-muted: #8892a4;
  --border:     #2a2a4a;
  --success:    #4caf50;
  --danger:     #f44336;
  --row-hover:  rgba(255,255,255,0.04);
  --font:       'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Tema claro ───────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg-dark:    #f0f4f8;
  --bg-card:    #ffffff;
  --bg-surface: #e2e8f0;
  --accent:     #e94560;
  --accent-h:   #c73652;
  --text:       #1a202c;
  --text-muted: #64748b;
  --border:     #cbd5e0;
  --success:    #16a34a;
  --danger:     #dc2626;
  --row-hover:  rgba(0,0,0,0.03);
}

body {
  background: var(--bg-dark);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
}

/* ── Navbar ───────────────────────────────────────────────────────────────── */
.navbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.navbar-links {
  display: flex;
  gap: 0.25rem;
  list-style: none;
}

.navbar-links a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  font-size: 0.875rem;
}

.navbar-links a:hover,
.navbar-links a.active {
  background: var(--bg-surface);
  color: var(--text);
}

/* Selector de tema — derecha del navbar */
.theme-selector {
  margin-left: auto;
  display: flex;
  gap: 2px;
  align-items: center;
}

.theme-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.theme-btn:hover {
  background: var(--bg-surface);
  color: var(--text);
}

.theme-btn.active {
  background: var(--bg-surface);
  color: var(--text);
  border-color: var(--border);
}

/* ── Container ────────────────────────────────────────────────────────────── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  padding: 0.45rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: var(--font);
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: var(--accent-h); }
.btn-secondary { background: var(--bg-surface); color: var(--text); }
.btn-secondary:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Status bar ───────────────────────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.countdown { color: var(--accent); font-weight: 700; }

/* ── Filtros ──────────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  padding: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1rem;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.filter-group label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filter-group input,
.filter-group select {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  font-size: 0.875rem;
  font-family: var(--font);
  min-width: 140px;
  appearance: none;
  -webkit-appearance: none;
}

.filter-group input:focus,
.filter-group select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Tabla ────────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
}

thead th {
  background: var(--bg-surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  text-align: left;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover      { background: var(--row-hover); }
tbody tr.clickable  { cursor: pointer; }

td {
  padding: 0.7rem 1rem;
  vertical-align: middle;
}

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: rgba(76,175,80,0.15);  color: #81c784; }
.badge-danger  { background: rgba(244,67,54,0.15);  color: #e57373; }

/* ── Foto dots ────────────────────────────────────────────────────────────── */
.foto-dots { display: flex; gap: 4px; }

.foto-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.foto-dot.on  { background: var(--success); }
.foto-dot.off { background: var(--border); }

/* ── Paginación ───────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  justify-content: center;
}

.page-info { color: var(--text-muted); font-size: 0.875rem; }

.total-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* ── Estados vacío / error ────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.error-msg {
  color: #e57373;
  font-size: 0.875rem;
  padding: 0.6rem 0.9rem;
  background: rgba(244,67,54,0.08);
  border: 1px solid rgba(244,67,54,0.2);
  border-radius: 6px;
  margin-bottom: 0.75rem;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem;
  max-width: 580px;
  width: 94%;
  max-height: 88vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.modal-close:hover { background: var(--border); color: var(--text); }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 2rem;
}

.detail-item label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: block;
  margin-bottom: 0.2rem;
}

.detail-item span { font-size: 0.875rem; }

.detail-full { grid-column: 1 / -1; }

/* ── Tracking controls ────────────────────────────────────────────────────── */
.tracking-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  padding: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1rem;
}

/* ── Mapa ─────────────────────────────────────────────────────────────────── */
#map {
  height: calc(100vh - 340px);
  min-height: 400px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
}

/* ── Botones de acción en tabla ───────────────────────────────────────────── */
.btn-accion {
  padding: 3px 8px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-surface);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn-accion:hover { opacity: 0.8; }
.btn-accion:disabled { opacity: 0.35; cursor: not-allowed; }

.acciones-cell { display: flex; gap: 4px; align-items: center; }

/* ── Modal mapa de verificación ───────────────────────────────────────────── */
.modal-mapa { max-width: 640px; width: 94%; }

#mapa-verificacion {
  height: 400px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
}

/* ── Modal de fotos ───────────────────────────────────────────────────────── */
.modal-fotos { max-width: 96vw; width: 96vw; max-height: 92vh; }

.fotos-grid {
  display: flex;
  gap: 1rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  align-items: flex-start;
  margin-top: 0.5rem;
}

.foto-item {
  flex: 1;
  min-width: 0;
  max-width: none;
  display: flex;
  flex-direction: column;
}

.foto-item img {
  width: 100%;
  height: auto;
  max-height: 65vh;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}

.foto-item p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  text-align: center;
}

/* ── Loader ───────────────────────────────────────────────────────────────── */
.loader {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Multi-select dropdown custom ─────────────────────────────────────────── */
.multi-select { position: relative; }

.ms-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  width: 100%;
  min-width: 170px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  font-size: 0.875rem;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s;
  white-space: nowrap;
}

.ms-trigger.open,
.ms-trigger:focus { outline: none; border-color: var(--accent); }

.ms-label {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.ms-arrow {
  flex-shrink: 0;
  font-size: 0.65rem;
  color: var(--text-muted);
  transition: transform 0.15s;
}

.ms-trigger.open .ms-arrow { transform: rotate(180deg); }

.ms-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 150;
  padding: 0.3rem 0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.ms-dropdown.open { display: block; }

.ms-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  user-select: none;
  transition: background 0.1s;
  white-space: nowrap;
}

.ms-option:hover { background: var(--row-hover); }

.ms-option:has(input:checked) {
  background: var(--accent-bg, rgba(233,69,96,0.1));
  font-weight: 600;
}

.ms-clear-btn {
  display: block;
  width: calc(100% - 1.5rem);
  margin: 0.3rem 0.75rem 0.15rem;
  padding: 0.4rem 0.5rem;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-family: var(--font);
  cursor: pointer;
  text-align: center;
  transition: color 0.15s;
}

.ms-clear-btn:hover { color: var(--accent); }

/* Neutraliza las reglas genéricas de .filter-group input para checkboxes */
.ms-option input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  min-width: 14px;
  flex-shrink: 0;
  cursor: pointer;
  padding: 0;
  border: unset;
  background: unset;
  border-radius: 0;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

/* Tablet (768px – 1199px) */
@media (max-width: 1199px) {
  .navbar { gap: 1rem; }
  .navbar-links a { padding: 0.4rem 0.5rem; }
}

/* Mobile (< 768px) */
@media (max-width: 767px) {
  .navbar {
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }
  .navbar-brand { font-size: 1rem; }
  .navbar-links { gap: 0; }
  .navbar-links a { font-size: 0.78rem; padding: 0.35rem 0.45rem; }
  #navbar-user-text { display: none; }
  .theme-selector { display: none; }

  .filters {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-group { width: 100%; }
  .filter-group input,
  .filter-group select,
  .ms-trigger { min-width: 0; width: 100%; box-sizing: border-box; }
  .ms-dropdown { min-width: 100%; }

  .pagination { flex-wrap: wrap; justify-content: center; }
  .tracking-controls { flex-direction: column; align-items: stretch; }
}
