:root {
  --bg: #0b1114;
  --panel: #141d22;
  --panel-2: #18242a;
  --line: #24333a;
  --text: #e7eef1;
  --muted: #93a6ae;
  --accent: #4fc3a1;
  --accent-2: #f0b429;
  --sidebar: 320px;
  --inspector: 340px;
  --topbar: 64px;
  font-synthesis-weight: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr var(--inspector);
  grid-template-rows: var(--topbar) 1fr;
  grid-template-areas:
    "top top top"
    "side view inspect";
  height: 100vh;
  overflow: hidden;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: linear-gradient(180deg, #16222a 0%, #111b20 100%);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--accent) 0%, #2b7f6b 60%, var(--accent-2) 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  flex: none;
}

.brand h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.eyebrow {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.view-modes {
  display: flex;
  gap: 4px;
  flex: 1;
  flex-wrap: wrap;
}

.view-button {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 7px 13px;
  border-radius: 7px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.view-button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.view-button.is-active {
  color: #0b1114;
  background: var(--accent);
  border-color: var(--accent);
}

.topbar-right {
  display: flex;
  gap: 22px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.stat strong {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------- panels */
.sidebar,
.inspector {
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #0e161a;
}

.sidebar {
  grid-area: side;
  border-right: 1px solid var(--line);
}

.inspector {
  grid-area: inspect;
  border-left: 1px solid var(--line);
}

.panel {
  flex: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}

.panel-muted {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.panel-muted p {
  margin: 0 0 8px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-note {
  margin: 10px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* ----------------------------------------------------------------- layers */
.layer-group + .layer-group {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.layer-group h3 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.layer-toggle {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 4px 9px;
  align-items: start;
  padding: 6px 6px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.12s;
}

.layer-toggle:hover {
  background: rgba(255, 255, 255, 0.035);
}

.layer-toggle input {
  appearance: none;
  width: 15px;
  height: 15px;
  margin: 1px 0 0;
  border: 1.5px solid #3d525c;
  border-radius: 4px;
  background: #0d1418;
  cursor: pointer;
  position: relative;
  transition: background 0.12s, border-color 0.12s;
}

.layer-toggle input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.layer-toggle input:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid #0b1114;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.layer-name {
  font-size: 13px;
  font-weight: 500;
}

.layer-hint {
  grid-column: 2;
  font-size: 10.5px;
  line-height: 1.4;
  color: #7c909a;
}

/* ------------------------------------------------------------------ fases */
.phase-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.phase-button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  padding: 9px 4px;
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.phase-button:hover {
  color: var(--text);
  border-color: #3a4d57;
}

.phase-button.is-active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #1a1206;
}

.panel-drone {
  display: none;
  border-color: #4a90d9;
}

body.has-drone .panel-drone {
  display: block;
}

.panel-ortho {
  display: none;
  border-color: #7bb662;
}

body.has-ortho .panel-ortho {
  display: block;
}

.panel-construccion {
  display: none;
  border-color: var(--accent-2);
}

body.is-construccion .panel-construccion {
  display: block;
  order: -1;
}

#construccion-steps {
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

#construccion-steps .phase-button {
  text-align: left;
  padding: 8px 9px;
  line-height: 1.25;
}

#construccion-steps .phase-button small {
  display: block;
  font-size: 9.5px;
  font-weight: 500;
  color: var(--muted);
  margin-top: 1px;
}

#construccion-steps .phase-button.is-active small {
  color: #1a1206;
}

.panel-section {
  display: none;
  border-color: var(--accent);
}

body.is-section .panel-section {
  display: block;
  order: -1;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.slider-row output {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  min-width: 38px;
  text-align: right;
}

.select-row {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.select-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 9px;
  font: inherit;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
}

.section-drawing {
  width: 100%;
  height: 184px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10191e;
}

.section-grid {
  stroke: #26363d;
  stroke-width: 1;
}

.section-grid-v {
  opacity: 0.45;
}

.section-axis,
.section-caption,
.section-mini-legend text {
  fill: #93a6ae;
  font: 10px "Segoe UI", system-ui, sans-serif;
}

.section-caption {
  fill: #c9d7dc;
  font-weight: 600;
}

.section-fill {
  fill-opacity: 0.7;
  stroke: rgba(255, 255, 255, 0.18);
  stroke-width: 0.8;
}

.section-terrain {
  fill: none;
  stroke: #f2efe4;
  stroke-width: 2.2;
}

.section-lining {
  fill: none;
  stroke: #9ee7d1;
  stroke-width: 1.8;
  stroke-dasharray: 4 3;
}

.section-key-terrain {
  fill: #f2efe4;
}

.section-key-lining {
  fill: #9ee7d1;
}

.section-key-fill {
  fill: var(--accent-2);
  opacity: 0.75;
}

/* ---------------------------------------------------------------- planos */
.plan-list {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.plan-button {
  appearance: none;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  cursor: pointer;
  display: grid;
  gap: 2px;
  transition: all 0.15s;
}

.plan-button:hover {
  border-color: #3a4d57;
}

.plan-button.is-active {
  border-color: var(--accent);
  background: rgba(79, 195, 161, 0.12);
}

.plan-button strong {
  font-size: 12.5px;
  font-weight: 600;
}

.plan-button small {
  font-size: 10.5px;
  color: var(--muted);
}

.meta,
.params {
  margin: 0;
  display: grid;
  gap: 9px;
}

.meta > div,
.param {
  display: grid;
  gap: 2px;
}

dt {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

dd {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.notes {
  margin: 10px 0 0;
  padding-left: 16px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--muted);
}

.notes li + li {
  margin-top: 4px;
}

/* -------------------------------------------------------- especificaciones */
.specs {
  margin-top: 10px;
  display: grid;
  gap: 4px;
}

.spec > summary {
  cursor: pointer;
  font-size: 11.5px;
  line-height: 1.5;
  padding: 4px 2px;
  border-radius: 4px;
  list-style: none;
  /* el numero de item y el titulo son columnas: asi el titulo largo sangra
     bajo si mismo en vez de volver al margen */
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.spec > summary::-webkit-details-marker {
  display: none;
}

.spec > summary::before {
  content: "▸";
  color: var(--muted);
  flex: none;
}

.spec[open] > summary::before {
  content: "▾";
}

.spec > summary:hover {
  background: rgba(255, 255, 255, 0.05);
}

.spec-item {
  flex: none;
  min-width: 30px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.spec ul {
  margin: 2px 0 0;
  padding-left: 32px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}

.spec ul li + li {
  margin-top: 3px;
}

.spec-note {
  margin: 6px 0 4px 32px;
  font-size: 11px;
  line-height: 1.5;
  font-style: italic;
  color: var(--muted);
}

[hidden] { display: none !important; }
.legend { flex-wrap: wrap; max-height: 190px; overflow: auto; }
.legend-entry { display:flex; align-items:center; gap:7px; border:0; background:transparent; color:var(--text); padding:2px; font:11px "Segoe UI",sans-serif; text-align:left; }
.legend-entry i { display:block; width:11px; height:11px; flex:none; border:1px solid #b7c5c533; }
.legend-entry:hover { color:white; background:#ffffff12; }
.element-card { max-height:65vh; overflow:auto; }
.element-card h2 { font-size:14px; line-height:1.5; padding-right:20px; }
.element-card dt { color:var(--muted); margin-top:9px; }
.element-card dd { margin:4px 0 12px; }
.element-card li,.element-card p { font-size:12px; line-height:1.6; }
.element-card a { color:#91c9c3; }
.close-card { float:right; font-size:22px; background:transparent; border:0; color:var(--text); }
.tour-card h2 { font-size:19px; margin:10px 0; }
.tour-card p { line-height:1.65; font-size:14px; }
.tour-card button { padding:8px 14px; margin-right:6px; color:var(--text); border:1px solid #53666d; background:#24373c; border-radius:4px; }
.map-reference { position:absolute; left:20px; top:20px; display:grid; gap:5px; color:#edf1eb; font:12px "Segoe UI",sans-serif; pointer-events:none; }
.north-arrow { font-size:22px; margin-bottom:10px; }
.scale-bar { height:7px; border:solid #edf1eb; border-width:0 1px 2px; }
.screen-labels { position:absolute; inset:0; pointer-events:none; overflow:hidden; }
.screen-label { position:absolute; left:0; top:0; color:#f0f4ee; background:#18282bd9; border-left:2px solid #a1b9b1; padding:4px 8px; font:12px "Segoe UI",sans-serif; white-space:nowrap; }
.screen-label::before { content:""; position:absolute; left:0; top:100%; height:16px; border-left:1px solid #a1b9b1; }
.survey-label { pointer-events:auto; cursor:pointer; border:1px solid #ddbb65; }
.hint { display:none; }
.contour-label { position:absolute; left:0; top:0; font:10px "Segoe UI",sans-serif; color:#eef0df; background:#35453bc9; padding:1px 3px; }
#view-modes { flex-wrap:wrap; }
.view-button { white-space:nowrap; }
/* --------------------------------------------------------------- viewport */
.viewport {
  grid-area: view;
  position: relative;
  min-width: 0;
  background: #0f1518;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
}

.hint {
  position: absolute;
  left: 16px;
  bottom: 14px;
  margin: 0;
  font-size: 11px;
  color: #7f949d;
  background: rgba(11, 17, 20, 0.7);
  padding: 5px 10px;
  border-radius: 6px;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.readout {
  position: absolute;
  top: 16px;
  right: 16px;
  display: grid;
  gap: 2px;
  padding: 10px 13px;
  border-radius: 9px;
  background: rgba(15, 23, 27, 0.9);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  font-size: 11.5px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  max-width: 280px;
}

.readout.is-visible {
  opacity: 1;
}

.readout.is-pinned {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.readout-note {
  color: var(--faint, #8496a4);
  font-size: 10px;
  line-height: 1.4;
  margin-top: 2px;
}

.readout strong {
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
}

.readout span {
  font-variant-numeric: tabular-nums;
}

.legend {
  position: absolute;
  right: 16px;
  bottom: 14px;
  display: flex;
  gap: 7px 14px;
  max-width: calc(100% - 32px);
  flex-wrap: wrap;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(15, 23, 27, 0.88);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.legend h4 {
  margin: 0 0 7px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  line-height: 1.55;
  white-space: nowrap;
}

.legend-row i {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.legend-row .legend-filter {
  background: linear-gradient(135deg, #5f6849, #9ca371);
  border: 1px dashed #d7d0b2;
}

.legend-row .legend-flow {
  width: 0;
  height: 0;
  border-radius: 0;
  background: transparent;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 12px solid var(--accent-2);
  box-shadow: none;
}

.legend-row .legend-storm-flow {
  width: 0;
  height: 0;
  border-radius: 0;
  background: transparent;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 12px solid #34bde3;
  box-shadow: none;
}

/* ---------------------------------------------------------------- loading */
.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  background: #0f1518;
  color: var(--muted);
  font-size: 13px;
  transition: opacity 0.4s;
  z-index: 3;
}

.loading small {
  font-size: 11px;
  color: #67797f;
}

.loading p {
  margin: 0;
}

.component-field { display: grid; gap: 6px; margin-bottom: 12px; font-size: 12px; color: #bad2d9; }
.component-field[hidden] { display: none; }
.component-field select { width: 100%; min-width: 0; padding: 9px; border: 1px solid #48616b; border-radius: 4px; background: #18282e; color: #f2f6f7; }
.component-actions { display: flex; gap: 8px; margin: 12px 0; }
.component-actions button { padding: 8px 10px; border: 1px solid #49626a; border-radius: 4px; background: #23383c; color: #eff5f5; cursor: pointer; }
.component-actions button:disabled { opacity: 0.4; cursor: default; }
.component-context { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.component-panel summary { font-size: 11px; color: #9bb5bf; cursor: pointer; }
.loading.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

/* -------------------------------------------------------------- responsive */
@media (max-width: 1280px) {
  :root {
    --sidebar: 280px;
    --inspector: 290px;
  }
  .layer-hint {
    display: none;
  }
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(340px, 52vh) auto auto;
    grid-template-areas:
      "top"
      "view"
      "side"
      "inspect";
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }
  .topbar {
    height: auto;
    flex-wrap: wrap;
    padding: 12px 14px;
    gap: 12px;
  }
  .topbar-right {
    width: 100%;
    justify-content: flex-start;
  }
  .stat {
    align-items: flex-start;
  }
  .sidebar,
  .inspector {
    border: 0;
    border-top: 1px solid var(--line);
  }
  .legend {
    position: static;
    margin: 12px;
  }
}
