:root {
  --bg: #f3f1ec;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --ink: #16191c;
  --ink-2: #5a6168;
  --line: #dedad2;
  --brand: #0f3b4c;
  --brand-ink: #ffffff;
  --accent: #e2742b;
  --ok: #1f7a4d;
  --ok-bg: #e5f4ec;
  --danger: #b3261e;
  --danger-bg: #fbe9e7;
  --warn-bg: #fff4dc;
  --warn-line: #e9b44c;
  --info-bg: #e7f0f6;
  --sel: #0f3b4c;
  --sel-bg: #e3eef2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111416; --surface: #1b1f22; --surface-2: #22272b; --ink: #eef0f1; --ink-2: #a3abb2; --line: #2f363b;
    --brand: #5fb3cf; --brand-ink: #071a22; --sel: #7cc5de; --sel-bg: #18323c; --ok: #5cc794; --ok-bg: #163126;
    --danger: #ff8a80; --danger-bg: #3a1a18; --warn-bg: #352a12; --warn-line: #b58a2e; --info-bg: #172833; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111416; --surface: #1b1f22; --surface-2: #22272b; --ink: #eef0f1; --ink-2: #a3abb2; --line: #2f363b;
  --brand: #5fb3cf; --brand-ink: #071a22; --sel: #7cc5de; --sel-bg: #18323c; --ok: #5cc794; --ok-bg: #163126;
  --danger: #ff8a80; --danger-bg: #3a1a18; --warn-bg: #352a12; --warn-line: #b58a2e; --info-bg: #172833; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; overscroll-behavior-y: none; }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select { font-size: 17px; } /* evita el zoom automático de Safari */
.boot { padding: 40vh 0; text-align: center; color: var(--ink-2); }

/* ---------- estructura ---------- */
.shell { max-width: 640px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--brand); color: var(--brand-ink); padding: calc(var(--safe-t) + 10px) 16px 10px; display: flex; align-items: center; gap: 12px; }
.topbar .brand { font-weight: 800; letter-spacing: .04em; font-size: 18px; }
.topbar .who { margin-left: auto; font-size: 14px; opacity: .9; text-align: right; }
.topbar button { background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 10px; padding: 6px 10px; font-size: 14px; }
.steps { display: flex; gap: 4px; padding: 10px 16px 0; overflow-x: auto; scrollbar-width: none; }
.steps::-webkit-scrollbar { display: none; }
.step-pill { flex: 1 0 auto; border: 0; background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 6px 10px; font-size: 13px; white-space: nowrap; }
.step-pill.done { color: var(--ok); }
.step-pill.current { background: var(--brand); color: var(--brand-ink); font-weight: 700; }
.step-pill:disabled { opacity: .55; }
main { flex: 1; padding: 14px 16px 140px; }
h1 { font-size: 24px; margin: 6px 0 14px; line-height: 1.2; }
h2 { font-size: 18px; margin: 18px 0 10px; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }

/* ---------- tarjetas y campos ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.field { margin-bottom: 14px; }
.field label, .label { display: block; font-weight: 600; margin-bottom: 6px; }
.input { width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 13px 14px; min-height: 52px; outline: none; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--sel-bg); }
textarea.input { min-height: 84px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: stretch; }
.row > .grow { flex: 1; min-width: 0; }
.req { color: var(--danger); }

/* ---------- botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 18px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.btn.big { width: 100%; min-height: 60px; font-size: 18px; }
.btn.send { width: 100%; min-height: 66px; font-size: 19px; font-weight: 800; letter-spacing: .02em; background: var(--ok); border-color: var(--ok); color: #fff; }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.link { border: 0; background: none; min-height: 40px; padding: 0 6px; color: var(--brand); }
.mic { width: 52px; min-width: 52px; padding: 0; font-size: 22px; }
.mic.big { width: 64px; min-width: 64px; min-height: 64px; border-radius: 50%; }
.mic.listening { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.1s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(179,38,30,.5); } 70% { box-shadow: 0 0 0 14px rgba(179,38,30,0); } 100% { box-shadow: 0 0 0 0 rgba(179,38,30,0); } }
.mic svg, .btn svg { width: 24px; height: 24px; }

/* ---------- opciones grandes (sin preselección) ---------- */
.choices { display: grid; gap: 10px; margin-bottom: 14px; }
.choices.two { grid-template-columns: 1fr 1fr; }
.choices.three { grid-template-columns: repeat(3, 1fr); }
.choice { position: relative; text-align: left; border: 2px solid var(--line); background: var(--surface); border-radius: 14px; padding: 14px; min-height: 58px; cursor: pointer; font-weight: 700; display: flex; flex-direction: column; justify-content: center; }
.choice small { font-weight: 400; color: var(--ink-2); margin-top: 3px; font-size: 13px; }
.choice.on { border-color: var(--sel); background: var(--sel-bg); box-shadow: inset 0 0 0 1px var(--sel); }
.choice.on::after { content: "✓"; position: absolute; top: 6px; right: 9px; color: var(--sel); font-size: 15px; }
.choices.three .choice { text-align: center; align-items: center; }

/* ---------- barra inferior ---------- */
.bottombar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding: 10px 16px calc(var(--safe-b) + 10px); }
.bottombar .inner { max-width: 608px; margin: 0 auto; }
.bottombar .totals { display: flex; justify-content: space-between; font-size: 15px; margin-bottom: 8px; }
.bottombar .totals b { font-size: 17px; }
.bottombar .hint { color: var(--danger); font-size: 13px; margin-bottom: 6px; text-align: center; }

/* ---------- cliente ---------- */
.client-card { border: 2px solid var(--ok); background: var(--ok-bg); }
.client-card .code { font-size: 14px; color: var(--ink-2); }
.client-card .name { font-size: 20px; font-weight: 800; margin: 2px 0 6px; }
.newbadge { display: inline-block; background: var(--danger); color: #fff; font-weight: 800; padding: 4px 10px; border-radius: 8px; letter-spacing: .04em; }
.notice { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.notice.warn { background: var(--warn-bg); border: 1.5px solid var(--warn-line); }
.notice.err { background: var(--danger-bg); color: var(--danger); border: 1.5px solid var(--danger); }
.notice.info { background: var(--info-bg); }

/* ---------- productos ---------- */
.search-wrap { position: sticky; top: calc(var(--safe-t) + 52px); z-index: 10; background: var(--bg); padding: 6px 0 10px; }
.voice-status { min-height: 20px; font-size: 14px; color: var(--ink-2); margin-top: 6px; }
.results { display: grid; gap: 8px; margin-bottom: 16px; }
.result { text-align: left; border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; cursor: pointer; width: 100%; }
.result:active { background: var(--sel-bg); }
.result .d { font-weight: 700; font-size: 16px; }
.result .m { font-size: 13px; color: var(--ink-2); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.result .in-order { color: var(--ok); font-weight: 700; }
.lines { display: grid; gap: 8px; }
.line { background: var(--surface); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; width: 100%; text-align: left; border: 0; cursor: pointer; }
.line .d { font-weight: 600; }
.line .c { font-size: 12px; color: var(--ink-2); font-family: ui-monospace, Menlo, monospace; }
.line .q { font-size: 20px; font-weight: 800; text-align: right; }
.line .p { font-size: 13px; color: var(--ink-2); }
.line .s { text-align: right; font-weight: 700; }
.empty { text-align: center; color: var(--ink-2); padding: 18px; border: 2px dashed var(--line); border-radius: 14px; }

/* ---------- hoja inferior (cantidad / confirmaciones) ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 640px; border-radius: 20px 20px 0 0; padding: 18px 16px calc(var(--safe-b) + 16px); max-height: 92dvh; overflow-y: auto; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet h3 { margin: 0 0 4px; font-size: 19px; }
.qty-input { font-size: 34px !important; font-weight: 800; text-align: center; min-height: 68px; letter-spacing: .03em; }
.qty-calc { text-align: center; font-size: 15px; color: var(--ink-2); min-height: 22px; margin: 6px 0 10px; }
.unit-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }

/* ---------- revisión ---------- */
.rv-sec { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.rv-sec .hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.rv-sec .hd b { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.kv { display: grid; grid-template-columns: 42% 1fr; gap: 4px 10px; font-size: 15px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 600; }
.highlight { border: 2px solid var(--accent); background: var(--warn-bg); }
.rv-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.rv-table td { padding: 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.rv-table .n { text-align: right; white-space: nowrap; padding-left: 8px; }
.total-row { display: flex; justify-content: space-between; font-size: 19px; font-weight: 800; padding-top: 10px; }
.legend { font-size: 13px; color: var(--ink-2); margin: 8px 0 14px; font-style: italic; }

/* ---------- inicio / listados ---------- */
.order-item { display: flex; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; cursor: pointer; }
.status { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.status.enviado { background: var(--ok-bg); color: var(--ok); }
.status.error, .status.mail_no_configurado { background: var(--danger-bg); color: var(--danger); }
.success { text-align: center; padding: 30px 10px; }
.success .big { font-size: 64px; }

#toast { position: fixed; left: 50%; top: calc(var(--safe-t) + 64px); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }
.demo-banner { background: var(--accent); color: #fff; text-align: center; font-size: 13px; font-weight: 700; padding: 6px; }
.login { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-t) + 60px) 20px 40px; }
.login .logo { font-size: 34px; font-weight: 900; letter-spacing: .08em; color: var(--brand); }
@media (min-width: 700px) { main { padding-top: 20px; } }

/* stock y mínimo */
.stk { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.stk-ok { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.stk-poco { background: var(--warn-bg); color: var(--ink); border: 1px solid var(--warn-line); }
.stk-sin { background: var(--danger-bg); color: var(--danger); }
.stk-msg { margin-top: 8px; color: var(--danger); font-weight: 600; font-size: 14px; }
.min-warn { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 10px; padding: 6px 10px; font-size: 14px; font-weight: 600; margin-bottom: 8px; text-align: center; }

/* aviso de precios */
.price-note { font-size: 12px; color: var(--ink-2); text-align: center; margin: -4px 0 8px; }
.price-alert { background: var(--danger-bg); border: 2px solid var(--danger); color: var(--ink); }

/* pedido desde foto */
.pending { background: var(--warn-bg); border: 1.5px solid var(--warn-line); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.pend-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--warn-line); font-size: 15px; }
.pend-row:first-of-type { border-top: 0; }
.pend-row.on { font-weight: 700; }
.pend-row .btn { min-height: 40px; padding: 0 12px; }
.ph-sheet { max-height: 94dvh; padding-bottom: 0; }
.ph-card { border: 1.5px solid var(--line); border-radius: 14px; padding: 10px; margin-top: 12px; }
.ph-card.ok { border-color: var(--ok); }
.ph-text { font-weight: 700; margin-bottom: 8px; }
.ph-opt { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left; border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px; margin-top: 6px; cursor: pointer; }
.ph-opt.on { border-color: var(--sel); background: var(--sel-bg); }
.ph-check { flex: 0 0 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--brand-ink); }
.ph-opt.on .ph-check { background: var(--sel); border-color: var(--sel); }
.ph-qty { margin-top: 8px; }
.ph-qty .input { max-width: 120px; text-align: center; font-weight: 700; }
.ph-qty .choice { min-height: 48px; padding: 8px 10px; font-size: 14px; }
.ph-foot { position: sticky; bottom: 0; background: var(--surface); padding: 12px 0 calc(var(--safe-b) + 12px); margin-top: 12px; border-top: 1px solid var(--line); }
.spinner { width: 40px; height: 40px; margin: 6px auto 12px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--brand); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ph-qty .choice.on::after { content: none; }

/* búsquedas recientes / marca fijada ("seguir en Koleston") */
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.chips .lbl { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.chip { border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600; min-height: 36px; cursor: pointer; text-transform: capitalize; }
.chip.on { background: var(--sel-bg); border-color: var(--sel); text-transform: none; cursor: default; }
.chip.x { color: var(--danger); text-transform: none; }
