:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --line: #e3e6eb;
  --ink: #202b3a;
  --ink-soft: #3c4a5e;
  --mute: #647080;
  --navy: #17232e;
  --navy-2: #1b2433;
  --accent: #ff5b04;
  --on-accent: #172326;
  --accent-soft: #fff1e8;
  --ok: #2c7a4b;
  --ok-bg: #edf7f0;
  --ok-line: #d4e9dc;
  --warn: #8a6414;
  --warn-bg: #fff7e4;
  --warn-line: #efdfb8;
  --info: #4a5f7a;
  --info-bg: #eef3f9;
  --info-line: #d8e2ee;
  --radius: 14px;
  --shadow: 0 6px 20px -10px rgba(20, 30, 45, .12);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid #3c668e; outline-offset: 2px; }

/* ---------- encabezado ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--navy);
  color: #edf0f5;
}
.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px 10px;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.brand-logo { height: 30px; width: auto; display: block; }
.brand-note {
  font-size: 11px;
  color: #93a2b5;
  line-height: 1.35;
  border-left: 1px solid rgba(255,255,255,.18);
  padding-left: 12px;
}
.progress-wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px 12px;
}
.progress-meta {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 12px;
  color: #b9c4d2;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.22);
  color: #c8d2df;
  font-size: 11px;
  line-height: 1.5;
  white-space: nowrap;
}
.chip-prio {
  border-color: rgba(255,255,255,.4);
  color: #fff;
  background: rgba(255,255,255,.1);
}
.progress-bar {
  height: 5px;
  border-radius: 4px;
  background: rgba(255,255,255,.14);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: #e9edee;
  transition: width .3s ease;
}

/* ---------- layout ---------- */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 20px 0;
  min-height: calc(100dvh - 120px);
  display: flex;
  flex-direction: column;
}
.view { animation: view-in .22s ease both; }
@keyframes view-in {
  from { opacity: 0; transform: translateX(14px); }
  to { opacity: 1; transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
  .view { animation: none; }
  .progress-fill { transition: none; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

/* ---------- bienvenida / cierre ---------- */
.center-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-bottom: 48px;
}
.center-view .card { text-align: center; }
.kicker {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--mute);
  margin: 0 0 10px;
}
h1.title { font-size: 26px; font-weight: 650; margin: 0 0 8px; }
.subtitle { color: var(--mute); font-size: 14px; margin: 0 0 22px; }
.meta-line { color: var(--mute); font-size: 13px; margin: 0 0 24px; }
.counts { display: flex; justify-content: center; gap: 22px; margin: 0 0 26px; flex-wrap: wrap; }
.count { text-align: center; }
.count b { display: block; font-size: 24px; font-weight: 650; }
.count span { font-size: 12px; color: var(--mute); }

/* ---------- pregunta ---------- */
.q-view { flex: 1; display: flex; flex-direction: column; padding-bottom: 150px; }
.q-text {
  font-size: clamp(22px, 5.6vw, 26px);
  font-weight: 600;
  line-height: 1.35;
  margin: 14px 0 22px;
  color: var(--ink);
}
.q-banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--info-bg);
  border: 1px solid var(--info-line);
  border-radius: 12px;
  padding: 13px 15px;
  font-size: 14px;
  color: var(--ink-soft);
  margin-bottom: 18px;
}
.ta {
  width: 100%;
  min-height: 150px;
  resize: none;
  border: 1px solid #cfd6df;
  border-radius: 12px;
  background: #fff;
  padding: 14px 16px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  line-height: 1.55;
}
.ta:focus { border-color: #8fa9c4; outline: none; box-shadow: 0 0 0 3px rgba(60,102,142,.15); }
.ta::placeholder { color: #9aa7b6; }
.saved-note {
  min-height: 18px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--ok);
  display: flex;
  align-items: center;
  gap: 5px;
}
.saved-note:empty::before { content: "\00a0"; }

.attach-zone { margin-top: 22px; }
.attach-list { display: grid; gap: 8px; margin-top: 12px; }
.attach-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbfc;
  padding: 9px 12px;
  font-size: 13px;
}
.attach-item .name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.attach-item .size { color: var(--mute); font-size: 12px; white-space: nowrap; }
.attach-item button {
  border: 0;
  background: transparent;
  color: var(--mute);
  font-size: 12px;
  padding: 6px;
  min-width: 44px;
}
.attach-item a { color: #405671; text-decoration: none; }
.attach-item a:hover { text-decoration: underline; }

/* ---------- barra inferior ---------- */
.bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
}
.bottombar-inner { max-width: 640px; margin: 0 auto; display: grid; gap: 10px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid #d4dae3;
  background: #fff;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
}
.btn:hover { background: #f3f5f8; }
.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 650;
  font-size: 16px;
  min-height: 54px;
  width: 100%;
}
.btn-primary:hover { background: #f05500; }
.btn-primary:disabled { opacity: .55; cursor: default; }
.secondary-row { display: flex; gap: 8px; }
.secondary-row .btn { flex: 1; font-size: 13px; min-height: 44px; padding: 8px 10px; }

/* ---------- hoja inferior (compartir) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(15, 22, 32, .45);
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 31;
  background: #fff;
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--line);
  padding: 22px 20px calc(24px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
  animation: sheet-in .22s ease both;
}
@keyframes sheet-in { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { font-size: 18px; font-weight: 650; margin: 0 0 6px; }
.sheet p { font-size: 13px; color: var(--mute); margin: 0 0 16px; }
.sheet label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-soft); margin-bottom: 6px; }
.sheet input[type="text"] {
  width: 100%;
  min-height: 46px;
  border: 1px solid #cfd6df;
  border-radius: 10px;
  padding: 10px 13px;
  font: inherit;
  margin-bottom: 14px;
}
.link-box {
  display: flex;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  background: #f8f9fb;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 14px 0;
}
.link-box .url { flex: 1; min-width: 0; font-size: 12px; color: var(--ink-soft); overflow-wrap: anywhere; }
.sheet .btn { min-height: 44px; font-size: 14px; }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet-actions .btn { flex: 1; }
.sheet .fine { font-size: 12px; margin-top: 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 112px);
  transform: translateX(-50%) translateY(-8px);
  z-index: 40;
  background: var(--navy-2);
  color: #eef1f6;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- resumen ---------- */
.review-sec { margin-bottom: 20px; }
.review-sec h3 { font-size: 13px; font-weight: 600; color: var(--mute); margin: 0 0 8px; text-transform: none; }
.review-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 15px;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--ink);
}
.review-item:hover { background: #fafbfd; }
.review-item .n { color: var(--mute); font-size: 12px; flex: 0 0 auto; padding-top: 2px; }
.review-item .t { flex: 1; min-width: 0; }
.pill {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill-ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.pill-warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.pill-info { background: var(--info-bg); border-color: var(--info-line); color: var(--info); }
.pill-pend { background: #f2f4f7; border-color: var(--line); color: var(--mute); }

/* ---------- admin ---------- */
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.admin-head h1 { font-size: 22px; font-weight: 650; margin: 0; }
.admin-sec { margin-bottom: 26px; }
.admin-sec h2 { font-size: 15px; font-weight: 650; margin: 0 0 12px; }
.admin-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
}
.admin-card .q-line { display: flex; gap: 10px; align-items: flex-start; }
.admin-card .q-line .n { color: var(--mute); font-size: 12px; padding-top: 2px; }
.admin-card .q-line .t { flex: 1; font-size: 14px; font-weight: 550; }
.admin-card .ans { margin-top: 10px; font-size: 13px; color: var(--ink-soft); background: #f8f9fb; border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.admin-card .ans.empty { color: #a3adba; font-style: italic; }
.admin-meta { margin-top: 10px; font-size: 12px; color: var(--mute); display: flex; gap: 14px; flex-wrap: wrap; }
.admin-docs { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.admin-docs a { font-size: 12px; color: #405671; border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; text-decoration: none; background: #fafbfc; }
.invite-row { display: flex; gap: 8px; flex-wrap: wrap; }
.invite-row input, .invite-row select {
  min-height: 46px;
  border: 1px solid #cfd6df;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  flex: 1;
  min-width: 140px;
}
table.inv { width: 100%; border-collapse: collapse; font-size: 13px; }
table.inv td, table.inv th { text-align: left; padding: 8px 6px; border-bottom: 1px solid #edf0f3; }
table.inv th { color: var(--mute); font-weight: 500; font-size: 12px; }

.error-view { text-align: center; padding-top: 60px; }
.error-view h1 { font-size: 20px; }
.error-view p { color: var(--mute); font-size: 14px; }

@media (min-width: 641px) {
  .app { padding-top: 40px; }
  .sheet { left: 50%; right: auto; transform: translateX(-50%); width: 560px; border-radius: 18px; bottom: 24px; }
}

#progress-label { white-space: nowrap; flex: none; }
.progress-meta .chips { flex-wrap: nowrap; min-width: 0; overflow: hidden; }
.progress-meta .chip { overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.mt-14 { margin-top: 14px; }
.mt-18 { margin-top: 18px; }
.m-link { margin: 12px 0 6px; }
.btn-auto { min-height: 46px; width: auto; }
.btn-xs { min-height: 34px; font-size: 12px; padding: 4px 10px; }
.quiet-link { color: #405671; text-decoration: none; border-bottom: 1px solid #c9d1d3; }
.quiet-link:hover { color: #202b3a; border-color: #647478; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
