/* PayClear — phone-first, white/black + teal (Life) / amber (Gym) */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --ink: #0a0a0a;
  --muted: #5c6663;
  --line: #e2e8e5;
  --accent: #0d9488;
  --accent-dark: #0f766e;
  --accent-soft: #ccfbf1;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --ok: #047857;
  --ok-bg: #d1fae5;
  --radius: 14px;
  --tap: 48px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.mode-gym {
  --accent: #ca8a04;
  --accent-dark: #a16207;
  --accent-soft: #fef9c3;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
  min-height: 100dvh;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + var(--safe-t)) 10px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.brand h1 { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.02em; }
.logo { color: var(--accent); font-size: 1.2rem; }

.mode-switch {
  display: flex;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  flex: 1;
  max-width: 180px;
  margin: 0 auto;
}

.mode-btn {
  flex: 1;
  min-height: 36px;
  border: none;
  background: transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 10px;
}
.mode-btn.active {
  background: var(--accent);
  color: #fff;
}
.mode-btn:active:not(.active) { background: var(--line); }

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  font-size: 1.3rem;
  border-radius: 12px;
  cursor: pointer;
  color: var(--ink);
  flex-shrink: 0;
}
.icon-btn:active { background: var(--line); }

.main {
  flex: 1;
  padding: 14px 14px calc(var(--nav-h) + var(--safe-b) + 20px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mode-hint {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin: 0 0 12px;
  line-height: 1.35;
}
.mode-hint strong { color: var(--ink); font-weight: 650; }

.pay-reminder {
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 12px;
  line-height: 1.4;
  text-align: center;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 30;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: transparent;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  min-height: var(--nav-h);
}
.nav-btn .nav-ico { font-size: 1.25rem; line-height: 1; }
.nav-btn.active { color: var(--accent); }
.nav-btn:active { background: var(--accent-soft); }

.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 4px 2px 10px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 14px;
  margin-bottom: 10px;
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.stat-row.three { grid-template-columns: 1fr 1fr 1fr; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.stat .label { font-size: 0.7rem; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.stat .value { font-size: 1.15rem; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; }
.stat .value.ok { color: var(--ok); }
.stat .value.warn { color: var(--warn); }
.stat .value.danger { color: var(--danger); }
.stat .value.accent { color: var(--accent-dark); }

.bill {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 12px 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  position: relative;
}
.bill:active { background: #f8faf9; }
.bill::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 4px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.bill.overdue::before { background: var(--danger); }
.bill.paid::before { background: var(--ok); }
.bill.due-soon::before { background: var(--warn); }

.bill-body { flex: 1; min-width: 0; }
.bill-name {
  font-weight: 650;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bill-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.bill-amt {
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
  letter-spacing: -0.02em;
}
.badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 999px;
}
.badge.due { background: var(--accent-soft); color: var(--accent-dark); }
.badge.overdue { background: var(--danger-bg); color: var(--danger); }
.badge.paid { background: var(--ok-bg); color: var(--ok); }
.badge.soon { background: var(--warn-bg); color: var(--warn); }

.empty {
  text-align: center;
  padding: 36px 20px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty p { color: var(--muted); margin-bottom: 16px; font-size: 0.95rem; }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-group .hint {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  margin-top: 4px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 1rem;
  background: var(--surface);
  color: var(--ink);
  appearance: none;
  -webkit-appearance: none;
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  width: 100%;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1.5px solid var(--line); }
.btn-secondary:active { background: var(--line); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-row { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.btn-row.horizontal { flex-direction: row; }
.btn-row.horizontal .btn { flex: 1; }

.link-out {
  display: block;
  padding: 12px 14px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 12px;
  font-weight: 650;
  font-size: 0.92rem;
  text-decoration: none;
  text-align: center;
  margin-bottom: 8px;
  border: 1px solid transparent;
}
.link-out:active { opacity: 0.85; }

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.search-bar input {
  flex: 1;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 1rem;
  background: var(--surface);
}
.filter-row { margin-bottom: 12px; }

.disclaimer {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  margin-top: 16px;
  padding: 0 8px;
  line-height: 1.45;
}

.detail-amt {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 4px 0 8px;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.detail-row .k { color: var(--muted); }
.detail-row .v { font-weight: 600; text-align: right; max-width: 60%; word-break: break-word; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 100;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal[hidden] { display: none; }
.modal-sheet {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + var(--safe-b));
  max-height: 90dvh;
  overflow-y: auto;
}
.modal-sheet h2 { font-size: 1.15rem; margin-bottom: 14px; }
.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 0 auto 14px;
}

.income-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
  text-align: center;
}

@media (min-width: 481px) {
  #app { box-shadow: 0 0 40px rgba(0,0,0,0.06); }
}

/* ===== v3: white / black / yellow, pay + staff ===== */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --ink: #0a0a0a;
  --muted: #6b6b6b;
  --line: #e7e7e4;
  --accent: #0a0a0a;
  --accent-dark: #0a0a0a;
  --accent-soft: #f3f3f0;
  --yellow: #ffd60a;
  --yellow-dark: #f2c200;
}
body.mode-gym { --accent: #0a0a0a; --accent-dark: #0a0a0a; --accent-soft: #f3f3f0; }

.logo {
  width: 18px; height: 18px; border-radius: 6px; background: var(--yellow);
  box-shadow: inset 0 0 0 2px var(--ink); display: inline-block;
}
.mode-switch { background: #f3f3f0; border-color: transparent; }
.mode-btn.active { background: var(--ink); color: #fff; }
.icon-btn.active { background: var(--yellow); }

.btn-primary { background: var(--yellow); color: var(--ink); letter-spacing: -0.01em; }
.btn-primary:active { background: var(--yellow-dark); }
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.4; cursor: default; }
.btn-narrow { flex: 0 0 84px !important; }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.badge.due { background: #f3f3f0; color: var(--ink); }
.bill::before { background: #d9d9d4; }
.bill, .card, .stat, .empty { border-color: var(--line); }
.stat .value { font-variant-numeric: tabular-nums; }

.nav-btn { font-size: 0.66rem; gap: 4px; }
.nav-btn .nav-ico {
  width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.nav-btn.active { color: var(--ink); }
.nav-btn.active .nav-ico { stroke-width: 2.3; }
.nav-btn.active span { font-weight: 800; }
.nav-btn:active { background: #f3f3f0; }

.help-line {
  font-size: 0.82rem; color: var(--ink); background: #fffbe0; border: 1px solid #f5e48a;
  border-radius: 10px; padding: 9px 12px; margin: 0 0 12px;
}
.card-title {
  font-size: 0.95rem; font-weight: 750; margin-bottom: 12px; letter-spacing: -0.01em;
}
.card-title span { font-weight: 500; color: var(--muted); font-size: 0.8rem; margin-left: 4px; }
.notice { font-size: 0.88rem; line-height: 1.45; }
.range-card { padding-bottom: 12px; }
.range-card .form-group { margin-bottom: 10px; }
.range-card .chip { min-height: 34px; padding: 6px 12px; font-size: 0.8rem; }
.empty.slim { padding: 18px 14px; margin-bottom: 10px; }
.empty.slim p { margin: 0; font-size: 0.88rem; }

.pay-row {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  margin-bottom: 8px; cursor: pointer;
}
.pay-row .bill-amt { font-variant-numeric: tabular-nums; }
.pay-row.missing { background: #fafaf8; border-style: dashed; }
.pay-row.missing .bill-name { color: var(--muted); }
.tick-ph {
  flex: 0 0 24px; height: 24px; border-radius: 7px; background: #f3f3f0; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.8rem;
}
.tick {
  -webkit-appearance: none; appearance: none; flex: 0 0 24px; width: 24px; height: 24px;
  border: 1.8px solid #bdbdb8; border-radius: 7px; background: #fff; margin: 0; cursor: pointer;
  display: inline-grid; place-content: center;
}
.tick::after {
  content: ""; width: 11px; height: 6px; border-left: 2.4px solid var(--ink); border-bottom: 2.4px solid var(--ink);
  transform: rotate(-45deg) translate(1px, -1px); opacity: 0;
}
.tick:checked { background: var(--yellow); border-color: var(--ink); }
.tick:checked::after { opacity: 1; }
.mini-btn {
  flex: 0 0 auto; min-height: 34px; padding: 6px 12px; border-radius: 999px; border: 1.5px solid var(--ink);
  background: #fff; font: inherit; font-size: 0.8rem; font-weight: 700; cursor: pointer; color: var(--ink);
}
.mini-btn:active { background: var(--yellow); }

.pay-bar {
  position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 8px); z-index: 10;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px; margin-top: 14px; box-shadow: 0 10px 30px rgba(0,0,0,0.08);
}
.pay-total { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.pay-total span { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.pay-total strong { font-size: 1.35rem; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.pay-bar .btn-row { margin-top: 0; }

.done-card { text-align: left; }
.done-k { font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ok); }
.done-sub { font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; line-height: 1.5; }

.switch-row { display: flex; gap: 10px; align-items: center; font-size: 0.88rem; margin: 2px 0 10px; cursor: pointer; }
.switch-row em { display: block; font-style: normal; color: var(--muted); font-size: 0.75rem; }
.card .hint { font-size: 0.74rem; color: var(--muted); line-height: 1.45; }
#pm-bpay .hint { margin: -6px 0 12px; }

.toast-undo {
  margin-left: 10px; background: var(--yellow); color: var(--ink); border: none; border-radius: 999px;
  padding: 4px 12px; font: inherit; font-weight: 800; cursor: pointer;
}

/* fixes */
.form-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.form-group input[type="date"] { min-width: 0; max-width: 100%; display: block; }
.pay-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  width: calc(100% - 20px); max-width: 460px; margin: 0;
  bottom: calc(var(--nav-h) + var(--safe-b) + 8px);
}
.main.has-paybar { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 150px); }
