/* ============ Tokens ============
   Ink navy background, parchment cards, coin-amber accent,
   sage for credit, rust for debt. Fraunces for display,
   Inter for body, IBM Plex Mono for all monetary figures
   (a receipt-printer cue that ties numbers to the subject). */
:root {
  --ink: #141b28;
  --ink-2: #1c2536;
  --parchment: #f6f1e4;
  --parchment-dim: #ece4d0;
  --line: #d8cdb2;
  --text: #24201a;
  --text-muted: #6b6455;
  --amber: #d1973a;
  --amber-deep: #a9752a;
  --sage: #4f8672;
  --rust: #bd5a42;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", monospace;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--parchment);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ============ Auth view ============ */
#view-auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(209,151,58,0.12), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(79,134,114,0.10), transparent 40%),
    var(--ink);
}
.auth-wrap { width: 100%; max-width: 420px; }
.brand { text-align: center; margin-bottom: 28px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--amber); color: var(--ink);
  font-family: var(--font-display); font-size: 28px; font-weight: 700;
  margin-bottom: 14px;
}
.brand h1 {
  font-family: var(--font-display); font-size: 2.4rem; font-weight: 600;
  margin: 0; letter-spacing: -0.01em;
}
.tagline { color: #b9b3a2; margin: 6px 0 0; font-size: 0.95rem; }

.auth-card {
  background: var(--parchment); color: var(--text);
  border-radius: var(--radius); padding: 22px 24px 26px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--parchment-dim); border-radius: 8px; padding: 4px; }
.tab-btn {
  flex: 1; border: none; background: transparent; padding: 9px 0;
  border-radius: 6px; font-weight: 600; color: var(--text-muted); font-size: 0.9rem;
}
.tab-btn.active { background: var(--ink); color: var(--parchment); }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
input, select {
  border: 1.5px solid var(--line); border-radius: 7px; padding: 10px 12px;
  font-size: 0.95rem; color: var(--text); background: #fff;
}
input:focus, select:focus { border-color: var(--amber); }

.btn-primary {
  background: var(--amber); color: var(--ink); border: none; border-radius: 7px;
  padding: 11px 16px; font-weight: 700; font-size: 0.95rem; transition: background 0.15s;
}
.btn-primary:hover { background: var(--amber-deep); }
.btn-ghost {
  background: transparent; border: 1.5px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 10px 14px; font-weight: 600; font-size: 0.9rem;
}
.btn-ghost:hover { background: var(--parchment-dim); }
.form-error { color: var(--rust); font-size: 0.85rem; margin: -4px 0 0; min-height: 1em; }
.form-hint { color: var(--text-muted); font-size: 0.8rem; margin: -6px 0 0; }

/* ============ App shell ============ */
#view-app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-mini { font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; display: flex; align-items: center; gap: 8px; }
.brand-mini .brand-mark { width: 28px; height: 28px; font-size: 16px; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 14px; color: #cfc9b8; font-size: 0.9rem; }
.topbar .btn-ghost { color: var(--parchment); border-color: rgba(255,255,255,0.25); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,0.06); }

.layout { flex: 1; display: grid; grid-template-columns: 260px 1fr; min-height: 0; }

.sidebar { border-right: 1px solid rgba(255,255,255,0.08); padding: 20px 16px; overflow-y: auto; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sidebar-head h2 { font-family: var(--font-display); font-size: 1rem; font-weight: 600; margin: 0; color: #cfc9b8; text-transform: uppercase; letter-spacing: 0.04em; }
.btn-icon {
  width: 26px; height: 26px; border-radius: 50%; border: none;
  background: var(--amber); color: var(--ink); font-weight: 700; font-size: 1rem; line-height: 1;
}
.group-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.group-list li button {
  width: 100%; text-align: left; background: transparent; border: none;
  color: #d8d2c2; padding: 9px 10px; border-radius: 7px; font-size: 0.92rem;
}
.group-list li button:hover { background: rgba(255,255,255,0.06); }
.group-list li button.active { background: var(--amber); color: var(--ink); font-weight: 700; }

.main { padding: 28px 32px; overflow-y: auto; background: var(--parchment); color: var(--text); }
.empty-state { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); text-align: center; gap: 10px; }
.empty-mark { font-family: var(--font-display); font-size: 3rem; color: var(--line); }

.group-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.group-header h2 { font-family: var(--font-display); font-size: 1.8rem; margin: 0; }
.muted { color: var(--text-muted); font-size: 0.9rem; margin: 4px 0 0; }
.group-actions { display: flex; gap: 10px; }

.section-label {
  font-family: var(--font-display); font-size: 0.85rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted); margin: 28px 0 12px;
}

/* Receipt-style balance card: dashed rule + torn top edge, echoing a paper receipt */
.receipt-card {
  background: #fff; border-radius: 4px; padding: 20px 22px 22px;
  max-width: 480px; position: relative;
  box-shadow: 0 8px 24px rgba(20,27,40,0.10);
  background-image: repeating-linear-gradient(90deg, var(--line) 0 8px, transparent 8px 16px);
  background-repeat: no-repeat; background-size: 100% 3px; background-position: top left;
}
.receipt-card h3 { font-family: var(--font-display); margin: 4px 0 14px; font-size: 1.1rem; }
.balance-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.balance-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 10px; border-bottom: 1px dashed var(--line); font-size: 0.92rem;
}
.balance-list li:last-child { border-bottom: none; padding-bottom: 0; }
.balance-line { font-family: var(--font-mono); font-weight: 500; }
.balance-line .amt { color: var(--rust); font-weight: 600; }
.btn-settle {
  background: var(--sage); color: #fff; border: none; border-radius: 6px;
  padding: 6px 11px; font-size: 0.78rem; font-weight: 700;
}
.btn-settle:hover { background: #3f6f5d; }

.expense-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.expense-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 4px; border-bottom: 1px solid var(--line);
}
.expense-list li:first-child { border-top: 1px solid var(--line); }
.expense-main { display: flex; flex-direction: column; gap: 3px; }
.expense-desc { font-weight: 600; }
.expense-meta { font-size: 0.82rem; color: var(--text-muted); }
.expense-amount { font-family: var(--font-mono); font-weight: 600; font-size: 1.05rem; }
.expense-list .btn-del { background: none; border: none; color: var(--text-muted); font-size: 0.85rem; margin-left: 14px; }
.expense-list .btn-del:hover { color: var(--rust); }
.expense-row-inner { display: flex; align-items: center; width: 100%; justify-content: space-between; }

/* ============ Modals ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,27,40,0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--parchment); color: var(--text); border-radius: var(--radius);
  padding: 24px 26px 26px; width: 100%; max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.4); max-height: 90vh; overflow-y: auto;
}
.modal-wide { max-width: 520px; }
.modal h3 { font-family: var(--font-display); margin: 0 0 16px; font-size: 1.3rem; }
.modal form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }
fieldset { border: none; padding: 0; margin: 0; }
legend { font-weight: 700; font-size: 0.85rem; color: var(--text-muted); padding: 0; margin-bottom: 8px; }
.split-type-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.split-tab {
  flex: 1; border: 1.5px solid var(--line); background: #fff; border-radius: 6px;
  padding: 7px 0; font-size: 0.82rem; font-weight: 600; color: var(--text-muted);
}
.split-tab.active { background: var(--ink); border-color: var(--ink); color: var(--parchment); }
.participants-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow-y: auto; }
.participants-list li { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; }
.participants-list input[type="checkbox"] { width: 16px; height: 16px; }
.participants-list .p-name { flex: 1; }
.participants-list input[type="number"] {
  width: 90px; padding: 6px 8px; font-family: var(--font-mono); font-size: 0.85rem;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.settle-text { font-size: 0.95rem; }

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid rgba(255,255,255,0.08); }
  .main { padding: 20px; }
}
