/* ============ Tokens ============ */
:root {
  --paper: #F4F7F6;
  --surface: #FFFFFF;
  --ink: #16302B;
  --ink-soft: #52665F;
  --line: #D6E0DC;
  --palm: #1D6B57;
  --palm-deep: #13493C;
  --palm-soft: #E4F1EC;
  --sun: #F4C95D;
  --error: #B3261E;
  --error-soft: #FBEAE8;
  --amber: #8A5A00;
  --amber-soft: #FDF3DC;
  --blue: #2B5A86;
  --blue-soft: #E6EEF7;

  --font-display: "Bricolage Grotesque", "Figtree", system-ui, sans-serif;
  --font-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;

  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 10px;

  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { box-sizing: inherit; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 90px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.55;
}
img { max-width: 100%; }
[hidden] { display: none !important; }
[tabindex="-1"]:focus { outline: none; }
:focus-visible { outline: 3px solid var(--palm); outline-offset: 2px; border-radius: 6px; }

h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.9rem, 6vw, 2.4rem); font-weight: 700; }
h2 { font-size: 1.45rem; font-weight: 650; }
h3 { font-size: 1.1rem; font-weight: 650; }
p { margin: 0; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ============ Formulario público ============ */
.shell { max-width: 560px; margin: 0 auto; padding: 20px 18px 56px; }

.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
}
.topbar.has-progress { border-bottom-color: var(--line); }
.topbar-inner { max-width: 560px; margin: 0 auto; padding: 14px 18px 12px; }
.brand { font-family: var(--font-display); font-weight: 650; font-size: 1rem; color: var(--palm-deep); }

.progress { margin-top: 10px; }
.progress-meta { display: flex; justify-content: space-between; font-size: .88rem; color: var(--ink-soft); margin-bottom: 6px; }
.progress-meta strong { color: var(--ink); font-weight: 600; }
.progress-track { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.progress-track span { height: 6px; border-radius: 99px; background: var(--line); transition: background .3s; }
.progress-track span.done { background: var(--palm); }

.view { display: grid; gap: 22px; }
.view > header { display: grid; gap: 10px; }
.lead { font-size: 1.08rem; color: var(--ink-soft); }
.fineprint { font-size: .9rem; color: var(--ink-soft); }
.description { white-space: pre-line; }

/* Características */
.features { gap: 24px; }
.feature-group { display: grid; gap: 12px; }
.feature-group h2 { font-size: 1.2rem; }
.feature-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px 18px; }
.feature-list li { position: relative; padding-left: 26px; line-height: 1.4; }
.feature-list li::before {
  content: ""; position: absolute; left: 0; top: .2em;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--palm-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 8.2l2.3 2.3 4.7-4.8' fill='none' stroke='%231D6B57' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat;
}
.feature-group + .feature-group { border-top: 1px solid var(--line); padding-top: 20px; }

/* La placa de precio: el elemento protagonista */
.plaque {
  background: var(--palm-deep);
  color: #fff;
  border-radius: var(--r-lg);
  padding: 22px 22px 20px;
  display: grid; gap: 12px;
  position: relative; overflow: hidden;
}
.plaque::after {
  content: ""; position: absolute; right: -40px; top: -40px;
  width: 150px; height: 150px; border-radius: 50%;
  border: 18px solid rgba(255,255,255,.06);
}
.plaque-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.plaque-row span { color: rgba(255,255,255,.78); }
.plaque-row strong { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.plaque-rent strong { font-family: var(--font-display); font-size: 2.3rem; font-weight: 700; }
.plaque-total { border-top: 1px dashed rgba(255,255,255,.3); padding-top: 14px; align-items: end; }
.plaque-total span { max-width: 60%; line-height: 1.3; }
.plaque-total strong { color: var(--sun); font-family: var(--font-display); font-size: 1.9rem; font-weight: 700; }
.plaque-note { font-size: .92rem; color: rgba(255,255,255,.78); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 20px 18px;
  display: grid; gap: 18px;
}

/* Campos */
.field { display: grid; gap: 8px; }
.field > label, .field > .q { font-weight: 600; font-size: 1.02rem; }
.hint { font-size: .9rem; color: var(--ink-soft); margin-top: -4px; }
.input {
  width: 100%; min-height: 54px; padding: 12px 14px;
  font: inherit; color: var(--ink);
  background: #fff; border: 1.5px solid var(--line); border-radius: var(--r-sm);
  transition: border-color .15s;
}
.input:hover { border-color: #b7c6c1; }
.input:focus { outline: none; border-color: var(--palm); box-shadow: 0 0 0 3px var(--palm-soft); }
.money { position: relative; }
.money::before { content: "$"; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); font-weight: 600; }
.money .input { padding-left: 30px; font-variant-numeric: tabular-nums; }

.field.invalid .input { border-color: var(--error); }
.field.invalid .choice button:not([aria-checked="true"]) { border-color: var(--error); }
.error { color: var(--error); font-size: .9rem; font-weight: 500; }
.error:empty { display: none; }

/* Botones de opción (Sí/No y listas) */
.choice { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.choice.stack { grid-template-columns: 1fr; }
.choice.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice.three button { padding: 10px 6px; }
.choice button {
  min-height: 54px; padding: 10px 12px;
  font: inherit; font-weight: 600; color: var(--ink);
  background: #fff; border: 1.5px solid var(--line); border-radius: var(--r-sm);
  cursor: pointer; text-align: center;
  transition: border-color .15s, background .15s;
}
.choice.stack button { text-align: left; padding-left: 16px; }
.choice button:hover { border-color: var(--palm); }
.choice button[aria-checked="true"] { background: var(--palm-soft); border-color: var(--palm); color: var(--palm-deep); }

.stepper { display: grid; grid-template-columns: 54px 1fr 54px; gap: 10px; max-width: 240px; }
.stepper .input { text-align: center; font-weight: 600; font-size: 1.15rem; }
.stepper button {
  min-height: 54px; font-size: 1.5rem; font-weight: 500; line-height: 1;
  background: #fff; border: 1.5px solid var(--line); border-radius: var(--r-sm); color: var(--ink); cursor: pointer;
}
.stepper button:hover { border-color: var(--palm); }

.check {
  display: grid; grid-template-columns: 26px 1fr; gap: 12px; align-items: start;
  padding: 16px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: #fff; cursor: pointer;
}
.field > label.check { font-weight: 400; font-size: .98rem; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--palm); cursor: pointer; }
.check.checked { border-color: var(--palm); background: var(--palm-soft); }
.field.invalid .check { border-color: var(--error); }

.callout { font-size: .93rem; padding: 12px 14px; border-radius: var(--r-sm); background: var(--blue-soft); color: #1f3f60; }
.summary { display: grid; gap: 6px; font-variant-numeric: tabular-nums; }
.summary div { display: flex; justify-content: space-between; }
.summary .sum-total { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 2px; font-weight: 700; }

.conditional { display: grid; gap: 18px; padding-left: 14px; border-left: 3px solid var(--palm-soft); }

/* Total de ingresos */
.income-total { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 14px 16px; border-radius: var(--r-sm); background: var(--palm-soft); color: var(--palm-deep); }
.income-total strong { font-family: var(--font-display); font-size: 1.35rem; font-variant-numeric: tabular-nums; }

/* Animales */
.pet-list { display: grid; gap: 12px; }
.pet-row { display: grid; gap: 12px; padding: 14px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: #fbfcfc; }
.pet-row.invalid { border-color: var(--error); }
.pet-row-head { display: flex; justify-content: space-between; align-items: center; }
.pet-row-fields { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 10px; }
.pet-row-fields label { display: grid; gap: 6px; font-weight: 600; font-size: .95rem; }
.link-btn { background: none; border: 0; padding: 6px 4px; font: inherit; font-weight: 600; color: var(--error); cursor: pointer; }
#add-pet { justify-self: start; }

/* Botones de acción */
.btn {
  min-height: 54px; padding: 12px 22px;
  font: inherit; font-weight: 650; font-size: 1.02rem;
  border-radius: var(--r-md); border: 1.5px solid transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--palm); color: #fff; }
.btn.primary:hover { background: var(--palm-deep); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink-soft); }
.btn.danger { background: transparent; color: var(--error); border-color: #e7b7b3; }
.btn.danger:hover { background: var(--error-soft); }
.btn[disabled] { opacity: .6; cursor: wait; }
.btn.small { min-height: 42px; padding: 8px 14px; font-size: .95rem; border-radius: var(--r-sm); }

.actions { display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.actions .btn.primary { width: 100%; }
.gate-actions { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }

.banner { padding: 12px 14px; border-radius: var(--r-sm); background: var(--error-soft); color: var(--error); font-weight: 500; }
.demo-note { margin-top: 24px; font-size: .85rem; text-align: center; color: var(--amber); background: var(--amber-soft); padding: 8px 12px; border-radius: var(--r-sm); }

.done-mark {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--palm-soft); color: var(--palm); display: grid; place-items: center;
}
.done-mark svg { width: 28px; height: 28px; }

.footer { margin-top: 36px; font-size: .9rem; color: var(--ink-soft); text-align: center; }
.footer a { color: var(--palm-deep); }

.loading { display: grid; place-items: center; min-height: 50vh; color: var(--ink-soft); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--palm); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.view.enter { animation: enter .28s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

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

/* ============ Dashboard ============ */
.admin { max-width: 1240px; margin: 0 auto; padding: 18px 18px 60px; }
.admin-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.tabs { display: flex; gap: 6px; background: #e8eeec; padding: 4px; border-radius: 12px; }
.tabs button { font: inherit; font-weight: 600; border: 0; background: transparent; padding: 8px 14px; border-radius: 9px; cursor: pointer; color: var(--ink-soft); }
.tabs button[aria-selected="true"] { background: #fff; color: var(--ink); }

.login { max-width: 400px; margin: 10vh auto 0; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; }
.kpi b { display: block; font-family: var(--font-display); font-size: 1.8rem; line-height: 1.1; }
.kpi span { font-size: .9rem; color: var(--ink-soft); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.toolbar .input { min-height: 44px; width: auto; flex: 1 1 200px; }
.toolbar select.input { flex: 0 1 220px; }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { white-space: normal; min-width: 90px; font-size: .84rem; font-weight: 600; color: var(--ink-soft); background: #f8faf9; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f6faf8; }
tbody tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; }
table .chip { font-size: .78rem; padding: 3px 8px; margin-left: 6px; }
.dl a { color: var(--palm-deep); }
.empty { padding: 40px 20px; text-align: center; color: var(--ink-soft); }

.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: .82rem; font-weight: 600; background: #eef2f1; color: var(--ink-soft); }
.pill.nuevo { background: var(--blue-soft); color: var(--blue); }
.pill.revisar { background: var(--amber-soft); color: var(--amber); }
.pill.contactar, .pill.visita_coordinada, .pill.solicitud_formal { background: var(--palm-soft); color: var(--palm-deep); }
.pill.arrendado { background: var(--palm-deep); color: #fff; }
.yes { color: var(--palm); font-weight: 600; }
.no { color: var(--amber); font-weight: 600; }

td.name-cell small.co { display: block; font-size: .85rem; font-weight: 500; color: var(--ink-soft); }
@media (max-width: 760px) { td.name-cell small.co { display: inline; margin-left: 6px; } }

/* Semáforo */
:root { --go: #3F8F3A; --go-soft: #E6F3E3; --wait: #C99A06; --wait-soft: #FBF1D2; --stop: #C8423B; --stop-soft: #FBE7E5; }
.light { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; font-size: .9rem; white-space: nowrap; }
.light i { width: 12px; height: 12px; border-radius: 50%; }
.light.verde { color: var(--go); } .light.verde i { background: var(--go); }
.light.amarillo { color: #8f6d00; } .light.amarillo i { background: var(--wait); }
.light.rojo { color: var(--stop); } .light.rojo i { background: var(--stop); }
.kpi.verde { border-top: 5px solid var(--go); }
.kpi.amarillo { border-top: 5px solid var(--wait); }
.kpi.rojo { border-top: 5px solid var(--stop); }
.result-card { display: grid; grid-template-columns: 72px 1fr; gap: 16px; align-items: center; padding: 16px; border-radius: var(--r-md); }
.result-card p { font-size: .95rem; }
.result-swatch { width: 72px; height: 72px; border-radius: 12px; }
.result-label { font-family: var(--font-display); font-size: 1.35rem !important; font-weight: 700; margin-bottom: 4px !important; }
.result-note { margin-top: 8px !important; font-size: .85rem !important; opacity: .85; }
.result-card.verde { background: var(--go-soft); } .result-card.verde .result-swatch { background: var(--go); } .result-card.verde .result-label { color: var(--go); }
.result-card.amarillo { background: var(--wait-soft); } .result-card.amarillo .result-swatch { background: var(--wait); } .result-card.amarillo .result-label { color: #8f6d00; }
.result-card.rojo { background: var(--stop-soft); } .result-card.rojo .result-swatch { background: var(--stop); } .result-card.rojo .result-label { color: var(--stop); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-size: .88rem; padding: 6px 11px; border-radius: 9px; font-weight: 500; }
.chip.ok { background: var(--palm-soft); color: var(--palm-deep); }
.chip.warn { background: var(--amber-soft); color: var(--amber); }
.chip.review { background: var(--blue-soft); color: var(--blue); }
.chip.muted { background: #eef2f1; color: var(--ink-soft); }

/* Panel lateral de detalle */
.overlay { position: fixed; inset: 0; background: rgba(22,48,43,.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(560px, 100%); background: var(--paper);
  overflow-y: auto; padding: calc(18px + env(safe-area-inset-top, 0px)) 20px calc(40px + env(safe-area-inset-bottom, 0px));
  box-shadow: -12px 0 40px rgba(22,48,43,.15);
  display: grid; gap: 18px; align-content: start;
}
.drawer-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.drawer-head p { color: var(--ink-soft); font-size: .92rem; }
.dl { display: grid; grid-template-columns: minmax(130px, 42%) 1fr; gap: 8px 14px; font-size: .95rem; }
.dl dt { color: var(--ink-soft); }
.dl dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.note { background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; font-size: .95rem; white-space: pre-wrap; }
.note small { display: block; color: var(--ink-soft); margin-top: 4px; font-size: .8rem; }
textarea.input { min-height: 90px; resize: vertical; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.preview { display: grid; gap: 6px; padding: 14px 16px; border-radius: var(--r-md); background: var(--palm-deep); color: #fff; }
.preview div { display: flex; justify-content: space-between; gap: 10px; }
.preview strong { color: var(--sun); font-variant-numeric: tabular-nums; }
.toggle { display: flex; gap: 10px; align-items: center; font-weight: 500; }
.toggle input { width: 20px; height: 20px; accent-color: var(--palm); }
.saved { color: var(--palm); font-weight: 600; }

@media (max-width: 760px) {
  .table-wrap { background: transparent; border: 0; }
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  tbody tr { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 10px; padding: 8px 4px; }
  td { border: 0; padding: 5px 12px; display: flex; justify-content: space-between; gap: 10px; white-space: normal; }
  td::before { content: attr(data-label); color: var(--ink-soft); font-size: .88rem; }
  td.name-cell { order: -1; justify-content: flex-start; flex-wrap: wrap; align-items: center; font-weight: 650; font-size: 1.05rem; }
  td.name-cell::before { content: none; }
}

/* Solo resaltar en rojo la fila de animal incompleta */
.field[data-for="pets"].invalid .pet-row:not(.invalid) .input,
.field[data-for="pets"].invalid .pet-row:not(.invalid) .choice button:not([aria-checked="true"]) { border-color: var(--line); }
.pet-row .choice button { font-size: .92rem; padding: 10px 4px; }
