:root {
  --bg: #f6f7f9;
  --card: #fff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4b5320;
  --accent-ink: #fff;
  --accent-soft: #eef0e2;
  --danger: #b91c1c;
  --ok: #15803d;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --card: #151b26;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #263041;
    --accent: #6b7a3a;
    --accent-soft: #22271a;
    --danger: #f87171;
    --ok: #4ade80;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(100px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 640px; margin: 0 auto; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

.top {
  display: flex; align-items: center; gap: 8px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 6px;
}
.top h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.back {
  border: 0; background: none; color: var(--accent);
  font-size: 17px; padding: 8px 8px 8px 0; font-weight: 600;
}

/* Browse */
.controls {
  position: sticky; top: 0; z-index: 4;
  background: var(--bg);
  padding: 8px 16px 10px;
}
#search {
  width: 100%; height: 48px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); font-size: 16px;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Category tiles */
.tiles {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  padding: 6px 16px 16px;
}
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 14px;
  min-height: 136px; padding: 16px; text-align: left;
  border: 1px solid var(--line); border-radius: 18px; background: var(--card);
  box-shadow: 0 1px 2px rgba(17, 24, 39, .04), 0 4px 12px rgba(17, 24, 39, .04);
  transition: transform .12s ease, box-shadow .12s ease;
}
.tile:active { transform: scale(.97); }
@media (hover: hover) { .tile:hover { box-shadow: 0 2px 4px rgba(17, 24, 39, .06), 0 8px 20px rgba(17, 24, 39, .08); } }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile.wide { grid-column: 1 / -1; flex-direction: row; align-items: center; min-height: 0; }
.ico {
  flex: none; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px;
  background: hsl(var(--hue) 85% 94%); color: hsl(var(--hue) 70% 34%);
}
.ico svg { width: 26px; height: 26px; }
.ttext { display: flex; flex-direction: column; margin-top: auto; }
.tile.wide .ttext { margin-top: 0; }
.tname { font-size: 17px; font-weight: 700; line-height: 1.2; }
.tcount { color: var(--muted); font-size: 14px; margin-top: 2px; }
.tbadge {
  position: absolute; top: 12px; right: 12px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 12px; font-weight: 700; border-radius: 10px; padding: 2px 8px;
}
@media (prefers-color-scheme: dark) {
  .ico { background: hsl(var(--hue) 40% 20%); color: hsl(var(--hue) 85% 72%); }
  .tile { box-shadow: none; }
}

.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-top: 1px solid var(--line); }
.item {
  display: flex; align-items: center; gap: 12px;
  min-height: 68px; padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--line);
  box-shadow: inset 4px 0 0 transparent;
}
.item.in { background: var(--accent-soft); box-shadow: inset 4px 0 0 var(--accent); }
.info { flex: 1; min-width: 0; cursor: pointer; }
.desc { font-weight: 600; font-size: 16px; }
.meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.num { font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

.add {
  flex: none; height: 44px; min-width: 76px; padding: 0 16px; border-radius: 22px;
  border: 1.5px solid var(--accent); background: var(--card); color: var(--accent); font-weight: 600;
}
.stepper { flex: none; display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 44px; height: 44px; border-radius: 22px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 22px; font-weight: 600; line-height: 1;
}
.stepper input {
  width: 52px; height: 44px; text-align: center; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); font-size: 18px; font-weight: 700;
}
.remove {
  flex: none; border: 0; background: none; color: var(--muted); font-size: 14px; padding: 8px 4px;
}

/* Review form */
.form { padding: 4px 16px 16px; }
.form h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 24px 0 10px; }
.opt { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 13px; color: var(--muted); }
.form label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 0; }
.form input, .form textarea {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
  font: inherit; font-size: 16px; min-height: 48px;
}
.form input:focus, .form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form input.bad { border-color: var(--danger); }
#neededDate { margin-top: 10px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg button {
  height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600;
}
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.error { color: var(--danger); font-weight: 600; margin: 16px 0 0; }
.error a { color: inherit; }

/* Bottom bar */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.primary {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; max-width: 608px; margin: 0 auto; height: 56px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); font-size: 17px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(75, 83, 32, .28);
}
.primary:disabled { opacity: .6; }
.badge { background: rgba(255,255,255,.22); border-radius: 12px; padding: 2px 10px; font-size: 15px; }

/* Done */
.done { text-align: center; padding: 48px 24px; }
.check {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 50%;
  background: var(--ok); color: #fff; font-size: 40px; line-height: 72px; font-weight: 700;
}
.done h2 { margin: 0 0 8px; font-size: 24px; }
.done p { color: var(--muted); margin: 0 0 8px; }
.done .note { background: var(--accent-soft); color: var(--text); border-radius: 12px; padding: 12px; font-size: 14px; }
.done .primary { margin-top: 28px; box-shadow: none; }

/* My requests */
.link {
  border: 0; background: none; color: var(--accent);
  font-size: 16px; font-weight: 600; padding: 8px 0;
}
.top .link { margin-left: auto; }
.done .link { margin-top: 12px; }
.req { cursor: pointer; }
.chev { flex: none; color: var(--muted); font-size: 24px; line-height: 1; }
.tag { background: var(--accent-soft); color: var(--text); border-radius: 6px; padding: 1px 6px; font-size: 12px; font-weight: 600; }
.detail {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 16px;
  margin: 0; padding: 8px 16px 20px; font-size: 15px;
}
.detail dt { color: var(--muted); }
.detail dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.detail .note {
  grid-column: 1 / -1; margin: 8px 0 0; padding: 10px 12px; border-radius: 12px;
  background: var(--accent-soft); font-size: 14px;
}
.qty { flex: none; min-width: 52px; text-align: right; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.detail-actions { padding: 20px 16px; }
.primary:disabled { box-shadow: none; }

/* Item photos */
.thumb {
  flex: none; display: grid; place-items: center; width: 52px; height: 52px; padding: 0;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.ph { border: 0; background: hsl(var(--hue, 220) 30% 95%); color: hsl(var(--hue, 220) 35% 55%); }
.thumb.ph svg { width: 24px; height: 24px; }
.details {
  color: var(--muted); font-size: 14px; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lightbox {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; background: rgba(0, 0, 0, .85); color: #fff; text-align: center;
}
.lightbox img { max-width: 100%; max-height: 75vh; border-radius: 12px; background: #fff; }
.lightbox p { margin: 0; font-weight: 600; }

/* Admin */
input[type="file"] { display: none !important; }
.admin .top .link { text-decoration: none; }
.lead { color: var(--muted); margin: 8px 0 0; }
#loginForm .primary, #editForm .primary { margin-top: 24px; }
.admin-bar { padding: 0 16px 12px; display: grid; gap: 10px; }
.admin-bar .primary { max-width: none; }
.admin-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.secondary {
  display: flex; align-items: center; justify-content: center; height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.danger {
  display: block; width: 100%; height: 52px; margin-top: 12px; border-radius: var(--radius);
  border: 1.5px solid var(--danger); background: none; color: var(--danger); font-size: 16px; font-weight: 700;
}
.status { margin: 0; padding: 10px 12px; border-radius: 12px; font-size: 14px; font-weight: 600; }
.status.ok { background: var(--accent-soft); color: var(--text); }
.status.info { background: var(--card); color: var(--muted); }
.status.bad { background: none; color: var(--danger); padding: 0; }
.count { color: var(--muted); font-size: 14px; margin: 0; padding: 0 16px 8px; }
.photo-edit { display: flex; align-items: center; gap: 16px; margin-top: 8px; }
.photo-preview {
  flex: none; display: grid; place-items: center; width: 112px; height: 112px; border-radius: 14px; overflow: hidden;
  border: 1px dashed var(--line); background: var(--card); color: var(--muted); font-size: 13px;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-actions { display: grid; gap: 6px; justify-items: start; }
.form .photo-actions label { margin: 0; font-size: 15px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two label { min-width: 0; }
.form textarea { resize: vertical; }
@media (prefers-color-scheme: dark) {
  .thumb.ph { background: hsl(var(--hue, 220) 25% 16%); color: hsl(var(--hue, 220) 45% 65%); }
}
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

/* Item grid */
.grid {
  list-style: none; margin: 0; padding: 4px 16px 16px;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 1px 2px rgba(17, 24, 39, .04), 0 4px 12px rgba(17, 24, 39, .04);
}
.card.in { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card-photo {
  display: grid; place-items: center; width: 100%; aspect-ratio: 1; padding: 0;
  border: 0; border-bottom: 1px solid var(--line); background: #fff;
}
.card-photo img { width: 100%; height: 100%; object-fit: contain; padding: 10px; display: block; }
.card-photo.ph { background: hsl(var(--hue, 220) 30% 95%); color: hsl(var(--hue, 220) 35% 55%); }
.card-photo.ph svg { width: 38%; height: 38%; }
.card-name {
  border: 0; background: none; color: var(--text); text-align: left;
  padding: 10px 12px 0; font-size: 15px; font-weight: 700; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { padding: 3px 12px 0; color: var(--muted); font-size: 13px; }
.card-qty { margin-top: auto; padding: 10px; }
.card .add { width: 100%; min-width: 0; height: 40px; }
.card .stepper { justify-content: space-between; }
.card .stepper button { width: 40px; height: 40px; font-size: 20px; }
.card .stepper input { flex: 1; min-width: 0; width: auto; height: 40px; font-size: 17px; }
.card-photo:focus-visible, .card-name:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Item details sheet */
body.locked { overflow: hidden; }
.sheet { position: fixed; inset: 0; z-index: 15; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); animation: sheet-fade .15s ease-out; }
.sheet-panel {
  position: relative; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom); animation: sheet-up .22s ease-out;
}
@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet-panel { max-width: 480px; border-radius: 20px; }
}
.sheet-close {
  position: absolute; top: 12px; right: 12px; z-index: 1; width: 36px; height: 36px; border-radius: 18px;
  border: 0; background: rgba(255, 255, 255, .9); color: #111827; font-size: 24px; line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
}
.sheet-photo { display: grid; place-items: center; aspect-ratio: 4 / 3; background: #fff; border-radius: 20px 20px 0 0; overflow: hidden; }
@media (min-width: 700px) { .sheet-photo { border-radius: 20px 20px 0 0; } }
.sheet-photo button { width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.sheet-photo img { width: 100%; height: 100%; object-fit: contain; padding: 16px; display: block; }
.sheet-photo.ph { background: hsl(var(--hue, 220) 30% 95%); color: hsl(var(--hue, 220) 35% 55%); }
.sheet-photo.ph svg { width: 28%; height: 28%; }
.sheet-info { padding: 18px 20px 0; }
.sheet-info h2 { margin: 0; font-size: 22px; line-height: 1.25; }
.sheet-info .meta { margin: 6px 0 0; }
.sheet-desc { margin: 14px 0 0; font-size: 16px; line-height: 1.5; white-space: pre-line; }
.sheet-qty { display: grid; gap: 12px; padding: 22px 20px 20px; }
.sheet-qty .stepper { justify-content: center; gap: 10px; }
.sheet-qty .stepper button { width: 52px; height: 52px; border-radius: 26px; font-size: 26px; }
.sheet-qty .stepper input { width: 88px; height: 52px; font-size: 22px; }
.sheet-qty .primary { max-width: none; box-shadow: none; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
@keyframes sheet-fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet-panel, .sheet-backdrop { animation: none; } }
@media (prefers-color-scheme: dark) {
  .card { box-shadow: none; }
  .card-photo.ph, .sheet-photo.ph { background: hsl(var(--hue, 220) 25% 16%); color: hsl(var(--hue, 220) 45% 65%); }
}

/* Admin: fill photos */
.fill { display: grid; gap: 14px; padding: 4px 16px 24px; }
.fill-progress { display: grid; gap: 6px; color: var(--muted); font-size: 14px; font-weight: 600; }
.track { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
#fillBar { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }
.fill-item { padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.fill-item h2 { margin: 4px 0 0; font-size: 20px; line-height: 1.25; }
.fill-item .meta { margin: 0; }
.fill-item #fillDesc { margin-top: 4px; }
.fill .primary { max-width: none; box-shadow: none; }
.drop {
  display: grid; place-items: center; gap: 8px; min-height: 190px; padding: 16px; text-align: center;
  border: 2px dashed var(--line); border-radius: 16px; background: var(--card); color: var(--muted);
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.saved { border-style: solid; border-color: var(--accent); }
.drop-text { margin: 0; font-size: 15px; line-height: 1.45; }
.drop-text b { color: var(--text); }
.drop-preview:empty { display: none; }
.drop-preview img { max-width: 160px; max-height: 160px; object-fit: contain; border-radius: 10px; background: #fff; }
#fillUrl {
  width: 100%; height: 48px; padding: 0 14px; font: inherit; font-size: 15px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
}
#fillUrl:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#fillDone .secondary { width: 100%; margin-top: 20px; }
#fillDone .primary { margin-top: 12px; }
#fillSkippedWrap { padding-top: 8px; }

/* Variation options */
.card .add.has { background: var(--accent-soft); }
.opts { display: grid; gap: 14px; margin-top: 16px; }
.opt-label { margin: 0 0 8px; color: var(--muted); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.opt-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.opt-chip {
  min-width: 56px; height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 16px; font-weight: 600;
}
.opt-chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.opt-chip:disabled { color: var(--muted); background: transparent; border-style: dashed; opacity: .45; text-decoration: line-through; cursor: not-allowed; }
.chosen { margin-top: 6px; }
.chosen ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.chosen button {
  display: flex; align-items: baseline; gap: 6px; width: 100%; padding: 10px 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); font-size: 15px;
}
.chosen button.on { border-color: var(--accent); }
.chosen-qty { font-weight: 800; }
.chosen .num { margin-left: auto; color: var(--muted); font-size: 13px; }

/* Standard picks and kits (from XYLEM → Material) */
.std { display: inline-block; background: var(--accent-soft); color: var(--text); border-radius: 6px; padding: 0 6px; font-size: 11px; font-weight: 700; }
.card.kit { grid-column: 1 / -1; padding: 12px 0 12px; }
.kit-head { display: grid; gap: 2px; padding: 0 12px; }
.kit-head b { font-size: 16px; }
.kit-lines { list-style: none; margin: 8px 0 0; padding: 0 12px; display: grid; gap: 4px; font-size: 14px; }
.kit-lines .qty { display: inline-block; min-width: 28px; font-weight: 700; }
.kit-lines .num { color: var(--muted); font-size: 12px; }
.tag.st-ordered, .tag.st-approved { background: #e0ecf8; color: #1d4a7a; }
.tag.st-delivered, .tag.st-received { background: #dcefe0; color: #1f5a2c; }
.tag.st-canceled { background: #e7e9ee; color: #353b48; }
