:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 14px rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Heebo', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; }

.boot-loader { display: flex; justify-content: center; padding: 40vh 0; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
}
.topbar .logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 18px; color: var(--primary);
  text-decoration: none; cursor: pointer; background: none; border: none; padding: 0;
}
.topbar .logo img { width: 28px; height: 28px; border-radius: 7px; }
.topbar .spacer { flex: 1; }
.topbar .title { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn {
  background: var(--primary-soft); color: var(--primary-dark);
  border: none; border-radius: 999px; padding: 7px 14px;
  font-weight: 600; font-size: 14px; cursor: pointer;
}
.back-btn {
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: var(--muted); padding: 2px 6px; line-height: 1;
}

.container { max-width: 760px; margin: 0 auto; padding: 16px 16px 96px; }

/* ---------- cards / general ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 10px; font-size: 16px; }
.muted { color: var(--muted); font-size: 13px; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.zero { color: var(--muted); }

.chip {
  display: inline-block; background: var(--bg); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 10px; font-size: 12px; color: var(--muted);
}
.chip.role-owner { background: var(--primary-soft); color: var(--primary-dark); border-color: transparent; }

.empty {
  text-align: center; color: var(--muted); padding: 36px 16px; font-size: 15px;
}
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 10px 16px; font-size: 15px; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-danger { background: none; border-color: var(--danger-soft); color: var(--danger); }
.btn-ghost { border-color: transparent; background: none; color: var(--primary-dark); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.fab {
  position: fixed; bottom: 22px; inset-inline-start: 22px; z-index: 15;
  background: var(--primary); color: #fff; border: none; border-radius: 999px;
  padding: 14px 22px; font-size: 16px; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 20px rgba(15, 118, 110, 0.4);
}

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--primary-soft); border-color: var(--primary);
}
.field textarea { resize: vertical; min-height: 64px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.form-error { color: var(--danger); font-size: 14px; margin: 8px 0; min-height: 18px; }

.check-list { display: flex; flex-direction: column; gap: 4px; }
.check-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
}
.check-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }
.check-item .share-input {
  width: 110px; margin-inline-start: auto;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
}
.split-remain { font-size: 13px; font-weight: 600; margin-top: 6px; }

.radio-row { display: flex; gap: 14px; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
/* undo the generic .field input styling for radios/checkboxes */
.radio-row input, .field input[type="radio"], .field input[type="checkbox"] {
  width: auto; border: none; padding: 0; accent-color: var(--primary);
}

/* ---------- login ---------- */
.auth-wrap { max-width: 400px; margin: 8vh auto 0; padding: 0 18px; }
.auth-logo { text-align: center; margin-bottom: 18px; }
.auth-logo img { width: 64px; height: 64px; border-radius: 16px; }
.auth-logo h1 { margin: 10px 0 2px; font-size: 26px; color: var(--primary); }
.auth-logo p { margin: 0; color: var(--muted); font-size: 14px; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.auth-tabs button {
  flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--border);
  background: none; font-weight: 600; cursor: pointer; color: var(--muted);
}
.auth-tabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.join-banner {
  background: var(--primary-soft); color: var(--primary-dark);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 14px;
  font-size: 14px; font-weight: 600; text-align: center;
}

/* ---------- project list ---------- */
.proj-card { cursor: pointer; transition: transform 0.1s; }
.proj-card:active { transform: scale(0.99); }
.proj-card .head { display: flex; align-items: baseline; gap: 8px; }
.proj-card .head .name { font-size: 17px; font-weight: 700; flex: 1; }
.proj-card .stats { display: flex; gap: 16px; margin-top: 8px; flex-wrap: wrap; }
.proj-card .stat .v { font-weight: 700; font-size: 15px; }
.proj-card .stat .k { font-size: 12px; color: var(--muted); }
.archived-badge { background: var(--bg); color: var(--muted); border-radius: 6px; padding: 2px 8px; font-size: 11px; }

/* ---------- tabs ---------- */
.tabs {
  position: sticky; top: 53px; z-index: 15;
  display: flex; gap: 2px; background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none; padding: 0 8px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: none; background: none; padding: 12px 14px; font-size: 14.5px;
  font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
  border-bottom: 2.5px solid transparent;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- summary strip ---------- */
.strip { display: flex; gap: 10px; margin-bottom: 14px; }
.strip .box {
  flex: 1; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px; text-align: center;
}
.strip .box .v { font-size: 18px; font-weight: 800; }
.strip .box .k { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters select {
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
  background: var(--card); font-size: 13px; color: var(--text); max-width: 46%;
}
.filters input[type="search"] {
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
  background: var(--card); font-size: 13px; color: var(--text); flex: 1; min-width: 120px;
}

/* ---------- expense list ---------- */
.month-head {
  display: flex; align-items: baseline; margin: 18px 4px 8px;
  font-size: 14px; font-weight: 700; color: var(--muted);
}
.month-head .sum { margin-inline-start: auto; font-weight: 600; font-size: 13px; }
.exp-item {
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 8px; display: flex; align-items: center;
  gap: 12px; cursor: pointer;
}
.exp-item .info { flex: 1; min-width: 0; }
.exp-item .desc { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp-item .meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; flex-wrap: wrap; }
.exp-item .amount { font-weight: 800; font-size: 16px; white-space: nowrap; }

/* ---------- balance ---------- */
.bal-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.bal-row:last-child { border-bottom: none; }
.bal-row .who { flex: 1; }
.bal-row .who .nm { font-weight: 700; }
.bal-row .who .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.bal-row .amt { font-weight: 800; font-size: 16px; white-space: nowrap; }
.bal-bar { height: 5px; border-radius: 4px; background: var(--bg); margin-top: 6px; overflow: hidden; }
.bal-bar > div { height: 100%; border-radius: 4px; }

.settle-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--bg); border-radius: 10px; margin-bottom: 8px; font-size: 14.5px;
}
.settle-row .txt { flex: 1; }
.settle-row b { font-weight: 800; }

.pay-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.pay-item:last-child { border-bottom: none; }
.pay-item .txt { flex: 1; }
.pay-item .date { color: var(--muted); font-size: 12.5px; }

/* ---------- report ---------- */
.rep-row { margin-bottom: 12px; }
.rep-row .line { display: flex; align-items: baseline; font-size: 14.5px; margin-bottom: 4px; }
.rep-row .line .nm { flex: 1; font-weight: 600; }
.rep-row .line .v { font-weight: 700; }
.rep-row .line .pct { color: var(--muted); font-size: 12px; margin-inline-start: 6px; }
.rep-bar { height: 7px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.rep-bar > div { height: 100%; background: var(--primary); border-radius: 4px; }

table.rep-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.rep-table th { text-align: start; color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.rep-table td { padding: 8px 4px; border-bottom: 1px solid var(--border); }
table.rep-table tr:last-child td { border-bottom: none; }

/* ---------- members ---------- */
.mem-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.mem-row:last-child { border-bottom: none; }
.mem-row .avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--primary-soft);
  color: var(--primary-dark); display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; flex-shrink: 0;
}
.mem-row .info { flex: 1; min-width: 0; }
.mem-row .nm { font-weight: 700; }
.mem-row .em { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.invite-box {
  background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-top: 10px;
  font-size: 13px; word-break: break-all;
}

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; padding: 18px 18px 26px;
  max-height: 92vh; overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 24px; }
  .modal { border-radius: 18px; padding: 22px; }
}
.modal .modal-head { display: flex; align-items: center; margin-bottom: 14px; }
.modal .modal-head h2 { margin: 0; font-size: 18px; flex: 1; }
.modal .close-x { background: none; border: none; font-size: 22px; color: var(--muted); cursor: pointer; padding: 2px 8px; }

/* ---------- receipts ---------- */
.receipt-row { display: flex; gap: 8px; flex-wrap: wrap; min-height: 24px; align-items: center; }
.receipt-thumb { position: relative; display: inline-block; }
.receipt-thumb img {
  width: 64px; height: 64px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--border); cursor: pointer; display: block;
}
.thumb-x {
  position: absolute; top: -6px; inset-inline-end: -6px;
  width: 20px; height: 20px; border-radius: 50%; border: none;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 1;
  cursor: pointer; padding: 0;
}

/* ---------- activity ---------- */
.act-row { display: flex; align-items: baseline; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.act-row:last-child { border-bottom: none; }
.act-row .act-txt { flex: 1; }
.act-row .date { color: var(--muted); font-size: 12px; white-space: nowrap; }

hr.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---------- toast ---------- */
#toast-root { position: fixed; bottom: 90px; inset-inline-start: 0; inset-inline-end: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--text); color: #fff; border-radius: 10px; padding: 10px 18px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
  max-width: 90vw;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.toast.warn { background: #d97706; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
