:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --card: #1b222c;
  --card-2: #222b36;
  --line: #2a333f;
  --text: #e8edf2;
  --muted: #8b97a6;
  --accent: #4f9dff;
  --accent-d: #3b82e0;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 80% at 50% 0%, #1a2230 0%, var(--bg) 60%);
}
.login-card {
  width: 100%; max-width: 360px; background: var(--card);
  border: 1px solid var(--line); border-radius: 20px; padding: 32px 24px;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.login-logo {
  width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 16px;
  display: grid; place-items: center; font-size: 26px; color: #fff;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 20px; font-size: 14px; }
.login-err { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---------- App shell ---------- */
.app { min-height: 100%; padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: rgba(14,17,22,.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.view { padding: 16px 16px 24px; max-width: 720px; margin: 0 auto; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(22,27,34,.95); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600;
}
.tab-ico { font-size: 18px; line-height: 1; }
.tab.active { color: var(--accent); }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 31;
  width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer;
  font-size: 30px; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-d));
  box-shadow: 0 10px 28px rgba(79,157,255,.45); display: grid; place-items: center;
}
.fab:active { transform: scale(.94); }

/* ---------- Cards / generic ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase;
  letter-spacing: .06em; margin: 22px 4px 10px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* stat grid */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.accent { background: linear-gradient(135deg, #1c2c44, #1b222c); border-color: #2d4566; }
.value.green { color: var(--green); } .value.amber { color: var(--amber); } .value.red { color: var(--red); }

/* list items */
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px;
}
.list-item:active { background: var(--card-2); }
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.li-right { text-align: right; white-space: nowrap; }
.li-amt { font-weight: 700; }

/* pills */
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.pill.supp { background: #1d3a52; color: #7fc0ff; }
.pill.equip { background: #3a2d52; color: #c4a7ff; }
.pill.paid { background: #14392c; color: var(--green); }
.pill.unpaid { background: #3d2222; color: var(--red); }
.pill.low { background: #3d3318; color: var(--amber); }
.pill.muted { background: var(--card-2); color: var(--muted); }
.pill.incountry { background: #143a3a; color: #5fe3d0; }

/* ---------- Buttons / forms ---------- */
.btn {
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  padding: 11px 16px; border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-d)); border-color: transparent; color: #fff; }
.btn-danger { background: #3a2222; border-color: #5a2c2c; color: var(--red); }
.btn-ghost { background: none; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 11px; font-size: 13px; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 6px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
input, select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 11px; padding: 12px 13px; font-size: 16px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 64px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.hint.good { color: var(--green); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.modal-sheet {
  position: relative; width: 100%; max-width: 720px; margin: 0 auto;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 22px 22px 0 0;
  max-height: 92vh; display: flex; flex-direction: column;
  animation: sheet-up .22s ease; padding-bottom: var(--safe-b);
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 8px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-body { padding: 8px 18px 22px; overflow-y: auto; }

@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-sheet { border-radius: 22px; max-height: 88vh; }
}

/* order builder line */
.oi {
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 10px; margin-bottom: 8px;
}
.oi { flex-wrap: wrap; display: flex; align-items: center; gap: 8px; }
.oi-name { flex: 1 1 100%; min-width: 0; }
.oi-name .li-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.oi .price { width: 78px; text-align: right; padding: 8px 6px; margin-left: auto; }

/* qty stepper */
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.stepper button { width: 36px; height: 38px; background: var(--card-2); border: 0; color: var(--text); font-size: 18px; cursor: pointer; }
.stepper button:active { background: var(--line); }
.stepper .qty { width: 46px; text-align: center; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-radius: 0; padding: 8px 2px; }
.line-check {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px;
  padding: 0 10px; border: 1px solid var(--line); border-radius: 9px;
  color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer;
}
.line-check input { width: auto; margin: 0; accent-color: var(--accent); }
.line-check:has(input:checked) { color: var(--amber); border-color: rgba(245, 158, 11, .45); background: rgba(245, 158, 11, .08); }

/* quick-add chips (usuals / bundles) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 14px; }
.chips[hidden] { display: none; }
.chips-label { font-size: 12px; color: var(--muted); font-weight: 600; margin-right: 2px; }
.chip {
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip:active { transform: scale(.96); }
.chip-strong { background: linear-gradient(135deg, var(--accent), var(--accent-d)); border-color: transparent; color: #fff; }

/* margin badge next to price */
.price-row { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.margin-badge {
  font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 999px; line-height: 1.4;
}
.margin-badge.m-good { background: #14392c; color: var(--green); }
.margin-badge.m-ok   { background: #3d3318; color: var(--amber); }
.margin-badge.m-low  { background: #3d2222; color: var(--red); }

/* compact order rows + month grouping */
.month-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; font-weight: 700; letter-spacing: .02em;
  padding: 14px 4px 6px; position: sticky; top: 56px; background: var(--bg); z-index: 4;
}
.order-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 11px; cursor: pointer;
}
.order-row:active { background: var(--card-2); }
.or-main { flex: 1; min-width: 0; }
.or-top { display: flex; align-items: baseline; gap: 8px; }
.or-cust { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.or-date { font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.or-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.or-sub .pill { font-size: 10px; padding: 2px 6px; }
.or-prod { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-status { font-size: 11px; font-weight: 700; color: var(--accent); background: #16263d; padding: 2px 7px; border-radius: 999px; }
.track { cursor: pointer; color: var(--accent); }
.or-track { font-size: 12px; color: var(--text); opacity: .82; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* stepped milestone progress */
.steps { display: flex; align-items: flex-start; margin-top: 10px; }
.steps.steps-lbl { margin-bottom: 14px; }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; position: relative; }
.step:not(:first-child)::before {
  content: ''; position: absolute; height: 2px; background: var(--line);
  left: -50%; right: 50%; top: 5px;
}
.step.done::before, .step.now::before { background: var(--accent); }
.step-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--line); position: relative; z-index: 1; transition: background .3s; }
.step.done .step-dot { background: var(--accent); }
.step.now .step-dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(79,157,255,.28); }
.step.warn .step-dot, .step.warn::before { background: var(--amber); }
.step.warn .step-dot { box-shadow: 0 0 0 3px rgba(251,191,36,.28); }
.step-lbl { font-size: 9.5px; line-height: 1.2; color: var(--muted); margin-top: 5px; text-align: center; }
.step.now .step-lbl { color: var(--accent); font-weight: 700; }
.step.done .step-lbl { color: var(--text); }

/* tracking timeline */
.timeline { margin-top: 12px; padding-left: 6px; }
.tl-item { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--line); }
.tl-item:last-child { border-left-color: transparent; padding-bottom: 0; }
.tl-dot { position: absolute; left: -6px; top: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.tl-now .tl-dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(79,157,255,.25); }
.tl-now .tl-desc { color: var(--accent); font-weight: 600; }
.tl-desc { font-size: 13px; line-height: 1.35; }
.tl-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.or-right { text-align: right; flex: 0 0 auto; }
.or-right .li-amt { font-weight: 700; font-size: 15px; }
.or-profit { font-size: 12px; color: var(--green); margin-top: 1px; }

/* restock rows */
.restock-row {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 11px;
}
.restock-row .li-main { flex: 1; min-width: 0; }
.restock-row .qty { width: 64px; text-align: center; padding: 8px 4px; }
.li-sub.out { color: var(--red); } .li-sub.lowtxt { color: var(--amber); }

/* searchable combobox */
.combo { position: relative; }
.combo-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5;
  background: var(--bg-2); border: 1px solid var(--accent); border-radius: 11px;
  max-height: 280px; overflow-y: auto; box-shadow: 0 12px 30px rgba(0,0,0,.5);
}
.combo-item {
  display: flex; justify-content: space-between; gap: 10px; padding: 11px 13px;
  border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px;
}
.combo-item:last-child { border-bottom: 0; }
.combo-item:hover { background: var(--card-2); }

/* product row open-link shortcut */
.li-link {
  flex: 0 0 auto; background: var(--card-2); border: 1px solid var(--line); color: var(--accent);
  width: 34px; height: 34px; border-radius: 9px; font-size: 16px; cursor: pointer; margin-left: 4px;
}
.li-link:active { transform: scale(.92); }
.totbar { display: flex; justify-content: space-between; padding: 14px 2px; font-size: 16px; }
.totbar .big { font-size: 22px; font-weight: 800; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 24px); transform: translateX(-50%) translateY(20px);
  background: #f1f5f9; color: #0e1116; font-weight: 600; font-size: 14px; padding: 11px 18px;
  border-radius: 999px; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 60;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #f87171; color: #1a0a0a; }

.topbar-actions { display: flex; gap: 4px; }

/* import box in product form */
.import-box { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 16px; }
.import-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.import-row input { font-size: 14px; }
.import-thumb { text-align: center; margin-bottom: 12px; }
.import-thumb img { max-height: 120px; max-width: 100%; border-radius: 10px; background: #fff; padding: 4px; }

/* product filters row */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.filters select { font-size: 14px; padding: 9px 11px; }
.picker-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.picker-filters select { min-width: 0; font-size: 13px; padding: 9px 10px; }

.search { margin-bottom: 14px; }
.seg { display: flex; gap: 8px; margin-bottom: 14px; }
.seg button { flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  color: var(--muted); font-weight: 600; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--card-2); color: var(--text); border-color: var(--accent); }
