:root {
  color-scheme: dark;
  --bg: #070b18;
  --panel: #111827;
  --panel-2: #0f172a;
  --line: rgba(255, 255, 255, 0.10);
  --text: #f8fafc;
  --muted: #94a3b8;
  --soft: #cbd5e1;
  --accent: #06b6d4;
  --accent-2: #0891b2;
  --danger: #ef4444;
  --warning: #f59e0b;
  --ok: #22c55e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(6, 182, 212, 0.12), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(239, 68, 68, 0.10), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.report-shell {
  width: min(1600px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.report-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.84);
  border-radius: 24px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(16px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 900;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 2vw, 2.25rem);
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.btn,
.chip {
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: #1f2937;
  color: #fff;
  font-weight: 900;
  border-radius: 12px;
  padding: 11px 14px;
  cursor: pointer;
}

.btn:hover,
.chip:hover {
  filter: brightness(1.08);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.filters-card,
.table-card,
.summary-card {
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.88);
  border-radius: 20px;
}

.filters-card {
  margin-top: 16px;
  padding: 18px;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #050816;
  color: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(6, 182, 212, 0.8);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.12);
}

.filters-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.checkline {
  display: inline-flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  margin-right: 8px;
  color: var(--soft);
}

.checkline input {
  width: auto;
}

.chip {
  padding: 8px 11px;
  border-radius: 999px;
  font-size: 0.8rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-top: 16px;
}

.summary-card {
  padding: 16px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.82rem;
}

.summary-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.75rem;
}

.summary-card.danger strong {
  color: #fecaca;
}

.summary-card.pending strong {
  color: #fde68a;
}

.summary-card.located strong {
  color: #bbf7d0;
}

.table-card {
  margin-top: 16px;
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.table-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.loading {
  color: var(--accent);
  font-weight: 900;
}

.hidden {
  display: none !important;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 355px);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1180px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  text-align: left;
  vertical-align: top;
  font-size: 0.88rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #0b1220;
  color: #cbd5e1;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.72rem;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: rgba(6, 182, 212, 0.10);
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 28px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 0.74rem;
  background: rgba(148, 163, 184, 0.15);
  color: #e2e8f0;
}

.badge.critical,
.badge.high {
  background: rgba(239, 68, 68, 0.20);
  color: #fecaca;
}

.badge.medium {
  background: rgba(245, 158, 11, 0.20);
  color: #fde68a;
}

.badge.pending {
  background: rgba(245, 158, 11, 0.18);
  color: #fde68a;
}

.badge.processed {
  background: rgba(34, 197, 94, 0.18);
  color: #bbf7d0;
}

.location-link {
  color: #67e8f9;
  font-weight: 900;
  text-decoration: none;
}

.location-link:hover {
  text-decoration: underline;
}

.detail-cell {
  max-width: 360px;
  color: #cbd5e1;
  line-height: 1.35;
}

.map-dialog {
  width: min(980px, calc(100vw - 28px));
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 24px;
  padding: 0;
  background: transparent;
  color: var(--text);
  box-shadow: 0 30px 90px rgba(0,0,0,0.60);
}

.map-dialog::backdrop {
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
}

.modal-card {
  background: #0f172a;
  border-radius: 24px;
  overflow: hidden;
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
}

.modal-header {
  border-bottom: 1px solid var(--line);
}

.close-btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255,255,255,0.20);
  border-radius: 12px;
  background: #111827;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.modal-info {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 14px 18px;
}

.modal-info div {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  border-radius: 14px;
  padding: 11px;
}

.modal-info span {
  display: block;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.68rem;
  font-weight: 900;
}

.modal-info strong {
  display: block;
  margin-top: 4px;
  color: #fff;
}

.alert-map {
  height: 460px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.modal-footer {
  justify-content: flex-end;
}

.leaflet-popup-content-wrapper {
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  box-shadow: 0 18px 42px rgba(0,0,0,0.55);
}

.leaflet-popup-tip {
  background: #0f172a;
}

.leaflet-popup-close-button {
  color: #cbd5e1 !important;
  font-weight: 900 !important;
}

.alert-popup {
  min-width: 230px;
}

.alert-popup h3 {
  margin: 0 0 8px;
  color: #fff;
}

.alert-popup-row {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 10px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.alert-popup-row:last-child {
  border-bottom: 0;
}

.alert-popup-row span {
  color: #94a3b8;
  font-weight: 800;
}

.alert-popup-row strong {
  color: #f8fafc;
}

@media (max-width: 1100px) {
  .report-header {
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .filters-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal-info {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 650px) {
  .report-shell {
    width: min(100vw - 18px, 100%);
    padding-top: 10px;
  }

  .filters-grid,
  .summary-grid,
  .modal-info {
    grid-template-columns: 1fr;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .btn {
    flex: 1;
  }

  .alert-map {
    height: 360px;
  }
}


/* v3: refuerzo de render Leaflet en modal */
.map-dialog .leaflet-pane,
.map-dialog .leaflet-tile,
.map-dialog .leaflet-marker-icon,
.map-dialog .leaflet-marker-shadow,
.map-dialog .leaflet-tile-pane,
.map-dialog .leaflet-overlay-pane,
.map-dialog .leaflet-shadow-pane,
.map-dialog .leaflet-marker-pane,
.map-dialog .leaflet-popup-pane {
  position: absolute;
}

.map-dialog .leaflet-tile-container {
  position: absolute;
  left: 0;
  top: 0;
}

.version-tag {
  display: inline-flex;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(6, 182, 212, 0.16);
  color: #67e8f9;
  font-weight: 900;
  font-size: 0.72rem;
}


/* =========================
   Ordenamiento por fecha
========================= */

.table-sort-button {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  margin: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
}

.table-sort-button:hover {
  color: #67e8f9;
}

#sortDateIndicator {
  color: #67e8f9;
  font-size: 0.8rem;
}


/* =========================
   Reportes v8
========================= */

.filter-target {
  grid-column: span 2;
}

.report-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.report-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 230px;
  padding: 20px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.88);
  color: var(--text);
  text-decoration: none;
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.26);
}

.report-card:hover {
  border-color: rgba(6, 182, 212, 0.62);
  transform: translateY(-1px);
}

.report-card-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(6, 182, 212, 0.15);
  color: #67e8f9;
  font-size: 24px;
}

.report-card h2 {
  margin: 0;
  font-size: 1.25rem;
}

.report-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.report-card .btn {
  width: fit-content;
  margin-top: auto;
}


/* =========================
   Reportes v9
========================= */

.client-filter-group {
  grid-column: span 2;
}

.header-actions a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
