/* Simulador de hipotecas (public/hipoteca/simulador.js). Paleta Hipoteca100 (variables de public/style.css).
   Todas las clases llevan el prefijo hp-; los botones reutilizan .btn / .btn.main del CRM. */
.hp-dlg {
  --hp-r-sm: 10px;
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 16px;
  width: min(1760px, calc(100vw - 24px));
  max-width: none;
  height: calc(100vh - 24px);
  max-height: none;
  background: var(--bg, #f4f6f8);
  color: var(--ink, #16222e);
  box-shadow: 0 16px 48px rgba(18, 36, 54, 0.25);
  overflow: hidden;
}
.hp-dlg[open] {
  display: flex;
  flex-direction: column;
}
.hp-dlg::backdrop {
  background: rgba(18, 36, 54, 0.45);
}
.hp-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--card, #fff);
  border-bottom: 1px solid var(--line, #dce3ea);
}
.hp-head h2 {
  font-size: 18.5px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--brand, #0f4c5c);
}
.hp-head p {
  margin-top: 2px;
  color: var(--muted, #566676);
}
.hp-x {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--hp-r-sm);
  border: 1px solid var(--line, #dce3ea);
  background: var(--card, #fff);
  color: var(--ink-2, #3c4b5a);
}
.hp-x:hover {
  border-color: var(--brand, #0f4c5c);
  color: var(--brand, #0f4c5c);
}
.hp-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
}
.hp-hidden {
  display: none !important;
}
.hp-muted {
  color: var(--muted, #566676);
}

/* Disposición a pantalla completa: datos | más datos | cuota | gastos y acciones. Cada columna con su propio scroll
   (solo si no cabe); el objetivo es que no haga falta ninguno. */
.hp {
  display: grid;
  gap: 12px;
  height: 100%;
}
.hp-outs {
  display: grid;
  gap: 12px;
  min-height: 0;
  min-width: 0;
}
@media (min-width: 1100px) {
  .hp {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2.7fr);
  }
  .hp-outs {
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr);
  }
  .hp-col {
    overflow: auto;
    min-height: 0;
  }
}
.hp-col-t {
  font-size: 15.5px;
  font-weight: 600;
  color: var(--brand);
}
.hp-form,
.hp-out {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 16px;
  border-radius: var(--r, 12px);
  background: var(--card, #fff);
  border: 1px solid var(--line, #dce3ea);
}
.hp-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

/* Campos */
.hp-field {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
  font-size: 14.7px;
  color: var(--ink, #16222e);
}
.hp-label {
  font-weight: 500;
  color: var(--ink-2, #3c4b5a);
}
.hp-field small {
  font-size: 13px;
  color: var(--muted, #566676);
}
.hp-field select,
.hp-input input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line, #dce3ea);
  border-radius: var(--hp-r-sm);
  padding: 0 12px;
  background: var(--card, #fff);
  font-size: 15.5px;
  color: var(--ink, #16222e);
}
.hp-field select:focus,
.hp-input input:focus {
  border-color: var(--brand, #0f4c5c);
}
.hp-input {
  position: relative;
  display: block;
}
.hp-input input {
  padding-right: 52px;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
  -moz-appearance: textfield;
}
.hp-input input::-webkit-inner-spin-button,
.hp-input input::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}
.hp-input i {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-style: normal;
  font-size: 13.5px;
  color: var(--muted, #566676);
  pointer-events: none;
}
.hp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
}
.hp-k {
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted, #566676);
}
.hp-seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.hp-seg button {
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line, #dce3ea);
  background: var(--card, #fff);
  color: var(--ink-2, #3c4b5a);
  font-size: 14.7px;
  font-weight: 500;
}
.hp-seg button:hover {
  border-color: var(--brand, #0f4c5c);
}
.hp-seg button.on {
  border-color: var(--brand, #0f4c5c);
  background: var(--brand, #0f4c5c);
  color: #fff;
}
.hp-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14.7px;
  color: var(--ink, #16222e);
  line-height: 1.4;
  cursor: pointer;
}
.hp-check input {
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  accent-color: var(--brand, #0f4c5c);
}
.hp-more {
  border: 1px solid var(--line, #dce3ea);
  border-radius: var(--hp-r-sm);
  padding: 12px 14px;
  background: var(--bg, #f4f6f8);
}
.hp-more summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--brand, #0f4c5c);
}
.hp-more-body {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}
.hp-vinc {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}
.hp-vinc legend {
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted, #566676);
}

/* Resultado */
.hp-market {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-radius: var(--hp-r-sm);
  background: var(--brand-2, #e6f0f2);
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink-2, #3c4b5a);
}
.hp-market > svg {
  flex: none;
  margin-top: 2px;
  color: var(--brand, #0f4c5c);
}
.hp-market > span {
  flex: 1;
  min-width: 200px;
}
.hp-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: none;
  padding: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--brand, #0f4c5c);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.hp-link:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.hp-hero {
  display: grid;
  gap: 3px;
  padding: 14px 18px;
  border-radius: var(--r, 12px);
  background: var(--brand, #0f4c5c);
  color: #fff;
}
.hp-hero .hp-k {
  color: #c9d3dd;
}
.hp-hero > b {
  font-size: 36px;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.hp-hero small {
  font-size: 14px;
  color: #dfe5ec;
}
.hp-hero small b {
  color: #fff;
}
.hp-compare {
  display: grid;
  gap: 6px;
}
.hp-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 8px 12px;
  border-radius: var(--hp-r-sm);
  border: 1px solid var(--line, #dce3ea);
  background: var(--card, #fff);
  color: var(--ink, #16222e);
  text-align: left;
}
.hp-opt:hover {
  border-color: var(--brand, #0f4c5c);
}
.hp-opt.on {
  border-color: var(--brand, #0f4c5c);
  background: var(--brand-2, #e6f0f2);
  box-shadow: inset 0 0 0 1px var(--brand, #0f4c5c);
}
.hp-opt-l,
.hp-opt-r {
  display: grid;
  gap: 1px;
  min-width: 0;
}
.hp-opt-r {
  flex: none;
  text-align: right;
}
.hp-opt b {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.hp-opt small {
  font-size: 13px;
  line-height: 1.35;
  color: var(--muted, #566676);
  font-variant-numeric: tabular-nums;
}
.hp-viab {
  display: grid;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--hp-r-sm);
  border: 1px solid var(--line, #dce3ea);
  border-left-width: 4px;
}
.hp-viab.viable {
  border-left-color: var(--green, #1e7b4a);
}
.hp-viab.justo {
  border-left-color: var(--amber, #8a5200);
}
.hp-viab.dificil {
  border-left-color: var(--red, #b42318);
}
.hp-viab-head {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.hp-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  background: var(--grey-bg, #eef1f4);
  color: var(--ink-2, #3c4b5a);
}
.hp-badge.viable,
.hp-badge.bien {
  background: var(--green-bg, #e5f4ec);
  color: var(--green, #1e7b4a);
}
.hp-badge.justo {
  background: var(--amber-bg, #fff4dc);
  color: var(--amber, #8a5200);
}
.hp-badge.dificil {
  background: var(--red-bg, #fdecea);
  color: var(--red, #b42318);
}
.hp-viab ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
}
.hp-viab li {
  position: relative;
  padding-left: 16px;
  font-size: 14.2px;
  line-height: 1.45;
  color: var(--ink, #16222e);
}
.hp-viab li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--muted, #566676);
}
.hp-viab li.bien::before {
  background: var(--green, #1e7b4a);
}
.hp-viab li.aviso::before {
  background: var(--amber, #8a5200);
}
.hp-viab li.info::before {
  background: var(--blue, #1f5fa8);
}
.hp-viab li.mal {
  color: var(--red, #b42318);
}
.hp-viab li.mal::before {
  background: var(--red, #b42318);
}
.hp-kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.hp-kpis span {
  display: grid;
  gap: 2px;
  padding: 8px 12px;
  border-radius: var(--hp-r-sm);
  border: 1px solid var(--line, #dce3ea);
  min-width: 0;
}
.hp-kpis small {
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted, #566676);
}
.hp-kpis b {
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.hp-kpis span.warn {
  border-color: var(--amber, #8a5200);
  background: var(--amber-bg, #fff4dc);
}
.hp-kpis span.warn b {
  color: var(--amber, #8a5200);
}
.hp-block {
  display: grid;
  gap: 2px;
}
.hp-block h3,
.hp-block summary {
  margin: 0 0 4px;
  font-size: 15.5px;
  font-weight: 600;
  color: var(--ink, #16222e);
}
.hp-block summary {
  cursor: pointer;
  color: var(--brand, #0f4c5c);
}
.hp-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line, #dce3ea);
  font-size: 14.7px;
  color: var(--ink-2, #3c4b5a);
}
.hp-line b {
  color: var(--ink, #16222e);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.hp-line.total {
  border-bottom: 0;
  color: var(--ink, #16222e);
  font-weight: 600;
}
.hp-line.total b {
  font-weight: 700;
}
.hp-line.fee {
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px dashed var(--line, #dce3ea);
  border-radius: var(--hp-r-sm);
}
.hp-table {
  display: grid;
  align-content: start;
  min-height: 0;
  flex: 1;
  overflow: auto;
  border: 1px solid var(--line, #dce3ea);
  border-radius: var(--hp-r-sm);
}
.hp-tr {
  display: grid;
  grid-template-columns: 0.5fr repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 6px 10px;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--line, #dce3ea);
}
.hp-tr span:not(:first-child) {
  text-align: right;
}
.hp-tr.head {
  position: sticky;
  top: 0;
  background: var(--bg, #f4f6f8);
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted, #566676);
}
.hp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.hp-actions .btn svg {
  flex: none;
}
.hp-hint {
  font-size: 13.5px;
  color: var(--muted, #566676);
}
.hp-disclaimer {
  padding-top: 8px;
  border-top: 1px solid var(--line, #dce3ea);
}
.hp-ok,
.hp-err {
  padding: 10px 12px;
  border-radius: var(--hp-r-sm);
  font-size: 14.2px;
}
.hp-ok {
  background: var(--green-bg, #e5f4ec);
  color: var(--green, #1e7b4a);
}
.hp-err {
  background: var(--red-bg, #fdecea);
  color: var(--red, #b42318);
}

@media (max-width: 600px) {
  .hp-dlg {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .hp-body {
    padding: 14px;
  }
  .hp-grid,
  .hp-compare {
    grid-template-columns: minmax(0, 1fr);
  }
  .hp-hero > b {
    font-size: 30px;
  }
}

/* Cabecera: botón Ajustes */
.hp-head-acc { display: flex; align-items: center; gap: 8px; }
.hp-ajustes-btn {
  height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--brand); font-weight: 600;
}
.hp-ajustes-btn:hover, .hp-ajustes-btn.on { border-color: var(--brand); background: var(--brand-2); }
.hp-ajustes { border: 1px solid var(--brand); background: var(--brand-2); border-radius: var(--r); padding: 16px 18px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px; }
.hp-badge.neutro { background: var(--grey-bg); color: var(--ink-2); }
.hp-viab { background: var(--card); border-color: var(--line); }

/* Paneles que ocupan las dos columnas del resultado (Ajustes, cuadro de amortización) */
.hp-outs > .hp-panel { grid-column: 1 / -1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 10px; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--r, 12px); padding: 16px; }
.hp-outs > .hp-ajustes { background: var(--brand-2); border-color: var(--brand); }
.hp-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hp-panel-head h3 { margin: 0; }
.hp-tabla-btn { align-self: flex-start; }
.hp-out .hp-actions { margin-top: auto; }
.hp-out .hp-actions .btn { flex: 1; justify-content: center; }
.hp-head p { max-width: 1100px; }

.hp-market { padding: 8px 12px; align-items: center; }
.hp-market > svg { margin-top: 0; }
.hp-hero { grid-template-columns: auto 1fr; column-gap: 18px; align-items: baseline; }
.hp-hero > .hp-k { grid-column: 1 / -1; }
.hp-hero > b { grid-row: span 3; align-self: center; }
.hp-hero > small { justify-self: end; text-align: right; }
.hp-viab li { line-height: 1.35; }
.hp-out .hp-block h3 { margin-bottom: 2px; }

.hp-outs .hp-kpis { gap: 6px; }
.hp-outs .hp-kpis span { padding: 6px 10px; }
.hp-hero > .hp-hero-full { grid-column: 1 / -1; justify-self: start; text-align: left; }
.hp-hero > b { grid-row: span 1; }
.hp-out .hp-actions { flex-wrap: nowrap; }
.hp-out .hp-actions .btn { flex: 1 1 0; min-width: 0; padding: 0 10px; }
.hp-out .hp-actions .btn:first-child { flex: 0.7 1 0; }
.hp-tabla-btn { align-self: flex-start; }
@media (max-height: 820px) {
  .hp-hero { padding: 10px 16px; }
  .hp-hero > b { font-size: 30px; }
  .hp-form, .hp-out { padding: 12px 14px; gap: 9px; }
  .hp-head { padding: 8px 18px; }
  .hp-field select, .hp-input input { height: 36px; }
  .hp-seg button { min-height: 32px; padding: 4px 12px; }
}

/* Opción elegida = la cuota principal */
.hp-opt-l { flex: 1 1 auto; }
.hp-opt.on { flex-wrap: wrap; row-gap: 6px; }
.hp-head > div:first-child { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.hp-head > div:first-child p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hp-head h2 { white-space: nowrap; }
.hp-opt-full { flex-basis: 100%; }
.hp-opt.on { background: var(--brand); border-color: var(--brand); box-shadow: none; color: #fff; padding: 12px 14px; }
.hp-opt.on .hp-k, .hp-opt.on small { color: #d5dde6; }
.hp-opt.on b { font-size: 28px; color: #fff; }
@media (max-height: 900px) { .hp-hidden-short { display: none; } }
@media (max-height: 820px) {
  .hp-field { gap: 2px; }
  .hp-grid { gap: 8px 10px; }
  .hp-opt { padding: 6px 10px; }
  .hp-opt.on { padding: 10px 12px; }
  .hp-viab { padding: 8px 12px; gap: 6px; }
  .hp-viab li { line-height: 1.3; }
  .hp-market { padding: 6px 10px; }
}
@media (max-width: 1440px) and (max-height: 820px) { .hp-dlg { width: 100vw; height: 100vh; border-radius: 0; } }
