:root {
  --bg: #faf7f0;
  --bg-2: #f1ead9;
  --ink: #211c16;
  --ink-soft: #6b6256;
  --line: #e3d9c4;
  --card: #fffdf8;
  --accent: #1f6f5c;
  --accent-soft: #d9efe7;
  --warn: #b4541f;
  --warn-soft: #f6e2d4;
  --good: #1f6f5c;
  --bad: #b4541f;
  --shadow: 0 1px 2px rgba(33, 28, 22, .06), 0 8px 24px rgba(33, 28, 22, .06);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15130f;
    --bg-2: #1d1a14;
    --ink: #f1ebdd;
    --ink-soft: #a89e8c;
    --line: #322c22;
    --card: #1f1b15;
    --accent: #4cc4a3;
    --accent-soft: #16302a;
    --warn: #e08a4f;
    --warn-soft: #2e2117;
    --good: #4cc4a3;
    --bad: #e08a4f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--bg-2), transparent 60%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: var(--shadow); padding: 36px 30px; max-width: 380px; width: 100%; text-align: center;
}
.brand { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.brand span { background: linear-gradient(120deg, var(--accent), var(--ink)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand.small { font-size: 1.15rem; }
.tagline { color: var(--ink-soft); margin: 14px 0 26px; line-height: 1.5; }
.gbtn { display: flex; justify-content: center; min-height: 44px; }
.fineprint { margin-top: 24px; font-size: .78rem; color: var(--ink-soft); }
.login-error { color: var(--bad); min-height: 1.2em; margin: 14px 0 0; font-size: .9rem; }

/* ---------- Shell ---------- */
.app { max-width: 640px; margin: 0 auto; padding: 0 16px 64px; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 2px; background: linear-gradient(var(--bg), color-mix(in srgb, var(--bg) 80%, transparent));
  backdrop-filter: blur(8px);
}
.me { display: flex; align-items: center; gap: 12px; }
.me-name { font-weight: 600; font-size: .92rem; }
.ghost {
  border: 1px solid var(--line); background: transparent; color: var(--ink-soft);
  padding: 7px 12px; border-radius: 10px; cursor: pointer; font-size: .82rem;
}
.ghost:hover { color: var(--ink); border-color: var(--ink-soft); }

.tabs {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 4px; margin-bottom: 18px;
}
.tab {
  border: 0; background: transparent; color: var(--ink-soft); font-weight: 600;
  padding: 9px 4px; border-radius: 10px; cursor: pointer; font-size: .9rem; transition: .15s;
}
.tab.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.panel { display: none; animation: fade .2s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Cards & list ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 1.05rem; }
.list { display: flex; flex-direction: column; gap: 12px; }

.tx {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.tx-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.tx-who { font-weight: 700; font-size: 1.02rem; line-height: 1.3; }
.tx-who .arrow { color: var(--ink-soft); font-weight: 500; }
.tx-amount { font-weight: 800; font-size: 1.1rem; white-space: nowrap; }
.tx-note { color: var(--ink-soft); font-size: .9rem; margin-top: 4px; }
.tx-meta { color: var(--ink-soft); font-size: .76rem; margin-top: 6px; }

.confirm-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; }
.chip {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-size: .72rem; font-weight: 700; border: 1.5px dashed var(--line); color: var(--ink-soft); background: transparent;
}
.chip.on { border-style: solid; border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.spacer { flex: 1; }

.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 11px; cursor: pointer; font-weight: 600; font-size: .85rem; transition: .15s;
}
.btn:hover { border-color: var(--ink-soft); }
.btn.paid { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.paid.active { background: var(--card); color: var(--accent); border-color: var(--accent); }
.btn.danger { color: var(--bad); border-color: transparent; padding: 8px 8px; }
.btn.danger:hover { background: var(--warn-soft); }

.empty { text-align: center; color: var(--ink-soft); padding: 48px 16px; }
.empty .big { font-size: 2rem; }

/* ---------- Form ---------- */
.form label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 14px; }
.form input, .form select {
  display: block; width: 100%; margin-top: 6px; padding: 11px 12px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 11px; background: var(--bg); color: var(--ink);
}
.form input:focus, .form select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { margin-bottom: 18px; }
.field-label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 8px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: flex; align-items: center; gap: 8px; padding: 9px 13px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--bg);
  cursor: pointer; font-weight: 600; font-size: .92rem; user-select: none; transition: .12s;
}
.check input { width: auto; margin: 0; accent-color: var(--accent); }
.check.sel { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.check.disabled { opacity: .38; cursor: not-allowed; }
.seg { display: flex; gap: 6px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.seg-btn { flex: 1; border: 0; background: transparent; color: var(--ink-soft); font-weight: 600; padding: 9px; border-radius: 9px; cursor: pointer; }
.seg-btn.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.primary {
  width: 100%; border: 0; background: var(--accent); color: #fff; font-weight: 700; font-size: 1rem;
  padding: 13px; border-radius: 12px; cursor: pointer; transition: .15s;
}
.primary:hover { filter: brightness(1.05); }
.primary:disabled { opacity: .6; cursor: default; }
.hint { color: var(--ink-soft); font-size: .82rem; margin: 2px 0 14px; }
.form-error { color: var(--bad); min-height: 1.2em; margin: 12px 0 0; font-size: .9rem; }

/* ---------- Totals ---------- */
.pairwise { display: flex; flex-direction: column; gap: 10px; }
.pw {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
.pw .amt { margin-left: auto; font-weight: 800; }
.lifetime { display: flex; flex-direction: column; gap: 12px; }
.life-row { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--bg); }
.life-head { display: flex; align-items: center; justify-content: space-between; }
.life-name { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.life-net { font-weight: 800; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.life-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 16px; margin-top: 10px; font-size: .82rem; color: var(--ink-soft); }
.life-grid b { color: var(--ink); font-weight: 700; }

.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: .72rem; font-weight: 800; color: #fff; flex: none;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 12px;
  font-size: .9rem; font-weight: 600; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; text-align: center;
}
