/* ---------- Colours and basics ---------- */
:root {
  --bg: #EDEFEA;
  --card: #FFFFFF;
  --line: #CFD5CB;
  --text: #1C221D;
  --muted: #5E685F;
  --accent: #7A1F3D;
  --good: #2F6B4F;
  --warn: #9A5B00;
  --bad: #A3261E;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* leave room for the bars at the bottom */
  padding-bottom: calc(140px + env(safe-area-inset-bottom));
}

main { max-width: 700px; margin: 0 auto; padding: 0 16px; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.top-inner { max-width: 700px; margin: 0 auto; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.top h1 { margin: 0; font-size: 26px; }
.area-label { color: var(--accent); font-weight: 700; }

h2 { font-size: 19px; margin: 18px 0 8px; }
.card h2 { margin-top: 0; }

/* ---------- Cards, inputs, buttons ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label { font-size: 13px; color: var(--muted); }
.card > label:first-child { font-size: 16px; font-weight: 600; color: var(--text); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #FBFCF9;
  font-size: 16px; /* 16px stops iPhone zooming in */
}
#search { margin: 4px 0 8px; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  background: var(--accent);
  color: #FFFFFF;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.btn.ghost { background: #E3E7E0; color: var(--text); }
.btn.small { padding: 9px 12px; font-size: 14px; }
.btn.danger { background: var(--bad); color: #FFFFFF; }
.file-btn { font-size: 16px; color: var(--text); }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.hint { font-size: 13px; color: var(--muted); margin: 0; }
.hit { color: var(--good); margin: 0; }
.miss { color: var(--warn); margin: 0; }

/* ---------- Chips (areas and categories) ---------- */
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 0 2px;
  -webkit-overflow-scrolling: touch;
}
.chip {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
#area-chips .chip { padding: 10px 16px; }

/* ---------- Voice box ---------- */
.voice-row { display: flex; gap: 8px; align-items: stretch; }
.mic {
  flex: none;
  width: 64px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 28px;
}
.mic.listening { background: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.check input { width: auto; }

/* ---------- Count list ---------- */
.category {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 18px 0 6px;
  display: flex;
  justify-content: space-between;
}

.item { flex-direction: column; margin: 8px 0; }
.item-top { display: flex; align-items: center; gap: 10px; }
.item-name { font-weight: 600; flex: 1; }
.all-areas { font-size: 12px; color: var(--muted); text-align: right; }
.item-total { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.low {
  color: var(--bad);
  border: 1px solid currentColor;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 4px;
  margin-left: 6px;
}
.controls { display: flex; gap: 14px; flex-wrap: wrap; }

.stepper {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 3px;
}
.stepper button {
  width: 48px;
  height: 46px;
  border: 0;
  background: #EDEFEA;
  font-size: 24px;
  font-weight: 600;
}
.stepper input {
  width: 60px;
  border: 0;
  border-radius: 0;
  text-align: center;
  font-size: 19px;
  font-weight: 600;
  background: #FFFFFF;
}

/* ---------- Log ---------- */
.take-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
}
.take-date { font-weight: 600; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
th { font-size: 11px; text-transform: uppercase; color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.up { color: var(--good); }
.down { color: var(--bad); }

/* ---------- Stock list ---------- */
.list-item { flex-direction: row; align-items: center; }
.list-item .info { flex: 1; }

/* ---------- Bottom bars ---------- */
.footer, .tabs {
  position: fixed;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.footer { bottom: calc(56px + env(safe-area-inset-bottom)); padding: 8px 16px; }
.footer span { flex: 1; color: var(--muted); font-size: 14px; }
.tabs { bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
.tabs button {
  flex: 1;
  height: 56px;
  border: 0;
  background: none;
  font-weight: 600;
  color: var(--muted);
}
.tabs button[aria-current="page"] { color: var(--accent); }

#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(130px + env(safe-area-inset-bottom));
  background: var(--text);
  color: #FFFFFF;
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 20;
}

[hidden] { display: none !important; }

.order-line { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }

@media (prefers-reduced-motion: reduce) { .mic.listening { animation: none; } }
