:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #1e3a8a;
  --brand-2: #2546a8;
  --owed: #dc2626;
  --owed-bg: #fef2f2;
  --paid: #15803d;
  --paid-bg: #f0fdf4;
  --wa: #25d366;
  --radius: 14px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px 96px; }

/* top bar */
.bar {
  position: sticky; top: 0; z-index: 5;
  background: var(--brand); color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
}
.bar-in { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.bar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar small { display: block; font-weight: 400; opacity: .8; font-size: 13px; }
.icon-btn {
  background: rgba(255,255,255,.12); border: 0; color: #fff;
  width: 40px; height: 40px; border-radius: 12px; font-size: 18px;
  display: inline-grid; place-items: center; flex: none;
}
.icon-btn:hover { background: rgba(255,255,255,.22); }

/* summary */
.hero { background: var(--brand); color: #fff; padding: 0 16px 22px; border-radius: 0 0 22px 22px; }
.hero-in { max-width: 760px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); border-radius: var(--radius); padding: 12px 14px; }
.stat span { font-size: 12.5px; opacity: .85; }
.stat b { display: block; font-size: 22px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.big { grid-column: 1 / -1; }
.stat.big b { font-size: 30px; }
.stat.owed { background: rgba(220,38,38,.25); border-color: rgba(252,165,165,.6); }

/* search + list */
.search {
  width: 100%; margin: 16px 0 10px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
.search:focus, .field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent;
}
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; background: none; border: 0; border-top: 1px solid var(--line); text-align: start;
}
.row:first-child { border-top: 0; }
.row:hover { background: #f8fafc; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700;
  background: #e0e7ff; color: var(--brand);
}
.row-main { flex: 1; min-width: 0; }
.row-main b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main small { color: var(--muted); font-size: 12.5px; }
.amt { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.owed { color: var(--owed); }
.amt.paid { color: var(--paid); }
.amt.zero { color: var(--muted); font-weight: 600; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* buttons */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--brand); color: #fff;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.job { background: #ea580c; }
.btn.pay { background: var(--paid); }
.btn.wa { background: var(--wa); color: #06361a; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid #c7d2fe; }
.btn.danger { background: transparent; color: var(--owed); border: 1px solid #fecaca; }
.btn.block { width: 100%; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0 10px; }
.actions .btn { padding: 14px 10px; font-size: 16px; }
.fab {
  position: fixed; right: max(16px, calc(50% - 364px)); bottom: calc(env(safe-area-inset-bottom) + 18px);
  box-shadow: 0 8px 24px rgba(30,58,138,.35); border-radius: 16px; padding: 14px 20px; z-index: 6;
}

/* timeline of a client */
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 18px 2px 8px; color: var(--muted); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.entry .avatar { border-radius: 12px; font-size: 18px; }
.entry.job .avatar { background: #ffedd5; }
.entry.pay .avatar { background: var(--paid-bg); }
.bal { display: block; color: var(--muted); font-size: 12px; font-weight: 500; text-align: end; }
.note { background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; padding: 10px 12px; margin-top: 12px; font-size: 14px; white-space: pre-wrap; }

/* modal */
.shade {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--card); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 16px);
}
@media (min-width: 600px) {
  .shade { align-items: center; }
  .sheet { border-radius: 20px; }
}
.sheet h2 { margin: 0 0 14px; font-size: 18px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input, .field textarea, .field select {
  width: 100%; padding: 12px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff;
}
.field textarea { min-height: 70px; resize: vertical; }
.field input.money { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sheet-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
.sheet-btns .btn { flex: 1 1 140px; }
.slip {
  background: #e7fbe9; border: 1px solid #bbf7d0; border-radius: 12px; padding: 12px;
  white-space: pre-wrap; font-family: inherit; font-size: 14px; line-height: 1.5; margin: 0 0 12px; overflow-wrap: anywhere;
}
.err { color: var(--owed); font-size: 14px; min-height: 20px; margin: 0 0 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

/* login */
.login { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.login .card { background: var(--card); border-radius: 18px; padding: 22px; border: 1px solid var(--line); }
.login h1 { text-align: center; margin: 12px 0 18px; font-size: 22px; }
.login img { display: block; margin: 0 auto; width: 56px; height: 56px; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translateX(-50%) translateY(20px);
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: .2s; z-index: 30; max-width: calc(100% - 32px); text-align: center;
}
#toast.on { opacity: 1; transform: translateX(-50%); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; border: 1px solid #cbd5e1; background: #fff; border-radius: 10px; padding: 9px 6px; font-weight: 600; }
.seg button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
