:root {
  --bg: #fbf4ea;
  --surface: #fffdf9;
  --ink: #3b2a1f;
  --muted: #9a8471;
  --line: #f0e2d2;
  --brown: #c4552f;        /* terracotta brand */
  --brown-dark: #a84322;
  --brown-soft: #fbe7dc;
  --green: #3f7d4e;
  --green-bg: #e7f2e8;
  --red: #c04538;
  --red-bg: #fbe9e4;
  --amber: #b26a16;
  --amber-bg: #fdf1dc;
  --gray-bg: #f1e9df;
  --radius: 16px;
  --radius-sm: 12px;
  --tabbar-h: 58px;
  --topbar-h: 56px;
  --shadow: 0 2px 12px rgba(120, 66, 32, .08);
  --shadow-lg: 0 12px 30px rgba(120, 66, 32, .18);
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  background: linear-gradient(120deg, #c4552f, #d9742c);
  color: #fff;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  box-shadow: 0 2px 10px rgba(120, 66, 32, .25);
}
.topbar h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .2px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.logo { font-size: 20px; }
.topbar-sub {
  font-size: 13px;
  opacity: .9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Hero (Home) ---------- */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  padding: 20px 18px;
  margin-bottom: 6px;
  color: #fff;
  background:
    radial-gradient(120% 140% at 90% -10%, rgba(255, 220, 160, .4), transparent 60%),
    linear-gradient(130deg, #c4552f, #d9742c 55%, #d99a3a);
  box-shadow: var(--shadow-lg);
}
.hero-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.hero-text { min-width: 0; }
.hero-eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  opacity: .9;
  margin: 0 0 4px;
}
.hero-title {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.2;
  margin: 0 0 8px;
}
.hero-sub { font-size: 13px; opacity: .92; margin: 0; }
.hero .hero-btn {
  flex: 0 0 auto;
  background: #fff;
  color: var(--brown-dark);
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: 0 3px 10px rgba(120, 66, 32, .25);
  min-height: 40px;
}

/* ---------- View / main ---------- */
.view {
  max-width: 540px;
  margin: 0 auto;
  padding: 14px 14px calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom));
  outline: none;
}
.view:focus { outline: none; }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(120, 66, 32, .06);
  z-index: 30;
  max-width: 540px;
  margin: 0 auto;
}
.tabbar[hidden] { display: none; }
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.tab-badge {
  position: absolute;
  top: 2px;
  right: 10px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: #d64541;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}
.tab-ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--brown); }
.tab.active::before {
  content: "";
  position: absolute;
  top: 0;
  width: 34px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--brown);
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
/* A delivery day whose order window has passed (after the 6pm cut-off) but
   that hasn't ended yet — kept visible, greyed out until the day is over. */
.card.closed { opacity: .55; filter: saturate(.8); }
.card.tappable {
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.card.tappable:active { transform: scale(.985); box-shadow: none; background: #f9efe6; }

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-title { font-size: 16px; font-weight: 700; margin: 0 0 2px; font-family: var(--serif); }
.card-sub { font-size: 13px; color: var(--muted); margin: 0; }

h2.section {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--ink);
  margin: 20px 2px 10px;
}
h2.section:first-child { margin-top: 0; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: .85;
}
.badge-open   { background: var(--green-bg); color: var(--green); }
.badge-closed { background: var(--red-bg);   color: var(--red); }
.badge-past   { background: var(--gray-bg);  color: var(--muted); }
.badge-full   { background: var(--amber-bg); color: var(--amber); }
.badge-over   { background: var(--red-bg);   color: var(--red); }

/* ---------- Fill meter ---------- */
.meter {
  position: relative;
  height: 20px;
  background: var(--gray-bg);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 2px;
}
.meter-fill {
  height: 100%;
  background: linear-gradient(90deg, #d9812f, var(--brown));
  border-radius: 999px;
  transition: width .3s ease;
}
.meter-fill.over { background: linear-gradient(90deg, #d0564b, var(--red)); }
.meter-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  text-shadow: 0 0 4px rgba(255,255,255,.7);
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: none;
  border-radius: 13px;
  font-size: 15px;
  font-weight: 700;
  padding: 12px 18px;
  cursor: pointer;
  background: linear-gradient(180deg, #d0632f, #b34a28);
  color: #fff;
  min-height: 46px;
  box-shadow: 0 3px 10px rgba(140, 70, 40, .28);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px) scale(.99); box-shadow: 0 1px 4px rgba(140,70,40,.25); }
.btn.primary { background: linear-gradient(180deg, #d0632f, #b34a28); color: #fff; }
.btn.ghost { background: var(--surface); color: var(--brown-dark); border: 1px solid var(--line); box-shadow: none; }
.btn.danger { background: linear-gradient(180deg, #d0564b, #b3352b); color: #fff; box-shadow: 0 3px 10px rgba(190, 60, 50, .28); }
.btn.soft { background: var(--brown-soft); color: var(--brown-dark); box-shadow: none; }
.btn.block { display: block; width: 100%; }
.btn.small { font-size: 13px; padding: 8px 13px; min-height: 36px; border-radius: 11px; }
.btn[disabled] { opacity: .5; }

.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row .btn { flex: 1; }

/* ---------- Forms ---------- */
.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 5px;
}
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.input, select.input, textarea.input {
  width: 100%;
  font-size: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  min-height: 46px;
}
.input:focus { outline: 2px solid var(--brown); outline-offset: -1px; border-color: transparent; }
textarea.input { min-height: 64px; resize: vertical; }

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}
.stepper button {
  width: 44px;
  height: 44px;
  font-size: 20px;
  font-weight: 700;
  border: none;
  background: var(--brown-soft);
  color: var(--brown-dark);
  cursor: pointer;
}
.stepper .stepper-val {
  min-width: 52px;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .span2 { grid-column: 1 / -1; }
.edit-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
}
.add-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}
.add-item select { flex: 1; min-width: 0; }

/* ---------- Lists / rows ---------- */
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }
.list-item .li-main { min-width: 0; }
.list-item .li-title { font-weight: 600; font-size: 15px; }
.list-item .li-sub { font-size: 13px; color: var(--muted); }
.list-item .li-right { display: flex; align-items: center; gap: 8px; }

.qty-chip {
  font-weight: 700;
  font-size: 15px;
  background: var(--brown-soft);
  color: var(--brown-dark);
  padding: 3px 11px;
  border-radius: 999px;
  white-space: nowrap;
}

.warn {
  background: var(--amber-bg);
  color: var(--amber);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  margin: 8px 0;
}
.danger-banner {
  background: var(--red-bg);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  margin: 8px 0;
}
.muted { color: var(--muted); }

.avail-line {
  margin: -2px 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.avail-line.warn { color: var(--red); }

/* ---------- Tabs strip (dates) ---------- */
.date-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 10px;
  -webkit-overflow-scrolling: touch;
}
.date-tab {
  flex: 0 0 auto;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.date-tab.active { background: var(--brown); color: #fff; border-color: var(--brown); }
.date-tab .dot { color: var(--green); }
.date-tab .dot.closed { color: var(--red); }

/* ---------- PO table ---------- */
.po-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.po-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
}
.po-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.po-table td.num, .po-table th.num { text-align: right; }
.po-total { font-size: 17px; font-weight: 700; text-align: right; padding-top: 10px; }
.po-breakdown { font-size: 12px; color: var(--muted); margin-top: 3px; }
.po-snapshot-note { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-icon {
  font-size: 40px;
  width: 84px;
  height: 84px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brown-soft);
  border-radius: 50%;
}
.empty h3 { margin: 0 0 4px; font-family: var(--serif); color: var(--ink); }
.empty p { margin: 0; }

/* ---------- Confirm dialog ---------- */
.confirm-layer {
  position: fixed;
  inset: 0;
  background: rgba(43, 33, 24, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}
.confirm-layer[hidden] { display: none; }
.confirm-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  max-width: 340px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.confirm-text { margin: 0 0 14px; font-size: 15px; line-height: 1.4; }
.confirm-actions { display: flex; gap: 8px; justify-content: flex-end; }
.confirm-actions .btn { flex: 0 1 auto; }

/* ---------- App-password lock ---------- */
.lock-layer {
  position: fixed;
  inset: 0;
  z-index: 80; /* above toast(70), confirm(60), tabbar(30), topbar(20) */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #c4552f, #d9742c 55%, #d99a3a);
}
.lock-layer[hidden] { display: none; }
.lock-card {
  width: 100%;
  max-width: 320px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 26px 22px 24px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.lock-emoji { font-size: 40px; margin: 0 0 6px; }
.lock-title { font-family: var(--serif); font-size: 19px; font-weight: 700; margin: 0 0 4px; color: var(--ink); }
.lock-sub { font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.lock-input { text-align: center; font-size: 22px; letter-spacing: 10px; }
.lock-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 8px 0 0; }
.lock-actions { margin-top: 14px; }
.lock-actions .btn { width: 100%; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px);
  transform: translate(-50%, 10px);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 70;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- More menu ---------- */
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 4px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}
.menu-item:last-child { border-bottom: none; }
.menu-item .chev { color: var(--muted); }

/* ---------- Chips (ingredient rows) ---------- */
.ing-row {
  display: grid;
  grid-template-columns: 1fr 88px 58px 40px;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}
.ing-row .unit { font-size: 13px; color: var(--muted); }

@media (min-width: 541px) {
  .view { padding-top: 20px; }
  .tabbar { border-radius: var(--radius) var(--radius) 0 0; }
}

/* ---------- Order status / source ---------- */
.src-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--brown-dark, #7a4a2a);
  background: var(--brown-soft, #f4e6da);
  padding: 1px 7px;
  border-radius: 999px;
  vertical-align: 2px;
}
.fulfill-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--green-dark, #2f6b2f);
  background: var(--green-soft, #eaf6ea);
  padding: 1px 7px;
  border-radius: 999px;
  vertical-align: 2px;
}
.fulfill-tag.courier { color: #7a4a2a; background: #f4e6da; }
.fulfill-sub {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}
.row-actions select.input { width: 100%; }

.sel-small {
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}

/* ---------- New-orders inbox ---------- */
.inbox {
  border: 2px solid #d64541;
}
.inbox h3 { color: #d64541; }
.inbox-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.inbox-item:last-child { border-bottom: none; }
.inbox-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.inbox-main:active { background: var(--red-bg); border-radius: 8px; }
.inbox-item .li-title { color: var(--ink); }
.inbox-arrow { color: var(--muted); font-size: 18px; font-weight: 700; }
.inbox-del {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  padding: 10px 10px 10px 6px;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.inbox-del:active { background: var(--red-bg); color: #d64541; }
