:root {
  --ink: #1c2420;
  --muted: #5c6a62;
  --line: #d9dfd9;
  --bg: #f4f6f4;
  --card: #ffffff;
  --brand: #20503a;
  --brand-dark: #173d2c;
  --accent: #c8871a;
  --danger: #b3372c;
  --ok: #1e7d46;
  --warn: #b3372c;
  --radius: 12px;
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: 76px;
}

.hidden { display: none !important; }

/* ---------- top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  background: var(--brand-dark); color: #fff;
  padding: 10px 14px;
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-tag { font-size: 12px; opacity: .85; font-style: italic; }
.top-user { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* ---------- layout ---------- */
main { max-width: 760px; margin: 0 auto; padding: 14px; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }

h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 18px 0 8px; }
h3 { font-size: 15px; margin: 14px 0 6px; }

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

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.big-money { font-size: 26px; font-weight: 700; }
.money-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.money-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.money-box .label { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.money-box .value { font-size: 22px; font-weight: 700; margin-top: 2px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-block; border: 1px solid var(--brand); background: var(--brand); color: #fff;
  border-radius: 10px; padding: 10px 16px; font-size: 15px; font-weight: 600;
  cursor: pointer; text-decoration: none; text-align: center;
}
.btn:active { background: var(--brand-dark); }
.btn-secondary { background: #fff; color: var(--brand); }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.5); color: #fff; }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-small { padding: 6px 10px; font-size: 13px; }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn[disabled] { opacity: .55; cursor: default; }

/* ---------- lists ---------- */
.list-item {
  display: block; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
  color: var(--ink); text-decoration: none;
}
.list-item .title { font-weight: 700; }
.chip {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .3px;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted);
  text-transform: uppercase; vertical-align: middle;
}
.chip.signed { color: var(--ok); border-color: var(--ok); }
.chip.owed { color: var(--warn); border-color: var(--warn); }
.chip.paid { color: var(--ok); border-color: var(--ok); }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="time"], input[type="tel"], select, textarea {
  width: 100%; padding: 10px; font-size: 16px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
textarea { min-height: 70px; resize: vertical; }
.checkline { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.checkline:last-child { border-bottom: none; }
.checkline input[type="checkbox"] { width: 22px; height: 22px; margin-top: 1px; flex: none; }
.checkline .step { flex: 1; }
.switchline { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.switchline input[type="checkbox"] { width: 22px; height: 22px; }

.check-panel { border-radius: var(--radius); padding: 12px 14px; margin: 6px 0 12px; border: 1px solid var(--line); background: #fbfcfb; }
.check-panel .per { font-size: 24px; font-weight: 800; }
.check-panel.ok { border-color: var(--ok); }
.check-panel.below_target { border-color: var(--accent); }
.check-panel.below_floor { border-color: var(--danger); background: #fdf3f2; }
.flag { font-weight: 700; }
.flag.ok { color: var(--ok); }
.flag.below_target { color: var(--accent); }
.flag.below_floor { color: var(--danger); }

/* ---------- signature ---------- */
.sig-wrap { border: 1px dashed var(--muted); border-radius: 10px; background: #fff; }
.sig-canvas { display: block; width: 100%; height: 180px; touch-action: none; border-radius: 10px; }
.sig-img { max-width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar a {
  flex: 1; text-align: center; padding: 12px 2px; font-size: 13px; font-weight: 600;
  color: var(--muted); text-decoration: none;
}
#tabbar a.active { color: var(--brand); box-shadow: inset 0 2px 0 var(--brand); }

/* ---------- auth ---------- */
.auth-wrap { max-width: 420px; margin: 40px auto; }
.auth-wrap .card { padding: 20px; }
.error-box {
  background: #fdf3f2; border: 1px solid var(--danger); color: var(--danger);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px;
}

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 92px; z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; box-shadow: 0 4px 18px rgba(0,0,0,.25);
}

/* ---------- agreement ---------- */
.agreement { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.agreement h1 { font-size: 19px; text-align: center; margin-bottom: 2px; }
.agreement .svc { text-align: center; font-weight: 600; }
.agreement .tagline-line { text-align: center; font-style: italic; color: var(--muted); margin-bottom: 12px; }
.agreement ol { padding-left: 20px; }
.agreement li { margin-bottom: 8px; }
.agreement .fill { border-bottom: 1px solid var(--ink); padding: 0 4px; font-weight: 600; }

@media print {
  #topbar, #tabbar, .no-print { display: none !important; }
  body { padding-bottom: 0; background: #fff; }
  main { max-width: none; padding: 0; }
}
