/* ==========================================================================
   Componentes
   ========================================================================== */

/* ---------- Respuesta táctil común ---------- */
.pressable {
  transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-1) var(--ease-out),
              box-shadow var(--dur-2) var(--ease-out), opacity var(--dur-1) var(--ease-out);
}
.pressable:active { transform: scale(.97); }
@media (hover: hover) {
  .pressable:hover { filter: brightness(1.03); }
}

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 50px; padding: 0 var(--s-6);
  border-radius: var(--r-md);
  font-size: var(--fs-headline); font-weight: 600; letter-spacing: -0.01em;
  white-space: nowrap; user-select: none; -webkit-user-select: none;
}
.btn:disabled { opacity: .45; pointer-events: none; }
.btn--primary { background: var(--accent); color: var(--text-on-accent); box-shadow: var(--shadow-accent); }
.btn--primary:active { background: var(--accent-press); }
.btn--tinted  { background: var(--accent-soft); color: var(--accent); }
.btn--plain   { color: var(--accent); padding: 0 var(--s-3); min-height: 44px; }
.btn--danger  { color: var(--danger); }
.btn--block   { width: 100%; }
.btn--sm      { min-height: 36px; padding: 0 var(--s-4); font-size: var(--fs-subhead); border-radius: var(--r-pill); }
.btn .spinner { width: 18px; height: 18px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: var(--r-pill);
  color: var(--accent);
}
.icon-btn--filled { background: var(--accent-soft); }

/* ---------- Spinner ---------- */
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.25px solid currentColor; border-right-color: transparent;
  animation: girar .7s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

/* ---------- Barra de cristal ---------- */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: var(--bg-elevated); }
}

.navbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  height: calc(var(--bar-h) + var(--safe-top));
  padding: var(--safe-top) var(--s-2) 0;
  border-bottom: .5px solid transparent;
  transition: border-color var(--dur-2) var(--ease-out), background-color var(--dur-2) var(--ease-out);
}
.navbar.is-scrolled { border-bottom-color: var(--hairline); }
/* Transparente sobre el título grande; cristal solo al desplazarse */
.navbar:not(.is-scrolled) { background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; pointer-events: none; }
.navbar__title {
  font-size: var(--fs-headline); font-weight: 600;
  opacity: 0; transform: translateY(6px);
  transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-snappy);
}
.navbar.is-scrolled .navbar__title { opacity: 1; transform: none; }
.navbar__lead  { justify-self: start; }
.navbar__trail { justify-self: end; }

/* ---------- Secciones agrupadas (inset grouped) ---------- */
.group { margin-top: var(--s-8); }
.group__head {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3);
  padding: 0 var(--s-1) var(--s-2);
}
.group__title { font-size: var(--fs-title-3); font-weight: 700; letter-spacing: -0.018em; }
.group__body {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.group__foot { padding: var(--s-2) var(--s-4) 0; }

.row {
  position: relative;
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 60px; padding: var(--s-3) var(--s-4);
}
.row + .row::before {
  content: ""; position: absolute; top: 0; right: 0; left: var(--row-inset, var(--s-4));
  border-top: .5px solid var(--hairline-2);
}
.row__icon {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
}
.row__icon--ok   { background: var(--success-soft); color: var(--success); }
.row__icon--wait { background: var(--warning-soft); color: var(--warning); }
.row__main { flex: 1; min-width: 0; }
.row__title { font-weight: 600; font-variant-numeric: tabular-nums; }
.row__sub { font-size: var(--fs-subhead); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__meta { font-size: var(--fs-footnote); color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row__error { font-size: var(--fs-footnote); color: var(--danger); margin-top: 2px; }

/* ---------- Campos ---------- */
.field { display: block; padding: var(--s-3) var(--s-4); position: relative; }
.field + .field::before, .field + .field-row::before, .field-row + .field::before, .field-row + .field-row::before,
.toggle-row + .field::before, .field + .toggle-row::before {
  content: ""; position: absolute; top: 0; right: 0; left: var(--s-4);
  border-top: .5px solid var(--hairline-2);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; position: relative; }
.field-row > .field + .field::before { top: 12px; bottom: 12px; left: 0; right: auto; border-top: 0; border-left: .5px solid var(--hairline-2); }
.field__label {
  display: block; font-size: var(--fs-footnote); font-weight: 500; color: var(--text-2);
  margin-bottom: 2px; letter-spacing: 0;
}
.field__label .opt { color: var(--text-3); font-weight: 400; }
.field__input {
  display: block; width: 100%;
  min-height: 30px; padding: 2px 0;
  border: 0; background: transparent; border-radius: 0;
  font-size: var(--fs-body); color: var(--text);
  -webkit-appearance: none; appearance: none;
}
.field__input::placeholder { color: var(--text-3); }
.field__input:focus-visible { outline: none; }
textarea.field__input { resize: none; min-height: 72px; line-height: 1.4; field-sizing: content; max-height: 220px; }
select.field__input {
  padding-right: 24px;
  background: no-repeat right 2px center / 12px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%237d829f' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.field:focus-within .field__label { color: var(--accent); }
.field.is-invalid .field__label { color: var(--danger); }
.field.is-invalid { background: var(--danger-soft); }
.field__hint { font-size: var(--fs-footnote); color: var(--danger); margin-top: 4px; }

/* ---------- Control segmentado ---------- */
.segmented {
  position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 3px; border-radius: 12px; background: var(--surface-2);
  isolation: isolate;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  position: relative; z-index: 1;
  display: grid; place-items: center; min-height: 36px; padding: 0 var(--s-3);
  font-size: var(--fs-subhead); font-weight: 600; color: var(--text-2);
  border-radius: 9px; cursor: pointer;
  transition: color var(--dur-2) var(--ease-out);
}
.segmented input:checked + label { color: var(--text); }
.segmented input:focus-visible + label { outline: 3px solid var(--accent-ring); }
.segmented__thumb {
  position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 3px;
  border-radius: 9px; background: var(--surface);
  box-shadow: 0 3px 8px rgb(0 0 0 / .12), 0 1px 1px rgb(0 0 0 / .04);
  transition: transform var(--dur-3) var(--ease-spring), width var(--dur-3) var(--ease-spring);
}
@media (prefers-color-scheme: dark) { .segmented__thumb { background: #3a4170; } }

/* ---------- Chips (opción única o múltiple) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); padding-top: var(--s-1); }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 var(--s-4);
  border-radius: var(--r-pill); background: var(--surface-2); color: var(--text-2);
  font-size: var(--fs-subhead); font-weight: 500; cursor: pointer;
  transition: background-color var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.chip span:active { transform: scale(.95); }
.chip input:checked + span { background: var(--accent); color: var(--text-on-accent); }
.chip input:focus-visible + span { outline: 3px solid var(--accent-ring); outline-offset: 2px; }

/* ---------- Interruptor ---------- */
.toggle-row {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
  min-height: 56px; padding: var(--s-2) var(--s-4); cursor: pointer;
}
.toggle-row__text { font-weight: 500; }
.switch { position: relative; flex: none; width: 51px; height: 31px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch__track {
  position: absolute; inset: 0; border-radius: var(--r-pill);
  background: var(--hairline-2);
  transition: background-color var(--dur-2) var(--ease-out);
}
.switch__track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgb(0 0 0 / .15), 0 3px 1px rgb(0 0 0 / .06);
  transition: transform var(--dur-3) var(--ease-spring);
}
.switch input:checked + .switch__track { background: var(--success); }
.switch input:checked + .switch__track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--accent-ring); outline-offset: 2px; }

/* ---------- Paso numérico (edad) ---------- */
.stepper { display: flex; align-items: center; gap: var(--s-2); }
.stepper__btn {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface-2); color: var(--accent);
}
.stepper__value {
  width: 3.2ch; text-align: center; border: 0; background: transparent; padding: 0;
  font-size: var(--fs-title-3); font-weight: 600; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.stepper__value::-webkit-outer-spin-button, .stepper__value::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper__value::placeholder { color: var(--text-3); }

/* ---------- Mosaico de selección (situaciones) ---------- */
.tiles { display: grid; gap: var(--s-2); }
.tile { position: relative; display: block; }
.tile input { position: absolute; opacity: 0; pointer-events: none; }
.tile__box {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 64px; padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md); background: var(--surface);
  box-shadow: var(--shadow-1), inset 0 0 0 1.5px transparent;
  cursor: pointer;
  transition: box-shadow var(--dur-2) var(--ease-out), background-color var(--dur-2) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.tile__box:active { transform: scale(.98); }
.tile__glyph {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--surface-2); color: var(--text-2);
  transition: background-color var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out);
}
.tile__text { flex: 1; min-width: 0; }
.tile__title { display: block; font-weight: 600; line-height: 1.25; }
.tile__sub { display: block; font-size: var(--fs-subhead); color: var(--text-2); }
.tile__check {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  border: 1.5px solid var(--hairline-2); color: transparent;
  transition: background-color var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out), transform var(--dur-3) var(--ease-spring);
}
.tile input:checked + .tile__box { box-shadow: var(--shadow-1), inset 0 0 0 1.5px var(--accent); background: var(--accent-soft); }
.tile input:checked + .tile__box .tile__glyph { background: var(--accent); color: var(--text-on-accent); }
.tile input:checked + .tile__box .tile__check { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); transform: scale(1.06); }
.tile input:focus-visible + .tile__box { outline: 3px solid var(--accent-ring); outline-offset: 2px; }
.tiles.is-invalid .tile__box { box-shadow: var(--shadow-1), inset 0 0 0 1.5px var(--danger); }

/* ---------- Fotos ---------- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: var(--s-2); padding: var(--s-3) var(--s-4) var(--s-4); }
.photo, .photo-add {
  position: relative; aspect-ratio: 1; border-radius: var(--r-sm); overflow: hidden;
}
.photo img { width: 100%; height: 100%; object-fit: cover; animation: aparecer var(--dur-3) var(--ease-spring) both; }
.photo__remove {
  position: absolute; top: 6px; right: 6px;
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: rgb(0 0 0 / .5); color: #fff;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.photo-add {
  display: grid; place-items: center; align-content: center; gap: 4px;
  background: var(--surface-2); color: var(--accent);
  font-size: var(--fs-footnote); font-weight: 600; cursor: pointer;
  border: 1.5px dashed var(--hairline-2);
}
.photo-add input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
@keyframes aparecer { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }

/* ---------- Isla de estado / aviso ---------- */
.island {
  position: fixed; z-index: 60; left: 50%; top: calc(var(--safe-top) + 10px);
  display: flex; align-items: center; gap: var(--s-2);
  max-width: min(92vw, 420px); padding: 10px 18px 10px 14px;
  border-radius: var(--r-pill);
  background: var(--glass-dark); color: #fff;
  -webkit-backdrop-filter: blur(20px) saturate(160%); backdrop-filter: blur(20px) saturate(160%);
  box-shadow: var(--shadow-3);
  font-size: var(--fs-subhead); font-weight: 500;
  transform: translate(-50%, -140%) scale(.9); opacity: 0;
  transition: transform var(--dur-3) var(--ease-spring), opacity var(--dur-2) var(--ease-out);
  pointer-events: none;
}
.island.is-visible { transform: translate(-50%, 0) scale(1); opacity: 1; pointer-events: auto; }
.island__icon { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; flex: none; }
.island__icon--ok { background: var(--success); }
.island__icon--warn { background: var(--warning); }
.island__icon--info { background: rgb(255 255 255 / .2); }

/* ---------- Diálogo de confirmación ---------- */
.dialog-backdrop {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center; padding: var(--s-6);
  background: rgb(8 10 30 / .38);
  opacity: 0; transition: opacity var(--dur-2) var(--ease-out);
}
.dialog-backdrop.is-open { opacity: 1; }
.dialog {
  width: min(100%, 300px); border-radius: var(--r-lg); overflow: hidden; text-align: center;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
  box-shadow: var(--shadow-3);
  transform: scale(1.12); opacity: 0;
  transition: transform var(--dur-3) var(--ease-spring), opacity var(--dur-1) var(--ease-out);
}
.dialog-backdrop.is-open .dialog { transform: scale(1); opacity: 1; }
.dialog__body { padding: var(--s-5) var(--s-4) var(--s-4); }
.dialog__title { font-size: var(--fs-headline); font-weight: 600; }
.dialog__msg { font-size: var(--fs-footnote); color: var(--text-2); margin-top: var(--s-1); line-height: 1.38; }
.dialog__actions { display: grid; grid-template-columns: 1fr 1fr; border-top: .5px solid var(--hairline-2); }
.dialog__actions button { min-height: 46px; font-size: var(--fs-headline); color: var(--accent); }
.dialog__actions button + button { border-left: .5px solid var(--hairline-2); }
.dialog__actions button:active { background: var(--hairline); }
.dialog__actions .is-strong { font-weight: 600; }
.dialog__actions .is-danger { color: var(--danger); }

/* ---------- Progreso por pasos ---------- */
.progress { display: grid; grid-auto-flow: column; gap: 6px; }
.progress__seg { height: 4px; border-radius: var(--r-pill); background: var(--hairline-2); overflow: hidden; }
.progress__seg i {
  display: block; height: 100%; width: 100%; background: var(--accent); border-radius: inherit;
  transform: scaleX(0); transform-origin: left;
  transition: transform var(--dur-3) var(--ease-snappy);
}
.progress__seg.is-done i, .progress__seg.is-current i { transform: scaleX(1); }
.progress__seg.is-current i { opacity: 1; }

/* ---------- Pastilla de estado ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 12px 0 10px;
  border-radius: var(--r-pill); font-size: var(--fs-footnote); font-weight: 600; letter-spacing: 0;
  background: var(--surface); color: var(--text-2); box-shadow: var(--shadow-1);
  transition: background-color var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out);
}
.pill__dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill--ok    { color: var(--success); }
.pill--off   { color: var(--warning); }
.pill--busy .pill__dot { animation: latir 1.1s var(--ease-out) infinite; }
@keyframes latir { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }
