/* app.css — visual language: navy app bar, soft canvas, white cards,
   pastel action tiles, pill chips, fixed bottom tab bar.
   Mobile first; capped at 720px on desktop. */

:root {
  --navy: #14396a;
  --navy-deep: #0d2a50;
  --blue: #1d6af0;
  --blue-soft: #e8f0fe;
  --mint: #17a673;
  --mint-soft: #e4f7ef;
  --pink: #e2574c;
  --pink-soft: #fdecea;
  --amber: #e8930c;
  --amber-soft: #fdf1de;
  --violet: #7b5cf0;
  --violet-soft: #eee9fd;

  --bg: #f4f6fa;
  --card: #ffffff;
  --line: #e5eaf2;
  --ink: #101c2e;
  --ink-2: #35435a;
  --muted: #6b7a90;

  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(16, 28, 46, .06), 0 8px 24px rgba(16, 28, 46, .06);
  --shadow-lift: 0 12px 32px rgba(16, 28, 46, .16);
  --nav-h: 64px;
  --tap: 44px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea, button { font-family: inherit; }
a { color: var(--blue); text-decoration: none; }

/* ---------------------------------------------------------- app chrome */

.app-shell {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
}

.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: #fff;
  padding: 12px 16px 14px;
  box-shadow: 0 4px 16px rgba(13, 42, 80, .18);
}

.app-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 42px; height: 42px;
  flex: 0 0 42px;
  border-radius: 50%;
  background: #fff;
  color: var(--navy);
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px;
  letter-spacing: .02em;
  box-shadow: inset 0 0 0 2px rgba(20, 57, 106, .12);
}

.brand { min-width: 0; flex: 1; }
.brand-name {
  display: flex; align-items: center; gap: 6px;
  font-size: 17px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-name svg { flex: 0 0 auto; opacity: .8; }
.brand-sub {
  display: flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: rgba(255, 255, 255, .72);
  margin-top: 2px;
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: #43d39e; flex: 0 0 6px; }
.dot.warn { background: var(--amber); }
.dot.bad { background: #ff7b72; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 30px; padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .38);
  background: rgba(255, 255, 255, .08);
  color: #fff; font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
.pill.solid { background: var(--blue); border-color: var(--blue); }
.icon-btn {
  width: 36px; height: 36px; flex: 0 0 36px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: #fff;
}
.icon-btn:active { background: rgba(255, 255, 255, .22); }

.page { padding: 16px 14px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 24px); }

/* ------------------------------------------------------------- blocks */

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  margin: 18px 2px 10px;
}
.section-head:first-child { margin-top: 2px; }
.section-title {
  font-size: 11.5px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}
.section-hint { font-size: 12px; color: var(--blue); font-weight: 600; }

.tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.tile {
  border: 0;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px 6px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-align: center;
}
.tile:active { transform: scale(.97); }
.tile-ico {
  width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center;
}
.tile-label { font-size: 11.5px; font-weight: 600; color: var(--ink-2); line-height: 1.2; }
.tile.cream .tile-ico { background: var(--amber-soft); color: var(--amber); }
.tile.pink .tile-ico { background: var(--pink-soft); color: var(--pink); }
.tile.mint .tile-ico { background: var(--mint-soft); color: var(--mint); }
.tile.violet .tile-ico { background: var(--violet-soft); color: var(--violet); }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  background: var(--card); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 12px;
}
.stat-label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 21px; font-weight: 800; letter-spacing: -.02em; margin-top: 3px; }
.stat-value.sm { font-size: 17px; }
.stat-note { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat.mint { background: var(--mint-soft); box-shadow: none; }
.stat.mint .stat-value { color: #0d7a53; }
.stat.pink { background: var(--pink-soft); box-shadow: none; }
.stat.pink .stat-value { color: #b23b32; }
.stat.amber { background: var(--amber-soft); box-shadow: none; }
.stat.amber .stat-value { color: #a86a06; }

/* chart */
.chart {
  display: flex; align-items: flex-end; gap: 10px;
  height: 130px; padding-top: 14px;
}
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart-bar {
  width: 100%; max-width: 26px; border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, #4c8df5, var(--blue));
  min-height: 3px;
}
.chart-bar.dim { background: #d9e4f7; }
.chart-lbl { font-size: 10.5px; color: var(--muted); }

/* chips */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  height: 34px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink-2);
  font-size: 12.5px; font-weight: 600;
}
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }

/* buttons */
.btn {
  height: var(--tap);
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 0 16px;
  font-size: 14px; font-weight: 650;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--ink);
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.success { background: var(--mint); border-color: var(--mint); color: #fff; }
.btn.danger { background: #fff; border-color: #f3c9c6; color: var(--pink); }
.btn.ghost { background: var(--bg); border-color: transparent; }
.btn.block { width: 100%; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 12.5px; border-radius: 10px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

/* fields */
.field { margin-bottom: 12px; }
.field > label {
  display: block; font-size: 11.5px; font-weight: 700;
  color: var(--muted); letter-spacing: .04em; text-transform: uppercase;
  margin-bottom: 6px;
}
.input, .select, .textarea {
  width: 100%; height: var(--tap);
  border: 1px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--ink);
  padding: 0 12px; font-size: 15px;
  outline: none;
}
.textarea { height: auto; min-height: 76px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 106, 240, .12);
}
.input::placeholder { color: #9aa7b8; }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.err { font-size: 11.5px; color: var(--pink); margin-top: 5px; }

/* search */
.search {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--line);
  border-radius: 14px; padding: 0 6px 0 12px; height: 48px;
  box-shadow: var(--shadow);
}
.search svg { color: var(--muted); flex: 0 0 auto; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: none;
  font-size: 15px; background: transparent; height: 100%;
}
.search .scan-btn {
  width: 38px; height: 38px; flex: 0 0 38px;
  border: 0; border-radius: 10px; background: var(--blue-soft); color: var(--blue);
  display: grid; place-items: center;
}

/* list rows */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%;
}
.list-row:last-child { border-bottom: 0; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-size: 14.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.list-right { text-align: right; flex: 0 0 auto; }
.list-amount { font-size: 14.5px; font-weight: 700; }
.thumb {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 11px;
  background: var(--blue-soft); color: var(--navy);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}

/* badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .03em;
  text-transform: uppercase;
}
.badge.paid { background: var(--mint-soft); color: #0d7a53; }
.badge.unpaid { background: var(--amber-soft); color: #a86a06; }
.badge.partial { background: var(--violet-soft); color: #5a3fd0; }
.badge.void { background: #eef1f5; color: var(--muted); }
.badge.due { background: var(--pink-soft); color: #b23b32; }

/* invoice card */
.inv-card { padding: 14px; }
.inv-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.inv-no { font-size: 14px; font-weight: 750; letter-spacing: -.01em; }
.inv-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.inv-amt { font-size: 18px; font-weight: 800; letter-spacing: -.02em; text-align: right; }
.inv-balance { font-size: 11.5px; color: var(--pink); text-align: right; margin-top: 1px; font-weight: 600; }
.inv-actions { display: flex; gap: 8px; margin-top: 12px; }
.inv-actions > * { flex: 1; }

/* cart */
.cart-line {
  padding: 12px 0;
  border-bottom: 1px dashed var(--line);
}
.cart-line:last-child { border-bottom: 0; }
.cart-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.cart-name { font-size: 14px; font-weight: 650; }
.cart-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.cart-total { font-size: 14.5px; font-weight: 750; white-space: nowrap; }
.cart-controls { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.stepper {
  display: inline-flex; align-items: center;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  height: 36px; background: #fff;
}
.stepper button {
  width: 36px; height: 36px; border: 0; background: #fff;
  font-size: 18px; font-weight: 600; color: var(--navy);
  display: grid; place-items: center;
}
.stepper button:active { background: var(--blue-soft); }
.stepper input {
  width: 46px; height: 36px; border: 0; text-align: center;
  font-size: 14px; font-weight: 650; outline: none; background: #fff;
}
.rate-input {
  width: 96px; height: 36px; border: 1px solid var(--line); border-radius: 10px;
  padding: 0 10px; text-align: right; font-size: 14px; font-weight: 600; outline: none;
}
.cart-x {
  margin-left: auto; width: 36px; height: 36px; border: 0; border-radius: 10px;
  background: var(--pink-soft); color: var(--pink); display: grid; place-items: center;
}

/* totals */
.totals { display: flex; flex-direction: column; gap: 7px; }
.total-row { display: flex; justify-content: space-between; font-size: 13.5px; color: var(--ink-2); }
.total-row.grand {
  border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px;
  font-size: 17px; font-weight: 800; color: var(--ink);
}
.words { font-size: 11.5px; color: var(--muted); margin-top: 8px; font-style: italic; }

/* empty */
.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty-ico {
  width: 54px; height: 54px; border-radius: 18px; margin: 0 auto 10px;
  background: #fff; box-shadow: var(--shadow); display: grid; place-items: center;
  color: #b9c4d4;
}
.empty-title { font-size: 14px; font-weight: 650; color: var(--ink-2); }
.empty-sub { font-size: 12.5px; margin-top: 3px; }

/* banner */
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  border-radius: 12px; padding: 11px 12px;
  background: var(--amber-soft); color: #8a5804;
  font-size: 12.5px; line-height: 1.4;
  margin-bottom: 12px;
}
.banner.info { background: var(--blue-soft); color: #12488f; }
.banner.good { background: var(--mint-soft); color: #0d6b4a; }

/* bottom nav */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  max-width: 720px; margin: 0 auto;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: #fff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 22px rgba(16, 28, 46, .07);
  display: flex;
}
.nav-item {
  flex: 1; border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: #93a1b5; font-size: 10.5px; font-weight: 600;
  padding-top: 4px;
}
.nav-item.on { color: var(--navy); }
.nav-item.on .nav-ico { background: var(--blue-soft); color: var(--navy); }
.nav-ico {
  width: 34px; height: 26px; border-radius: 9px;
  display: grid; place-items: center; color: inherit;
}

/* sheet / modal */
.scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(9, 20, 36, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .16s ease-out;
}
.sheet {
  width: 100%; max-width: 720px;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  max-height: 92vh; display: flex; flex-direction: column;
  animation: rise .2s cubic-bezier(.2, .8, .3, 1);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 12px;
  background: #fff; border-radius: 20px 20px 0 0;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.sheet-title { font-size: 16px; font-weight: 750; flex: 1; min-width: 0; }
.sheet-close {
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: var(--bg); color: var(--ink-2); display: grid; place-items: center;
}
.sheet-body { padding: 14px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: #fff; border-top: 1px solid var(--line);
  display: flex; gap: 10px; flex: 0 0 auto;
}
.sheet-foot > .btn { flex: 1; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }

/* toast */
.toast-wrap {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 18px);
  z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  background: rgba(16, 28, 46, .94); color: #fff;
  padding: 10px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-lift);
  animation: rise .18s ease-out;
  max-width: 90vw;
}
.toast.bad { background: #b23b32; }
.toast.good { background: #0d7a53; }

/* scan overlay */
.scan-stage { position: relative; background: #000; border-radius: 14px; overflow: hidden; }
.scan-stage video { width: 100%; display: block; }
.scan-frame {
  position: absolute; inset: 18% 12%;
  border: 2px solid rgba(255, 255, 255, .9); border-radius: 14px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .35);
}
.scan-hint {
  position: absolute; left: 0; right: 0; bottom: 12px; text-align: center;
  color: #fff; font-size: 12.5px; text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}

/* split rows in sheets */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 13.5px; }
.kv + .kv { border-top: 1px solid var(--line); }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-weight: 650; text-align: right; }

.divider { height: 1px; background: var(--line); margin: 12px 0; }

/* ------------------------------------------------------------- printing */

#print-root { display: none; }

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .app-shell, .bottom-nav, .toast-wrap, .scrim { display: none !important; }
  #print-root { display: block !important; }
  .no-print { display: none !important; }
}

/* invoice document markup (also used for the on-screen preview) */
.doc { color: #000; font-size: 12px; background: #fff; }
.doc-sheet { padding: 6px 0; }
.doc-head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 2px solid #000; padding-bottom: 8px; }
.doc-shop { font-size: 17px; font-weight: 800; }
.doc-shop small { display: block; font-weight: 400; font-size: 10.5px; color: #333; margin-top: 3px; }
.doc-title { text-align: right; }
.doc-title b { font-size: 13px; letter-spacing: .1em; text-transform: uppercase; }
.doc-title div { font-size: 10.5px; color: #333; margin-top: 2px; }
.doc-party { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid #999; }
.doc-party h4 { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: #555; margin-bottom: 3px; }
.doc table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.doc th {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .05em; text-align: left;
  border-bottom: 1px solid #000; padding: 4px 3px; color: #333;
}
.doc td { padding: 5px 3px; border-bottom: 1px solid #e3e3e3; vertical-align: top; }
.doc td.n, .doc th.n { text-align: right; }
.doc-sum { margin-top: 10px; display: flex; justify-content: flex-end; }
.doc-sum table { width: 58%; margin: 0; }
.doc-sum td { border-bottom: 0; padding: 2px 0; font-size: 11.5px; }
.doc-sum tr.grand td { border-top: 1.5px solid #000; font-weight: 800; font-size: 13.5px; padding-top: 5px; }
.doc-foot { margin-top: 14px; display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; }
.doc-words { font-size: 10.5px; font-style: italic; color: #333; }
.doc-sign { text-align: center; font-size: 10px; color: #333; }
.doc-sign .line { border-top: 1px solid #000; padding-top: 3px; margin-top: 26px; }
.doc-thermal { width: 72mm; font-size: 10px; }
.doc-thermal .doc-title b { font-size: 10px; }

@media (max-width: 420px) {
  .tiles { gap: 8px; }
  .tile-ico { width: 42px; height: 42px; }
  .tile-label { font-size: 10.5px; }
  .stat-value { font-size: 19px; }
}
