:root {
  --ink: #0B2540;
  --ink-soft: #1C3A58;
  --muted: #5B6B7E;
  --muted-2: #94A3B5;
  --line: #E4EAF0;
  --line-soft: #F0F4F8;
  --bg: #F6F9FC;
  --surface: #FFFFFF;
  --brand: #1E54E0;
  --brand-dk: #1642B4;
  --brand-tint: #EEF3FE;
  --green: #18A34B;
  --green-dk: #0F7A38;
  --green-tint: #E7F6EE;
  --warn: #D82A2A;
  --warn-tint: #FDECEC;
  --orange: #E58A1A;
  --orange-tint: #FCEFD8;
  --shadow-sm: 0 1px 3px rgba(10,37,64,.05);
  --shadow-md: 0 6px 24px rgba(10,37,64,.08);
  --shadow-lg: 0 20px 56px rgba(10,37,64,.14);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 600;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--brand); text-decoration: none; }

/* === LAYOUT === */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 18px 32px;
  box-shadow: var(--shadow-sm);
}
.header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  color: var(--ink);
  letter-spacing: -.01em;
}
.header .sub {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-top: 4px;
}

.contenedor {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
}

.sidebar { display: flex; flex-direction: column; gap: 16px; }
.principal { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* === TARJETAS === */
.tarjeta {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  padding: 18px;
  transition: box-shadow .2s;
}
.tarjeta:hover { box-shadow: var(--shadow-md); }

.tarjeta h2 {
  margin: 0 0 14px 0;
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
}
.tarjeta h3 {
  margin: 0 0 10px 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink-soft);
}

/* === FORMS === */
.campo { margin-bottom: 12px; }
label.campo-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: .02em;
}
select, input[type="number"], input[type="text"], input[type="file"] {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  transition: all .2s;
  outline: none;
}
select:focus, input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(30,84,224,.12);
}

input[type="file"] {
  padding: 9px;
  font-size: 13px;
}

.slider-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--brand);
}
.slider-row input[type="number"] {
  width: 78px;
  text-align: center;
  padding: 8px;
}

/* === BOTONES === */
.boton {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 12px 22px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all .2s;
  overflow: hidden;
}
.boton-primario {
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.boton-primario::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.25) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform .55s;
}
.boton-primario:hover { background: var(--brand-dk); box-shadow: var(--shadow-md); }
.boton-primario:hover::before { transform: translateX(100%); }

.boton-exito {
  background: var(--green);
  color: #fff;
  border-radius: 9px;
}
.boton-exito:hover { background: var(--green-dk); }

.boton:disabled {
  opacity: .55;
  cursor: not-allowed;
}

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

/* === TABLAS === */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table th, table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line-soft);
}
table th {
  font-weight: 800;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* === BADGES === */
.badge {
  display: inline-block;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
}
.badge-azul { background: var(--brand-tint); color: var(--brand-dk); }
.badge-verde { background: var(--green-tint); color: var(--green-dk); }
.badge-naranja { background: var(--orange-tint); color: var(--orange); }
.badge-rojo { background: var(--warn-tint); color: var(--warn); }

/* === PANEL DE PARÁMETROS CALCULADOS === */
.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.kv {
  background: var(--line-soft);
  border-radius: 9px;
  padding: 10px 12px;
}
.kv-label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.kv-valor {
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
  margin-top: 2px;
}

/* === CANVAS COBERTURA === */
.cobertura-cont {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
#canvas-cobertura {
  background: var(--line-soft);
  border-radius: 12px;
  cursor: grab;
  border: 1px solid var(--line);
}
#canvas-cobertura:active { cursor: grabbing; }

.info-cobertura {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.info-cobertura strong { color: var(--ink); }

/* === RESULTADOS === */
.grid-resultados {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.grid-resultados .tarjeta { min-width: 0; }

.img-comparativa {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.img-comparativa figure { margin: 0; }
.img-comparativa figcaption {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.img-comparativa img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: block;
}

.ber-grande {
  text-align: center;
  padding: 12px;
  background: var(--brand-tint);
  border-radius: 10px;
}
.ber-grande .valor {
  font-size: 28px;
  font-weight: 900;
  color: var(--brand-dk);
}
.ber-grande .lbl {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

#preview-imagen {
  max-width: 100%;
  margin-top: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: none;
}

#mapa-sc-canvas, #constelacion-canvas, #montecarlo-canvas {
  width: 100%;
  height: auto;
  background: var(--surface);
}

.estado {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.estado.ok { color: var(--green-dk); }
.estado.err { color: var(--warn); }

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2.5px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: girar .8s linear infinite;
  vertical-align: middle;
}
@keyframes girar { to { transform: rotate(360deg); } }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}
.skeleton {
  background: var(--line-soft);
  border-radius: 8px;
  animation: pulse 2s ease-in-out infinite;
  min-height: 200px;
}

.aviso {
  background: var(--warn-tint);
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  margin-top: 10px;
}

/* === LIGHTBOX === */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 37, 64, 0.88);
  z-index: 1000;
  display: flex !important;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: fadeIn .25s;
}
.lightbox[style*="none"] { display: none !important; }
.lightbox img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  background: var(--surface);
}
.lightbox-cerrar {
  position: absolute;
  top: 20px;
  right: 28px;
  color: #fff;
  font-size: 42px;
  font-weight: 800;
  cursor: pointer;
  line-height: 1;
}
.img-comparativa img {
  cursor: zoom-in;
  transition: transform .15s;
}
.img-comparativa img:hover { transform: scale(1.02); }

/* === MODAL MONTE CARLO === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 37, 64, 0.7);
  z-index: 1001;
  display: flex !important;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .25s;
}
.modal[style*="none"] { display: none !important; }
.modal-contenido {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: min(1100px, 95vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  gap: 16px;
}
.modal-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
}
.modal-acciones { display: flex; gap: 10px; }
.modal-body {
  padding: 22px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.modal-body canvas {
  width: 100% !important;
  height: 60vh !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* === RESPONSIVE === */
@media (max-width: 1024px) {
  .contenedor { grid-template-columns: 1fr; }
  .grid-resultados { grid-template-columns: 1fr; }
}
