:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #15181c;
  --muted: #5f6873;
  --border: #dde1e6;
  --accent: #1a7f4b;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --chip: #eef1f4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --card: #1b1f24;
    --text: #eef0f2;
    --muted: #9aa3ad;
    --border: #2d333a;
    --accent: #2ea86a;
    --accent-text: #06140c;
    --danger: #f2877f;
    --chip: #262b31;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Login */
.login { max-width: 420px; margin: 0 auto; padding: 18vh 16px 0; }
.login h1 { font-size: 28px; margin: 0 0 24px; }
.login label { display: block; font-weight: 600; margin-bottom: 8px; }
.login input { margin-bottom: 16px; }
.error { color: var(--danger); margin: 0 0 16px; }

/* Inputs: 17px+ font keeps iOS Safari from zooming on focus */
input[type=search], input[type=password] {
  width: 100%;
  font-size: 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  display: block; width: 100%;
  min-height: 52px;
  font-size: 18px; font-weight: 600;
  border: 0; border-radius: 12px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn:disabled { opacity: .6; }

/* Main screen: the header stays put and only the results list scrolls, so the
   header can never end up covering orders (iOS shifts sticky headers when the
   keyboard opens). */
body.app {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  padding-bottom: 0;
}

/* Search header */
.bar {
  flex: none;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 8px;
  border-bottom: 1px solid var(--border);
}
.search-wrap { position: relative; }
.search-wrap input { padding-right: 48px; }
input[type=search]::-webkit-search-cancel-button { display: none; }
.clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px;
  border: 0; background: none; color: var(--muted);
  font-size: 28px; line-height: 1; cursor: pointer;
}
.segmented {
  display: flex; gap: 4px; margin-top: 10px; padding: 3px;
  background: var(--chip); border-radius: 11px;
}
.segmented button {
  flex: 1; min-height: 38px;
  border: 0; border-radius: 9px; background: none;
  color: var(--muted); font: inherit; font-size: 16px; font-weight: 600; cursor: pointer;
}
.segmented button[aria-selected="true"] {
  background: var(--card); color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.view-done .bar { border-bottom-color: var(--accent); }
.status-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px; color: var(--muted);
  padding-top: 8px;
}
.link {
  background: none; border: 0; padding: 8px 0;
  color: var(--accent); font: inherit; text-decoration: none; cursor: pointer;
}

/* Results */
#results {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 12px max(16px, calc((100% - 688px) / 2)) calc(env(safe-area-inset-bottom) + 40px);
}
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 10px;
  overflow: hidden;
}
.card-head {
  display: block; width: 100%; text-align: left;
  padding: 14px 16px;
  background: none; border: 0; color: inherit; font: inherit;
  cursor: pointer;
}
.card-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.name { font-weight: 700; font-size: 19px; overflow-wrap: anywhere; }
.ref { font-size: 13px; color: var(--muted); white-space: nowrap; }
.meta { color: var(--muted); font-size: 15px; overflow-wrap: anywhere; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip { background: var(--chip); border-radius: 999px; padding: 2px 10px; font-size: 13px; }
mark { background: #ffe58a; color: #15181c; border-radius: 3px; }

.detail { border-top: 1px solid var(--border); padding: 12px 16px 16px; }
.items { list-style: none; margin: 0 0 12px; padding: 0; }
.items li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.items li:last-child { border-bottom: 0; }
.qty { font-weight: 700; margin-right: 6px; }
.item-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.items li.done .item-row { opacity: .5; }
.picked { color: var(--accent); font-size: 14px; font-weight: 600; }
.chip.partial { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.step {
  width: 40px; height: 40px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--chip); color: var(--text);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.step:disabled { opacity: .35; }
.step-count { min-width: 1.5em; text-align: center; font-weight: 700; font-size: 18px; }
.sub { color: var(--muted); font-size: 14px; }
.note { background: var(--chip); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.total { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 14px; }
.contact a { color: var(--accent); }
.contact.spaced { margin-bottom: 14px; }

#toast {
  position: fixed; left: 16px; right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  max-width: 480px; margin: 0 auto;
  padding: 14px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg);
  font-weight: 600; text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
#toast.err { background: var(--danger); color: #fff; }
