:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f766e;
  --brand-dark: #0b5d57;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --ok: #15803d;
  --ok-bg: #f0fdf4;
  --info: #1d4ed8;
  --info-bg: #eff6ff;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 14px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 500px at 50% -10%, #0f766e22, transparent), var(--bg);
}
.login-card {
  width: min(380px, 100%);
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.login-logo { width: 64px; height: 64px; margin: 0 auto; }
.login-card h1 { margin: 4px 0 0; font-size: 24px; }
.login-card .muted { margin: 0 0 8px; }
.login-card form { display: contents; }
.login-qr {
  border-top: 1px solid #e2e8f0;
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.login-qr img { background: #fff; border-radius: 10px; }
.login-qr p { margin: 0; }
@media (max-width: 640px) {
  .login-qr { display: none; }
}

/* ---------- shell ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 34px; height: 34px; }
.brand strong { display: block; font-size: 15px; }
.brand .muted { color: #94a3b8; }
.icon-btn {
  background: transparent;
  border: 0;
  color: inherit;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(148, 163, 184, .15); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

.view {
  padding: 16px;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  max-width: 760px;
  margin: 0 auto;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  padding: 8px 2px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}
.nav-item svg { width: 22px; height: 22px; fill: currentColor; }
.nav-item.active { color: var(--brand); font-weight: 600; }

/* ---------- components ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 10px; font-size: 15px; }
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 2px 8px;
}
.section-title h2 { font-size: 16px; margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 12px 14px; }
.stat .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat .value { font-size: 20px; font-weight: 700; letter-spacing: -.3px; }
.stat .value.danger { color: var(--danger); }
.stat .value.ok { color: var(--ok); }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.danger { background: var(--danger-bg); color: var(--danger); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.muted { background: #f1f5f9; color: var(--muted); }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row .end { text-align: right; }
.row .end .amount { font-weight: 700; font-size: 14px; }

.search {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.search input { flex: 1; }

input, select, textarea {
  width: 100%;
  font: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
textarea { resize: vertical; min-height: 70px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 13px; font-weight: 600; color: #334155; }
.field .hint { font-size: 12px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; }
tr.overdue td { background: var(--danger-bg); }

.fab-row { display: flex; gap: 10px; margin: 4px 0 12px; }
.fab-row .btn { flex: 1; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 16px;
  font-size: 14px;
}

.code-box {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  padding: 16px;
  background: #f1f5f9;
  border-radius: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.qr-box { text-align: center; padding: 8px 0; }
.qr-box img, .qr-box svg { width: min(280px, 100%); height: auto; background: #fff; border-radius: 12px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, .5);
  display: grid;
  place-items: end center;
  padding: 0;
}
.modal {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp .18s ease-out;
}
@media (min-width: 640px) {
  .modal-backdrop { place-items: center; padding: 24px; }
  .modal { border-radius: 18px; }
}
@keyframes slideUp { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 8px;
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-body {
  padding: 4px 18px 22px;
  overflow-y: auto;
  padding-bottom: calc(22px + env(safe-area-inset-bottom));
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 80;
  box-shadow: var(--shadow);
  max-width: 90vw;
  text-align: center;
}
.toast.error { background: var(--danger); }
