:root {
  --azul: #114F9C;
  --azul-oscuro: #0C3D7A;
  --celeste: #37BBED;
  --amarillo: #FDC72C;
  --bg: #F3F5F7;
  --surface: #FFFFFF;
  --border: #D8DEE5;
  --border-strong: #AEB8C4;
  --text: #1A2430;
  --muted: #5C6773;
  --ok: #1E7F4F;
  --ok-bg: #E4F3EA;
  --warn: #7A5200;
  --warn-bg: #FFF1C2;
  --danger: #B42318;
  --danger-bg: #FDECEA;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 var(--font);
  min-height: 100dvh;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--celeste); outline-offset: 2px; }

/* ---------- cabecera ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo { height: 34px; width: auto; display: block; }
.top-mid { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-mid strong { color: var(--text); font-weight: 600; }
.top-right { display: flex; align-items: center; gap: 12px; }
.who { font-size: 14px; color: var(--muted); }
.lang { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 999px; overflow: hidden; }
.lang button {
  border: 0; background: transparent; padding: 6px 12px; font-size: 13px; font-weight: 600; letter-spacing: .04em; color: var(--muted);
}
.lang button[aria-pressed="true"] { background: var(--azul); color: #fff; }
.link { background: none; border: 0; color: var(--azul); padding: 4px; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }

@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 8px 12px; }
  .logo { height: 28px; }
  .top-mid { order: 3; flex-basis: 100%; }
  .top-right { margin-left: auto; }
  .who { display: none; }
}

main { max-width: 960px; margin: 0 auto; padding: 20px 16px 120px; }

/* ---------- piezas comunes ---------- */
h1 { font-size: 22px; line-height: 1.25; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); font-weight: 600;
}
.btn:hover { border-color: var(--azul); }
.btn.primary { background: var(--azul); border-color: var(--azul); color: #fff; }
.btn.primary:hover { background: var(--azul-oscuro); }
.btn.warn { background: var(--amarillo); border-color: #E8B100; color: #2A2000; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=search], input[inputmode=numeric], textarea, select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; min-height: 48px;
}
textarea { min-height: 140px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--azul); outline: none; box-shadow: 0 0 0 3px rgba(55,187,237,.35); }
.error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }

/* ---------- login ---------- */
.login { max-width: 420px; margin: 8vh auto 0; }
.login h1 { margin-bottom: 4px; }
.login p { margin: 0 0 20px; }
.login .btn { width: 100%; }

/* ---------- panel ---------- */
.panel-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.panel-head .grow { flex: 1; min-width: 220px; }
.panel-head select { min-height: 44px; }
.big-new { width: 100%; min-height: 64px; font-size: 18px; margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs button {
  border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--azul); border-bottom-color: var(--azul); }
.count { display: inline-block; min-width: 24px; padding: 0 7px; border-radius: 999px; font-size: 13px; line-height: 22px; text-align: center; margin-left: 6px; background: var(--bg); color: var(--text); }
.tabs button[data-tab="pending"] .count { background: var(--warn-bg); color: var(--warn); }
.tabs button[data-tab="complete"] .count { background: var(--ok-bg); color: var(--ok); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.toolbar input { flex: 1; min-width: 200px; min-height: 44px; }
.list { display: grid; gap: 8px; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
}
.row .name { font-weight: 600; }
button.row.pick { width: 100%; text-align: left; font: inherit; color: inherit; }
button.row.pick:hover { border-color: var(--azul); }
button.row.pick.dim { background: var(--bg); }
button.row.pick.dim .name { color: var(--muted); }
.mesa { display: inline-block; min-width: 64px; margin-right: 8px; font-size: 13px; font-weight: 700; color: var(--azul); }
input[type=file] { display: block; padding: 10px 0; }
.row .meta { font-size: 14px; color: var(--muted); }
.row .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .04em; padding: 2px 8px; border-radius: 4px; text-transform: uppercase; vertical-align: 2px; margin-left: 6px; }
.badge.pending { background: var(--warn-bg); color: var(--warn); }
.badge.complete { background: var(--ok-bg); color: var(--ok); }
.progress-mini { height: 4px; background: var(--bg); border-radius: 2px; margin-top: 8px; max-width: 260px; overflow: hidden; }
.progress-mini i { display: block; height: 100%; background: var(--amarillo); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
@media (max-width: 640px) {
  .row { grid-template-columns: 1fr; }
  .row .actions { justify-content: stretch; }
  .row .actions .btn { flex: 1; }
}

/* ---------- encuesta ---------- */
.survey-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.survey-head .who-buyer { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-state { font-size: 13px; color: var(--muted); white-space: nowrap; }
.save-state.offline { color: var(--warn); font-weight: 600; }
.bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 12px; }
.bar i { display: block; height: 100%; background: var(--azul); transition: width .25s ease; }
.jump { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.jump button {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 14px; font-weight: 600; color: var(--muted); padding: 0;
}
.jump button.done { background: var(--ok-bg); border-color: #9BCDB1; color: var(--ok); }
.jump button.missing { border-color: var(--danger); color: var(--danger); }
.jump button[aria-current="step"] { background: var(--azul); border-color: var(--azul); color: #fff; }
.q-card { padding: 24px; }
.q-num { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.q-num .req { color: var(--danger); margin-left: 4px; }
.q-title { font-size: 22px; line-height: 1.3; font-weight: 600; margin: 0 0 6px; }
.q-alt { font-size: 15px; color: var(--muted); margin: 0 0 18px; }
.q-hint { font-size: 14px; color: var(--muted); margin: -10px 0 16px; }
.choices { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 14px; min-height: 56px; padding: 12px 16px;
  border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; text-align: left; width: 100%;
}
.choice input { width: 22px; height: 22px; accent-color: var(--azul); flex: none; margin: 0; }
.choice:has(input:checked) { border-color: var(--azul); background: #EAF2FB; }
.choice .alt { display: block; font-size: 13px; color: var(--muted); }
.other-input { margin-top: 4px; }
.rating { display: flex; gap: 10px; flex-wrap: wrap; }
.rating button {
  width: 64px; height: 64px; border-radius: 10px; border: 1px solid var(--border-strong); background: #fff;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 0;
}
.rating button svg { width: 26px; height: 26px; }
.rating button span { font-size: 13px; font-weight: 700; color: var(--muted); }
.rating button.on { border-color: var(--azul); background: #EAF2FB; }
.rating button.on svg { color: var(--azul); }
.rating button svg { color: var(--border-strong); }
.rating-legend { display: flex; justify-content: space-between; max-width: 360px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.clear { margin-top: 12px; }

.footbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.footbar .inner { max-width: 960px; margin: 0 auto; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.footbar .pause { justify-self: center; }
@media (max-width: 640px) {
  .footbar .inner { grid-template-columns: 1fr 1fr; }
  .footbar .pause { grid-column: 1 / -1; grid-row: 1; justify-self: stretch; }
}

/* ---------- resumen final ---------- */
.review dl { margin: 0; display: grid; gap: 12px; }
.review dt { font-size: 14px; color: var(--muted); }
.review dd { margin: 2px 0 0; font-weight: 600; }
.review dd.empty-a { color: var(--muted); font-weight: 400; font-style: italic; }
.review dd.missing { color: var(--danger); }
.review .item { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }

/* ---------- eventos ---------- */
.ev-list { display: grid; gap: 8px; margin-bottom: 24px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 30;
  background: var(--text); color: #fff; padding: 12px 18px; border-radius: 8px; max-width: calc(100% - 32px);
  font-size: 15px; box-shadow: 0 6px 24px rgba(0,0,0,.18);
}
.toast.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #E8C766; }

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

/* ---------- celular ---------- */
button, a, input, label { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.top { padding-top: calc(10px + env(safe-area-inset-top)); }

@media (max-width: 640px) {
  main { padding: 14px 12px 190px; }
  .top { padding-left: 12px; padding-right: 12px; }
  .top-mid { font-size: 13px; }
  h1 { font-size: 20px; }
  .card { padding: 16px; }

  /* panel */
  .panel-head { gap: 8px; margin-bottom: 12px; }
  .panel-head { flex-wrap: nowrap; align-items: center; }
  .panel-head .grow { min-width: 0; flex: 1 1 0; }
  .panel-head > .btn { flex: none; }
  .big-new { min-height: 58px; margin-bottom: 12px; }
  .tabs button { flex: 1; padding: 12px 6px; }
  .toolbar input { min-width: 0; flex: 1 1 100%; }
  .toolbar .btn { flex: 1; }
  .row { padding: 12px; gap: 10px; }
  button.row.pick { grid-template-columns: 1fr auto; align-items: center; }
  button.row.pick > .btn { min-width: 76px; }
  .mesa { display: block; min-width: 0; margin: 0 0 2px; }
  .badge { margin-left: 4px; }

  /* encuesta: navegación de preguntas en una sola fila deslizable */
  .jump { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -12px 12px; padding: 2px 12px; scroll-padding: 0 48px; }
  .jump::-webkit-scrollbar { display: none; }
  .jump button { flex: none; width: 34px; height: 34px; }
  .q-card { padding: 18px 16px; }
  .q-title { font-size: 19px; }
  .q-alt { font-size: 14px; margin-bottom: 14px; }
  .choice { min-height: 54px; padding: 10px 12px; gap: 12px; }
  .rating { gap: 6px; flex-wrap: nowrap; }
  .rating button { flex: 1 1 0; width: auto; min-width: 0; height: 60px; }
  .rating-legend { max-width: none; }
  .review .item { grid-template-columns: 1fr; }
  .review .item .btn { justify-self: start; }

  .footbar { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .footbar .inner { gap: 8px; }
  .footbar .btn { min-height: 48px; padding: 8px 10px; }
  .toast { bottom: calc(140px + env(safe-area-inset-bottom)); }
  .login { margin-top: 4vh; }
}
