/* IMB Order — цэвэрхэн, орчин үеийн загвар.
   Зөөлөн градиент дэвсгэр + шилэн (glass) карт + бөөрөнхий товч.
   Брэнд: хар/цагаан үндсэн, ягаан #F7ADBA акцент, ягаан дээр зөвхөн хар бичиг. */
:root {
  --bg: #fdf7f9;
  --surface: #ffffff;
  --glass: rgba(255, 255, 255, .72);
  --glass-line: rgba(255, 255, 255, .9);
  --text: #0b0b0f;
  --muted: #6b6b76;
  --line: #ececf1;
  --primary: #0b0b0f;
  --primary-text: #ffffff;
  --accent: #f7adba;
  --accent-soft: #fde8ec;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --err: #b91c1c;
  --err-bg: #fee2e2;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 1px 2px rgba(16, 16, 32, .04), 0 8px 24px rgba(16, 16, 32, .06);
  --nav-h: 68px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px);
  background-color: var(--bg);
  /* Зөөлөн урсгалтай градиент: ягаан → тоор → лаванда → цэнхэр */
  background-image:
    radial-gradient(60% 50% at 0% 0%, rgba(247, 173, 186, .55), transparent 70%),
    radial-gradient(50% 45% at 100% 10%, rgba(196, 181, 253, .45), transparent 70%),
    radial-gradient(55% 45% at 90% 100%, rgba(147, 197, 253, .40), transparent 70%),
    radial-gradient(45% 40% at 10% 95%, rgba(253, 186, 140, .35), transparent 70%);
  background-attachment: fixed;
}
a { color: inherit; }
h1, h2 { letter-spacing: -.02em; line-height: 1.2; }
h1 { font-size: 1.75rem; font-weight: 800; margin: 8px 0 18px; }
h2 { font-size: 1.15rem; font-weight: 700; margin: 32px 0 12px; }

.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }

/* --- Дээд мөр (шилэн) --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, .6);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.brand img { height: 28px; width: auto; display: block; }
.brand-tag {
  background: var(--accent); color: #000; font-size: .68rem; font-weight: 700;
  padding: 3px 8px; border-radius: 999px; letter-spacing: .06em; text-transform: uppercase;
}
.who { margin-left: auto; text-align: right; line-height: 1.25; min-width: 0; }
.who-name { display: block; font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-sub { display: block; font-size: .74rem; color: var(--muted); }
.btn-ghost {
  background: var(--surface); color: var(--text); border: 0; box-shadow: var(--shadow);
  border-radius: 999px; padding: 8px 14px; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
}

/* --- Цэс: утсанд доод талд, том дэлгэцэнд дээд талд --- */
.nav {
  position: fixed; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 10;
  display: flex; height: var(--nav-h); padding: 6px;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border: 1px solid var(--glass-line); border-radius: 999px; box-shadow: var(--shadow);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 500;
  border-radius: 999px; transition: background .15s, color .15s;
}
.nav a .ico { width: 22px; height: 22px; }
.nav a.on { color: #000; background: var(--accent); font-weight: 700; }

@media (min-width: 800px) {
  body { padding-bottom: 32px; }
  .nav {
    position: sticky; top: 62px; bottom: auto; left: auto; right: auto;
    width: fit-content; height: auto; margin: 14px auto 0; gap: 4px;
  }
  .nav a { flex: none; flex-direction: row; gap: 8px; padding: 9px 18px; font-size: .9rem; }
  .nav a .ico { width: 18px; height: 18px; }
}

/* --- Карт, жагсаалт --- */
.card {
  background: var(--surface); border: 1px solid var(--glass-line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card.empty { text-align: center; color: var(--muted); padding: 44px 16px; }
.list { display: grid; gap: 10px; }
.list > * { min-width: 0; }
.row-link {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  text-decoration: none; padding: 14px 18px; transition: transform .1s;
}
.row-link:active { transform: scale(.99); }
.row-link .right { text-align: right; }
.is-off { opacity: .55; }
.plain { list-style: none; padding: 0; margin: 0 0 14px; }
.plain li { padding: 10px 0; border-bottom: 1px solid var(--line); }

.tag {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  background: #f3f3f6; font-size: .76rem; font-weight: 600; white-space: nowrap;
}
.tag-dark { background: var(--primary); color: var(--primary-text); }
.tag-accent { background: var(--accent); color: #000; }
.tag-off { background: var(--err-bg); color: var(--err); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 8px 0; }
.back { display: block; margin: 4px 0; color: var(--muted); text-decoration: none; font-weight: 500; }

/* --- Маягт --- */
.stack { display: grid; gap: 16px; }
label { display: grid; gap: 6px; font-size: .88rem; font-weight: 600; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* iOS томруулахгүй */
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fafafc; color: var(--text); transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; background: #fff; border-color: #000; box-shadow: 0 0 0 4px var(--accent-soft);
}
label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
label.check input { width: 20px; height: 20px; accent-color: #000; }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; }
[hidden] { display: none !important; }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 22px; border-radius: 999px;
  border: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: transform .1s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-accent { background: var(--accent); color: #000; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* --- Мэдэгдэл --- */
.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: .92rem; font-weight: 500; }
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--err-bg); color: var(--err); }

/* --- Нэвтрэх: илүү тод градиент + шилэн карт --- */
.login-page {
  padding-bottom: 0;
  background-color: #f6d5e0;
  background-image:
    radial-gradient(70% 60% at 0% 0%, #f7adba, transparent 70%),
    radial-gradient(60% 55% at 100% 0%, #c4b5fd, transparent 70%),
    radial-gradient(65% 60% at 100% 100%, #93c5fd, transparent 70%),
    radial-gradient(60% 55% at 0% 100%, #fdba8c, transparent 70%);
}
.login-page .wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; }
.login-card {
  width: 100%; max-width: 380px; padding: 32px 22px;
  background: rgba(255, 255, 255, .62);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid rgba(255, 255, 255, .8); border-radius: 28px;
  box-shadow: 0 20px 60px rgba(60, 20, 60, .15);
}
.login-logo { display: block; width: 120px; height: auto; margin: 0 auto 14px; }
.login-sub { text-align: center; margin: 0 0 26px; font-size: 1.05rem; font-weight: 700; letter-spacing: -.01em; }
.login-sub .muted { font-weight: 500; }
.login-card input { background: rgba(255, 255, 255, .85); }

/* ================================================================ Захиалга */
.min0 { min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.center { text-align: center; }
.mt { margin-top: 10px; }
.meta { margin: -6px 0 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.qty-sum { margin-top: 6px; font-weight: 700; font-size: .95rem; }
.btn-sm { min-height: 36px; padding: 6px 14px; font-size: .85rem; }
.chip {
  display: inline-block; margin-top: 2px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow); font-size: .82rem; font-weight: 600; text-decoration: none;
}

/* Төлөвийн таг */
.st-draft     { background: #f3f3f6; color: #55556a; }
.st-pending   { background: #fef3c7; color: #92400e; }
.st-returned  { background: var(--err-bg); color: var(--err); }
.st-prepared  { background: #dbeafe; color: #1e40af; }
.st-delivered { background: #ede9fe; color: #5b21b6; }
.st-completed { background: var(--ok-bg); color: var(--ok); }

.note { padding: 12px 16px; border-radius: var(--radius-sm); margin: 0 0 14px; font-size: .92rem; }
.note-warn { background: #fff7ed; color: #9a3412; border-left: 4px solid #fb923c; }

/* Код оруулах */
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; font-size: 1.1rem; font-weight: 600; letter-spacing: .02em; }
#lookup-error { margin: 12px 0 0; }
.picker { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line); }
.picker-head { margin-bottom: 8px; }
.picker-head .strong { font-size: 1.1rem; }
.picker-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.picker-actions .btn-primary { flex: 1; }
.colors { list-style: none; margin: 0; padding: 0; }
.colors li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.color-name { min-width: 0; font-weight: 500; }
.stepper { display: inline-flex; align-items: center; background: #f3f3f6; border-radius: 999px; padding: 3px; flex: none; }
.stepper button {
  width: 38px; height: 38px; border-radius: 999px; border: 0; background: var(--surface);
  font-size: 1.25rem; font-weight: 600; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.06); color: var(--text);
}
.stepper button:active { transform: scale(.92); }
.stepper input {
  width: 56px; text-align: center; border: 0; background: transparent; padding: 6px 2px;
  font-weight: 700; font-size: 1.05rem; box-shadow: none;
  -moz-appearance: textfield; appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { box-shadow: none; background: transparent; }

/* Бүтээгдэхүүний карт */
.prod { padding: 14px 18px; }
.prod-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.lines { list-style: none; margin: 10px 0 0; padding: 0; }
.lines li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .95rem;
}
.prod-total {
  display: flex; justify-content: space-between; padding-top: 10px; margin-top: 2px;
  font-weight: 700; font-size: .92rem;
}

/* Доод үйлдлийн мөр (утсанд цэсний дээр) */
.has-actionbar { padding-bottom: calc(var(--nav-h) + 110px + env(safe-area-inset-bottom)); }
.actionbar {
  position: fixed; z-index: 9; left: 12px; right: 12px;
  bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 10px 10px 18px; border-radius: 999px;
  background: rgba(11, 11, 15, .92); color: #fff;
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  box-shadow: 0 12px 32px rgba(0,0,0,.2);
}
.actionbar .totals { display: flex; gap: 14px; font-size: .85rem; opacity: .9; }
.actionbar .big { font-size: 1.2rem; font-weight: 800; }
.actionbar .btn-primary { background: var(--accent); color: #000; }
.actionbar .btn:disabled { opacity: .35; }
.actionbar.three { padding: 8px; gap: 6px; }
.actionbar.three form { flex: 1; }
.actionbar.three .btn { width: 100%; padding: 10px 6px; font-size: .85rem; background: rgba(255,255,255,.12); color: #fff; box-shadow: none; }
.actionbar.three .btn-primary { background: var(--accent); color: #000; }
@media (min-width: 800px) {
  .has-actionbar { padding-bottom: 110px; }
  .actionbar { bottom: 20px; max-width: 736px; margin: 0 auto; }
}

.danger-zone { margin: 22px 0 0; }
.link-danger { background: none; border: 0; color: var(--err); font: inherit; font-size: .88rem; text-decoration: underline; cursor: pointer; }

/* Дэлгэрэнгүй */
.info { display: grid; gap: 8px; margin-bottom: 14px; }
.info > div { display: flex; justify-content: space-between; gap: 12px; }
.steps { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); padding: 0; margin: 0 0 16px; }
.steps li { position: relative; text-align: center; font-size: .74rem; color: var(--muted); }
.steps li::before {
  content: ""; position: absolute; top: 8px; left: -50%; right: 50%; height: 3px; background: var(--line); z-index: 0;
}
.steps li:first-child::before { display: none; }
.steps li.done::before { background: #000; }
.steps .dot {
  position: relative; z-index: 1; display: block; width: 18px; height: 18px; margin: 0 auto 6px;
  border-radius: 999px; background: var(--surface); border: 3px solid var(--line);
}
.steps li.done .dot { background: var(--accent); border-color: #000; }
.steps li.done { color: var(--text); font-weight: 600; }
.steps .lbl, .steps .at { display: block; }
.steps .at { font-weight: 400; color: var(--muted); font-size: .7rem; }

.check-cell { display: inline-flex; align-items: center; gap: 8px; flex: none; }
.ordered { min-width: 28px; text-align: right; font-weight: 700; }
.given { width: 64px; padding: 8px; text-align: center; font-weight: 600; }
.tick {
  width: 42px; height: 42px; border-radius: 999px; border: 2px solid var(--line);
  background: var(--surface); color: transparent; font-size: 1.2rem; font-weight: 900; cursor: pointer;
}
.tick[aria-pressed="true"] { background: #000; border-color: #000; color: var(--accent); }
.lines li.is-checked > .min0 { text-decoration: line-through; text-decoration-color: rgba(0,0,0,.3); color: var(--muted); }
.lines li.is-short .given { border-color: var(--err); color: var(--err); background: var(--err-bg); }
.lines li.saving { opacity: .5; }
.short-badge { background: var(--err-bg); color: var(--err); padding: 2px 8px; border-radius: 999px; font-size: .85rem; }
.ok-mark { color: var(--ok); }

.totals-card { display: flex; justify-content: space-around; text-align: center; margin-top: 14px; }
.totals-card > div { display: grid; }
.totals-card .big { font-size: 1.6rem; font-weight: 800; }
.totals-card .big.short { color: var(--err); }

.timeline { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.timeline li { display: grid; gap: 2px; padding: 10px 14px; background: var(--surface); border-radius: var(--radius-sm); font-size: .9rem; }

.return-box { margin-top: 16px; }
.return-box summary { cursor: pointer; font-weight: 600; color: var(--err); }

/* Шүүлтүүр */
.filters { display: grid; gap: 14px; margin-bottom: 12px; }
.seg { display: flex; gap: 4px; background: #f3f3f6; padding: 4px; border-radius: 999px; overflow-x: auto; }
.seg-item { flex: 1; display: block; }
.seg-item input { position: absolute; opacity: 0; pointer-events: none; }
.seg-item span {
  display: block; text-align: center; padding: 8px 12px; border-radius: 999px;
  font-size: .85rem; font-weight: 600; color: var(--muted); white-space: nowrap; cursor: pointer;
}
.seg-item input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.filters > * { min-width: 0; }
.filter-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.filter-grid input { min-width: 0; }
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-radius: 18px; overflow: visible; }
.seg-item { position: relative; }
.seg-item span { padding: 8px 6px; }
@media (min-width: 560px) { .seg { grid-template-columns: repeat(4, minmax(0, 1fr)); border-radius: 999px; } }
.who-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.filter-grid .span2 { grid-column: span 2; }
.filter-actions { display: flex; gap: 8px; justify-content: flex-end; }


/* ================================================================ Түүх, Зарлага */
.seg.seg-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); border-radius: 999px; }
.seg.seg-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); border-radius: 999px; }
.day-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  margin: 20px 4px 8px; font-weight: 700; font-size: .95rem;
}
.day-head span:last-child { color: var(--muted); font-weight: 500; font-size: .82rem; }
.exp-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; }
.exp-note {
  margin-top: 8px; padding: 8px 12px; border-radius: 10px; background: #f6f6f9;
  font-size: .9rem; color: #33333d; white-space: pre-wrap; overflow-wrap: anywhere;
}
.cat-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.cat-return          { background: #dbeafe; color: #1e40af; }
.cat-defect          { background: var(--err-bg); color: var(--err); }
.cat-no_receipt_sale { background: #fef3c7; color: #92400e; }
.cat-other           { background: #f3f3f6; color: #55556a; }
.stepper-wide { display: flex; justify-content: space-between; }
.stepper-wide input { flex: 1; width: auto; min-width: 0; }
.muted-light { color: rgba(255, 255, 255, .75); font-size: .9rem; }
textarea { resize: vertical; }
