:root {
  --bg: #f4f4f5;
  --card: #ffffff;
  --text: #18181b;
  --muted: #6b6b73;
  --border: #e2e2e6;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --accent-soft: #fff1e8;
  --green: #15803d;
  --green-soft: #e8f6ed;
  --amber-soft: #fef3c7;
  --amber-text: #92400e;
  --danger: #b91c1c;
  --radius: 12px;
  --tap: 44px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --card: #1c1d20;
    --text: #f2f2f3;
    --muted: #a0a0a8;
    --border: #2e2f34;
    --accent: #f97316;
    --accent-text: #1a0a00;
    --accent-soft: #3a1f0f;
    --green: #4ade80;
    --green-soft: #12301d;
    --amber-soft: #3b2f0b;
    --amber-text: #fcd34d;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }
/* Class styles that set display must not un-hide [hidden] elements. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
h1 { font-size: 22px; margin: 0; line-height: 1.2; }
h2 { font-size: 15px; margin: 20px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.green { color: var(--green); }
a { color: var(--accent); }

/* ---------- buttons ---------- */
button, .btn, input, textarea, select { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); min-width: var(--tap); padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--card);
  text-decoration: none; cursor: pointer; font-weight: 600; color: var(--text);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn.on-green { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.icon-btn { padding: 0; width: var(--tap); font-size: 22px; }

/* ---------- header ---------- */
.header { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.header .title { flex: 1; min-width: 0; }
.header .sub { font-size: 14px; color: var(--muted); }
.daynav { display: flex; gap: 4px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px;
}
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.metric {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; text-align: left; min-height: 72px; display: flex; flex-direction: column; justify-content: space-between;
}
button.metric { cursor: pointer; }
.metric .label { font-size: 12px; color: var(--muted); line-height: 1.2; }
.metric .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .value.add { font-size: 15px; color: var(--accent); }
.metric.profit .value { color: var(--green); }
.metric.profit .value.neg { color: var(--danger); }

.lbs { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.lbs-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lbs-left { font-weight: 700; font-size: 18px; }
.bar { height: 10px; background: var(--border); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.out > span { background: var(--danger); }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 12px; min-height: var(--tap); padding: 10px 12px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--text); text-decoration: none; font-weight: 600;
  border: 1px solid var(--accent);
}

/* ---------- order list ---------- */
.orders { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.order { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.order.done { opacity: .6; }
.order-main {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: 12px; cursor: pointer;
  min-height: var(--tap);
}
.order-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.order-items { margin-top: 2px; }
.order-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.order-actions {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 12px;
}
.order-actions .spacer { flex: 1; }
.order-actions .btn { font-size: 14px; padding: 0 12px; }
.order-actions .del { color: var(--danger); }

.pill { font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.pill.new { background: var(--accent-soft); color: var(--accent); }
.pill.ready { background: var(--amber-soft); color: var(--amber-text); }
.pill.picked_up { background: var(--green-soft); color: var(--green); }

.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; position: relative; }
.field > label, .field > .label { font-size: 14px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=tel], input[type=date], input:not([type]), textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font-size: 17px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card);
}
textarea { min-height: 72px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: var(--tap); padding: 0 14px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--card); font-weight: 600; cursor: pointer;
}
.chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.small { min-height: var(--tap); min-width: var(--tap); padding: 0 12px; font-size: 15px; }
input.chip-date { width: auto; min-width: 0; flex: 1 1 140px; border-radius: 99px; font-size: 15px; }

.suggest {
  list-style: none; margin: 0; padding: 4px 0; position: absolute; top: 100%; left: 0; right: 0; z-index: 5;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.12);
}
.suggest button { display: block; width: 100%; text-align: left; min-height: var(--tap); padding: 8px 12px; background: none; border: 0; cursor: pointer; }
.suggest .ph { color: var(--muted); font-size: 14px; margin-left: 6px; }

.item { padding: 10px 0; border-top: 1px solid var(--border); }
.item:first-child { border-top: 0; padding-top: 0; }
.item-row { display: flex; align-items: center; gap: 8px; }
.item-name { flex: 1; min-width: 0; }
.item-name .price { font-size: 13px; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper .qty { min-width: 48px; text-align: center; font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.stepper .btn { width: var(--tap); padding: 0; font-size: 22px; }
.quick { margin-top: 8px; }

.rawtext {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; margin: 0;
  background: var(--bg); border-radius: 8px; padding: 10px;
}
.flag { display: inline-block; margin-top: 8px; font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 99px; background: var(--amber-soft); color: var(--amber-text); }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--card); border-top: 1px solid var(--border);
}
.savebar-inner { max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.savebar .total { flex: 1; }
.savebar .total .label { font-size: 13px; color: var(--muted); }
.savebar .total .value { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.savebar .btn { min-width: 140px; min-height: 50px; font-size: 18px; }
body.adding .tabbar { display: none; }
body.signin .tabbar { display: none; }
form.signin { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
form.signin label { font-weight: 700; }

/* drafts */
.draft { display: flex; flex-direction: column; gap: 10px; }
.draft .parsed { display: flex; flex-wrap: wrap; gap: 6px; }
.draft .actions { display: flex; gap: 8px; }
.draft .actions .btn { flex: 1; }
.list { display: flex; flex-direction: column; gap: 10px; }

/* menu settings */
.menu-row { display: grid; grid-template-columns: 1fr 96px auto; gap: 8px; align-items: center; }
.menu-row + .menu-row { margin-top: 10px; }
.menu-row .unit { font-size: 12px; color: var(--muted); grid-column: 1 / -1; margin-top: -4px; }
.switch { display: flex; align-items: center; gap: 6px; min-height: var(--tap); font-size: 14px; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 52px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 15px;
}
.tabbar a[aria-current=page] { color: var(--accent); }
.badge { background: var(--accent); color: var(--accent-text); font-size: 12px; border-radius: 99px; padding: 1px 7px; }

/* ---------- dialog + toast ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; background: var(--card); color: var(--text);
  width: min(92vw, 360px); padding: 16px;
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog label { font-weight: 700; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }
.dialog-actions .btn:first-child { margin-right: auto; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(env(safe-area-inset-bottom) + 80px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-weight: 600;
  max-width: calc(100vw - 32px);
}

/* talk box + editable drafts */
form.talk { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
form.talk label { font-weight: 700; }
.draft-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ai { font-size: 13px; font-weight: 700; }
.ai.pending { color: var(--accent); }
.ai.done { color: var(--green); }
.ai.failed { color: var(--muted); }
.dgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.dfield { display: flex; flex-direction: column; gap: 4px; min-width: 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.dfield.wide { grid-column: 1 / -1; }
.dfield input { color: var(--text); font-weight: 400; min-width: 0; }

/* brand: still logo with a spinning tricolor ring */
.loader { position: relative; display: inline-block; width: var(--size, 112px); height: var(--size, 112px); flex: none; vertical-align: middle; }
.loader img { width: 100%; height: 100%; display: block; }
.loader::after {
  content: ''; position: absolute; inset: calc(var(--ring, 5px) * -1.8); border-radius: 50%;
  background: conic-gradient(#0a7a4b 0 38%, transparent 0 50%, #ce1126 0 88%, transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--ring, 5px)), #000 calc(100% - var(--ring, 5px) + 1px));
  mask: radial-gradient(farthest-side, transparent calc(100% - var(--ring, 5px)), #000 calc(100% - var(--ring, 5px) + 1px));
  animation: brand-spin 1.1s linear infinite;
}
.loader.sm { --size: 20px; --ring: 2.5px; margin-right: 8px; }
@keyframes brand-spin { to { transform: rotate(360deg); } }
@keyframes brand-pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .loader::after { animation: brand-pulse 1.6s ease-in-out infinite; } }
.splash { min-height: 60vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; color: var(--muted); font-weight: 600; }
.brand-mark { width: 44px; height: 44px; flex: none; }
.brand-hero { display: block; width: 140px; height: 140px; margin: 8px auto 4px; }
.ai.pending { display: inline-flex; align-items: center; }

/* customer order page (/order) */
body.portal #view { padding-bottom: calc(env(safe-area-inset-bottom) + 110px); }
.portal-head { position: relative; text-align: center; }
.portal-head h1 { margin-top: 4px; }
.portal-head .lang { position: absolute; top: 0; right: 0; }
.chip:disabled { opacity: .45; cursor: not-allowed; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.pay { text-align: center; margin-top: 16px; }
.thanks { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.thanks .card { width: 100%; }
.webswitch { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* order placed: brand moment */
.placing {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px;
  padding: 24px; text-align: center; animation: placing-in .25s ease-out;
}
.placing .loader { --size: 168px; --ring: 6px; }
.tagline {
  margin: 0; font-size: 22px; font-weight: 700; font-style: italic; letter-spacing: .01em;
  color: var(--accent); animation: placing-in .5s .2s ease-out both;
}
@keyframes placing-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .placing, .tagline { animation: none; } }
