:root {
  --brand: #4f46e5; --brand2: #7c3aed; --ink: #111827; --muted: #6b7280; --line: #e5e7eb;
  --bg: #f4f4fb; --ok: #059669; --okbg: #d1fae5; --warn: #c2410c; --warnbg: #ffedd5;
  --mid: #a16207; --midbg: #fef9c3; --info: #1d4ed8; --infobg: #dbeafe; --bad: #dc2626;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; }
body {
  font-family: "Baloo Bhai 2", "Noto Sans Gujarati", "Gujarati Sangam MN", "Shruti", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.45;
}
body.noscroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }

/* Auth screens */
.auth {
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 20px 24px;
  background: linear-gradient(160deg, var(--brand), var(--brand2));
}
.auth .logo {
  width: 84px; height: 84px; border-radius: 22px; background: rgba(255,255,255,.18); color: #fff;
  display: grid; place-items: center; font-size: 46px; font-weight: 800; margin-bottom: 14px;
}
.auth h1 { color: #fff; font-size: 26px; margin-bottom: 4px; text-align: center; }
.auth p.sub { color: rgba(255,255,255,.85); margin-bottom: 20px; text-align: center; }
.auth .card { width: 100%; max-width: 400px; }

/* Header + tabs */
header.top {
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(135deg, var(--brand), var(--brand2)); color: #fff;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}
header.top .brand { font-size: 20px; font-weight: 800; }
header.top .who { font-size: 13px; opacity: .85; }
main#view { padding: 14px 14px calc(150px + env(safe-area-inset-bottom)); }
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr); max-width: 560px; margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  border: 0; background: none; padding: 8px 2px 6px; font-size: 13px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 0; cursor: pointer;
}
nav.tabs button span { font-size: 20px; line-height: 1.2; }
nav.tabs button.on { color: var(--brand); font-weight: 700; }

h1.title { font-size: 22px; font-weight: 800; margin: 2px 2px 12px; }
h2 { font-size: 20px; margin-bottom: 12px; }
h3 { font-size: 16px; margin: 18px 0 8px; color: var(--brand); }

/* Cards & lists */
.card { background: #fff; border-radius: 16px; padding: 14px; box-shadow: 0 1px 3px rgba(17,24,39,.08); }
.list { display: flex; flex-direction: column; gap: 10px; }
.list .card { cursor: pointer; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: #fff; border-radius: 14px; padding: 10px; text-align: center; box-shadow: 0 1px 3px rgba(17,24,39,.08); }
.stat b { display: block; font-size: 18px; color: var(--brand); }
.stat span { font-size: 13px; color: var(--muted); }

.search {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; margin-bottom: 10px;
}
.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; font-size: 14px;
  white-space: nowrap; cursor: pointer;
}
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.tag { border-radius: 999px; padding: 1px 10px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.st-working { background: var(--infobg); color: var(--info); }
.st-pending { background: var(--warnbg); color: var(--warn); }
.st-partial { background: var(--midbg); color: var(--mid); }
.st-paid { background: var(--okbg); color: var(--ok); }
.filterbar { background: var(--infobg); color: var(--info); border-radius: 10px; padding: 6px 10px; margin-bottom: 10px; font-size: 14px; display: flex; justify-content: space-between; }

/* Buttons */
.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px; margin-top: 12px;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 16px; cursor: pointer;
}
.btn.ghost { background: #eef2ff; color: var(--brand); }
.btn.wa { background: #16a34a; }
.btn.danger { background: #fee2e2; color: var(--bad); }
.btn:disabled { opacity: .5; }
.link { border: 0; background: none; color: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; }
.fab {
  position: fixed; z-index: 7; right: max(16px, calc(50% - 264px)); bottom: calc(76px + env(safe-area-inset-bottom));
  border: 0; border-radius: 999px; padding: 13px 20px; background: var(--brand); color: #fff; font-weight: 800; font-size: 16px;
  box-shadow: 0 8px 20px rgba(79,70,229,.4); cursor: pointer;
}

/* Forms */
label { display: block; font-size: 14px; font-weight: 700; color: #374151; margin-top: 10px; }
label input, label select, label textarea, .picker input {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px; border: 1px solid #d1d5db; border-radius: 10px;
  background: #fff; font-weight: 400; font-size: 16px;
}
label input:focus, label select:focus, label textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.warn { color: var(--warn); font-size: 14px; margin-top: 6px; }
.err { color: var(--bad); font-size: 14px; margin-top: 8px; min-height: 20px; }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; }

.picker { position: relative; }
.pk-list {
  display: none; position: absolute; left: 0; right: 0; top: 100%; z-index: 3; background: #fff; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,.12); max-height: 260px; overflow-y: auto;
}
.pk-list.open { display: block; }
.pk-list button {
  display: flex; justify-content: space-between; width: 100%; border: 0; background: none; text-align: left;
  padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; font-weight: 400;
}
.pk-list button span { color: var(--muted); font-size: 13px; }
.pk-list .pk-add { color: var(--brand); font-weight: 700; }

.calc { background: #eef2ff; border-radius: 12px; padding: 12px; margin-top: 12px; }
.calc .row { padding: 2px 0; }
.calc .total { font-size: 20px; font-weight: 800; color: var(--brand); border-top: 1px dashed #c7d2fe; margin-top: 6px; padding-top: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { text-align: right; font-weight: 700; }
.audit { font-size: 13px; color: var(--muted); margin-top: 14px; border-top: 1px solid var(--line); padding-top: 8px; }

/* Sheets (pop-up forms) */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 20; background: rgba(17,24,39,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  position: relative; background: #fff; width: 100%; max-width: 560px; max-height: 94vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet .x {
  position: absolute; top: 10px; right: 10px; border: 0; background: #f3f4f6; width: 34px; height: 34px;
  border-radius: 50%; font-size: 16px; cursor: pointer;
}
.sheet img.invoice { width: 100%; border-radius: 10px; border: 1px solid var(--line); }

#toast {
  position: fixed; left: 50%; bottom: calc(140px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 15px; z-index: 40;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }
.proto { background: var(--midbg); color: var(--mid); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 12px; }
.menu .card { margin-bottom: 10px; }
.menu .item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.menu .item:last-child { border-bottom: 0; }
