/* ===== Fonts (self-hosted for offline use) ===== */
@font-face { font-family: 'Space Grotesk'; src: url('../fonts/space-grotesk-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Space Grotesk'; src: url('../fonts/space-grotesk-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('../fonts/inter-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('../fonts/inter-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('../fonts/inter-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('../fonts/inter-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('../fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('../fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }

/* ===== Tokens ===== */
:root {
  --bg: #F0EFEA;
  --surface: #FFFFFF;
  --surface-sunken: #E8E7E1;
  --navy: #1A2033;
  --navy-2: #2A3150;
  --ink: #23273A;
  --muted: #6E7280;
  --line: #DCDBD4;
  --amber: #C8822A;
  --amber-ink: #7A4E14;
  --teal: #1E7A73;
  --teal-bg: #E1F1EF;
  --success: #2F7A4F;
  --success-bg: #E5F2EA;
  --danger: #B23B3B;
  --danger-bg: #FBEAEA;
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 20px;
  --shadow: 0 1px 2px rgba(26,32,51,0.06), 0 4px 14px rgba(26,32,51,0.06);
  --font-display: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'Inter', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
svg { width: 20px; height: 20px; flex-shrink: 0; display: block; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, h3, .display { font-family: var(--font-display); letter-spacing: -0.01em; }
button, input, select, textarea { font-family: inherit; }
a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ===== App shell ===== */
#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding-bottom: 84px;
  position: relative;
}

.topbar { position: sticky; top: 0; z-index: 20; background: var(--navy); color: #fff; padding: 18px 18px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 3px solid var(--amber); }
.topbar .title-block { display: flex; flex-direction: column; }
.topbar > svg { width: 30px; height: 30px; color: rgba(255,255,255,0.25); }
.topbar .eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #B7BCD6;
}
.topbar h1 { margin: 2px 0 0; font-size: 20px; font-weight: 700; color: #fff; }
.topbar .icon-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.16);
  color: #fff;
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.topbar .icon-btn svg { width: 19px; height: 19px; }
.topbar .icon-btn:active { background: rgba(255,255,255,0.18); }

.view { padding: 16px; animation: viewIn 220ms ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===== Bottom nav ===== */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  z-index: 30;
  box-shadow: 0 -2px 10px rgba(26,32,51,0.06);
}
.tabbar button {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 2px;
  color: var(--muted);
  font-size: 11px;
  border-radius: 10px;
  cursor: pointer;
}
.tabbar button svg { width: 21px; height: 21px; }
.tabbar button.active { color: var(--navy); }
.tabbar button.active svg { color: var(--amber); }
.tabbar .fab {
  color: #fff;
  background: var(--navy);
  border-radius: 12px;
  margin: -14px 4px 0;
  padding-top: 10px;
  box-shadow: 0 3px 10px rgba(26,32,51,0.3);
}
.tabbar .fab.active { color: #fff; }
.tabbar .fab svg { color: var(--amber); }

/* ===== Cards & lists ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card-tight { padding: 12px 14px; }

.stat-row { display: flex; gap: 10px; margin-bottom: 14px; }
.stat {
  flex: 1;
  background: var(--navy);
  color: #fff;
  border-radius: var(--radius-m);
  padding: 14px;
  position: relative;
  overflow: hidden;
}
.stat::after {
  content: '';
  position: absolute; right: -14px; top: -14px;
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(200,130,42,0.25);
}
.stat .label { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: #B7BCD6; }
.stat .value { font-family: var(--font-display); font-size: 20px; font-weight: 700; margin-top: 4px; }

.section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 18px 2px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.doc-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.doc-row:last-child { border-bottom: none; }
.doc-tag {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-family: var(--font-display); font-weight: 700; font-size: 13px;
}
.doc-tag.invoice { background: #E9ECF6; color: var(--navy-2); }
.doc-tag.quote { background: #FBF0DE; color: var(--amber-ink); }
.doc-tag.challan { background: var(--teal-bg); color: var(--teal); }
.doc-row .info { flex: 1; min-width: 0; }
.doc-row .info .name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-row .info .meta { font-size: 12px; color: var(--muted); font-family: var(--font-mono); margin-top: 2px; }
.doc-row .amount { font-family: var(--font-mono); font-weight: 500; font-size: 14px; text-align: right; }
.doc-row .amount .status { display: block; font-size: 10.5px; margin-top: 3px; }

.status-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 20px;
}
.status-pill.draft { background: var(--surface-sunken); color: var(--muted); }
.status-pill.sent, .status-pill.dispatched { background: #E9ECF6; color: var(--navy-2); }
.status-pill.paid, .status-pill.accepted, .status-pill.delivered { background: var(--success-bg); color: var(--success); }
.status-pill.overdue, .status-pill.rejected { background: var(--danger-bg); color: var(--danger); }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state svg { width: 52px; height: 52px; color: var(--line); margin-bottom: 12px; }
.empty-state h3 { margin: 0 0 6px; color: var(--ink); font-size: 16px; }
.empty-state p { margin: 0; font-size: 13.5px; line-height: 1.5; }

/* ===== Forms ===== */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-s);
  padding: 11px 12px;
  font-size: 15px;
  color: var(--ink);
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--navy); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

.toggle-group { display: flex; gap: 8px; }
.toggle-group button {
  flex: 1;
  border: 1.5px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-s);
  padding: 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.toggle-group button.active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-s);
  padding: 13px 18px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:active { background: var(--navy-2); }
.btn-amber { background: var(--amber); color: #26170A; }
.btn-ghost { background: var(--surface-sunken); color: var(--ink); }
.btn-outline { background: transparent; color: var(--navy); border: 1.5px solid var(--line); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn-sm { padding: 8px 12px; font-size: 13px; width: auto; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.fab-add {
  position: fixed;
  right: 18px;
  bottom: 92px;
  z-index: 25;
  width: 56px; height: 56px;
  border-radius: 18px;
  background: var(--amber);
  color: #26170A;
  border: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(200,130,42,0.4);
  cursor: pointer;
}
.fab-add svg { width: 26px; height: 26px; }

/* ===== Line items editor ===== */
.item-card {
  border: 1.5px solid var(--line);
  border-radius: var(--radius-s);
  padding: 12px;
  margin-bottom: 10px;
  position: relative;
}
.item-card .item-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}
.item-card .remove-item {
  position: absolute;
  top: 10px; right: 10px;
  background: none; border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 2px;
}
.item-card .remove-item svg { width: 16px; height: 16px; }
.item-card .item-amount {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 600;
  margin-top: 6px;
  color: var(--navy);
}

.totals-box {
  background: var(--surface-sunken);
  border-radius: var(--radius-m);
  padding: 14px 16px;
}
.totals-row { display: flex; justify-content: space-between; font-size: 13.5px; padding: 4px 0; color: var(--ink); }
.totals-row.muted { color: var(--muted); }
.totals-row.grand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: var(--navy);
  border-top: 1.5px dashed var(--line);
  margin-top: 6px;
  padding-top: 10px;
}
.totals-words { font-size: 11.5px; color: var(--muted); margin-top: 8px; font-style: italic; }

/* ===== Stamp badge (signature element) ===== */
.stamp {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 2px solid currentColor;
  border-radius: 40px;
  padding: 4px 10px;
  transform: rotate(-3deg);
}
.stamp.paid { color: var(--success); }
.stamp.pop-in { animation: stampPop 320ms cubic-bezier(.2,1.6,.4,1); }
@keyframes stampPop { 0% { transform: rotate(-3deg) scale(0.4); opacity: 0; } 60% { transform: rotate(-3deg) scale(1.12); opacity: 1; } 100% { transform: rotate(-3deg) scale(1); } }

/* ===== Modal / sheet ===== */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(26,32,51,0.45);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 180ms ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 86vh;
  overflow-y: auto;
  animation: slideUp 220ms ease;
}
@keyframes slideUp { from { transform: translateY(16px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 0 0 14px; font-size: 18px; }
.sheet-handle {
  width: 36px; height: 4px; background: var(--line); border-radius: 4px;
  margin: 0 auto 14px;
}

.customer-pick {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border: 1.5px solid var(--line); border-radius: var(--radius-s);
  margin-bottom: 8px; cursor: pointer;
}
.customer-pick .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}

.toast {
  position: fixed;
  bottom: 96px; left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 11px 18px;
  border-radius: 30px;
  font-size: 13.5px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
  z-index: 60;
  animation: toastIn 200ms ease;
  display: flex; align-items: center; gap: 8px;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.logo-drop {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-s);
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
}
.logo-drop img { max-height: 56px; max-width: 100%; }

.install-banner {
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  color: #fff;
  border-radius: var(--radius-m);
  padding: 14px 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.install-banner .txt { flex: 1; font-size: 13px; line-height: 1.4; }
.install-banner .txt b { display: block; font-family: var(--font-display); font-size: 14.5px; margin-bottom: 2px; }
