:root {
  --brand: #0f766e;
  --bg: #f4faf8;
  --surface: #ffffff;
  --text: #10211e;
  --muted: #566a65;
  --border: #d5e4e0;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #dff1ee;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #7a4e00;
  --warn-soft: #fff1cc;
  --info: #1d4f91;
  --info-soft: #e3eefb;
  --ok: #11693f;
  --ok-soft: #dcf4e7;
  --rx: #5b3a9e;
  --rx-soft: #eee8fb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 33, 30, .06), 0 4px 14px rgba(16, 33, 30, .05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1412;
    --surface: #13201d;
    --text: #e6f1ee;
    --muted: #9db3ad;
    --border: #253934;
    --primary: #2dd4bf;
    --primary-ink: #04211d;
    --primary-soft: #12342f;
    --danger: #ff8a80;
    --danger-soft: #3a1815;
    --warn: #ffd37a;
    --warn-soft: #3a2c0b;
    --info: #9cc4ff;
    --info-soft: #14284a;
    --ok: #7ee2a8;
    --ok-soft: #10301f;
    --rx: #cdb8ff;
    --rx-soft: #2a2047;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.4rem; line-height: 1.25; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.stack > * + * { margin-top: 12px; }
.stack-lg > * + * { margin-top: 20px; }

:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 8px; }

/* ---------- Estrutura ---------- */
#app { max-width: 720px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--brand); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
.topbar img { width: 30px; height: 30px; border-radius: 8px; }
.topbar .brand { font-weight: 700; font-size: 1.1rem; letter-spacing: .2px; }

.offline { background: var(--warn-soft); color: var(--warn); padding: 8px 16px; font-size: .875rem; text-align: center; }

main { flex: 1; padding: 16px 16px calc(90px + env(safe-area-inset-bottom)); }
main:focus { outline: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  max-width: 720px; margin: 0 auto;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; position: relative; min-height: 58px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--primary); }
.count {
  position: absolute; top: 5px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: .7rem; line-height: 18px; text-align: center;
}

#toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: #10211e; color: #fff; font-size: .9rem; text-align: center;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-color-scheme: dark) { #toast { background: #e6f1ee; color: #10211e; } }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.back { display: inline-block; margin-bottom: 10px; text-decoration: none; font-weight: 600; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
a.card { display: block; color: inherit; text-decoration: none; }
a.card:active { background: var(--primary-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 650; cursor: pointer; text-decoration: none;
  background: var(--primary); color: var(--primary-ink);
}
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.field { display: block; }
.field > label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field > small { display: block; margin-top: 4px; color: var(--muted); }
input, textarea, select {
  width: 100%; min-height: 46px; padding: 10px 12px;
  font: inherit; font-size: 16px; /* 16px evita o zoom automático no iOS */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
}
textarea { min-height: 84px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 22px; min-height: 22px; height: 22px; flex: none; accent-color: var(--primary); }
input[type="file"] { padding: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .9rem; }

.error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
.notice { background: var(--info-soft); color: var(--info); padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); }
.empty .big { font-size: 2.4rem; display: block; margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.muted { background: var(--border); color: var(--muted); }
.badge.rx { background: var(--rx-soft); color: var(--rx); }

.seg { display: flex; padding: 3px; gap: 3px; background: var(--primary-soft); border-radius: 12px; }
.seg button {
  flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent;
  font: inherit; font-weight: 650; color: var(--muted); cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .9rem;
}
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 650; }

/* ---------- Montra ---------- */
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; margin-top: 12px; }
@media (min-width: 600px) { .grid { grid-template-columns: 1fr 1fr; } }
.product { display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-content: start; }
.tile { width: 56px; height: 56px; border-radius: 14px; display: grid; place-items: center; font-size: 1.9rem; background: var(--primary-soft); }
.product h3 { margin-bottom: 2px; }
.product .desc { margin-top: 6px; font-size: .9rem; color: var(--muted); }
.product .foot { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.price { font-size: 1.1rem; font-weight: 750; }

/* ---------- Pedido ---------- */
.line { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--border); }
.line:first-child { border-top: 0; padding-top: 0; }
.qty { display: inline-flex; align-items: center; gap: 4px; }
.qty button { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1.2rem; cursor: pointer; }
.qty output { min-width: 28px; text-align: center; font-weight: 700; }
.linktxt { justify-self: start; border: 0; background: none; color: var(--danger); font: inherit; font-size: .85rem; cursor: pointer; padding: 4px 0; text-decoration: underline; }
.error .linktxt { color: inherit; }
.total { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.15rem; font-weight: 750; padding-top: 12px; border-top: 1px solid var(--border); margin-top: 4px; }
.radio-card { display: flex; gap: 10px; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.radio-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }

/* ---------- Listas de pedidos ---------- */
a.card.order-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.order-row .sub { grid-column: 1 / -1; font-size: .875rem; color: var(--muted); }

.steps { display: flex; list-style: none; padding: 0; margin: 0; }
.steps li { flex: 1; text-align: center; font-size: .72rem; color: var(--muted); position: relative; padding-top: 22px; }
.steps li::before { content: ""; position: absolute; top: 4px; left: 50%; width: 14px; height: 14px; border-radius: 50%; transform: translateX(-50%); background: var(--border); z-index: 1; }
.steps li::after { content: ""; position: absolute; top: 10px; left: -50%; width: 100%; height: 2px; background: var(--border); }
.steps li:first-child::after { display: none; }
.steps li.done::before, .steps li.done::after { background: var(--primary); }
.steps li.now { color: var(--text); font-weight: 700; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.copy-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .5px; }
.rx-img { display: block; width: 100%; max-height: 420px; object-fit: contain; border-radius: 10px; background: var(--primary-soft); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions .btn { flex: 1 1 160px; }

.auth { padding-top: 8px; }
.auth h1 { margin: 18px 0 4px; }
.noscript { padding: 24px; text-align: center; }

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

/* ---------- Códigos de recuperação ---------- */
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.codes span { padding: 10px; text-align: center; border: 1px dashed var(--border); border-radius: 10px; background: var(--primary-soft); font-size: 1.05rem; }
.secret { font-size: 1.15rem; word-spacing: .4em; overflow-wrap: anywhere; }
