/* Frameflow · Componentes reutilizables (Boton/*, Campo/Texto, Tarjeta/Perfil, chips, hoja, menú) */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }  /* la transición entre pantallas no debe crear scroll horizontal */

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: var(--fs-title); line-height: 1.25; font-weight: 700; }
h2 { font-size: var(--fs-sub); line-height: 1.3; font-weight: 600; }
h3 { font-size: var(--fs-body); font-weight: 600; }
h1:focus, main:focus { outline: none; }
a { color: var(--blue); }
img { max-width: 100%; display: block; }
button, input, select { font: inherit; color: inherit; }

.muted { color: var(--text-2); }
.on-bg { color: var(--text-2-bg); }
.label-sm { font-size: var(--fs-label); font-weight: 500; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--blue); color: #fff; padding: 12px 16px; border-radius: 8px;
}
.skip-link:focus { top: 8px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 12px 20px;
  border: 2px solid transparent; border-radius: var(--radius);
  font-size: 16px; font-weight: 600; line-height: 1.2; text-align: center; text-decoration: none;
  cursor: pointer; transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:active { transform: scale(.985); }
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--blue); color: #fff; }               /* Boton/Primario */
.btn-primary:hover { background: #1953b8; }
.btn-primary:active { background: var(--blue-dark); }
.btn-secondary { background: #fff; color: var(--blue); border-color: var(--blue); } /* Boton/Secundario */
.btn-secondary:active { background: var(--blue-light); }
.btn-wa { background: var(--wa-btn); color: #fff; }                   /* Boton/WhatsApp */
.btn-wa:hover { background: var(--wa-btn-dark); }
.btn-wa:active { background: var(--wa-btn-dark); }
.btn-text { background: transparent; color: var(--blue); padding-inline: 12px; }
.btn-text:active { background: var(--blue-light); }
.btn-sm { min-height: var(--tap); padding: 8px 14px; font-size: 15px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); flex: none;
  border: 0; border-radius: 50%; background: transparent; color: var(--text); cursor: pointer;
  text-decoration: none;
}
.iconbtn:active { background: rgba(17, 24, 39, .08); }
.icon { width: 24px; height: 24px; flex: none; }
.icon-sm { width: 18px; height: 18px; flex: none; }

/* ---------- Campo/Texto ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-size: var(--fs-label); font-weight: 500; }
.input {
  width: 100%; min-height: 52px; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  background: #fff; font-size: 16px; color: var(--text);
  appearance: none; -webkit-appearance: none;
}
.input::placeholder { color: var(--text-2); opacity: 1; }
.input:focus { outline: 3px solid var(--blue-light); border-color: var(--blue); }
.field.has-error .input { border-color: var(--error); background: #FFF7F7; }
.field-hint { font-size: var(--fs-label); color: var(--text-2); }
.field-error {
  display: none; align-items: flex-start; gap: 6px;
  font-size: var(--fs-label); font-weight: 500; color: var(--error);
}
.field.has-error .field-error, .form-error.show { display: flex; }
.form-error {
  display: none; align-items: flex-start; gap: 6px; padding: 10px 12px; border-radius: 10px;
  background: var(--error-bg); color: var(--error); font-size: var(--fs-label); font-weight: 500;
}
select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23111827' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px;
}

/* ---------- Chips (opciones seleccionables) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 8px 16px;
  border: 1.5px solid var(--border); border-radius: 999px; background: #fff;
  font-size: 16px; font-weight: 500; color: var(--text); cursor: pointer;
  transition: background-color .12s, border-color .12s;
}
.chip:active { background: var(--blue-light); }
.chip[aria-checked="true"], .chip[aria-pressed="true"] {
  background: var(--blue-light); border-color: var(--blue); color: var(--blue-dark); font-weight: 600;
}
.chip[aria-checked="true"]::after, .chip[aria-pressed="true"]::after {
  content: ""; width: 16px; height: 16px; flex: none; margin-left: -2px;
  background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230F3E96' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E");
}
.chip-ic { font-size: 18px; line-height: 1; }
.chip-removable { min-height: 40px; padding: 4px 8px 4px 14px; font-size: 14px; background: var(--blue-light); border-color: var(--blue); color: var(--blue-dark); }
.chip-removable::after { content: none !important; }

/* Etiquetas no interactivas */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px;
  background: #fff; border: 1px solid var(--border);
  font-size: var(--fs-label); font-weight: 500; color: var(--text);
}
.tag-blue { background: var(--blue-light); border-color: transparent; color: var(--blue-dark); }
.tag-ok { background: var(--ok); border-color: transparent; color: var(--ok-text); font-weight: 600; }
.tag-gray { background: #E5E7EB; border-color: transparent; color: #1F2937; }
.tag-warn { background: #FEF3C7; border-color: transparent; color: #78350F; }

/* ---------- Tarjeta / avatar ---------- */
.card { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 16px; }
.card-blue { background: var(--blue-light); box-shadow: none; }

.avatar {
  --h: 215; --s: 56px;
  width: var(--s); height: var(--s); flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: hsl(var(--h) 60% 88%); color: hsl(var(--h) 65% 22%);
  font-weight: 700; font-size: calc(var(--s) * .36); letter-spacing: .02em;
}
.avatar-lg { --s: 72px; }

/* Tarjeta/Perfil */
.profile-card { display: flex; align-items: center; gap: 14px; }
.profile-card .who { min-width: 0; }
.profile-card .who h2 { overflow-wrap: anywhere; }
.profile-card .who p { color: var(--text-2); }

/* ---------- Progreso ---------- */
.progress { height: 6px; border-radius: 99px; background: #DBE4F5; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--blue); border-radius: 99px; transition: width .3s; }

/* ---------- Menú general ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex; background: #fff; border-top: 1px solid var(--border);
}
body.pmv .bottom-nav, body.focus .bottom-nav { display: none; }
.nav-item {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--text-2); font-size: 13px; font-weight: 500; padding: 6px 2px;
}
.nav-item[aria-current="page"] { color: var(--blue); font-weight: 700; }
.nav-item[aria-current="page"] .icon { stroke-width: 2.6; }
.nav-item:active { background: var(--blue-light); }
.nav-item .long { display: none; }

@media (min-width: 900px) {
  .bottom-nav { display: none; }
  .nav-item .long { display: inline; } .nav-item .short { display: none; }
}

.desktop-nav { display: none; }
@media (min-width: 900px) {
  .desktop-nav { display: flex; gap: 4px; }
  .desktop-nav .nav-item {
    flex-direction: row; gap: 8px; min-height: var(--tap); padding: 8px 14px; border-radius: 10px; font-size: 15px; white-space: nowrap;
  }
  .desktop-nav .nav-item[aria-current="page"] { background: var(--blue-light); }
}
body.pmv .desktop-nav, body.focus .desktop-nav { display: none; }

/* ---------- Hoja modal (contacto, reporte) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(17, 24, 39, .5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease-out;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 90vh; overflow: auto;
  background: #fff; border-radius: 20px 20px 0 0; padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow-lg); animation: rise .22s ease-out;
}
.sheet h2 { margin-bottom: 4px; }
.sheet .sheet-actions { display: grid; gap: 10px; margin-top: 16px; }
.quote {
  margin-top: 12px; padding: 14px; border-radius: var(--radius);
  background: var(--ok); border-left: 4px solid var(--wa); color: var(--ok-text); overflow-wrap: anywhere;
}
.radio-list { display: grid; gap: 8px; margin-top: 12px; }
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; padding: 16px; }
  .sheet { border-radius: 20px; }
}

/* ---------- Aviso emergente ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom, 0px)); z-index: 80;
  transform: translate(-50%, 24px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 420px); padding: 12px 18px; border-radius: 12px;
  background: #111827; color: #fff; font-size: 15px; font-weight: 500; text-align: center;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
