:root {
  --red: #c00000;
  --red-dark: #8f0000;
  --panel-head: #3c3c3c;
  --cat-bg: #f1f1f1;
  --line: #dcdcdc;
  --text: #1d1d1d;
  --toolbar-h: 50px;
  --status-h: 26px;
  --panel-w: 340px;
  --hl: #ff6d00;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; color: var(--text); background: #fff; overflow: hidden; }

/* ---------- Barra de herramientas ---------- */
#toolbar {
  flex: 0 0 var(--toolbar-h); height: var(--toolbar-h);
  display: flex; align-items: stretch;
  background: var(--red);
  overflow-x: auto; scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }
#toolbar button {
  flex: 0 0 var(--toolbar-h); width: var(--toolbar-h);
  display: grid; place-items: center; padding: 0;
  border: 0; background: transparent; color: #fff; cursor: pointer;
}
#toolbar button:hover:not(:disabled) { background: rgba(255, 255, 255, .16); }
#toolbar button.active { background: var(--red-dark); box-shadow: inset 0 -3px 0 #fff; }
#toolbar button:disabled { opacity: .4; cursor: default; }
#toolbar button:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }
.tb-sep { flex: 0 0 1px; width: 1px; margin: 10px 6px; background: rgba(255, 255, 255, .35); }
.tb-spacer { flex: 1 1 auto; }

/* ---------- Mapa ---------- */
#viewer { position: relative; flex: 1 1 auto; min-height: 0; }
#map { position: absolute; inset: 0; background: #fff; }
#map.cursor-crosshair .maplibregl-canvas-container,
#map.cursor-crosshair .maplibregl-canvas-container.maplibregl-interactive,
#map.cursor-crosshair .maplibregl-canvas { cursor: crosshair !important; }
.maplibregl-map { font: inherit; }
.maplibregl-ctrl-attrib { font-size: 11px; }

.zoombox { position: absolute; z-index: 5; border: 2px dashed var(--red); background: rgba(192, 0, 0, .12); pointer-events: none; }

#progress { position: absolute; top: 0; left: 0; right: 0; height: 3px; z-index: 1100; overflow: hidden; opacity: 0; transition: opacity .2s; pointer-events: none; }
#progress::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 35%; background: var(--red); animation: slide 1s infinite ease-in-out; }
body.is-loading #progress { opacity: 1; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
@media (prefers-reduced-motion: reduce) { #progress::before { animation-duration: 3s; } }

/* ---------- Paneles ---------- */
.panel-header {
  flex: 0 0 auto; height: 34px; padding: 0 6px 0 10px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel-head); color: #fff; font-size: 17px;
}
.panel-header button { border: 0; background: transparent; color: #ccc; font-size: 22px; line-height: 1; padding: 2px 6px; cursor: pointer; }
.panel-header button:hover { color: #fff; }
.msg { margin: 0; padding: 14px 12px; font-size: 13px; color: #666; }

#layer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 1000;
  width: var(--panel-w); max-width: 92vw;
  display: flex; flex-direction: column;
  background: #fff; box-shadow: -2px 0 8px rgba(0, 0, 0, .25);
}
#layer-tree { flex: 1 1 auto; overflow-y: auto; }

.cat-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--cat-bg); border-bottom: 1px solid var(--line);
  font-size: 14px; font-weight: 600; cursor: pointer; user-select: none;
}
.cat-toggle { width: 18px; height: 18px; padding: 0; border: 0; background: transparent; color: var(--red); font-size: 20px; font-weight: 700; line-height: 1; cursor: pointer; }
.cat-head input, .layer-label input { width: 16px; height: 16px; margin: 0; accent-color: #333; }

.layer { border-bottom: 1px solid #f0f0f0; }
.layer-line { display: flex; align-items: center; padding: 8px 12px 8px 20px; }
.layer-label { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; cursor: pointer; }
.layer.disabled .layer-label { color: #9a9a9a; cursor: not-allowed; }
.legend-toggle { padding: 0 6px; border: 0; background: transparent; color: var(--red); font-size: 20px; font-weight: 700; line-height: 1; cursor: pointer; transition: transform .15s; }
.legend-toggle[aria-expanded="true"] { transform: rotate(90deg); }
.legend { padding: 2px 12px 10px 46px; overflow-x: auto; }
.legend img { display: block; max-width: none; }
.legend-item { display: flex; align-items: center; gap: 8px; padding: 2px 0; font-size: 12.5px; }
.legend-item svg { flex: 0 0 auto; }
.legend-item.legend-off { opacity: 0.4; }
.layer.out-of-scale .layer-text { color: #8a8a8a; font-style: italic; }
.legend-msg { font-size: 12px; color: #777; }

#info-panel {
  position: absolute; left: 12px; top: 12px; z-index: 1000;
  width: 420px; max-width: calc(100% - 24px - var(--panel-w)); max-height: calc(100% - 24px);
  display: flex; flex-direction: column;
  background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
}

#goto-panel {
  position: absolute; left: 12px; top: 12px; z-index: 1001;
  width: 300px; max-width: calc(100% - 24px - var(--panel-w));
  background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
}
.panel-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.panel-body label { font-size: 12px; color: #555; }
.panel-body select, .panel-body input[type="text"] {
  font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid #ccc; border-radius: 3px; width: 100%;
}
.goto-fields { display: grid; grid-template-columns: auto 1fr; gap: 6px 8px; align-items: center; }
.goto-fields label { text-align: right; }
.goto-error { margin: 0; font-size: 12px; color: #b3261e; }
#goto-go {
  font: inherit; font-size: 13px; padding: 7px 10px; border: 0; border-radius: 3px;
  background: #1565c0; color: #fff; cursor: pointer;
}
#goto-go:hover { background: #0d47a1; }

#export-panel {
  position: absolute; left: 12px; top: 12px; z-index: 1001;
  width: 320px; max-width: calc(100% - 24px - var(--panel-w));
  max-height: calc(100% - 24px); display: flex; flex-direction: column;
  background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
}
#export-panel .panel-body { overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.export-layers-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; color: #555; margin-top: 2px; }
.link-btn { font: inherit; font-size: 12px; border: 0; background: none; color: #1565c0; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.export-layers { overflow-y: auto; max-height: 260px; border: 1px solid #ddd; border-radius: 3px; padding: 4px 8px; }
.export-cat { font-size: 11px; font-weight: 600; color: #666; text-transform: uppercase; letter-spacing: .03em; margin: 8px 0 2px; }
.export-cat:first-child { margin-top: 4px; }
.export-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 13px; }
.export-row input { flex: 0 0 auto; }
.export-row .out-of-scale { color: #999; font-size: 11px; margin-left: 4px; }
.export-note { font-size: 11px; color: #777; margin: 4px 0 0; }
#export-go {
  font: inherit; font-size: 13px; padding: 7px 10px; border: 0; border-radius: 3px;
  background: #1565c0; color: #fff; cursor: pointer;
}
#export-go:hover { background: #0d47a1; }
#export-go:disabled { background: #9fb8d6; cursor: default; }
.info-body { overflow-y: auto; }
.info-group h4 { margin: 0; padding: 7px 12px; background: var(--cat-bg); border-bottom: 1px solid var(--line); font-size: 13px; color: var(--red); }
.info-feature { border-bottom: 1px solid #eee; }
.info-feature summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.info-zoom { padding: 2px 8px; border: 1px solid var(--red); border-radius: 2px; background: #fff; color: var(--red); font-size: 12px; cursor: pointer; }
.info-zoom:hover { background: var(--red); color: #fff; }
.info-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.info-table th, .info-table td { padding: 3px 12px; text-align: left; vertical-align: top; border-top: 1px solid #f0f0f0; word-break: break-word; }
.info-table th { width: 38%; font-weight: 600; color: #555; }
.info-error { padding: 8px 12px; font-size: 12.5px; color: #a40000; }

/* ---------- Mediciones (marcadores HTML de MapLibre) ---------- */
.measure-label { padding: 2px 6px; background: #fff; border: 1px solid var(--red); border-radius: 2px; color: #222; font-size: 12px; font-weight: 600; white-space: nowrap; pointer-events: none; }
.measure-live small { font-weight: 400; color: #666; }

/* ---------- Barra de estado ---------- */
#statusbar {
  flex: 0 0 var(--status-h); height: var(--status-h);
  display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: center; text-align: center;
  background: #111; color: #eee; font-size: 13px; font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
  #toolbar button { flex-basis: 44px; width: 44px; }
  #statusbar { font-size: 11px; }
}
