:root {
  --bg: #faf6f1;
  --surface: #ffffff;
  --surface-2: #f3ece4;
  --line: #e6dccf;
  --text: #2a211b;
  --muted: #7a6a5c;
  --brand: #b4541a;
  --brand-ink: #ffffff;
  --brand-soft: #fbe7d8;
  --good: #1f7a4d;
  --good-soft: #dff3e8;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --info: #3b5bab;
  --info-soft: #e3e9f8;
  --warn: #8a5a00;
  --warn-soft: #fdf0cf;
  --violet: #6b46b5;
  --violet-soft: #ece4fa;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Bengali", "Hind Siliguri", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15110e; --surface: #1f1915; --surface-2: #2a221c; --line: #3a2f27; --text: #f3ebe3; --muted: #b3a291;
    --brand: #e7894b; --brand-ink: #1a120c; --brand-soft: #3b2618;
    --good: #5fcf95; --good-soft: #183326; --bad: #ff8a80; --bad-soft: #3a1c1a; --info: #93acf0; --info-soft: #1d2540;
    --warn: #f1c35a; --warn-soft: #3a2e12; --violet: #b9a0f0; --violet-soft: #2a2140;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15110e; --surface: #1f1915; --surface-2: #2a221c; --line: #3a2f27; --text: #f3ebe3; --muted: #b3a291;
  --brand: #e7894b; --brand-ink: #1a120c; --brand-soft: #3b2618;
  --good: #5fcf95; --good-soft: #183326; --bad: #ff8a80; --bad-soft: #3a1c1a; --info: #93acf0; --info-soft: #1d2540;
  --warn: #f1c35a; --warn-soft: #3a2e12; --violet: #b9a0f0; --violet-soft: #2a2140;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--brand); }
h3 { font-size: 1rem; margin: 18px 0 8px; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); text-align: center; gap: 12px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row-between h3 { margin: 0; }

/* ---------- layout */
.shell { min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.topbar {
  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)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.brand img { border-radius: 8px; }
.me { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
main { max-width: 860px; margin: 0 auto; padding: 12px 16px 24px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex;
  background: var(--surface); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px;
  background: none; border: 0; color: var(--muted); font-size: .72rem; border-radius: 10px;
}
.tabbar .ti { font-size: 1.25rem; line-height: 1.2; }
.tabbar button.on { color: var(--brand); font-weight: 700; }
.tabbar button.add .ti {
  display: grid; place-items: center; width: 40px; height: 32px; border-radius: 12px; background: var(--brand); color: var(--brand-ink); font-weight: 700;
}
@media (min-width: 900px) {
  .shell { padding: 0 0 0 220px; }
  .tabbar { top: 0; right: auto; width: 220px; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding: 72px 12px 12px; gap: 4px; }
  .tabbar button { flex: 0; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; font-size: .95rem; }
  .tabbar button.on { background: var(--brand-soft); }
  .tabbar button.add { order: -1; margin-bottom: 8px; background: var(--brand); color: var(--brand-ink); }
  .tabbar button.add .ti { width: auto; height: auto; background: none; color: inherit; }
  .topbar { padding-left: 24px; }
}

/* ---------- controls */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 14px 16px; margin-bottom: 12px; }
.card.pad h3:first-child { margin-top: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 8px 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .88rem; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn.danger { color: var(--bad); }
.btn.dot::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.btn:disabled { opacity: .55; }
.icon-btn { border: 0; background: var(--surface-2); width: 38px; height: 38px; border-radius: 50%; font-size: 1.05rem; flex: none; }
.linkish { border: 0; background: none; color: var(--brand); padding: 0 4px; text-decoration: underline; text-align: left; }

label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--muted); font-weight: 600; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text); font-size: 16px; font-weight: 400;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 50%, transparent); outline-offset: 0; border-color: var(--brand); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); flex-wrap: wrap; }
label.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
.hint { font-weight: 400; font-size: .8rem; color: var(--muted); width: 100%; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form h3 { margin: 6px 0 -4px; }
.grid2, .grid3 { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 520px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid3 { grid-template-columns: 1fr 1fr 1fr; } }
.grid2 .full { grid-column: 1 / -1; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.seg label { color: var(--muted); }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: block; text-align: center; padding: 10px 6px; border-radius: 9px; font-weight: 600; }
.seg input:checked + span { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--brand); }
.seg.small span { padding: 6px; }
.warn { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: .9rem; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
details { margin: 10px 0; }
summary { cursor: pointer; font-weight: 600; padding: 6px 0; }

/* ---------- auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; padding: 24px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.auth-card img { margin: 0 auto; border-radius: 14px; }
.auth-card h1 { margin: 0; font-size: 1.4rem; }
.auth-card label { text-align: left; }

/* ---------- orders list */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.search { flex: 1; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 10px; align-items: end; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: .88rem; white-space: nowrap;
}
.chip b { font-weight: 700; margin-left: 2px; color: var(--muted); }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chip.on b { color: inherit; }
.stage-hint { margin: 0 0 8px; min-height: 1em; }
.list { display: flex; flex-direction: column; gap: 10px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.order { overflow: hidden; border-left: 4px solid var(--line); }
.order.st-new { border-left-color: var(--warn); }
.order.st-to_pack { border-left-color: var(--brand); }
.order.st-shipped { border-left-color: var(--info); }
.order.st-delivered { border-left-color: var(--violet); }
.order.st-completed { border-left-color: var(--good); }
.order.st-cancelled { border-left-color: var(--bad); opacity: .75; }
.o-open { padding: 12px 14px 8px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.o-head { display: flex; align-items: center; gap: 8px; }
.o-no { color: var(--muted); font-weight: 700; font-size: .9rem; }
.o-name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.o-line { font-size: .9rem; }
.phone { font-weight: 600; text-decoration: none; font-variant-numeric: tabular-nums; }
.phone.big { font-size: 1.1rem; }
.o-addr { font-size: .9rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.o-items { font-weight: 600; }
.o-money { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .92rem; }
.due { color: var(--bad); font-weight: 700; }
.paid { color: var(--good); font-weight: 700; }
.o-when { font-size: .88rem; font-weight: 600; color: var(--info); }
.o-note { font-size: .9rem; background: var(--warn-soft); color: var(--text); border-radius: 8px; padding: 6px 10px; margin-top: 4px; white-space: pre-wrap; }
.o-note.parcel { background: var(--info-soft); }
.o-note.bad { background: var(--bad-soft); }

.badge { flex: none; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.st-new { background: var(--warn-soft); color: var(--warn); }
.badge.st-to_pack { background: var(--brand-soft); color: var(--brand); }
.badge.st-shipped { background: var(--info-soft); color: var(--info); }
.badge.st-delivered { background: var(--violet-soft); color: var(--violet); }
.badge.st-completed { background: var(--good-soft); color: var(--good); }
.badge.st-cancelled { background: var(--bad-soft); color: var(--bad); }

.flags { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); }
.flag {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border: 0; background: none;
  font-size: .72rem; color: var(--muted); line-height: 1.2; text-align: center;
}
.flag + .flag { border-left: 1px solid var(--line); }
.box {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line);
  font-weight: 800; font-size: .9rem; flex: none;
}
.flag.on { color: var(--good); font-weight: 700; }
.flag.on .box, .flag-row.on .box { background: var(--good); border-color: var(--good); color: #fff; }
.flag:disabled { opacity: .45; }
.flag.on:disabled { opacity: .8; }

/* ---------- detail */
.detail .d-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.detail .d-row.big { font-size: 1.15rem; }
.d-addr { white-space: pre-wrap; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 6px 0 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0 0 10px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
table.items { width: 100%; border-collapse: collapse; font-size: .93rem; margin: 6px 0 10px; }
table.items td { padding: 6px 2px; border-bottom: 1px solid var(--line); }
table.items .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.items tr.sum td { font-weight: 700; }
.flag-list { display: flex; flex-direction: column; gap: 6px; }
.flag-row {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 12px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: left;
}
.flag-row .by { grid-column: 2; }
.flag-row.on { border-color: var(--good); background: var(--good-soft); }
.flag-row.danger.on { border-color: var(--bad); background: var(--bad-soft); }
.flag-row.danger.on .box { background: var(--bad); border-color: var(--bad); }
.flag-row:disabled { opacity: .55; }
.flag-row .fl { font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 4px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; font-size: .92rem; }
.timeline.big li { padding: 10px 14px; }
.chg { display: block; font-size: .85rem; color: var(--muted); }
.chg s { opacity: .7; }
.tick { color: var(--good); font-weight: 700; }
.untick { color: var(--bad); font-weight: 600; }

/* ---------- order form */
.item-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); position: relative; margin-bottom: 8px;
}
@media (min-width: 560px) { .item-row { grid-template-columns: 1.1fr 1fr 1.3fr 1fr auto; align-items: end; } }
.item-row .rm { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; }
@media (min-width: 560px) { .item-row .rm { position: static; } }
.stepper { display: flex; }
.stepper button { width: 42px; border: 1px solid var(--line); background: var(--surface); font-size: 1.2rem; font-weight: 700; }
.stepper button:first-child { border-radius: 10px 0 0 10px; }
.stepper button:last-child { border-radius: 0 10px 10px 0; }
.stepper input { border-radius: 0; text-align: center; border-left: 0; border-right: 0; min-width: 0; }
.totals { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; }
.totals div { display: flex; justify-content: space-between; }
.totals .sum { font-weight: 700; font-size: 1.1rem; border-top: 1px solid var(--line); padding-top: 4px; }

/* ---------- dashboard */
.periods { margin-bottom: 10px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } .kpi.hero { grid-column: span 2; } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.kpi span { color: var(--muted); font-size: .85rem; font-weight: 600; }
.kpi b { font-size: 1.45rem; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: .8rem; }
.kpi.hero { background: var(--brand-soft); border-color: transparent; }
.kpi.hero b { font-size: 1.8rem; color: var(--brand); }
.pipeline { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 700px) { .pipeline { grid-template-columns: repeat(6, 1fr); } }
.pipe { border: 0; border-radius: 12px; padding: 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; background: var(--surface-2); font-size: .82rem; }
.pipe b { font-size: 1.35rem; }
.pipe.st-new { background: var(--warn-soft); color: var(--warn); }
.pipe.st-to_pack { background: var(--brand-soft); color: var(--brand); }
.pipe.st-shipped { background: var(--info-soft); color: var(--info); }
.pipe.st-delivered { background: var(--violet-soft); color: var(--violet); }
.pipe.st-completed { background: var(--good-soft); color: var(--good); }
.pipe.st-cancelled { background: var(--bad-soft); color: var(--bad); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 170px; overflow-x: auto; padding-top: 6px; }
.bar { flex: 1 0 22px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 2px; }
.bar .col { width: 70%; max-width: 32px; background: var(--brand); border-radius: 5px 5px 2px 2px; }
.bar .v { font-size: .72rem; color: var(--muted); }
.bar .x { font-size: .7rem; color: var(--muted); white-space: nowrap; }
.share { display: grid; grid-template-columns: minmax(90px, auto) 1fr auto; align-items: center; gap: 10px; padding: 5px 0; font-size: .92rem; }
.share .track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.share .track span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.share .num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- team */
.role { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.role-admin { background: var(--brand-soft); color: var(--brand); }
.role-message { background: var(--info-soft); color: var(--info); }
.role-parcel { background: var(--good-soft); color: var(--good); }
.person {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 10px 4px;
  background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left;
}
.person.off { opacity: .55; }
.roles { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.roles legend { font-size: .88rem; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.role-opt { flex-direction: row; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); }
.role-opt input { width: 20px; height: 20px; min-height: 0; margin-top: 2px; accent-color: var(--brand); flex: none; }
.role-opt span { display: flex; flex-direction: column; }
.role-opt small { color: var(--muted); font-weight: 400; }
.role-opt:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.price-row { align-items: end; }

/* ---------- sheet */
#sheet-root { display: none; }
#sheet-root.open { display: block; position: fixed; inset: 0; z-index: 20; }
.backdrop { position: absolute; inset: 0; background: rgba(20, 12, 6, .45); animation: fade .15s ease-out; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 20px 20px 0 0; animation: up .2s ease-out;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 1.12rem; }
.sheet-body { overflow-y: auto; padding: 14px 16px calc(24px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; top: 50%; bottom: auto; transform: translate(-50%, -50%); width: 560px; max-height: 88vh; border-radius: 20px; animation: fade .15s ease-out; }
  .sheet.wide { width: 720px; }
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet, .backdrop { animation: none; } }

/* ---------- toast */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .92rem; max-width: calc(100vw - 32px);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); color: #fff; }
