:root {
  --bg: #f6f1e7;
  --surface: #fffcf6;
  --surface-2: #efe8da;
  --ink: #2b2822;
  --muted: #6c6458;
  --line: #e3dac8;
  --sage: #7d9a7f;
  --sage-ink: #4a674e;
  --sage-strong: #5f7f63;
  --sage-soft: #e3ebdd;
  --amber-ink: #8a5a0f;
  --amber-soft: #f5e6c6;
  --rose-ink: #9b3c33;
  --rose-soft: #f3ddd8;
  --violet-ink: #575083;
  --violet-soft: #e6e2f0;
  --gray-ink: #5f5a52;
  --gray-soft: #e9e4da;
  --wa: #1f8a4c;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(60, 50, 30, 0.06), 0 4px 14px rgba(60, 50, 30, 0.05);
  --nav-h: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.45;
}
body.no-scroll { overflow: hidden; }
a { color: var(--sage-ink); }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1040px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 28px; height: 28px; border-radius: 50%; background: var(--sage); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 0.85rem; }
.brand-name { font-weight: 700; }
.brand-sub { color: var(--muted); font-size: 0.85rem; }
.user-chip { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--muted); }

.container { max-width: 1040px; margin: 0 auto; padding: 20px 16px calc(var(--nav-h) + 32px); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 4px 8px; font-size: 0.72rem; color: var(--muted); text-decoration: none; min-height: var(--nav-h);
  justify-content: center;
}
.nav a svg { width: 22px; height: 22px; }
.nav a.active { color: var(--sage-ink); font-weight: 600; }
.nav a.active svg { stroke: var(--sage-ink); }

@media (min-width: 760px) {
  .nav {
    position: static; border: 0; background: transparent; padding: 0; gap: 4px; justify-content: flex-start;
  }
  .nav a { flex: none; flex-direction: row; min-height: 0; padding: 7px 12px; border-radius: 999px; font-size: 0.92rem; gap: 6px; }
  .nav a svg { width: 18px; height: 18px; }
  .nav a.active { background: var(--sage-soft); }
  .container { padding-bottom: 48px; }
  .topbar-inner { gap: 24px; }
  .brand-sub { display: none; }
}

/* ---------- componentes ---------- */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: 999px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 0.95rem; padding: 10px 18px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--sage-strong); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--sage-ink); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--rose-ink); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--rose-ink); border-color: #e6c4bd; }
.btn-sm { min-height: 36px; padding: 6px 14px; font-size: 0.875rem; }
.btn-wa { background: var(--wa); color: #fff; }
.btn-wa:hover { background: #18723f; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; color: var(--sage-ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }
.icon-btn { background: none; border: 0; font-size: 1.6rem; line-height: 1; width: 44px; height: 44px; cursor: pointer; color: var(--muted); border-radius: 50%; }
.icon-btn:hover { background: var(--surface-2); }
:focus-visible { outline: 3px solid rgba(95, 127, 99, 0.45); outline-offset: 2px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.section { margin-top: 26px; }
.section-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.count { background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 1px 9px; font-size: 0.8rem; font-weight: 600; }

.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.b-interesada { background: var(--amber-soft); color: var(--amber-ink); }
.b-en_validacion { background: var(--violet-soft); color: var(--violet-ink); }
.b-activa { background: var(--sage-soft); color: var(--sage-ink); }
.b-baja { background: var(--rose-soft); color: var(--rose-ink); }
.b-no_concreto { background: var(--gray-soft); color: var(--gray-ink); }
.b-warn { background: #f8dcc4; color: #8a3f0f; }
.b-info { background: var(--surface-2); color: var(--muted); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat span { display: block; color: var(--muted); font-size: 0.82rem; }
.stat strong { display: block; font-size: 1.6rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }

/* filas compactas */
.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px;
}
.row-main { flex: 1; min-width: 0; text-decoration: none; color: inherit; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 0.85rem; color: var(--muted); }
.row-sub.alert { color: var(--rose-ink); font-weight: 600; }
.row-sub.warn { color: var(--amber-ink); font-weight: 600; }
.wa-mini {
  flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--wa); color: #fff;
  display: grid; place-items: center;
}
.wa-mini svg { width: 20px; height: 20px; }
.empty { color: var(--muted); padding: 14px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius-sm); font-size: 0.92rem; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

/* tarjetas de distribuidora */
.cards { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 760px) { .cards { grid-template-columns: 1fr 1fr; } }
.dcard { display: flex; flex-direction: column; gap: 10px; }
.dcard-link { text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 8px; }
.dcard-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.dcard-top h3 { font-size: 1.05rem; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.metrics div { background: var(--bg); border-radius: 8px; padding: 6px 8px; }
.metrics dt { font-size: 0.72rem; color: var(--muted); }
.metrics dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.dates { font-size: 0.85rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.dates b { color: var(--ink); font-weight: 600; }

/* filtros */
.filters { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 14px; }
@media (min-width: 640px) { .filters { grid-template-columns: 2fr 1fr 1fr; } .filters.f4 { grid-template-columns: 1fr 1fr 1fr 1.5fr; } }

/* formularios */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: span 2; } }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label, .field > .label { font-size: 0.85rem; font-weight: 600; color: var(--ink); }
.hint { font-size: 0.8rem; color: var(--muted); }
.input, select.input, textarea.input {
  font: inherit; font-size: 16px; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; min-height: 44px; width: 100%;
}
textarea.input { min-height: 88px; resize: vertical; }
.input:focus { outline: none; border-color: var(--sage); box-shadow: 0 0 0 3px rgba(125, 154, 127, 0.25); }
.input:disabled { background: var(--surface-2); color: var(--muted); }
.invalid .input, .input.invalid { border-color: var(--rose-ink); }
.field-error { color: var(--rose-ink); font-size: 0.8rem; font-weight: 600; }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 0.95rem; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--sage-strong); flex: none; }
.radios { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-pill { position: relative; }
.radio-pill input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.radio-pill span {
  display: inline-flex; align-items: center; min-height: 42px; padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; font-size: 0.95rem;
}
.radio-pill input:checked + span { border-color: var(--sage-strong); background: var(--sage-soft); color: var(--sage-ink); font-weight: 600; }
.radio-pill input:focus-visible + span { outline: 3px solid rgba(95, 127, 99, 0.45); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.form-legend { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; margin-top: 6px; }

/* ficha */
.ficha-head { display: flex; flex-direction: column; gap: 10px; }
.ficha-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 0.9rem; margin-bottom: 10px; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { padding: 2px 0; }
.timeline li + li { border-top: 1px solid var(--line); padding-top: 10px; }
.timeline .meta { font-size: 0.8rem; color: var(--muted); }
.timeline .nota { white-space: pre-wrap; overflow-wrap: anywhere; }
.status-panel { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--bg); }

/* columnas interesadas */
.columns { display: grid; grid-template-columns: 1fr; gap: 18px; }
@media (min-width: 760px) { .columns { grid-template-columns: 1fr 1fr; } }
.column { background: var(--surface-2); border-radius: var(--radius); padding: 12px; }
.column > .section-head { padding: 4px 4px 0; }

/* tabla de pedidos */
.table-wrap { overflow-x: auto; }
table.tabla { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: 0.92rem; }
.tabla th, .tabla td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.tabla th { font-size: 0.78rem; color: var(--muted); font-weight: 600; background: var(--bg); }
.tabla td.num, .tabla th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tabla tr:last-child td { border-bottom: 0; }
.totales { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.92rem; color: var(--muted); margin-bottom: 10px; }
.totales b { color: var(--ink); }
.plist { display: none; }
@media (max-width: 639px) {
  .table-wrap { display: none; }
  .plist { display: flex; }
}

/* hoja inferior (modal) */
#sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(43, 40, 34, 0.38); animation: fade 0.18s ease-out; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0; padding: 6px 16px calc(20px + env(safe-area-inset-bottom));
  animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet header { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); padding: 8px 0; z-index: 1; }
@media (min-width: 640px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: min(520px, calc(100vw - 32px)); border-radius: 20px; animation: fade 0.18s ease-out; }
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } }

.confirm-box { border: 1px solid #e6c4bd; background: var(--rose-soft); border-radius: var(--radius-sm); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.notice { background: var(--amber-soft); color: var(--amber-ink); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 0.9rem; }
.notice.ok { background: var(--sage-soft); color: var(--sage-ink); }
.notice.err { background: var(--rose-soft); color: var(--rose-ink); }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 60; max-width: min(92vw, 520px);
  font-size: 0.92rem; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
#toast.err { background: var(--rose-ink); }
@media (min-width: 760px) { #toast { bottom: 24px; } }

/* páginas públicas */
.public { min-height: 100vh; display: flex; flex-direction: column; }
.public-wrap { width: 100%; max-width: 560px; margin: 0 auto; padding: 28px 16px 48px; }
.public-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.public h1 { font-size: 1.7rem; }
.lead { color: var(--muted); margin-top: 6px; }
.user-pick { display: grid; grid-template-columns: 1fr; gap: 8px; }
.user-pick .radio-pill span { width: 100%; justify-content: flex-start; border-radius: var(--radius-sm); min-height: 52px; font-weight: 600; }
.pin-input { letter-spacing: 0.5em; font-size: 1.4rem; text-align: center; font-variant-numeric: tabular-nums; }
.asesor-pick { display: grid; gap: 8px; }
.asesor-pick .radio-pill span { width: 100%; border-radius: var(--radius-sm); min-height: 56px; flex-direction: column; align-items: flex-start; justify-content: center; padding: 8px 14px; }
.asesor-pick small { color: var(--muted); font-weight: 400; }
.hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.draft-banner { background: #fbe3a6; color: #6b4a00; font-weight: 700; text-align: center; padding: 10px 16px; letter-spacing: 0.04em; border-bottom: 1px solid #ecc96a; }
.prose h2 { margin: 22px 0 8px; font-size: 1.05rem; }
.prose p, .prose li { color: #3e3a33; }
.prose ul { padding-left: 20px; }
.success { text-align: center; padding: 28px 16px; }
.success .check-big { width: 64px; height: 64px; border-radius: 50%; background: var(--sage-soft); color: var(--sage-ink); display: grid; place-items: center; margin: 0 auto 14px; font-size: 2rem; }

.list-count { margin-bottom: 8px; }
.mt { margin-top: 12px; }
h2.inline { display: inline; }
details > summary { cursor: pointer; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 6px; }
.ficha-head .status-panel { background: var(--surface); border: 1px solid var(--line); }
.ficha-head .metrics div { background: var(--surface); border: 1px solid var(--line); }
