:root {
  --ground: #F6F5F1;
  --paper: #FFFFFF;
  --ink: #1B1D24;
  --ink-2: #4A4E5A;
  --line: #E2E0D8;
  --line-2: #EFEDE6;
  --field: #D5D3CB;
  --dark: #1F2433;
  --dark-2: #C9CCD6;
  --blue: #2448C9;
  --blue-d: #1A3596;
  --blue-l: #E9EEFC;
  --orange: #C2410C;
  --orange-d: #9A3209;
  --orange-l: #FFF4EC;
  --orange-b: #E9B595;
  --red-d: #8A2A08;
  --red-l: #FDE8E1;
  --green: #1E6B3C;
  --green-l: #EAF5EE;
  --purple: #6A2BB8;
  --purple-l: #F1EAFB;
  --gray-l: #EDECE7;
  --r: 14px;
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Unbounded', 'Manrope', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; }
a { color: var(--blue); }
a:hover { color: var(--blue-d); }
h1 { font-family: var(--display); font-weight: 600; font-size: 28px; letter-spacing: -0.01em; margin: 0; line-height: 1.2; }
h2 { font-size: 18px; font-weight: 800; margin: 0 0 12px; }
h3 { font-size: 15px; font-weight: 800; margin: 16px 0 8px; }
p { margin: 0 0 10px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.loading, .empty { padding: 24px; text-align: center; color: var(--ink-2); }
.empty.err { color: var(--red-d); }

/* ---------- Ilova tuzilmasi ---------- */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding: 12px 24px; background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { font-family: var(--display); font-weight: 600; font-size: 16px; color: var(--ink); text-decoration: none; }
.brand.big { font-size: 24px; text-align: center; }
.nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1 1 500px; }
.nav-a { padding: 9px 12px; border-radius: 10px; text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: 14px; white-space: nowrap; }
.nav-a:hover { background: var(--ground); color: var(--ink); }
.nav-a[aria-current="page"] { background: var(--blue); color: #fff; font-weight: 700; }
.me { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.me-a { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.me-n { display: flex; flex-direction: column; line-height: 1.2; }
.me-n small { color: var(--ink-2); font-size: 12px; }
.ava { display: inline-flex; width: 36px; height: 36px; border-radius: 50%; background: var(--dark); color: #fff; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; flex: none; }
.ava.r-admin { background: #B23A0A; }
.ava.r-keyaccount { background: var(--purple); }
.ava.r-omborchi { background: var(--green); }
.ava.r-usta, .ava.r-agent { background: var(--blue); }

.main { max-width: 1360px; margin: 0 auto; padding: 24px 24px 64px; }
.main.mobile { max-width: 640px; padding: 16px 16px 96px; }
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--paper); border-top: 1px solid var(--line); padding: 6px 6px calc(8px + env(safe-area-inset-bottom)); z-index: 10; }
.bottom-nav .nav-a { flex: 1; text-align: center; min-height: 48px; display: flex; align-items: center; justify-content: center; font-size: 13px; padding: 6px 4px; white-space: normal; line-height: 1.15; }
.app.has-bottom .me-n { display: none; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; margin-bottom: 20px; }
.page-head .sub, .sub { color: var(--ink-2); font-size: 15px; margin-top: 6px; }
.back { display: inline-block; font-weight: 700; font-size: 14px; text-decoration: none; margin-bottom: 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 20px; }
.narrow { max-width: 760px; }

.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 16px; }
.right { text-align: right; }
.center { text-align: center; }
.small { font-size: 13px; }
.hint { color: var(--ink-2); font-size: 13px; margin-bottom: 8px; }
.t-red { color: var(--orange-d); }
.t-green { color: var(--green); }

.cols { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.col-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.col-side { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 16px; }
.span2 { grid-column: 1 / -1; }

/* ---------- Kartalar va ko'rsatkichlar ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; margin-bottom: 20px; }
.col-main > .card, .col-side > .card, .two > .card { margin-bottom: 0; }
.card.tight { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; margin-bottom: 0; }
.card-head { margin-bottom: 4px; }
.card-head h2 { margin-bottom: 12px; }
.accent-border { border: 2px solid var(--blue); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stats.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats.three-col { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; text-align: left; min-width: 0; }
.stat-l { font-size: 13px; color: var(--ink-2); font-weight: 700; }
.stat-v { font-family: var(--display); font-size: 24px; font-weight: 600; line-height: 1.15; overflow-wrap: anywhere; }
.stat-v small { font-family: var(--font); font-size: 14px; color: var(--ink-2); font-weight: 600; }
.stat-s { font-size: 13px; color: var(--ink-2); }
.stat.warn { background: var(--orange-l); border-color: var(--orange-b); }
.stat.warn .stat-l { color: var(--orange-d); }
.stat.good { background: var(--green-l); border-color: #A8D5B7; }
.stat.dark { background: var(--dark); border-color: var(--dark); color: #fff; }
.stat.dark .stat-l, .stat.dark .stat-s { color: var(--dark-2); }
.stat.pick { cursor: pointer; font: inherit; color: inherit; }
.stat.pick.on { background: var(--dark); border-color: var(--dark); color: #fff; }
.stat.pick.on .stat-l, .stat.pick.on .stat-s, .stat.pick.on .stat-v small { color: var(--dark-2); }
.three-col .stat { padding: 12px; }
.three-col .stat-v { font-size: 20px; font-family: var(--font); font-weight: 800; }

.bar { flex: 1; height: 8px; background: #E8E6DF; border-radius: 4px; min-width: 60px; overflow: hidden; }
.bar-in { height: 8px; background: var(--blue); border-radius: 4px; }
.bar-in.warn { background: var(--orange); }

.hbars { display: flex; align-items: flex-end; gap: 6px; height: 200px; border-bottom: 1px solid var(--field); padding-top: 8px; }
.hbar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; min-width: 0; }
.hbar span { font-size: 11px; font-weight: 700; }
.hbar small { font-size: 11px; color: var(--ink-2); position: relative; top: 18px; }
.hbar-in { width: 100%; max-width: 40px; background: var(--blue); border-radius: 6px 6px 0 0; }

/* ---------- Jadval ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; color: var(--ink-2); font-size: 12.5px; font-weight: 700; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 11px 8px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl td.b { font-weight: 700; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #FAFAF7; }

.list { display: flex; flex-direction: column; }
.li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-2); text-decoration: none; color: inherit; font-size: 14px; }
.li:last-child { border-bottom: 0; }
.li > span { display: flex; flex-direction: column; min-width: 0; }
.li small { color: var(--ink-2); font-size: 12.5px; }
.li.check { justify-content: flex-start; cursor: pointer; }
.li.check input { width: 22px; height: 22px; flex: none; }
.rank { list-style: none; margin: 0; padding: 0; counter-reset: r; }
.rank li { counter-increment: r; display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-2); }
.rank li::before { content: counter(r); width: 26px; height: 26px; border-radius: 50%; background: var(--gray-l); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; flex: none; }
.rank li:first-child::before { background: var(--orange); color: #fff; }
.rank li > span { flex: 1; display: flex; flex-direction: column; }
.rank li small { color: var(--ink-2); font-size: 12px; }

.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; background: var(--gray-l); color: var(--ink-2); }
.badge.blue { background: var(--blue-l); color: var(--blue-d); }
.badge.green { background: var(--green-l); color: var(--green); }
.badge.orange { background: var(--orange-l); color: var(--orange-d); }
.badge.red { background: var(--red-l); color: var(--red-d); }
.badge.purple { background: var(--purple-l); color: #4B1D87; }

.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert { display: block; background: var(--orange-l); border-radius: 12px; padding: 11px 14px; font-size: 14px; color: var(--ink); text-decoration: none; }
.alert.red { background: var(--red-l); }
a.alert:hover { color: var(--ink); filter: brightness(0.98); }

.chip { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: 64px; min-height: 48px; padding: 4px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--ground); color: var(--ink); cursor: pointer; text-decoration: none; font-weight: 700; font-size: 14px; }
.chip small { font-size: 11px; font-weight: 600; }
.chip.on { background: var(--blue); border-color: var(--blue); color: #fff; }

.debt-box { background: var(--red-l); color: var(--red-d); border-radius: 12px; padding: 12px 14px; margin: 12px 0; font-size: 13px; font-weight: 700; }
.debt-box b { display: block; font-family: var(--display); font-weight: 600; font-size: 20px; color: var(--ink); margin-top: 4px; }
.mini-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mini-stats > div { background: var(--ground); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; }
.mini-stats small { color: var(--ink-2); font-size: 12px; font-weight: 700; }

/* ---------- Tugmalar va formalar ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent; font-weight: 700; font-size: 14.5px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-d); color: #fff; }
.btn.accent { background: var(--orange); color: #fff; }
.btn.accent:hover { background: var(--orange-d); color: #fff; }
.btn.ghost { background: var(--paper); border-color: var(--field); color: var(--ink); }
.btn.ghost:hover { background: var(--ground); }
.btn.ghost.danger { color: var(--red-d); }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 13px; }
.btn.big { min-height: 54px; font-size: 16px; font-weight: 800; width: 100%; margin-top: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--field); background: var(--paper); font-size: 20px; line-height: 1; cursor: pointer; flex: none; color: var(--ink-2); }
.icon-btn:hover { background: var(--ground); color: var(--ink); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.inp { min-height: 44px; padding: 0 12px; border: 1px solid var(--field); border-radius: 10px; background: var(--paper); font-size: 15px; width: 100%; min-width: 0; }
select.inp { padding-right: 28px; }
.toolbar .inp, .page-head .inp, .row .inp { width: auto; }
.form-err { color: var(--red-d); font-weight: 700; font-size: 14px; min-height: 0; }
.form-err:empty { display: none; }
.form-err:not(:empty) { background: var(--red-l); padding: 10px 12px; border-radius: 10px; }
.check-box { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--ground); cursor: pointer; font-size: 14px; margin: 10px 0; }
.check-box input { width: 22px; height: 22px; margin: 0; flex: none; }
.check-box span { display: flex; flex-direction: column; }
.check-box small { color: var(--ink-2); font-size: 13px; }

.items { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.items-row { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; padding-bottom: 8px; border-bottom: 1px solid var(--line-2); }
.items-row select.inp { flex: 1 1 180px; width: auto; }
.items-row .inp.qty { flex: 0 0 96px; width: 96px; }
.items-info { flex: 1 1 100%; order: 5; font-size: 12.5px; color: var(--ink-2); }
.items-info:empty { display: none; }
.items-info.bad { color: var(--red-d); font-weight: 800; }
.items-total { font-weight: 800; }

/* ---------- Telefon ekranlari ---------- */
.m-stack { display: flex; flex-direction: column; gap: 14px; }
.m-stack h1 { font-size: 22px; }
.m-stack h2 { margin: 0; }
.m-stack .card { margin-bottom: 0; }
.m-hello .sub { font-size: 14px; margin-top: 4px; }
.m-dark { background: var(--dark); color: #fff; border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.m-dark.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.m-dark-l { font-size: 12.5px; color: var(--dark-2); font-weight: 600; }
.m-dark-t { font-size: 18px; font-weight: 800; }
.m-dark-v { font-family: var(--display); font-size: 30px; font-weight: 600; }
.m-dark-v small { font-family: var(--font); font-size: 14px; color: var(--dark-2); }
.m-dark-s { font-size: 13px; color: var(--dark-2); }
.stepper { display: flex; align-items: center; gap: 10px; }
.step-b { width: 48px; height: 48px; border-radius: 14px; border: 1px solid var(--field); background: var(--paper); font-size: 24px; font-weight: 700; cursor: pointer; }
.step-b.plus { background: var(--blue); color: #fff; border-color: var(--blue); }
.stepper.big .step-b { width: 64px; height: 64px; font-size: 28px; }
.step-v { min-width: 40px; text-align: center; font-size: 20px; font-weight: 800; }
.step-v.big { font-family: var(--display); font-size: 40px; font-weight: 600; min-width: 110px; }
.brak-row { padding-top: 12px; border-top: 1px solid var(--line-2); margin-top: 6px; }
.big-n { font-size: 18px; font-weight: 800; }
.seg { gap: 6px; }
.seg-b { flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--field); background: var(--paper); font-weight: 700; cursor: pointer; }
.seg-b.on.green { background: var(--green); border-color: var(--green); color: #fff; }
.seg-b.on.red { background: var(--orange-d); border-color: var(--orange-d); color: #fff; }
.seg-b.on.orange { background: var(--orange-l); border-color: var(--orange-b); color: var(--orange-d); }
.card.tight .row .btn { flex: 1; }

/* ---------- Kirish sahifasi ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 400px; background: var(--paper); border: 1px solid var(--line); border-radius: 20px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-box .sub { text-align: center; margin: -6px 0 6px; }

/* ---------- Modal va bildirishnoma ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(20, 22, 30, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 50; overflow-y: auto; }
.modal { width: 100%; max-width: 480px; background: var(--paper); border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px 20px 20px; }
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(92vw, 460px); }
.toast { background: var(--dark); color: #fff; padding: 12px 16px; border-radius: 12px; font-weight: 700; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); }
.toast.err { background: var(--red-d); }
.toast.warn { background: var(--orange-d); }

@media (max-width: 720px) {
  .top { padding: 10px 16px; gap: 10px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .me-n { display: none; }
  .main { padding: 16px 16px 64px; }
  h1 { font-size: 22px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-v { font-size: 19px; }
  .card { padding: 14px; }
  .toolbar .inp { flex: 1 1 140px; }
}

/* Telefonda kiritish maydonlarining shrifti 16px dan KICHIK bo'lsa, iOS Safari
   maydonga bosilganda ekranni o'zi kattalashtiradi va orqaga qaytarmaydi —
   sahifa "yopishib qolgandek" tuyuladi, kursorni ham topib bo'lmaydi.
   Shuning uchun telefonda aniq 16px qilamiz. Kompyuterda 15px qolaveradi. */
@media (max-width: 767px) {
  .inp,
  input[type="text"], input[type="password"], input[type="number"],
  input[type="tel"], input[type="email"], input[type="search"],
  input[type="date"], input[type="time"], input:not([type]),
  select, textarea {
    font-size: 16px;
  }
}
