@font-face {
  font-family: Manrope;
  src: url('assets/Manrope-Variable.ttf') format('truetype');
  font-weight: 200 800;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f7f3ee;
  --surface: #ffffff;
  --ink: #1f1f1f;
  --muted: #706a64;
  --line: #ddd2c5;
  --soft: #efe6da;
  --accent: #c2612c;
  --accent-soft: rgba(194, 97, 44, 0.12);
  --green: #5f7f5f;
  --green-soft: rgba(95, 127, 95, 0.14);
  --amber: #a07a2e;
  --amber-soft: rgba(160, 122, 46, 0.16);
  --red: #8a4a4a;
  --red-soft: rgba(138, 74, 74, 0.12);
  --shadow: 0 10px 30px rgba(35, 30, 25, 0.10);
  --radius: 16px;
}

[data-theme='dark'] {
  color-scheme: dark;
  --bg: #171a1d;
  --surface: #202427;
  --ink: #f2eee8;
  --muted: #a9a29a;
  --line: #33383c;
  --soft: #2a2e31;
  --accent: #d9804f;
  --accent-soft: rgba(217, 128, 79, 0.16);
  --green: #8fbf8f;
  --green-soft: rgba(143, 191, 143, 0.16);
  --amber: #d6b25e;
  --amber-soft: rgba(214, 178, 94, 0.16);
  --red: #d08a8a;
  --red-soft: rgba(208, 138, 138, 0.16);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Manrope, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; }

button { font: inherit; color: inherit; cursor: pointer; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 16px calc(28px + env(safe-area-inset-bottom));
}

/* top bar */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: linear-gradient(var(--bg) 78%, transparent);
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 46px; height: 46px; flex: 0 0 auto;
  background: #f7f3ee;
  border: 1px solid var(--line);
  border-radius: 14px;
  display: grid; place-items: center;
  overflow: hidden;
}
.logo img { width: 42px; height: 42px; display: block; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text b { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; }
.brand-text small { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.icon-btn {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:active { transform: scale(0.96); }

/* stats */
.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 6px 0 14px;
}
.stat {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat b { font-size: 24px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.stat small { font-size: 12px; color: var(--muted); }
.stat[aria-pressed='true'] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.stat.primary b { color: var(--accent); }

/* search */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 12px;
  height: 46px;
  margin-bottom: 10px;
}
.search svg { width: 18px; height: 18px; color: var(--muted); flex: 0 0 auto; }
.search input {
  flex: 1; min-width: 0;
  border: 0; background: transparent; outline: none;
  font: inherit; color: var(--ink);
  font-size: 15px;
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button,
.search input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
.search .clear {
  border: 0; background: var(--soft); color: var(--muted);
  width: 24px; height: 24px; border-radius: 50%;
  font-size: 16px; line-height: 1; padding: 0;
}

/* filter chips */
.filters { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.chips {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 40px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.chip[aria-pressed='true'] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

/* list */
.list-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin-bottom: 8px;
  font-size: 13px; font-weight: 700;
}
.list-head .hint { font-weight: 500; color: var(--muted); font-size: 12px; }
.orders { display: flex; flex-direction: column; gap: 8px; }
.order {
  width: 100%; text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
}
.order:active { transform: scale(0.995); }
.order-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.order-top { display: flex; align-items: center; gap: 8px; }
.order-id { font-size: 15px; font-weight: 800; letter-spacing: -0.01em; }
.order-client { font-size: 13px; color: var(--ink); }
.order-sub { font-size: 12px; color: var(--muted); }
.order-right { text-align: right; flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.order-sum { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.order-store { font-size: 11px; color: var(--muted); }
.order .chev { width: 16px; height: 16px; color: var(--line); flex: 0 0 auto; }

.tag {
  display: inline-flex; align-items: center;
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 11px; font-weight: 800;
  background: var(--soft); color: var(--muted);
  white-space: nowrap;
}
.tag.new { color: var(--accent); background: var(--accent-soft); }
.tag.packing { color: var(--amber); background: var(--amber-soft); }
.tag.shipped { color: var(--green); background: var(--green-soft); }
.tag.cancel { color: var(--red); background: var(--red-soft); }

.load-more {
  width: 100%; margin-top: 10px;
  padding: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 14px; font-weight: 700;
  color: var(--ink);
}
.empty { text-align: center; padding: 28px 10px; }
.empty b { font-size: 16px; }
.empty p { color: var(--muted); font-size: 13px; margin: 6px 0 14px; }
.footnote { margin-top: 22px; text-align: center; font-size: 11px; color: var(--muted); }

/* skeleton */
.skeleton .order { pointer-events: none; }
.sk {
  background: linear-gradient(90deg, var(--soft) 25%, var(--surface) 50%, var(--soft) 75%);
  background-size: 200% 100%;
  animation: sk 1.2s infinite;
  border-radius: 8px;
  height: 14px;
}
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }

/* sheet */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(20, 16, 12, 0.42);
  backdrop-filter: blur(2px);
}
.sheet {
  position: fixed; z-index: 21;
  left: 0; right: 0; bottom: 0;
  max-height: 92vh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: slide-up 0.22s ease-out;
}
@keyframes slide-up { from { transform: translateY(18px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-grab { width: 42px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 10px; }
.sheet-close {
  position: absolute; top: 12px; right: 12px;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 20px; line-height: 1; padding: 0 0 2px;
}
.sheet h2 { margin: 2px 44px 4px 0; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.sheet .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.block .k {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 700; margin-bottom: 3px;
}
.block .v { font-size: 15px; font-weight: 700; }
.block .d { font-size: 12.5px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.block a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }

.items { width: 100%; border-collapse: collapse; margin-top: 2px; }
.items td { padding: 6px 0; font-size: 13px; vertical-align: top; }
.items td.r { text-align: right; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.items tr + tr td { border-top: 1px solid var(--line); }
.total {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 15px; font-weight: 800;
}
.total .cur { font-variant-numeric: tabular-nums; font-size: 17px; }

.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.btn {
  border-radius: 13px;
  padding: 14px 18px;
  font-size: 15px; font-weight: 800;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--ink);
}
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.ghost { border-color: var(--line); color: var(--ink); background: transparent; }
.btn.danger { background: var(--red); color: #fff; }
.btn:active { transform: scale(0.995); }
.btn[disabled] { opacity: 0.5; }

.note {
  font-size: 12.5px; line-height: 1.45;
  color: var(--muted);
  background: var(--soft);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 10px 0;
}
.note b { color: var(--ink); }

/* success */
.done { text-align: center; padding: 8px 0 4px; }
.done .ok {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--green-soft); color: var(--green);
  display: inline-grid; place-items: center;
  font-size: 30px; margin-bottom: 10px;
}
.done h2 { margin: 0 0 6px; }
.done p { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0 0 16px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  border-radius: 40px;
  padding: 11px 18px;
  font-size: 13px; font-weight: 700;
  z-index: 40;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow);
}

/* new order form */
.form-input {
  width: 100%;
  height: 44px;
  margin-top: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  outline: none;
}
.form-input::placeholder { color: var(--muted); }
.form-input:focus { border-color: var(--ink); }
.results { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.result-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left;
  background: var(--soft); border: 0; border-radius: 10px;
  padding: 9px 11px; font: inherit; color: var(--ink);
}
.result-row .rn { flex: 1; min-width: 0; font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-row .rp { font-size: 12px; color: var(--muted); white-space: nowrap; }
.result-row .plus { width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: var(--bg); display: grid; place-items: center; font-size: 16px; line-height: 1; flex: 0 0 auto; }
.cart { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.cart:empty { display: none; }
.cart-row { display: flex; align-items: center; gap: 8px; }
.cart-name { flex: 1; min-width: 0; font-size: 13px; }
.cart-sum { font-size: 12px; font-weight: 700; white-space: nowrap; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--ink); font-size: 15px; line-height: 1; padding: 0 0 2px; }
.qty span { font-size: 13px; font-weight: 700; min-width: 18px; text-align: center; }
.block .chips { margin-top: 6px; }
.icon-btn.add { background: var(--ink); color: var(--bg); border-color: var(--ink); font-size: 24px; line-height: 1; padding: 0 0 3px; }

/* section switcher */
.sections {
  display: flex; gap: 4px; margin: 2px 0 12px; padding: 4px;
  background: var(--soft); border-radius: 14px;
}
.section-tab {
  flex: 1; border: 0; border-radius: 11px; padding: 9px 4px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: 12px; font-weight: 800; white-space: nowrap;
}
.section-tab[aria-selected='true'] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(35, 30, 25, 0.10); }

/* production */
.prod-qty { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.prod-qty span { font-size: 13px; color: var(--muted); }
.prod-qty button { width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 18px; line-height: 1; padding: 0 0 2px; }
.prod-qty b { min-width: 26px; text-align: center; font-size: 17px; }
.prod-product { font-size: 15px; font-weight: 800; }
.prod-material { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
.prod-material:first-of-type { border-top: 0; }
.prod-material .pm-name { flex: 1; min-width: 0; }
.prod-material .pm-value { white-space: nowrap; color: var(--muted); }
.prod-material.short .pm-value { color: var(--red); font-weight: 700; }
.prod-state { margin-top: 8px; font-size: 12px; }
.prod-state.ok { color: var(--green); font-weight: 700; }
.prod-line { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.prod-line:first-of-type { border-top: 0; }
.prod-line .pm-name { flex: 1; min-width: 0; }
.prod-line-sum { color: var(--muted); font-size: 12px; white-space: nowrap; }
.prod-remove { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 0 2px; flex: 0 0 auto; }
.prod-state.bad { color: var(--red); font-weight: 700; }

/* order list: product summary */
.order-products { font-size: 11.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* order card: status button and stock */
.status-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 8px; font: inherit; font-size: 14px; font-weight: 700; color: var(--ink);
}
.status-btn .caret { color: var(--muted); font-size: 12px; }
.stage-row { display: flex; align-items: center; justify-content: space-between; width: 100%; background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 13px 2px; font: inherit; font-size: 14px; color: var(--ink); text-align: left; }
.stage-row:last-child { border-bottom: 0; }
.stage-row.current { font-weight: 800; }
.stage-check { color: var(--green); font-weight: 800; }
.stock-line { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 5px 0; border-top: 1px solid var(--line); }
.stock-name { font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stock-value { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.stock-note { margin-top: 10px; display: flex; flex-direction: column; gap: 2px; }

/* order form cart */
.cart-item { border-top: 1px solid var(--line); padding: 9px 0 7px; }
.cart-item:first-child { border-top: 0; }
.cart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.cart-edit { display: flex; align-items: center; gap: 10px; margin-top: 7px; flex-wrap: wrap; }
.mini-field { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--muted); }
.mini-input { width: 62px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; font-size: 13px; padding: 0 8px; text-align: right; outline: none; }
.mini-input:focus { border-color: var(--ink); }
.cart-edit .cart-sum { margin-left: auto; }
.delivery-item .cart-name { color: var(--muted); }
.total-line { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 2px 0; }
.total-sum { margin-top: 4px; }
.icon-btn.spin svg { animation: spin 0.9s linear infinite; }
.icon-btn[disabled] { opacity: 0.55; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon-btn.spin svg { animation: none; } }

/* stock summaries */
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.block-head .k { margin-bottom: 0; }
.block-head .chip { padding: 5px 12px; }
.list-head { align-items: center; }
.list-actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.list-actions .chip { padding: 5px 12px; }
.stock-totals { display: flex; gap: 18px; margin-top: 6px; flex-wrap: wrap; }
.stock-total { display: flex; flex-direction: column; gap: 1px; }
.stock-total b { font-size: 20px; font-weight: 800; line-height: 1; }
.stock-total small { font-size: 11px; color: var(--muted); }
.stock-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.stock-row:first-of-type { border-top: 0; }
.stock-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.stock-row-name { font-size: 13px; }
.stock-row-meta { font-size: 11px; color: var(--muted); }
.stock-row-value { font-size: 13px; font-weight: 700; white-space: nowrap; }
.stock-row-value.zero { color: var(--muted); font-weight: 500; }

/* help button and onboarding tour */
.help-fab {
  position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(35, 30, 25, 0.18);
  font: inherit; font-size: 19px; font-weight: 800;
  z-index: 30;
}
.help-fab:active { transform: scale(0.96); }
.help-hint {
  position: fixed; right: 70px; bottom: calc(24px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg);
  border: 0; border-radius: 14px; padding: 9px 13px;
  font: inherit; font-size: 12px; font-weight: 700;
  z-index: 30; box-shadow: 0 8px 24px rgba(35, 30, 25, 0.22);
  animation: hint-in 0.25s ease-out;
}
.help-hint::after {
  content: ''; position: absolute; right: -5px; bottom: 16px;
  width: 10px; height: 10px; background: var(--ink);
  transform: rotate(45deg);
}
@keyframes hint-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.tour { position: fixed; inset: 0; z-index: 60; }
.tour-hole {
  position: fixed; border-radius: 16px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(15, 12, 10, 0.62);
  border: 2px solid rgba(255, 255, 255, 0.9);
  transition: top 0.18s ease, left 0.18s ease, width 0.18s ease, height 0.18s ease;
}
.tour-card {
  position: fixed; left: 16px; right: 16px; max-width: 430px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px 16px 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.tour-step { font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.tour-card h3 { margin: 4px 0 5px; font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.tour-card p { margin: 0; font-size: 13px; line-height: 1.45; color: var(--muted); }
.tour-actions { display: flex; align-items: center; gap: 8px; margin-top: 13px; }
.tour-actions .btn { padding: 10px 14px; font-size: 13px; border-radius: 11px; }
.tour-actions .btn[disabled] { opacity: 0.4; }
.tour-skip { margin-right: auto; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 12px; padding: 0; }

/* access gate */
.gate { position: fixed; inset: 0; z-index: 80; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 22px; box-shadow: var(--shadow); }
.gate-card h2 { margin: 0 0 8px; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.gate-card p { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.gate-card .form-input { margin-top: 0; }
.gate-error { min-height: 16px; margin-top: 8px; color: var(--red); font-size: 12.5px; }

[hidden] { display: none !important; }

@media (min-width: 600px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
