:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;   /* lluvia */
  --series-2: #eb6834;   /* evapotranspiración */
  --accent: #1b5e20;
  --bare: #ecebe6;
  --seq-0: #f3f7fd;
  --seq-1: #cde2fb;
  --seq-2: #86b6ef;
  --seq-3: #3987e5;
  --seq-4: #1c5cab;
  --seq-5: #0d366b;
  --warning-bg: #fff6e0;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --accent: #66bb6a;
    --bare: #2a2a28;
    --seq-0: #1f2530;
    --seq-1: #184f95;
    --seq-2: #1c5cab;
    --seq-3: #2a78d6;
    --seq-4: #5598e7;
    --seq-5: #9ec5f4;
    --warning-bg: #3a2f12;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text);
  line-height: 1.45;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; color: var(--accent); }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; margin-top: 1.4rem; }
.hint, .sub { color: var(--text-2); font-size: 0.85rem; margin: 0.3rem 0 0.6rem; }

.top {
  display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); background: var(--surface);
}
.tagline { margin: 0.2rem 0 0; color: var(--text-2); }
.notice {
  margin: 0; padding: 0.5rem 0.9rem; border-radius: var(--radius);
  background: var(--warning-bg); font-size: 0.9rem;
}

.layout {
  display: grid; grid-template-columns: minmax(300px, 360px) 1fr; gap: 1.25rem;
  padding: 1.25rem 1.5rem; align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.panel {
  position: sticky; top: 1rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto;
}
@media (max-width: 900px) { .panel { position: static; max-height: none; } }
.step { margin-bottom: 1.1rem; }
.num {
  display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--accent); color: var(--surface); font-size: 0.8rem; margin-right: 0.3rem;
}
#map { height: 220px; border-radius: var(--radius); border: 1px solid var(--border); }
.coords { font-size: 0.8rem; color: var(--muted); margin: 0.4rem 0 0; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.chip {
  border: 1px solid var(--border); background: var(--page); color: var(--text);
  border-radius: 999px; padding: 0.25rem 0.7rem; font-size: 0.8rem; cursor: pointer;
}
.chip:hover, .chip.active { border-color: var(--accent); color: var(--accent); }

select, button { font: inherit; }
select {
  width: 100%; padding: 0.45rem; border-radius: 8px; border: 1px solid var(--axis);
  background: var(--surface); color: var(--text);
}
.field { display: block; margin-top: 0.7rem; font-size: 0.9rem; }
.field select { margin-top: 0.3rem; }
.check { display: flex; gap: 0.5rem; align-items: center; font-size: 0.9rem; margin-top: 0.4rem; }

.prio { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 0.5rem; margin-bottom: 0.5rem; }
.prio label { font-size: 0.9rem; }
.prio output { font-weight: 600; font-variant-numeric: tabular-nums; }
.prio input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }

.primary {
  width: 100%; padding: 0.75rem; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--surface); font-weight: 600; font-size: 1rem; cursor: pointer;
}
.primary:disabled { opacity: 0.6; cursor: wait; }
.ghost {
  border: 1px solid var(--axis); background: transparent; color: var(--text);
  border-radius: 8px; padding: 0.4rem 0.8rem; cursor: pointer;
}

.results { min-width: 0; }
.empty, .loading, .error {
  background: var(--surface); border: 1px dashed var(--axis); border-radius: var(--radius);
  padding: 2rem; text-align: center; color: var(--text-2);
}
.error { border-style: solid; border-color: #d03b3b; color: #d03b3b; }
.warn {
  background: var(--warning-bg); border-radius: var(--radius); padding: 0.6rem 0.9rem;
  margin-bottom: 0.8rem; font-size: 0.9rem;
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; margin-bottom: 1.25rem;
}
.section-title { margin: 0.5rem 0 0; font-size: 1.2rem; }
.chart-box { position: relative; height: 260px; }
.table-view summary { cursor: pointer; font-size: 0.85rem; color: var(--text-2); margin-top: 0.4rem; }
.scroll-x { overflow-x: auto; }

table.data { border-collapse: collapse; width: 100%; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 0.35rem 0.45rem; text-align: center; border-bottom: 1px solid var(--grid); }
table.data th:first-child, table.data td:first-child { text-align: left; white-space: nowrap; }
table.data th { color: var(--text-2); font-weight: 600; }
.risk td.cell { border: 2px solid var(--surface); border-radius: 6px; min-width: 2.6rem; }
.risk .row-note { display: block; color: var(--muted); font-size: 0.75rem; font-weight: 400; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.8rem; }
.tile { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem; background: var(--page); }
.tile .label { font-size: 0.8rem; color: var(--text-2); }
.tile .value { font-size: 1.4rem; font-weight: 600; margin: 0.2rem 0; }
.tile .detail { font-size: 0.78rem; color: var(--muted); }

/* Fase 2: simulador y rotaciones */
.scenario-controls { display: flex; flex-wrap: wrap; gap: 1.2rem; align-items: end; }
.scenario-controls label { display: flex; flex-direction: column; font-size: 0.9rem; min-width: 220px; }
.scenario-controls input { accent-color: var(--series-2); }

.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; margin: 0.6rem 0 0.9rem; font-size: 0.8rem; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.swatch {
  display: inline-grid; place-items: center; min-width: 1.9rem; height: 1.2rem; border-radius: 4px;
  font-size: 0.68rem; font-weight: 600; color: #fff;
}

.rotations { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 1250px) { .rotations { grid-template-columns: 1fr; } }
.rot {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; display: flex; flex-direction: column; gap: 0.7rem; min-width: 0;
}
.rot.current { border-color: var(--axis); }
.rot.best { border: 2px solid var(--accent); }
.badge {
  align-self: flex-start; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.15rem 0.55rem; border-radius: 999px; background: var(--page); border: 1px solid var(--border); color: var(--text-2);
}
.rot.best .badge { color: var(--accent); border-color: var(--accent); }
.rot h3 { margin: 0; font-size: 1.05rem; }
.rot .desc { font-size: 0.85rem; color: var(--text-2); margin: 0; }
.total { display: flex; align-items: baseline; gap: 0.4rem; }
.total .big { font-size: 2.2rem; font-weight: 700; }
.total .of { color: var(--text-2); font-size: 0.85rem; }

.bars { display: grid; gap: 0.35rem; }
.bar-row { display: grid; grid-template-columns: 9.5rem 1fr 2rem; align-items: center; gap: 0.5rem; font-size: 0.8rem; }
.bar-row .name { color: var(--text-2); }
.bar-row .name.prio-high { color: var(--text); font-weight: 600; }
.bar-track, .bar-fill { display: block; }
.bar-track { height: 8px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; }

.cal { display: grid; grid-template-columns: 2.6rem repeat(12, minmax(0, 1fr)); gap: 2px; font-size: 0.66rem; }
.cal .mh { text-align: center; color: var(--muted); }
.cal .yl { color: var(--muted); align-self: center; }
.cal .c {
  height: 1.55rem; border-radius: 4px; display: grid; place-items: center;
  color: #fff; font-weight: 600; overflow: hidden; white-space: nowrap;
}
.cal .c.bare { background: var(--bare); color: var(--muted); font-weight: 400; }
.cal .c.dark-text { color: #0b0b0b; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.kpi { background: var(--page); border-radius: 8px; padding: 0.45rem 0.6rem; }
.kpi .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 0.72rem; color: var(--text-2); }

.rot details { border-top: 1px solid var(--grid); padding-top: 0.4rem; }
.rot summary { cursor: pointer; font-weight: 600; font-size: 0.88rem; padding: 0.2rem 0; }
.rot details ul { margin: 0.3rem 0 0.2rem; padding-left: 1.1rem; font-size: 0.84rem; }
.rot details li { margin-bottom: 0.3rem; }
.rot details.risks summary { color: #b3541e; }

/* Fase 3: mapa de zonas */
#zones-map { height: 380px; border-radius: var(--radius); border: 1px solid var(--border); margin-top: 0.7rem; }
.zone-controls { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: center; justify-content: space-between; }
.seg { display: inline-flex; border: 1px solid var(--axis); border-radius: 8px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; color: var(--text-2); padding: 0.4rem 0.8rem; cursor: pointer;
  border-right: 1px solid var(--axis); font-size: 0.85rem;
}
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--accent); color: var(--surface); }
.inline { display: inline-flex; gap: 0.4rem; align-items: center; font-size: 0.85rem; }
.inline select { width: auto; max-width: 320px; }
.legend .swatch:empty { min-width: 1.2rem; }

.glossary dt { font-weight: 600; margin-top: 0.7rem; }
.glossary dd { margin: 0.15rem 0 0; color: var(--text-2); font-size: 0.9rem; }
.method ul { padding-left: 1.1rem; font-size: 0.9rem; color: var(--text-2); }
.foot { padding: 1rem 1.5rem 2rem; font-size: 0.8rem; color: var(--muted); text-align: center; }

/* Fase 4: "Explain it simply" y diagnóstico */
.explain-btn {
  display: flex; align-items: center; gap: 0.9rem; margin-bottom: 1.25rem; padding: 0.9rem 1.2rem;
  background: var(--accent); color: var(--surface); border-radius: var(--radius); text-decoration: none;
  box-shadow: 0 4px 14px rgba(27, 94, 32, 0.25); transition: transform 0.15s;
}
.explain-btn:hover { transform: translateY(-2px); }
.explain-btn small { opacity: 0.85; }
.explain-ic { font-size: 1.8rem; }

/* "Explain it simply" 3D dentro del programa */
button.explain-btn { font: inherit; border: 0; cursor: pointer; text-align: left; width: 100%; }
.modal { position: fixed; inset: 0; z-index: 2000; background: rgba(10, 14, 10, 0.72); display: grid; place-items: center; padding: 1.2rem; }
.modal[hidden] { display: none; }
.modal-box { position: relative; width: min(1180px, 100%); height: min(92vh, 900px); background: #f4f1ea; border-radius: 16px; overflow: hidden; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4); }
.modal-box iframe { width: 100%; height: 100%; border: 0; display: block; }
.modal-close {
  position: absolute; top: 0.6rem; right: 0.7rem; z-index: 2; width: 2.3rem; height: 2.3rem; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, 0.95); color: #1d1d1b; font-size: 1.05rem; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.rot .diag-list { list-style: none; padding-left: 0; }
.rot .diag-list .idea { color: var(--accent); }
.explain-hint { margin-top: -0.8rem; margin-bottom: 1.2rem; }
