:root {
  --fondo: #f3f4f6;
  --panel: #ffffff;
  --texto: #1f2328;
  --suave: #5b636e;
  --borde: #d0d5dc;
  --acento: #b42318;
  --boton: #e9ecf0;
  --rejilla: #d9dce1;
  --error-fondo: #fdecea;
  --aviso-fondo: #fff7e0;
  --enlace: #1d5fbf;
  --barra: #2563c9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #15181c;
    --panel: #1e2227;
    --texto: #e7e9ec;
    --suave: #9aa3ad;
    --borde: #353b43;
    --acento: #f2766b;
    --boton: #2b3138;
    --rejilla: #464d57;
    --error-fondo: #3b1d1b;
    --aviso-fondo: #33290f;
    --enlace: #7fb0ff;
    --barra: #5b9bff;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
}

.barra {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--borde);
}

.barra h1 { font-size: 1.15rem; margin: 0; }

.acciones { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  font: inherit;
  padding: 7px 14px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  background: var(--boton);
  color: var(--texto);
  cursor: pointer;
}
button:hover:not(:disabled) { filter: brightness(0.95); }
button:disabled { opacity: 0.5; cursor: default; }
button.principal { background: var(--acento); border-color: var(--acento); color: #fff; }

.contenido {
  display: grid;
  grid-template-columns: minmax(280px, 400px) 1fr;
  gap: 16px;
  padding: 16px 20px;
  max-width: 1300px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 16px;
  min-width: 0;
}

label { display: block; font-weight: 600; margin-bottom: 6px; }

textarea {
  width: 100%;
  margin-bottom: 10px;
  font: 0.95rem ui-monospace, Consolas, monospace;
  padding: 8px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  background: var(--fondo);
  color: var(--texto);
  resize: vertical;
}

.fila-botones { display: flex; gap: 8px; flex-wrap: wrap; }

.fichero { color: var(--suave); word-break: break-all; margin: 16px 0 4px; font-size: 0.9rem; }

.estadisticos {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: start;
  gap: 4px 12px;
  margin: 16px 0 0;
}
.estadisticos dt { text-align: right; color: var(--suave); }
.estadisticos dt::after { content: " ="; }
.estadisticos dd { margin: 0; font-variant-numeric: tabular-nums; }

.tabla-desplazable { overflow-x: auto; }

.resultados { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.resultados th, .resultados td { border: 1px solid var(--borde); padding: 4px 6px; text-align: right; }
.resultados th { background: var(--boton); text-align: center; }
.resultados td:first-child { text-align: center; font-weight: 600; }

.subtitulo { font-size: 0.95rem; margin: 16px 0 6px; }
.parametros { margin: 0; font-variant-numeric: tabular-nums; }
.parametros dt { font-weight: 600; margin-top: 6px; }
.parametros dd { margin: 2px 0 0 12px; }
.parametros .metodo { font-weight: normal; color: var(--suave); font-size: 0.85rem; }

.mensaje { border-radius: 6px; padding: 8px 12px; margin-top: 12px; }
.mensaje p { margin: 4px 0; }
.mensaje.error { background: var(--error-fondo); }
.mensaje.aviso { background: var(--aviso-fondo); }

.grafico h2 {
  font-size: 1.05rem;
  text-align: center;
  color: var(--acento);
  text-decoration: underline;
  font-style: italic;
  margin: 0 0 12px;
}

.lienzo svg { width: 100%; height: auto; display: block; }
.lienzo .vacio { color: var(--suave); text-align: center; padding: 60px 0; }

.rejilla { stroke: var(--rejilla); stroke-width: 1px; vector-effect: non-scaling-stroke; shape-rendering: crispEdges; }
.eje { stroke: var(--texto); stroke-width: 1; }
.etiqueta, .leyenda, .titulo-eje { fill: var(--texto); font-size: 12px; }
.titulo-eje { fill: var(--suave); }
.barras rect, .muestra { fill: var(--barra); }
.barras.con-filete rect { stroke: var(--panel); stroke-width: 0.75; }
.barras rect:hover { fill-opacity: 0.75; }

/* Página de ayuda */
.ayuda {
  max-width: 880px;
  margin: 16px auto;
  padding: 8px 28px 24px;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 8px;
  line-height: 1.6;
}
.ayuda h2 { font-size: 1.25rem; margin: 32px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--borde); }
.ayuda h3 { font-size: 1.05rem; margin: 20px 0 6px; color: var(--acento); }
.ayuda section, .ayuda article { scroll-margin-top: 12px; }
.ayuda li { margin: 4px 0; }
.ayuda a { color: var(--enlace); }
.ayuda code { font: 0.9em ui-monospace, Consolas, monospace; background: var(--fondo); padding: 1px 4px; border-radius: 4px; }
.entradilla { font-size: 1.05rem; }
.indice { background: var(--fondo); border-radius: 8px; padding: 4px 20px 12px; margin: 16px 0; }
.indice h2 { border: none; margin: 12px 0 4px; font-size: 1.05rem; }
.indice ol { margin: 0; padding-left: 22px; }
.indice ol ol { list-style: lower-alpha; }
.formula {
  font-family: "Cambria Math", "STIX Two Math", "Latin Modern Math", Georgia, serif;
  font-size: 1.08rem;
  text-align: center;
  background: var(--fondo);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 10px 0;
  overflow-x: auto;
  white-space: nowrap;
}
.nota, .aviso-texto { background: var(--aviso-fondo); border-radius: 6px; padding: 8px 14px; }
.pequeno { font-size: 0.9rem; color: var(--suave); }
.definiciones dt { font-weight: 600; margin-top: 12px; }
.definiciones dd { margin: 4px 0 0 16px; }
.metodo-ayuda { border-left: 3px solid var(--borde); padding-left: 16px; margin: 20px 0; }
.columnas { columns: 2 260px; }
.ayuda .resultados { margin: 8px 0; }
.referencias li { margin: 8px 0; }
a.boton {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  background: var(--boton);
  color: var(--texto);
  text-decoration: none;
}
a.boton:hover { filter: brightness(0.95); }
.creditos { color: var(--suave); font-size: 0.85rem; }

@media (max-width: 800px) {
  .contenido { grid-template-columns: 1fr; padding: 12px; }
  .ayuda { margin: 0; border-radius: 0; border-left: none; border-right: none; padding: 4px 16px 20px; }
  .formula { white-space: normal; }
}

@media print {
  /* Paleta clara aunque el sistema esté en modo oscuro (ejes, etiquetas y cruces usan estas variables) */
  :root { --texto: #1f2328; --suave: #5b636e; --borde: #d0d5dc; --rejilla: #d9dce1; --acento: #b42318; --panel: #fff; --barra: #2563c9; }
  .barra .acciones, #form-datos, .mensaje.aviso, .ayuda-volver { display: none; }
  body, .panel, .barra { background: #fff; color: #000; }
  .contenido { grid-template-columns: 1fr; padding: 0; }
  .panel, .ayuda { border: none; }
  .grafico { break-inside: avoid; }
  .tabla-desplazable { max-height: none; overflow: visible; }
  .ayuda img.mapa { max-width: 100%; }
  .ayuda { max-width: none; margin: 0; padding: 0; background: #fff; color: #000; }
  .ayuda h3 { color: #b42318; }
  .resultados th { background: #e9ecf0; }
  .ayuda a { color: #000; }
  .indice, .formula, code { background: #f3f4f6; }
  .nota, .aviso-texto { background: #fff7e0; }
  .metodo-ayuda, .ayuda h2 { break-inside: avoid-page; }
  .ayuda h2, .ayuda h3 { break-after: avoid; }
  .rejilla { stroke: #d9dce1; }
  .barras rect, .muestra { fill: #2563c9; }
  .barras.con-filete rect { stroke: #fff; }
}

/* Formulario de datos */
.grupo { border: 1px solid var(--borde); border-radius: 6px; padding: 8px 12px 10px; margin: 0 0 12px; }
.grupo legend { font-weight: 600; padding: 0 4px; }
label.opcion { display: flex; gap: 6px; align-items: baseline; font-weight: normal; margin: 4px 0; cursor: pointer; }
.campos { margin-top: 8px; }
.campos[hidden] { display: none; }
.datos .formula { font-size: 0.98rem; margin: 6px 0 10px; white-space: normal; }
.rejilla-campos { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; }
.rejilla-campos label { margin: 0; font-weight: 600; }
.con-unidad { display: flex; align-items: center; gap: 6px; }
.con-unidad > span, .con-unidad > a { color: var(--suave); font-size: 0.9rem; min-width: 34px; }
.con-unidad > a { color: var(--enlace); }
input[type="text"], .rejilla-campos input {
  font: inherit;
  width: 100%;
  max-width: 9em;
  padding: 5px 8px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  background: var(--fondo);
  color: var(--texto);
  font-variant-numeric: tabular-nums;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--enlace); outline-offset: 1px; }
.datos > .tabla-desplazable { margin-top: 16px; max-height: 60vh; overflow-y: auto; }
.resultados thead th { position: sticky; top: 0; }
.resultados .unidad { font-weight: normal; color: var(--suave); font-size: 0.85rem; }
.resultados td:first-child { font-weight: normal; }
.resumen-grafico { text-align: center; color: var(--suave); margin: -4px 0 8px; font-size: 0.92rem; }
.ayuda img.mapa { display: block; max-width: 100%; height: auto; margin: 12px auto; border-radius: 6px; border: 1px solid var(--borde); }
.ayuda figure { margin: 12px 0; }
.ayuda figcaption { text-align: center; color: var(--suave); font-size: 0.9rem; }

@media print {
  .datos > .tabla-desplazable { max-height: none; overflow: visible; }
  .resultados thead th { position: static; }
  .resumen-grafico { color: #5b636e; }
  .lienzo svg { max-width: 680px; margin: 0 auto; }
}

/* ---- Máximas lluvias ---- */
:root { --serie: #2a78d6; --pedido: #eb6834; }
@media (prefers-color-scheme: dark) { :root { --serie: #3987e5; --pedido: #d95926; } }

select {
  font: inherit;
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  background: var(--fondo);
  color: var(--texto);
}
.rejilla-campos input { max-width: 11em; }
.pista { color: var(--suave); font-size: 0.88rem; margin: 8px 0 0; }
.pista code, .lote code { font: 0.9em ui-monospace, Consolas, monospace; background: var(--fondo); padding: 1px 4px; border-radius: 4px; }
.resultados tr.pedido td { font-weight: 700; background: var(--aviso-fondo); }
.estadisticos .destacado { font-weight: 700; }
.estadisticos .unidad { color: var(--suave); font-weight: normal; font-size: 0.85rem; }
.calculado { color: var(--suave); font-size: 0.88rem; line-height: 1.5; margin: 12px 0 0; }
.datos > .tabla-desplazable { max-height: none; }

.grafico h2.segundo { margin-top: 24px; }
.serie { fill: none; stroke: var(--serie); stroke-width: 2px; stroke-linejoin: round; }
.punto circle:first-child { fill: var(--serie); stroke: var(--panel); stroke-width: 2px; }
.punto.pedido rect { fill: var(--pedido); stroke: var(--panel); stroke-width: 2px; }
.punto .diana { fill: transparent; stroke: none; }
.punto:hover circle:first-child, .punto:hover rect { filter: brightness(1.15); }
.muestra-punto { fill: var(--serie); stroke: var(--panel); stroke-width: 2px; }
.muestra-pedido { fill: var(--pedido); stroke: var(--panel); stroke-width: 2px; }

.mapa { position: relative; max-width: 422px; margin: 0 auto; cursor: crosshair; }
.mapa img { display: block; width: 100%; height: auto; }
.marca {
  position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border-radius: 50%; background: var(--pedido); border: 2px solid var(--panel);
  box-shadow: 0 0 0 1px var(--texto); pointer-events: none;
}
.leyenda-mapa { display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--suave); font-size: 0.85rem; margin-top: 8px; }
.escala { display: inline-flex; align-items: center; gap: 6px; }
.rampa { display: inline-block; width: 160px; height: 10px; border-radius: 2px;
  background: linear-gradient(90deg, #cde2fb, #9ec5f4, #6da7ec, #3987e5, #256abf, #184f95, #0d366b); }

.registro, .lote { grid-column: 1 / -1; }
.registro h2, .lote h2 { font-size: 1.05rem; margin: 0 0 10px; }
.registro .fila-botones { margin-top: 10px; align-items: center; }
.registro .resultados td { text-align: right; }
.registro .resultados td:first-child { text-align: left; }
.registro .sin-dato { text-align: center !important; color: var(--suave); }
.vacio-texto { color: var(--suave); margin: 0; }
.lote textarea { margin-top: 8px; }
.fichero-boton { position: relative; overflow: hidden; font-weight: normal; margin: 0; cursor: pointer; }
.fichero-boton input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

@media print {
  :root { --serie: #2a78d6; --pedido: #eb6834; }
  .registro, .lote, .leyenda-mapa, #btn-ejemplo { display: none; }
  .resultados tr.pedido td { background: #fff7e0; }
  .calculado { color: #5b636e; }
  .mapa { max-width: 320px; }
}
.ayuda pre { background: var(--fondo); border-radius: 6px; padding: 8px 12px; overflow-x: auto; }
.ayuda pre code { background: none; padding: 0; }
@media print { .ayuda pre { background: #f3f4f6; } }
.fichero-boton { display: inline-block; padding: 7px 14px; border: 1px solid var(--borde); border-radius: 6px; background: var(--boton); color: var(--texto); }
.fichero-boton:hover { filter: brightness(0.95); }
.con-unidad input { min-width: 0; flex: 1 1 auto; }
@media print { .datos > .tabla-desplazable { max-width: 480px; } }

/* ================================================
   PIE DE PÁGINA
   ================================================ */
.pie {
    text-align: center;
    padding: 0.8rem 1rem;
    font-size: 0.78rem;
    color: var(--gris-oscuro);
    background: var(--blanco);
    border-top: 1px solid var(--gris-medio);
}

.pie-legal {
    font-size: 0.7rem;
    color: #888;
    max-width: 900px;
    margin: 0 auto;
    line-height: 1.4;
}
