/* Purchasing app — mobile-first, built for phones in kitchens and markets.
   Thai-friendly font stack; every tap target >= 44px. */

:root {
  --ink: #22251f;
  --ink-soft: #6b6f63;
  --paper: #f4f3ee;
  --card: #ffffff;
  --line: #ddddd2;
  --accent: #1d6a4f;        /* market-stall green */
  --accent-ink: #ffffff;
  --warn: #a63d2f;
  --chip: #eceada;
  --done: #9aa392;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Noto Sans Thai', 'Sarabun', 'Leelawadee UI', 'Segoe UI',
               -apple-system, 'Helvetica Neue', sans-serif;
  font-size: 17px;
  line-height: 1.55;
}

/* ---------- Header ---------- */
.topbar { background: var(--ink); color: #f4f3ee; }
.topbar-inner {
  max-width: 960px; margin: 0 auto; padding: 10px 14px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
}
.brand { font-weight: 700; margin-right: auto; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px; }
.topbar a {
  color: #f4f3ee; text-decoration: none; padding: 8px 10px;
  border-radius: 6px; font-size: 15px;
}
.topbar a:hover { background: rgba(255,255,255,.12); }
.lang-switch { border: 1px solid rgba(255,255,255,.4); }

/* ---------- Layout ---------- */
.wrap { max-width: 960px; margin: 0 auto; padding: 14px 12px 96px; }
h1 { font-size: 22px; margin: 10px 2px 14px; }
h2 { font-size: 17px; margin: 0 0 10px; }
small, .hint { color: var(--ink-soft); font-size: 14px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 14px;
}
.card.narrow { max-width: 420px; margin: 48px auto; }

/* ---------- Forms ---------- */
label { display: block; margin-bottom: 10px; font-size: 15px; color: var(--ink-soft); }
input[type=text], input[type=password], input[type=number],
input[type=date], input[type=search], select {
  display: block; width: 100%; margin-top: 4px;
  padding: 11px 12px; font-size: 17px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  color: var(--ink);
}
input:focus, select:focus, button:focus-visible {
  outline: 3px solid rgba(29,106,79,.35); outline-offset: 1px;
}
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.inline-form label { margin: 0; flex: 1 1 180px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.grid-form label { margin: 0; }
.copyrow { display: flex; gap: 8px; }
/* 16px minimum on every input — below that iOS Safari zooms the page on focus */
.copyrow input { flex: 1; font-size: 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block; border: 1px solid var(--line); background: #fff;
  color: var(--ink); font-family: inherit; font-size: 16px;
  padding: 11px 16px; border-radius: 8px; cursor: pointer;
  text-decoration: none; min-height: 44px;
  white-space: nowrap; overflow-wrap: normal;
}
.btn:hover { border-color: var(--ink-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.big { width: 100%; padding: 14px; font-size: 18px; }
.btn.small { padding: 7px 12px; font-size: 14px; min-height: 36px; }
.btn.danger { color: var(--warn); border-color: var(--warn); }

/* ---------- Messages / badges ---------- */
.msg { padding: 10px 12px; border-radius: 8px; font-size: 15px; }
.msg.ok { background: #e4efe6; color: #1d5232; }
.msg.error { background: #f6e4e1; color: var(--warn); }
.badge { padding: 3px 10px; border-radius: 999px; font-size: 13px; white-space: nowrap; }
.badge.draft { background: var(--chip); }
.badge.submitted { background: #dcebe4; color: #1d5232; }
.badge.purchased { background: #e2e2da; color: var(--ink-soft); }
.badge.cancelled { background: #f6e4e1; color: var(--warn); }
.badge.received { background: var(--accent); color: var(--accent-ink); }

/* Order composition chips on the dashboard */
.order-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.order-chips .badge, .order-chips .split-chip { font-size: 12px; }
.badge.cat-food { background: #e4efe6; color: #1d5232; }
.badge.cat-consumable { background: #e2e2da; color: #52524a; }
.badge.cat-bar { background: #e9e2f2; color: #4b3a78; }
.warn-text { color: var(--warn); }
.ok-text { color: #1d5232; }
small.warn-text, small.ok-text { white-space: nowrap; }

/* Partial receiving: amount input next to the tick.
   input[type=number].x — the extra specificity is required to beat the
   global input[type=number] { display:block; width:100% } rule above. */
.recv-form { display: flex; gap: 4px; align-items: center; }
input[type=number].recv-qty {
  display: inline-block; width: 72px; margin-top: 0;
  font-size: 15px; padding: 6px 6px; text-align: right;
}
.tick-form { display: flex; gap: 6px; align-items: center; flex: none; }
/* .tick.tick-labeled: compound selector so this beats the plain .tick
   rule further down (46px square for the driver list) regardless of order */
.tick.tick-labeled {
  width: auto; height: 46px; padding: 0 14px;
  font-size: 15px; font-weight: 600; white-space: nowrap;
}

/* Chef receiving tick-off */
.btn.recv { min-width: 38px; min-height: 38px; }
.btn.recv.done { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
tr.line-received td { opacity: .55; }
tr.line-received td:nth-child(2) { text-decoration: line-through; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
/* Long Thai product names have no spaces — let them wrap instead of
   pushing the table off the card */
td { overflow-wrap: anywhere; }
.card { overflow-x: auto; }
th { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
th a.sort { color: inherit; text-decoration: none; }
th a.sort:hover { color: var(--ink); text-decoration: underline; }
.online-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: #3da35d; box-shadow: 0 0 0 3px rgba(61,163,93,.2);
  vertical-align: middle; margin-right: 2px;
}

/* ---------- Item photos (drag & drop upload + driver thumbnails) ---------- */
.photo-drop {
  width: 54px; height: 54px; border: 1.5px dashed var(--line); border-radius: 10px;
  display: grid; place-items: center; cursor: pointer; overflow: hidden;
  color: var(--ink-soft); font-size: 20px; background: #fff;
}
.photo-drop img { width: 100%; height: 100%; object-fit: cover; }
.photo-drop.drag { border-color: var(--ink); border-style: solid; background: #fdfcf7; }
.photo-drop.busy { opacity: .4; pointer-events: none; }
.photo-remove { display: inline; }
.linklike {
  border: 0; background: none; color: var(--ink-soft); cursor: pointer;
  font-size: 12px; padding: 2px 4px;
}
.linklike:hover { color: #b3372f; }
.pick-photo { flex: none; margin-right: 10px; }
.pick-photo img {
  width: 46px; height: 46px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--line); display: block;
}

/* Purchasing qty correction inputs (specificity: see .recv-qty note) */
input[type=number].qty-edit { width: 96px; text-align: right; display: inline-block; margin-top: 0; }
.note-edit { min-width: 140px; }

/* LINE share button */
.btn.line { border-color: #06c755; color: #06c755; }
.btn.line:hover { background: #06c755; color: #fff; }
tr.inactive td { opacity: .45; }
/* Row the user just acted on (anchor target after deactivate/category toggle) */
tr:target td { background: #f6edcf; }
td.actions form { display: inline; }
/* Action buttons inside table cells wrap cleanly with breathing room */
td .btn { margin: 2px 6px 2px 0; }
td form { display: inline-block; }

/* ---------- Tabs (restaurant switcher) ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tab {
  padding: 9px 14px; border-radius: 999px; text-decoration: none;
  color: var(--ink); background: var(--chip); font-size: 15px;
}
.tab.active { background: var(--ink); color: #f4f3ee; }
button.tab { border: 0; cursor: pointer; font-family: inherit; }
.cat-tabs { margin-bottom: 8px; }
.cat-tabs .tab { font-weight: 600; }
.store-tabs { margin-bottom: 10px; }
.store-tabs .tab { font-size: 13px; padding: 10px 12px; }

/* ---------- Chef order form ---------- */
.filter { margin-bottom: 10px; }
.item-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item-row {
  display: grid; grid-template-columns: 1fr 150px; gap: 4px 10px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); align-items: center;
}
.item-row:last-child { border-bottom: none; }
/* Rows already in the order float to the top, tinted so they read as a group */
.item-row.has-qty {
  background: #eef5ef;
  box-shadow: inset 3px 0 0 var(--accent);
}
.item-row.has-qty input[type=number] { border-color: var(--accent); font-weight: 600; }
.item-name { display: flex; flex-direction: column; }
.item-qty { display: flex; align-items: center; gap: 6px; }
.item-qty input { width: 90px; text-align: right; }
.unit { color: var(--ink-soft); font-size: 14px; min-width: 34px; }
.line-note { grid-column: 1 / -1; font-size: 16px !important; padding: 7px 10px !important; }

.sticky-actions {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: rgba(244,243,238,.96); border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; max-width: none;
}
.sticky-actions .btn { flex: 1; }
.sticky-actions .btn.primary { flex: 2; }

/* ---------- Pickup list ---------- */
.progress { font-size: 15px; color: var(--ink-soft); margin: 0 2px 10px; }
.source-group h2 {
  margin: -14px -14px 10px; padding: 12px 14px;
  background: var(--ink); color: #f4f3ee; border-radius: var(--radius) var(--radius) 0 0;
  font-size: 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.check-all-form { flex: none; }
.check-all {
  background: transparent; color: inherit; font-family: inherit;
  border: 1.5px solid rgba(255,255,255,.55); border-radius: 999px;
  padding: 7px 14px; font-size: 13px; cursor: pointer; min-height: 36px;
  white-space: nowrap;
}
.check-all:hover { background: rgba(255,255,255,.15); }
.source-group.type-wet_market h2 { background: var(--accent); }
.source-group.type-supplier h2 { background: #4a5568; }

.pick-item {
  display: flex; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.pick-item:last-child { border-bottom: none; }
.pick-item.done .pick-name,
.pick-item.done .pick-total { text-decoration: line-through; color: var(--done); }

.tick {
  width: 46px; height: 46px; flex: none;
  border: 2px solid var(--line); border-radius: 10px; background: #fff;
  font-size: 22px; color: var(--accent); cursor: pointer;
}
.pick-item.done .tick { background: var(--accent); border-color: var(--accent); color: #fff; }

.pick-body { flex: 1; min-width: 0; }
.pick-main { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }
.pick-name { font-weight: 600; }
.pick-total { white-space: nowrap; }
.pick-split { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.split-chip {
  background: var(--chip); border-radius: 999px; padding: 3px 10px;
  font-size: 13px; color: var(--ink-soft);
}
.split-chip.done { text-decoration: line-through; opacity: .6; }

/* ---------- Wider screens ---------- */
@media (min-width: 700px) {
  .item-row { grid-template-columns: 1fr 170px 220px; }
  .line-note { grid-column: auto; }
  .sticky-actions { position: static; background: none; border: none; padding: 14px 0; }
}

/* ---------- Small phones ---------- */
@media (max-width: 460px) {
  h1 { font-size: 20px; }
  th, td { padding: 9px 6px; }
  .topbar a { padding: 8px 8px; font-size: 14px; }
  .card { padding: 12px; }
  /* receiving rows: keep amount + button compact so the item text fits */
  input[type=number].recv-qty { width: 58px; padding: 6px 4px; }
  .tick.tick-labeled { padding: 0 10px; font-size: 14px; }
  .pick-item { gap: 8px; }
}
