:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e7e9f0;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --dr: #c2410c;
  --cr: #047857;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d14; --card: #151925; --text: #e8ebf5; --muted: #8b93a7; --line: #232838;
    --accent: #8b8cff; --accent-soft: #1f2240; --dr: #fb923c; --cr: #34d399; --danger: #f87171;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d14; --card: #151925; --text: #e8ebf5; --muted: #8b93a7; --line: #232838;
  --accent: #8b8cff; --accent-soft: #1f2240; --dr: #fb923c; --cr: #34d399; --danger: #f87171;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Devanagari", sans-serif;
  min-height: 100vh; overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.dr { color: var(--dr); }
.cr { color: var(--cr); }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-mark { width: 44px; height: 44px; border-radius: 14px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; border-radius: 12px; font-weight: 600; transition: transform .05s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--accent-soft); color: var(--accent); }
.btn-block { width: 100%; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }

/* ---------- app shell */
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  padding: 12px 16px 0;
}
.topline { display: flex; align-items: center; gap: 10px; max-width: 760px; margin: 0 auto; }
.who { flex: 1; min-width: 0; }
.who b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { color: var(--muted); font-size: 12px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); }
.icon-btn:active { background: var(--line); }
.tabs {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 12px 0 12px;
  max-width: 760px; margin: 0 auto;
}
.tabs::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line);
  font-size: 14px; font-weight: 500; white-space: nowrap; color: var(--muted);
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
main { max-width: 760px; margin: 0 auto; padding: 4px 16px 120px; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card);
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  display: flex; justify-content: center;
}
.bottomnav .inner { display: flex; width: 100%; max-width: 560px; }
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0;
  color: var(--muted); font-size: 11px; font-weight: 500; position: relative;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn.on { color: var(--accent); }
.badge {
  position: absolute; top: 2px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; display: grid; place-items: center;
}

/* ---------- cards & lists */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.hero { padding: 18px; margin-bottom: 14px; }
.hero .label { font-size: 13px; color: var(--muted); }
.hero .big { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0 2px; }
.hero .row { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.hero .row div { font-size: 13px; color: var(--muted); }
.hero .row b { display: block; color: var(--text); font-size: 15px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.toolbar .input { padding: 11px 12px; }
.select { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.daterange { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: -4px 0 12px; }
.daterange span { display: block; font-size: 12px; color: var(--muted); margin: 0 0 4px 2px; }
.daterange .input { padding: 10px 12px; }
.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 8px; }
.list { overflow: hidden; }
.item { display: flex; gap: 12px; padding: 13px 14px; border-top: 1px solid var(--line); align-items: center; }
.item:first-child { border-top: 0; }
.item.tap:active { background: var(--accent-soft); }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .end { text-align: right; }
.item .end .sub { font-size: 12px; }
.datebox { width: 42px; flex: none; text-align: center; line-height: 1.1; }
.datebox b { display: block; font-size: 17px; }
.datebox span { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 8px; }

/* ---------- stepper & cart */
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; flex: none; }
.stepper button { width: 34px; height: 34px; font-size: 18px; color: var(--accent); }
.stepper input { width: 46px; height: 34px; text-align: center; border: 0; background: transparent; outline: none; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.add-btn { padding: 8px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 14px; flex: none; }
.cartbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(70px + env(safe-area-inset-bottom)); z-index: 25;
  max-width: 736px; margin: 0 auto; background: var(--text); color: var(--bg); border-radius: 16px;
  padding: 12px 14px 12px 18px; display: flex; align-items: center; gap: 12px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .25); animation: up .2s ease-out;
}
.cartbar .main { flex: 1; }
.cartbar small { opacity: .7; display: block; font-size: 12px; }
.cartbar .btn { background: var(--accent); color: #fff; padding: 10px 16px; }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.pill.new { background: #fef3c7; color: #92400e; }
.pill.exported { background: #dbeafe; color: #1e40af; }
.pill.accepted { background: #dcfce7; color: #166534; }
.pill.rejected, .pill.cancelled { background: #fee2e2; color: #991b1b; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pill.new { background: #3b2f0b; color: #fcd34d; }
  :root:not([data-theme="light"]) .pill.exported { background: #172554; color: #93c5fd; }
  :root:not([data-theme="light"]) .pill.accepted { background: #052e16; color: #86efac; }
  :root:not([data-theme="light"]) .pill.rejected, :root:not([data-theme="light"]) .pill.cancelled { background: #3f0d0d; color: #fca5a5; }
}

/* ---------- bottom sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 40; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--card);
  border-radius: 22px 22px 0 0; max-height: 92vh; display: flex; flex-direction: column;
  max-width: 760px; margin: 0 auto; animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 10px auto 2px; }
.sheet header { display: flex; align-items: center; gap: 8px; padding: 6px 16px 10px; }
.sheet header h2 { flex: 1; font-size: 18px; margin: 0; }
.sheet .body { overflow-y: auto; padding: 0 16px 16px; }
.sheet footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
@keyframes fade { from { opacity: 0; } }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl .r { text-align: right; }
.totals { margin-top: 12px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .net { font-size: 18px; font-weight: 700; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; margin-bottom: 12px; }
.kv span { color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 60;
  font-size: 14px; max-width: calc(100vw - 32px); animation: up .2s ease-out;
}
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.groupchips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: -2px 0 12px; }
.groupchips::-webkit-scrollbar { display: none; }
.groupchips .chip { padding: 6px 12px; font-size: 13px; }
textarea.input { resize: vertical; min-height: 64px; }
@media (min-width: 700px) { .hero .big { font-size: 34px; } }
