:root {
  color-scheme: light;
  --purple: rgb(65, 2, 101);
  --purple-hover: #55107f;
  --purple-tint: #f5eff9;
  --purple-line: #ddd0e6;
  --ink: #23102f;
  --muted: #655570;
  --error: #b3261e;
  --white: #fff;
  --radius: 12px;
  --tap: 54px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--white);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible { outline: 3px solid rgba(65, 2, 101, .4); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden;
}

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px max(20px, env(safe-area-inset-right)) 10px max(20px, env(safe-area-inset-left));
  background: var(--purple); color: var(--white);
}
.brand { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.brand span { font-weight: 400; }
.tabs { display: flex; gap: 4px; }
.tab {
  min-height: 44px; padding: 0 14px;
  background: none; border: 0; border-radius: 10px;
  color: rgba(255, 255, 255, .8); font-size: 15px; font-weight: 600; white-space: nowrap;
}
.tab[aria-current="page"] { background: var(--white); color: var(--purple); }

.account { display: flex; align-items: center; gap: 10px; min-width: 0; }
.seller { max-width: 130px; overflow: hidden; color: rgba(255, 255, 255, .8); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.logout {
  min-height: 40px; padding: 0 12px; background: none;
  border: 1.5px solid rgba(255, 255, 255, .55); border-radius: 10px;
  color: var(--white); font-size: 14px; font-weight: 600;
}

/* Inicio de sesión */
.auth {
  position: fixed; inset: 0; z-index: 50; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  padding: max(40px, 8vh) 16px 32px; background: var(--purple);
}
.auth-brand { flex: none; color: var(--white); font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.auth-brand span { font-weight: 400; }
.auth-card { flex: none; width: min(440px, 100%); padding: 28px 24px; background: var(--white); border-radius: 16px; }
.auth-card .muted { margin-bottom: 18px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .check { margin-bottom: 14px; }

/* Vistas */
main { max-width: 860px; margin: 0 auto; padding: 24px 20px calc(32px + env(safe-area-inset-bottom)); }
.narrow { max-width: 620px; margin: 0 auto; }
.center { text-align: center; max-width: 520px; margin: 0 auto; padding-top: 24px; }
h1 { margin: 0 0 8px; font-size: 26px; line-height: 1.2; letter-spacing: -.01em; }
h2 { margin: 0; font-size: 20px; line-height: 1.25; }
.muted { margin: 0 0 20px; color: var(--muted); }
.hint { margin: 0 0 16px; color: var(--muted); font-size: 15px; }
.empty { margin: 32px 0; text-align: center; color: var(--muted); }

.edit-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-bottom: 18px; padding: 12px 16px;
  background: var(--purple-tint); border-radius: var(--radius); font-size: 15px; font-weight: 500;
}
.edit-banner .link { flex: none; min-height: 36px; }

/* Pasos */
.stepper { display: flex; gap: 6px; margin: 0 0 24px; padding: 0; list-style: none; }
.stepper li { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; font-weight: 600; }
.stepper li::before {
  content: ""; display: block; height: 6px; margin-bottom: 6px;
  border-radius: 3px; background: var(--purple-line);
}
.stepper li.done::before, .stepper li.current::before { background: var(--purple); }
.stepper li.current { color: var(--purple); }

/* Formulario */
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 18px; font-size: 26px; font-weight: 700; line-height: 1.2; letter-spacing: -.01em; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 16px; }
.full { grid-column: 1 / -1; }
.field { min-width: 0; }

label, .label { display: block; margin-bottom: 6px; font-size: 15px; font-weight: 600; }
small { color: var(--muted); font-size: 14px; font-weight: 400; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

input[type="text"], input[type="tel"], input[type="email"], input[type="password"], textarea {
  display: block; width: 100%; min-height: var(--tap); padding: 12px 14px;
  background: var(--white); border: 1.5px solid var(--purple-line); border-radius: var(--radius);
  font-size: 18px;
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: #8a7c94; }
input:focus, textarea:focus { outline: 0; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(65, 2, 101, .14); }
input:disabled { background: var(--purple-tint); color: var(--muted); }

.invalid input[type="password"], .invalid input[type="text"], .invalid input[type="tel"], .invalid input[type="email"], .invalid textarea,
.invalid .photo, .invalid .signature { border-color: var(--error); }
.error { margin: 6px 0 0; color: var(--error); font-size: 15px; font-weight: 500; }

.phone { display: flex; }
.phone-prefix {
  flex: none; display: flex; align-items: center; padding: 0 12px;
  background: var(--purple); border-radius: var(--radius) 0 0 var(--radius);
  color: var(--white); font-size: 17px; font-weight: 600;
}
.phone input { min-width: 0; border-radius: 0 var(--radius) var(--radius) 0; }

.check {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap); margin: 0;
  font-size: 17px; font-weight: 500;
}
.check input { flex: none; width: 26px; height: 26px; margin: 0; accent-color: var(--purple); }

.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.chip {
  min-height: var(--tap); padding: 8px 10px;
  background: var(--white); border: 1.5px solid var(--purple-line); border-radius: var(--radius);
  font-size: 16px; font-weight: 500; line-height: 1.2;
}
.chip[aria-checked="true"] { background: var(--purple); border-color: var(--purple); color: var(--white); }

.options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.option {
  display: flex; flex-direction: column; gap: 6px; min-height: 150px; padding: 16px;
  background: var(--white); border: 1.5px solid var(--purple-line); border-radius: var(--radius);
  text-align: left;
}
.option-name { font-size: 18px; font-weight: 700; line-height: 1.25; }
.option-desc { color: var(--muted); font-size: 15px; line-height: 1.35; }
.option-tick {
  display: flex; align-items: center; justify-content: center; align-self: flex-end; margin-top: auto;
  width: 28px; height: 28px; border: 1.5px solid var(--purple-line); border-radius: 50%;
  color: var(--white); font-size: 16px; font-weight: 700; line-height: 1;
}
.option[aria-pressed="true"] { background: var(--purple-tint); border-color: var(--purple); box-shadow: inset 0 0 0 1px var(--purple); }
.option[aria-pressed="true"] .option-tick { background: var(--purple); border-color: var(--purple); }

/* Fotos */
.photo {
  position: relative; display: flex; align-items: center; justify-content: center;
  aspect-ratio: 8 / 5; margin: 0; overflow: hidden; cursor: pointer;
  background: var(--purple-tint); border: 1.5px dashed var(--purple); border-radius: var(--radius);
  color: var(--purple);
}
.photo:focus-within { box-shadow: 0 0 0 3px rgba(65, 2, 101, .3); }
.photo.filled { border-style: solid; }
.photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 600; }
.photo-empty svg { width: 38px; height: 38px; fill: currentColor; }
.photo-retake {
  position: absolute; right: 8px; bottom: 8px; padding: 6px 12px;
  background: var(--purple); border-radius: 8px; color: var(--white); font-size: 14px; font-weight: 600;
}

/* Firma */
.summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px;
  margin: 0 0 20px; padding: 14px 16px;
  background: var(--purple-tint); border-radius: var(--radius);
}
.summary dt { color: var(--muted); font-size: 13px; }
.summary dd { margin: 0; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.signature {
  position: relative; height: 260px;
  background: var(--white); border: 1.5px solid var(--purple); border-radius: var(--radius); overflow: hidden;
}
.signature canvas { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.signature-line { position: absolute; left: 24px; right: 24px; bottom: 54px; border-bottom: 1.5px solid var(--purple-line); }
#terms-field { margin-top: 12px; }

.link {
  padding: 0; background: none; border: 0;
  color: var(--purple); font-weight: 600; text-decoration: underline; text-underline-offset: 2px;
}
.label-row .link { min-height: 36px; font-size: 15px; }

/* Botones */
.actions {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; gap: 12px; margin-top: 24px; padding: 12px 0 max(4px, env(safe-area-inset-bottom));
  background: var(--white);
}
.btn {
  flex: 1; display: flex; align-items: center; justify-content: center; min-height: 56px; padding: 0 20px;
  border-radius: var(--radius); border: 1.5px solid transparent;
  font-size: 18px; font-weight: 600; text-align: center;
}
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--purple); color: var(--white); }
.btn-primary:hover { background: var(--purple-hover); }
.btn-ghost { background: var(--white); border-color: var(--purple); color: var(--purple); }
.btn-ghost:hover { background: var(--purple-tint); }
#back { flex: 0 0 34%; }
.wide { width: 100%; flex: none; }

/* Contrato listo */
.done-mark {
  display: flex; align-items: center; justify-content: center;
  width: 72px; height: 72px; margin: 0 auto 16px;
  background: var(--purple); border-radius: 50%; color: var(--white);
}
.done-mark svg { width: 42px; height: 42px; }
.send { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.send .note { margin: 2px 0 8px; color: var(--muted); font-size: 15px; }

/* Clientes */
.records { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.record {
  display: block; width: 100%; padding: 14px 16px;
  background: var(--white); border: 1.5px solid var(--purple-line); border-radius: var(--radius); text-align: left;
}
.record:hover { background: var(--purple-tint); }
.record strong { display: block; font-size: 18px; line-height: 1.25; overflow-wrap: anywhere; }
.record span { color: var(--muted); font-size: 15px; }

/* Ventanas */
.sheet {
  width: min(680px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0;
  border: 0; border-radius: 16px; color: var(--ink);
}
.sheet[open] { display: flex; flex-direction: column; }
.sheet::backdrop { background: rgba(35, 16, 47, .55); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--purple-line);
}
.sheet-body { overflow-y: auto; padding: 20px; }
.sheet-body h3 { margin: 18px 0 4px; font-size: 16px; }
.sheet-body h3:first-child { margin-top: 0; }
.sheet-body p { margin: 0; }
.icon-btn {
  flex: none; width: 44px; height: 44px; background: none; border: 0; border-radius: 10px;
  color: var(--purple); font-size: 28px; line-height: 1;
}
.icon-btn:hover { background: var(--purple-tint); }
.details { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 0 0 20px; }
.details dt { color: var(--muted); font-size: 13px; }
.details dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.details .full { grid-column: 1 / -1; }
.record-images { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.record-images figure { margin: 0; }
.record-images figcaption { margin-bottom: 4px; color: var(--muted); font-size: 13px; }
.record-images img { display: block; width: 100%; border: 1px solid var(--purple-line); border-radius: 8px; }
.record-images .sig { grid-column: 1 / -1; }
.record-images .sig img { max-height: 140px; object-fit: contain; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); padding: 12px 18px;
  background: var(--ink); border-radius: 10px; color: var(--white); font-size: 15px; text-align: center;
}

/* Teléfono */
@media (max-width: 640px) {
  body { font-size: 16px; }
  .topbar { flex-wrap: wrap; gap: 6px 12px; padding-top: 8px; padding-bottom: 8px; }
  .brand { font-size: 20px; }
  .tabs { order: 3; flex-basis: 100%; justify-content: space-between; }
  .tab { flex: 1; padding: 0 6px; font-size: 14px; }
  main { padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); }
  legend, h1 { font-size: 23px; }
  .grid { grid-template-columns: 1fr; }
  .chips { grid-template-columns: repeat(2, 1fr); }
  .options { grid-template-columns: 1fr; }
  .option { min-height: 0; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .option-name { flex: 1; }
  .option-tick { order: 2; margin: 0; }
  .option-desc { order: 3; flex-basis: 100%; }
  .stepper li { font-size: 0; }
  .stepper li.current { font-size: 13px; white-space: nowrap; }
  .stepper li.current { flex: 2.4; }
  .summary { grid-template-columns: 1fr 1fr; }
  .signature { height: 210px; }
  .signature-line { bottom: 44px; }
}
