:root {
  --bg: #f3f1ec; --panel: #ffffff; --ink: #17201f; --muted: #6b7774; --line: #e3dfd6;
  --brand: #0f3d3e; --brand-2: #1f6f6b; --accent: #e8a33d; --accent-ink: #3b2a0d;
  --ok: #2f8f5b; --warn: #d08a14; --bad: #c2453a; --info: #2f6fb5;
  --soft: #eef4f2; --radius: 12px; --shadow: 0 1px 2px rgba(15,61,62,.06), 0 4px 16px rgba(15,61,62,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: 'Manrope', system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-2); }
.mono, .num { font-family: 'JetBrains Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 10% -10%, #1f6f6b 0, transparent 60%), var(--brand); }
.login form { background: var(--panel); width: 100%; max-width: 360px; padding: 28px; border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.02em; }
.login p { margin: 0 0 20px; color: var(--muted); }
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; }
.logo i { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; color: var(--accent-ink); font-style: normal; font-size: 15px; }

/* Layout */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #d8e7e4; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.side .logo { color: #fff; padding: 4px 8px 18px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: inherit; text-decoration: none; font-weight: 600; margin-bottom: 2px; }
.side nav a:hover { background: rgba(255,255,255,.07); }
.side nav a.on { background: rgba(255,255,255,.13); color: #fff; }
.side nav a .ic { width: 20px; text-align: center; opacity: .9; }
.side .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .5; padding: 14px 10px 6px; }
.side .me { margin-top: 18px; padding: 12px 10px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; }
.side .me b { color: #fff; display: block; }
.main { padding: 22px 26px 60px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; flex: 1; min-width: 180px; }
.mobile-top { display: none; }
.tabbar { display: none; }

/* Mobile app layout (agent / courier / small screens) */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .side.open { display: block; position: fixed; inset: 0; z-index: 50; width: 260px; }
  .main { padding: 70px 14px 90px; }
  .mobile-top { display: flex; position: fixed; top: 0; left: 0; right: 0; z-index: 40; height: 56px; align-items: center; gap: 10px; padding: 0 14px; background: var(--brand); color: #fff; }
  .mobile-top .logo { color: #fff; flex: 1; font-size: 15px; }
  .mobile-top button { background: none; border: 0; color: #fff; font-size: 20px; padding: 6px; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { flex: 1; text-align: center; padding: 8px 2px 9px; font-size: 11px; font-weight: 600; color: var(--muted); text-decoration: none; }
  .tabbar a .ic { display: block; font-size: 19px; margin-bottom: 1px; }
  .tabbar a.on { color: var(--brand-2); }
  .top h2 { font-size: 19px; }
  .hide-m { display: none !important; }
}

/* Components */
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) { .g2, .g3 { grid-template-columns: 1fr; } }
.stat { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stat .l { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 22px; font-weight: 800; margin-top: 4px; letter-spacing: -.02em; }
.stat .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat.accent { background: var(--brand); color: #fff; }
.stat.accent .l, .stat.accent .s { color: #b9d3cf; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 9px; font-weight: 700; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: #c9c3b6; }
.btn.p { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.p:hover { background: var(--brand-2); }
.btn.a { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: #fff; border-color: #f0c9c4; color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.lg { padding: 12px 18px; font-size: 15px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.sp { flex: 1; }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.inp, input:not([type]), input[type=text], input[type=number], input[type=password], input[type=date], input[type=month], input[type=tel], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(31,111,107,.12); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters > * { width: auto; min-width: 130px; }
.filters input[type=search] { min-width: 220px; flex: 1; }
.chk { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-weight: 600; }
.chk input { width: 18px; height: 18px; }
.days { display: flex; gap: 4px; }
.days label { flex: 1; text-align: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px 0; cursor: pointer; font-weight: 700; font-size: 12px; }
.days input { display: none; }
.days label:has(input:checked) { background: var(--brand); color: #fff; border-color: var(--brand); }

table.t { width: 100%; border-collapse: collapse; }
.tw { overflow-x: auto; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #faf9f6; position: sticky; top: 0; }
table.t td { padding: 10px 12px; border-bottom: 1px solid #f0ede6; vertical-align: middle; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #faf8f3; }
table.t td.r, table.t th.r { text-align: right; }
table.t tfoot td { font-weight: 800; background: #faf9f6; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; background: #eee; }
.b-yangi { background: #e5effa; color: var(--info); }
.b-tasdiqlandi { background: #e9f3ee; color: #23744a; }
.b-yigildi { background: #f1ecfb; color: #6a48b0; }
.b-yolda { background: #fdf2e0; color: #a5680a; }
.b-yetkazildi { background: #dff1e6; color: #1d6b41; }
.b-bekor { background: #f8e3e1; color: var(--bad); }
.b-qaytarildi { background: #ede9e3; color: #6b5f4d; }
.debt { color: var(--bad); font-weight: 800; }
.pos { color: var(--ok); font-weight: 800; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 8px 12px; border-radius: 9px; font-weight: 700; color: var(--muted); cursor: pointer; }
.tabs button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.tabs button .n { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 6px; font-size: 11px; margin-left: 4px; }

/* Modal */
.ov { position: fixed; inset: 0; background: rgba(15,30,30,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 14px; overflow: auto; }
.md { background: var(--panel); border-radius: 16px; width: 100%; max-width: 560px; box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.md.wide { max-width: 920px; }
.md .mh { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.md .mh h3 { margin: 0; flex: 1; font-size: 17px; }
.md .mh button { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.md .mb { padding: 18px; }
.md .mf { padding: 12px 18px 16px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--line); }
@media (max-width: 860px) { .ov { padding: 0; align-items: flex-end; } .md { border-radius: 18px 18px 0 0; max-height: 92vh; overflow: auto; } }

#toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.2); max-width: 380px; font-weight: 600; animation: tin .2s; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes tin { from { transform: translateY(-8px); opacity: 0; } }

/* Order builder & field cards */
.plist { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow: auto; }
.pitem { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.pitem.on { border-color: var(--brand-2); background: var(--soft); }
.pitem .nm { flex: 1; min-width: 0; }
.pitem .nm b { display: block; font-size: 14px; }
.pitem .nm small { color: var(--muted); }
.qty { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.qty button { border: 0; background: #f6f4ef; width: 34px; height: 34px; font-size: 18px; font-weight: 700; cursor: pointer; }
.qty input { width: 58px; border: 0; text-align: center; padding: 0; height: 34px; border-radius: 0; box-shadow: none !important; }
.summary { position: sticky; top: 16px; }
.summary .ln { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.summary .ln.bonus { color: var(--ok); }
.summary .tot { display: flex; justify-content: space-between; font-size: 20px; font-weight: 800; padding-top: 12px; }
.warn { background: #fff6e6; border: 1px solid #f3dcae; color: #7a5208; border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-size: 13px; }
.cl { display: flex; gap: 12px; align-items: center; padding: 13px 14px; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 8px; cursor: pointer; }
.cl .av { width: 40px; height: 40px; border-radius: 11px; background: var(--soft); color: var(--brand); display: grid; place-items: center; font-weight: 800; flex-shrink: 0; }
.cl .av.done { background: var(--ok); color: #fff; }
.cl .av.seen { background: #fdf2e0; color: #a5680a; }
.cl .in { flex: 1; min-width: 0; }
.cl .in b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cl .in small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; font-weight: 600; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.map { height: 520px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.gps-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #999; margin-right: 6px; }
.gps-dot.on { background: #3ddc84; box-shadow: 0 0 0 3px rgba(61,220,132,.25); }
.chart-box { position: relative; height: 260px; }
.progress { height: 8px; background: #eee; border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress i { display: block; height: 100%; background: var(--brand-2); }
.progress i.hi { background: var(--ok); }
.progress i.lo { background: var(--warn); }

@media print { .side, .tabbar, .mobile-top, .top .btn, .filters { display: none !important; } .main { padding: 0; } .shell { display: block; } }
.filters > input, .filters > select { width: auto; flex: 0 1 auto; }
.filters > input[type=search] { flex: 1 1 220px; }
@media (max-width: 860px) { .filters > input, .filters > select { flex: 1 1 140px; } }
