:root {
  --abyss: #08181f;
  --chart: #0f2a34;
  --chart-hi: #163a47;
  --foam: #e6eff1;
  --depth: #6e94a0;
  --buoy: #ffb627;
  --port: #e5484d;
  --starboard: #3dd68c;
  --hairline: rgba(110, 148, 160, 0.22);
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "Space Grotesk", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  background: var(--abyss);
  color: var(--foam);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

/* ---------- encabezado ---------- */
.masthead {
  padding-bottom: 18px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--hairline);
}

.masthead h1 {
  font-size: clamp(26px, 4.4vw, 40px);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.05;
}

.masthead-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.imei {
  color: var(--buoy);
  font-size: clamp(14px, 2.4vw, 22px);
  font-weight: 500;
  font-family: var(--mono);
}

.subtitle {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--depth);
  margin: 0;
  text-align: right;
}

.masthead-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-left: auto;
}

.btn-pdf {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--foam);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-pdf:hover {
  color: var(--buoy);
  border-color: var(--buoy);
}

.btn-pdf:focus-visible {
  outline: 2px solid var(--buoy);
  outline-offset: 2px;
}

/* ---------- estado ---------- */
.status {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--depth);
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  background: var(--chart);
}

.status.is-hidden {
  display: none;
}

.status.is-error {
  color: var(--port);
  border-color: rgba(229, 72, 77, 0.35);
}

.status.is-ok {
  color: var(--starboard);
  border-color: rgba(61, 214, 140, 0.35);
}

/* ---------- mapa ---------- */
#map {
  height: min(60vh, 520px);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  background: var(--chart);
}

/* Static map for PDF only — live Leaflet stays on screen */
.map-print {
  display: none;
}

.leaflet-container {
  font-family: var(--sans);
  font-size: 12px;
}

.leaflet-popup.infobox-popup .leaflet-popup-content-wrapper {
  background: var(--chart);
  color: #fff;
  border-radius: 10px;
  border: 1px solid var(--hairline);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  padding: 0;
}

.leaflet-popup.infobox-popup .leaflet-popup-tip {
  background: var(--chart);
  border: none;
  box-shadow: none;
}

.leaflet-popup.infobox-popup .leaflet-popup-content {
  margin: 28px 18px 16px;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.35;
  min-width: 220px;
}

.leaflet-popup.infobox-popup .leaflet-popup-close-button {
  color: #fff !important;
  font: 26px/30px var(--sans) !important;
  font-weight: 400 !important;
  top: 10px !important;
  right: 10px !important;
  width: 30px !important;
  height: 30px !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.leaflet-popup.infobox-popup .leaflet-popup-close-button:hover {
  color: #fff !important;
  opacity: 0.85;
}

.infobox {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 14px 4px 0;
}

.ib-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 22px;
}

.ib-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: #fff;
}

.ib-left svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: #fff;
}

.ib-label {
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}

.ib-value {
  color: #fff;
  font-weight: 400;
  text-align: right;
  white-space: nowrap;
}

.leaflet-bar a {
  background: var(--chart);
  color: var(--foam);
  border-color: var(--hairline);
}

.leaflet-bar a:hover {
  background: var(--chart-hi);
  color: var(--buoy);
}

.leaflet-control-attribution {
  background: rgba(8, 24, 31, 0.82) !important;
  color: var(--depth);
}

.leaflet-control-attribution a {
  color: var(--depth);
}

.leaflet-control-layers {
  background: var(--chart);
  color: var(--foam);
  border: 1px solid var(--hairline);
  border-radius: 3px;
}

.legend {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--depth);
  margin: 10px 2px 30px;
}

.legend .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 7px;
  vertical-align: 1px;
}

.legend .dot.starboard {
  background: var(--starboard);
}

.legend .dot.port {
  background: var(--port);
}

.legend .dot.buoy {
  background: var(--buoy);
}

/* ---------- tabla ---------- */
.log-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.log-head h2 {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0;
}

.log-head p {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--depth);
  margin: 0;
}

.tablescroll {
  border: 1px solid var(--hairline);
  border-radius: 3px;
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: nowrap;
}

thead th {
  background: var(--chart);
  color: var(--depth);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--hairline);
}

tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid rgba(110, 148, 160, 0.1);
}

tbody tr {
  cursor: pointer;
  transition: background 0.12s;
}

tbody tr:hover,
tbody tr:focus-visible {
  background: var(--chart);
  outline: none;
}

tbody tr.is-active {
  background: var(--chart-hi);
  box-shadow: inset 3px 0 0 var(--buoy);
}

.num {
  color: var(--depth);
}

td.coord {
  color: #b9d3d9;
}

.powered {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--depth);
  margin: 22px 0 0;
  text-align: center;
}

.powered a {
  color: var(--depth);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.powered a:hover {
  color: var(--depth);
}

@media (max-width: 640px) {
  .wrap {
    padding: 20px 14px 60px;
  }

  #map {
    height: 52vh;
  }
}

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

/* ---------- print / PDF (light) ---------- */
@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  html,
  body {
    background: #fff !important;
    color: #1a1a1a !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .wrap {
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .btn-pdf,
  #status,
  #map,
  .legend,
  .leaflet-control-zoom,
  .leaflet-control-layers,
  .leaflet-popup {
    display: none !important;
  }

  .masthead {
    border-bottom-color: #ccc;
  }

  .masthead h1 {
    color: #111;
  }

  .imei {
    color: #c47a00;
  }

  .subtitle,
  .log-head p,
  .powered,
  .powered a,
  .num {
    color: #555 !important;
  }

  .log-head h2 {
    color: #111;
  }

  .map-print {
    display: block !important;
    width: 100%;
    max-width: 100%;
    height: auto;
    margin: 0 0 18px;
    border: 1px solid #ccc;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .tablescroll {
    border: 1px solid #ccc;
    border-radius: 0;
    overflow: visible;
  }

  thead th {
    background: #f0f0f0 !important;
    color: #444 !important;
    border-bottom-color: #ccc;
  }

  tbody td {
    color: #222;
    border-bottom-color: #e5e5e5;
  }

  td.coord {
    color: #333 !important;
  }

  tbody tr {
    cursor: default;
  }

  tbody tr.is-active {
    background: transparent;
    box-shadow: none;
  }

  tbody tr:hover,
  tbody tr:focus-visible {
    background: transparent;
  }
}
