:root {
  color-scheme: light;
  --bg: #f6f5f0;
  --panel: #ffffff;
  --ink: #18211f;
  --muted: #66716d;
  --line: #d9ded8;
  --green: #167a5b;
  --blue: #1d62a8;
  --amber: #b76b00;
  --red: #b83b3b;
}

* {
  box-sizing: border-box;
}

/* Fallback minimo de Leaflet si el CSS del CDN no carga. */
.leaflet-container {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: #ddd;
  outline: 0;
  touch-action: none;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-container img,
.leaflet-container svg {
  max-width: none;
  max-height: none;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  user-select: none;
}

.leaflet-map-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 10px;
}

.leaflet-right {
  right: 10px;
}

.leaflet-bottom {
  bottom: 10px;
}

.leaflet-left {
  left: 10px;
}

.leaflet-control-zoom,
.leaflet-draw {
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
}

.leaflet-control-zoom a,
.leaflet-draw-toolbar a {
  display: block;
  width: 34px;
  height: 34px;
  color: #111;
  background: #fff;
  line-height: 34px;
  text-align: center;
  text-decoration: none;
  border-bottom: 1px solid #ccc;
}

.leaflet-control-attribution {
  padding: 3px 6px;
  background: rgba(255, 255, 255, 0.85);
  font-size: 11px;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  min-height: 100vh;
}

.map-panel {
  min-height: 100vh;
}

#map {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  z-index: 0;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: 100vh;
  overflow: auto;
  padding: 22px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 40px rgba(18, 33, 31, 0.08);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.08;
}

h2 {
  margin-bottom: 10px;
  font-size: 15px;
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.status-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbf8;
}

.status-grid span,
.detail-list dt {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 15px;
}

.controls {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 98, 168, 0.14);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

button {
  min-height: 40px;
  padding: 8px 10px;
  color: #fff;
  background: var(--blue);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.95);
}

button:nth-child(2) {
  background: var(--green);
}

#finishDraw,
#clearZone {
  background: var(--amber);
}

#undoPoint {
  color: var(--ink);
  background: #e8e5d8;
}

#map.drawing {
  cursor: crosshair;
}

.detail-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.detail-list dd {
  margin: 0;
  word-break: break-word;
}

.truck-list,
.log {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.truck-item,
.log-entry {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbf8;
  font-size: 13px;
}

.truck-item.inside {
  border-color: rgba(22, 122, 91, 0.5);
  background: rgba(22, 122, 91, 0.08);
}

.truck-item strong {
  display: block;
}

.truck-item span,
.log-entry {
  color: var(--muted);
}

.leaflet-draw-toolbar a {
  width: 34px;
  height: 34px;
}

.truck-marker {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: #fff;
  background: var(--blue);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
  font-size: 13px;
  font-weight: 800;
}

.truck-marker.inside {
  background: var(--red);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .map-panel,
  #map {
    min-height: 58vh;
  }

  .side-panel {
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
