:root {
  --indigo: #4f46e5;
  --indigo-d: #4338ca;
  --ink: #1e1b2e;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f5f6fb;
  --card: #ffffff;
  --ok: #16a34a;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; color: var(--ink); background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--indigo); color: #fff;
}
.brand { font-weight: 800; display: inline-flex; align-items: center; gap: 8px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: rgba(255,255,255,.2); font-size: 13px; font-weight: 900;
}
.pill {
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: rgba(255,255,255,.18);
}

/* Contenido */
main { padding: 14px 14px 92px; max-width: 720px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.view-head h1 { font-size: 22px; margin: 0; }

.search {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  font-size: 16px; margin-bottom: 12px; background: #fff;
}

/* Botones (touch targets grandes) */
.btn {
  min-height: 46px; padding: 11px 16px; border: 1px solid var(--line);
  border-radius: 12px; background: #fff; color: var(--ink);
  font-weight: 700; font-size: 15px; cursor: pointer;
}
.btn.primary { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn.primary:active { background: var(--indigo-d); }
.btn.ghost { background: #eef0fb; border-color: #dfe2f7; color: var(--indigo-d); }
.btn:disabled { opacity: .5; }

/* Tarjetas de contacto */
.cards { display: grid; gap: 10px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px;
}
.card .nom { font-weight: 800; font-size: 16px; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.card .badge {
  display: inline-block; margin-top: 8px; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: #eef2ff; color: var(--indigo-d);
}
.card .card-actions { display: flex; gap: 8px; margin-top: 10px; }
.card .card-actions .btn { min-height: 38px; padding: 7px 12px; font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.mt { margin-top: 12px; }
.mt summary { cursor: pointer; font-weight: 700; color: var(--indigo-d); font-size: 14px; }
#imp-preview { margin-top: 6px; font-weight: 700; color: var(--ink); }
.chk { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink); font-weight: 600; margin: 4px 0 10px; }
.chk input { width: 20px; height: 20px; }
.chk-off { color: var(--muted); }
.chk-off input { opacity: .5; }
.tag-off { font-size: 12px; font-weight: 700; color: #b45309; background: #fef3c7; border-radius: 999px; padding: 2px 8px; }
.tag-on { font-size: 12px; font-weight: 800; color: #047857; background: #d1fae5; border-radius: 999px; padding: 2px 8px; }
.export-row { margin-top: 14px; }

/* Formularios */
.field { display: grid; gap: 5px; margin-bottom: 12px; font-size: 13px; color: var(--muted); font-weight: 700; }
.field input, .field select, .cartilla-row input {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  font-size: 16px; background: #fff; color: var(--ink);
}
textarea#cat-json {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  font-size: 13px; font-family: ui-monospace, monospace; background: #fff; color: var(--ink);
  resize: vertical; margin-bottom: 10px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.row4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; }
@media (max-width: 480px) {
  .row3, .row4 { grid-template-columns: 1fr 1fr; }
}

.subcard {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 14px;
}
.subcard strong { display: block; margin-bottom: 10px; }
.cartilla-box .hint { margin: -2px 0 10px; }
.cartilla-row { display: flex; gap: 8px; align-items: stretch; }
.cartilla-row input { flex: 1; min-width: 0; }
.cartilla-row .btn { white-space: nowrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1; min-width: 90px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  background: #eef2ff; color: var(--indigo-d); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; font-weight: 700;
}
.checks { display: grid; gap: 8px; }
.checks label { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); font-weight: 600; }
.checks input { width: 20px; height: 20px; }

.mini-list { margin-top: 10px; display: grid; gap: 6px; }
.mini-list div { font-size: 14px; padding: 8px 10px; background: #f8f9ff; border-radius: 8px; }
.lnk-rm { float: right; border: 0; background: #fee2e2; color: #b91c1c; border-radius: 6px; width: 24px; height: 24px; font-weight: 800; cursor: pointer; }
/* Tarjetas de comparación de planes */
#cot-comparacion { margin-top: 14px; }
.cmp { position: relative; }
.cmp-total { font-size: 26px; font-weight: 800; color: var(--indigo-d); margin: 4px 0 0; }
.cmp-label { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.badge.best { position: absolute; top: 12px; right: 12px; background: #dcfce7; color: #166534; margin: 0; }
.cmp.fail { opacity: .75; }
.cmp.fail .sub { color: #b91c1c; }

/* Encabezado de la prepaga elegida */
.pp-title { display: flex; align-items: center; gap: 9px; margin: 2px 0 12px; }
.pp-title .dot { width: 12px; height: 12px; border-radius: 999px; background: var(--pp, var(--indigo)); }
.pp-title b { font-size: 17px; color: var(--pp, var(--ink)); letter-spacing: .3px; }

/* Resultado de cotización (tarjeta linda, color por prepaga) */
.cot-result {
  margin-top: 14px; border: 1px solid var(--line); border-radius: 16px;
  overflow: hidden; background: #fff; box-shadow: 0 6px 20px rgba(30,27,46,.06);
}
.cot-result-head { background: var(--pp, var(--indigo)); color: #fff; padding: 13px 18px; }
.cot-result-head .pp { font-size: 11px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; opacity: .85; }
.cot-result-head .plan { font-size: 17px; font-weight: 800; margin-top: 1px; }
.cot-body { padding: 12px 18px 16px; }
.cot-line { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 15px; border-bottom: 1px dashed var(--line); }
.cot-line span { color: var(--muted); font-weight: 600; }
.cot-line b { color: var(--ink); font-weight: 700; white-space: nowrap; }
.cot-line.desc b { color: var(--ok); }
.cot-total {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding-top: 13px; margin-top: 5px; border-top: 2px solid var(--ink);
}
.cot-total span { font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.cot-total b { font-size: 27px; font-weight: 900; color: var(--pp, var(--indigo)); white-space: nowrap; }
.cot-note { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.cot-empty { margin-top: 14px; color: var(--muted); font-size: 14px; text-align: center; padding: 18px; border: 1px dashed var(--line); border-radius: 14px; }
.cot-error { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: #fef2f2; color: #b91c1c; font-weight: 700; font-size: 14px; }
.cot-ask { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: #fffbeb; color: #92400e; font-weight: 600; font-size: 14px; }

/* Compartir la cotización (copiar / WhatsApp) */
.cot-share { display: flex; gap: 8px; margin-top: 14px; }
.cot-share .btn { flex: 1; min-height: 42px; padding: 9px 12px; font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn.wa:active { background: #1eb257; }
.copied-ok { color: var(--ok); font-weight: 800; font-size: 13px; text-align: center; margin-top: 8px; min-height: 16px; }

/* Botón "+ Agregar" listo (tras cotizar) */
.btn.add-ready { background: #ecfdf5; border-color: #6ee7b7; color: #047857; }

/* Eco del monto formateado bajo el input de sueldo/aporte */
.money-echo { font-size: 12.5px; font-weight: 700; color: var(--indigo-d); margin-top: 6px; min-height: 15px; }
.money-echo:empty { display: none; }

/* "Más opciones" plegable (campos de nicho) */
.mas-opciones { margin: 0 0 12px; border-top: 1px dashed var(--line); padding-top: 6px; }
.mas-opciones > summary {
  cursor: pointer; font-weight: 700; color: var(--indigo-d); font-size: 14px;
  list-style: none; display: flex; align-items: center; gap: 7px; padding: 8px 0;
}
.mas-opciones > summary::-webkit-details-marker { display: none; }
.mas-opciones > summary::before { content: "▸"; font-size: 12px; }
.mas-opciones[open] > summary::before { content: "▾"; }
.mas-opciones[open] > summary { margin-bottom: 6px; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: grid; place-items: end center; z-index: 20;
}
.modal[hidden] { display: none; }
/* hidden SIEMPRE oculta: sin esto, .field/.row2 (display:grid/flex) pisan el atributo */
[hidden] { display: none !important; }
.modal-card {
  background: #fff; width: 100%; max-width: 640px; border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 20px);
  max-height: 92vh; overflow-y: auto;
}
.modal-card h2 { margin: 0 0 14px; font-size: 20px; }

/* Barra de pestañas inferior */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; border: 0; background: none; padding: 8px 0 10px;
  display: grid; gap: 2px; justify-items: center; font-size: 12px; font-weight: 700;
  color: var(--muted); cursor: pointer;
}
.tab span { font-size: 20px; }
.tab.active { color: var(--indigo); }
