/* Registro de visita — cuaderno de campo para el celular.
   Legible bajo luz fuerte, botones para el pulgar, y un solo gesto protagonista:
   el micrófono, que resalta el campo como un marcador amarillo mientras escucha. */

:root {
  --paper: #EEF2F0;
  --surface: #FFFFFF;
  --ink: #17252A;
  --muted: #56676B;
  --line: #CBD6D2;
  --pine: #244C41;
  --pine-2: #2F6354;
  --pine-soft: #DCE9E3;
  --marker: #FFD84D;
  --marker-soft: #FFF3BF;
  --danger: #A8321F;
  --danger-soft: #F7E1DC;

  --t-friccion: #9A3B12;   --t-friccion-bg: #FBE6D8;
  --t-oportunidad: #1D5480; --t-oportunidad-bg: #DFECF7;
  --t-riesgo: #8E1F1F;     --t-riesgo-bg: #F6DEDE;
  --t-fortaleza: #244C41;  --t-fortaleza-bg: #DCE9E3;

  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r-field: 10px;
  --r-pill: 999px;
  --topbar-h: 56px;
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 24px; height: 24px; flex: none; fill: currentColor; }
:focus-visible { outline: 3px solid var(--pine-2); outline-offset: 2px; }

.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;
}

/* ── Barra superior ───────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  min-height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 8px 0 8px;
  background: var(--pine);
  color: #fff;
}
.topbar-title {
  flex: 1; min-width: 0; margin: 0 6px;
  font-size: 1.15rem; font-weight: 700; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  display: grid; place-items: center;
  width: 48px; height: 48px; border: 0; border-radius: 50%;
  background: transparent; color: inherit;
}
.icon-btn:active { background: rgba(255, 255, 255, .14); }

.sync {
  flex: none; max-width: 46%;
  padding: 4px 10px; border-radius: var(--r-pill);
  font-size: .78rem; line-height: 1.2; text-align: right;
  background: rgba(255, 255, 255, .14);
}
.sync.ok::before { content: "✓ "; }
.sync.off { background: var(--marker); color: var(--ink); }
.sync.err { background: #F2B8A8; color: var(--ink); }

/* Barra de sesión activa: siempre visible bajo el encabezado */
.active-bar {
  position: sticky; top: calc(var(--topbar-h) + var(--safe-top)); z-index: 19;
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 44px; padding: 8px 16px;
  border: 0; border-bottom: 1px solid var(--line);
  background: var(--surface); color: var(--muted);
  font-size: .92rem; text-align: left;
}
.active-bar .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.active-bar.on { color: var(--ink); background: var(--pine-soft); }
.active-bar.on .dot { background: var(--pine-2); box-shadow: 0 0 0 4px rgba(47, 99, 84, .18); }
.active-bar span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Pantalla y bloques ───────────────────────────────────────── */
.screen {
  max-width: 640px; margin: 0 auto;
  padding: 18px 16px calc(32px + var(--safe-bottom));
}
.screen.with-tabs { padding-bottom: calc(var(--tabbar-h) + 40px + var(--safe-bottom)); }

.block-head { margin-bottom: 18px; }
.block-title { margin: 0; font-size: 1.45rem; line-height: 1.15; font-weight: 700; letter-spacing: -.01em; }
.block-help { margin: 6px 0 0; color: var(--muted); font-size: .95rem; max-width: 60ch; }
.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 18px; }
.section-label { margin: 28px 0 10px; font-size: 1rem; color: var(--muted); font-weight: 700; }

.back-link {
  display: inline-flex; align-items: center; gap: 2px;
  margin: -6px 0 8px -10px; padding: 8px 10px; min-height: 44px;
  border: 0; background: none; color: var(--pine-2); font-weight: 700;
}
.back-link svg { width: 20px; height: 20px; }

/* ── Campos ───────────────────────────────────────────────────── */
.field { margin: 0 0 20px; }
.field > label, .field > .label {
  display: block; margin-bottom: 6px;
  font-weight: 700; font-size: .98rem;
}
.opt { font-weight: 400; color: var(--muted); font-size: .88rem; }
.hint { margin: -2px 0 8px; color: var(--muted); font-size: .88rem; }
.field-error { margin: -12px 0 16px; color: var(--danger); font-size: .9rem; }

.field-row {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 4px 4px 4px 0;
  border-radius: calc(var(--r-field) + 4px);
  transition: background-color .2s;
}
.field-row input, .field-row textarea {
  flex: 1; min-width: 0; width: 100%;
  min-height: 48px; padding: 11px 13px;
  border: 1.5px solid var(--line); border-radius: var(--r-field);
  background: var(--surface);
  font-size: 17px; line-height: 1.4;
}
.field-row textarea { resize: none; overflow: hidden; }
.field-row input:focus, .field-row textarea:focus { border-color: var(--pine-2); outline: none; box-shadow: 0 0 0 3px rgba(47, 99, 84, .18); }

/* Micrófono: el elemento protagonista */
.mic {
  display: grid; place-items: center; flex: none;
  width: 48px; height: 48px;
  border: 1.5px solid var(--line); border-radius: 50%;
  background: var(--surface); color: var(--pine);
}
.mic:active { background: var(--pine-soft); }
.mic.rec {
  border-color: var(--ink); background: var(--marker); color: var(--ink);
  animation: listen 1.4s ease-out infinite;
}
.mic.rec svg { width: 20px; height: 20px; }
@keyframes listen {
  0% { box-shadow: 0 0 0 0 rgba(255, 216, 77, .9); }
  100% { box-shadow: 0 0 0 14px rgba(255, 216, 77, 0); }
}
.field-row.listening { background: var(--marker-soft); }
.field-row.listening input, .field-row.listening textarea { border-color: #C9A400; background: #FFFBEA; }

/* Opciones fijas */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 8px 15px;
  border: 1.5px solid var(--line); border-radius: var(--r-pill);
  background: var(--surface); text-align: left; line-height: 1.25;
}
.chip[aria-pressed="true"] { background: var(--pine); border-color: var(--pine); color: #fff; }
.chip .order {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--marker); color: var(--ink); font-size: .85rem;
}
.chips.stack { flex-direction: column; align-items: stretch; }
.chips.stack .chip { border-radius: var(--r-field); }

.chips.tipos .chip-friccion[aria-pressed="true"]    { background: var(--t-friccion-bg);    border-color: var(--t-friccion);    color: var(--t-friccion); }
.chips.tipos .chip-oportunidad[aria-pressed="true"] { background: var(--t-oportunidad-bg); border-color: var(--t-oportunidad); color: var(--t-oportunidad); }
.chips.tipos .chip-riesgo[aria-pressed="true"]      { background: var(--t-riesgo-bg);      border-color: var(--t-riesgo);      color: var(--t-riesgo); }
.chips.tipos .chip-fortaleza[aria-pressed="true"]   { background: var(--t-fortaleza-bg);   border-color: var(--t-fortaleza);   color: var(--t-fortaleza); }
.chips.tipos .chip[aria-pressed="true"] { font-weight: 700; }

.chips.scale { flex-wrap: nowrap; gap: 6px; }
.chips.scale .chip { flex: 1; justify-content: center; border-radius: var(--r-field); padding: 8px 0; font-weight: 700; }
.scale-ends { display: flex; justify-content: space-between; margin-top: 4px; color: var(--muted); font-size: .85rem; }

.readout { margin: 0 0 8px; color: var(--muted); }

/* Citas */
.quote { display: flex; align-items: flex-start; gap: 2px; margin-bottom: 8px; }
.quote .field-row { flex: 1; }
.quote textarea { font-style: italic; }
.link-danger {
  display: grid; place-items: center; width: 44px; height: 48px; margin-top: 4px;
  border: 0; background: none; color: var(--muted);
}

/* ── Botones ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border: 1.5px solid transparent; border-radius: var(--r-field);
  font-weight: 700; line-height: 1.2;
}
.btn svg { width: 22px; height: 22px; }
.btn-primary { background: var(--pine); color: #fff; }
.btn-primary:active { background: var(--pine-2); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-small { min-height: 40px; padding: 6px 12px; font-size: .9rem; background: var(--surface); border-color: var(--pine-2); color: var(--pine); }
.btn-wide { width: 100%; margin-bottom: 18px; }
.btn-danger { width: 100%; margin-top: 12px; background: none; border-color: var(--danger-soft); color: var(--danger); }
.btn-danger-ghost { background: none; border-color: var(--danger-soft); color: var(--danger); }
.btn-camera {
  width: 100%; border-style: dashed; border-color: var(--pine-2);
  background: transparent; color: var(--pine);
}

.badge {
  flex: none; padding: 3px 10px; border-radius: var(--r-pill);
  background: var(--pine-soft); color: var(--pine); font-size: .82rem; font-weight: 700;
}

/* ── Listas ───────────────────────────────────────────────────── */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.visit-card, .item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px 16px; min-height: 64px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); text-align: left;
}
.visit-card { flex-direction: column; align-items: flex-start; gap: 2px; }
.visit-card.remote { background: transparent; border-style: dashed; }
.visit-name { font-weight: 700; font-size: 1.08rem; }
.visit-meta, .item-meta { color: var(--muted); font-size: .9rem; }
.item-num {
  flex: none; display: grid; place-items: center;
  min-width: 40px; height: 40px; padding: 0 6px; border-radius: 10px;
  background: var(--paper); color: var(--pine); font-weight: 700;
}
.item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.item-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tag { padding: 1px 8px; border-radius: var(--r-pill); font-size: .8rem; font-weight: 700; }
.tag-friccion    { background: var(--t-friccion-bg);    color: var(--t-friccion); }
.tag-oportunidad { background: var(--t-oportunidad-bg); color: var(--t-oportunidad); }
.tag-riesgo      { background: var(--t-riesgo-bg);      color: var(--t-riesgo); }
.tag-fortaleza   { background: var(--t-fortaleza-bg);   color: var(--t-fortaleza); }

.empty { margin: 8px 0; color: var(--muted); max-width: 48ch; }

/* ── Fotos ────────────────────────────────────────────────────── */
.photos { padding-top: 6px; }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.thumb {
  display: flex; flex-direction: column; gap: 4px; padding: 0;
  border: 0; background: none; text-align: left;
}
.thumb img {
  width: 100%; aspect-ratio: 1; object-fit: cover; display: block;
  border-radius: 8px; background: var(--line);
}
.thumb-cap { font-size: .78rem; color: var(--muted); line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ── Barra de pestañas (los cuatro bloques) ───────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tabbar-h); border: 0; background: none; color: var(--muted);
  font-size: .78rem; font-weight: 700;
}
.tab[aria-current="page"] { color: var(--pine); }
.tab[aria-current="page"] svg { background: var(--pine-soft); border-radius: var(--r-pill); padding: 3px 16px; box-sizing: content-box; }

/* ── Hoja inferior ────────────────────────────────────────────── */
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; margin: auto auto 0;
  padding: 0; border: 0; border-radius: 18px 18px 0 0;
  background: var(--surface); color: var(--ink);
}
.sheet::backdrop { background: rgba(23, 37, 42, .5); }
.sheet-inner { padding: 20px 16px calc(20px + var(--safe-bottom)); }
.sheet-title { margin: 0 0 16px; font-size: 1.3rem; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 8px; }
.sheet-actions.three { grid-template-columns: 1fr 1fr 1.4fr; }
.sheet-actions .btn { padding-left: 8px; padding-right: 8px; font-size: .95rem; }
.preview { display: block; width: 100%; max-height: 46vh; object-fit: contain; border-radius: 10px; background: var(--paper); margin-bottom: 16px; }

/* ── Idioma ───────────────────────────────────────────────────── */
.screen-lang { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; gap: 28px; padding-top: calc(32px + var(--safe-top)); }
.lang-mark {
  display: grid; place-items: center; width: 72px; height: 72px; border-radius: 50%;
  background: var(--marker); color: var(--ink);
}
.lang-mark svg { width: 34px; height: 34px; }
.lang-list { display: grid; gap: 10px; }
.lang-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 16px 18px; min-height: 64px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); text-align: left;
}
.lang-name { font-size: 1.3rem; font-weight: 700; }
.lang-prompt { color: var(--muted); }
.lang-option[aria-pressed="true"] { border-color: var(--pine); background: var(--pine-soft); }
.lang-list.compact .lang-option { min-height: 52px; padding: 12px 16px; }
.lang-list.compact .lang-name { font-size: 1.1rem; }
.block { margin-bottom: 8px; }

/* ── Aviso ────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 50;
  bottom: calc(var(--tabbar-h) + 14px + var(--safe-bottom));
  max-width: 560px; margin: 0 auto; padding: 12px 16px;
  border-radius: 12px; background: var(--ink); color: #fff; font-size: .95rem;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .mic.rec { animation: none; box-shadow: 0 0 0 4px rgba(255, 216, 77, .8); }
  .toast, .field-row { transition: none; }
}
