:root {
  --bg: #EEF2EF;
  --surface: #FFFFFF;
  --ink: #1F2C29;
  --muted: #5C6D67;
  --border: #DCE4DF;

  --primary: #1F6F63;
  --primary-dark: #154E45;

  --owe: #B5502D;
  --owe-soft: #F6E3DA;
  --paid: #3F8F5F;
  --paid-soft: #DFEEE3;
  --credit: #2E6FA3;
  --credit-soft: #DCE9F4;

  --radius: 10px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Karla", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
}

h1, h2 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--primary-dark);
  margin: 0 0 0.2em;
}

h1 { font-size: 1.9rem; }
h2.section-title { font-size: 1.15rem; margin-top: 2rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.eyebrow {
  display: inline-block;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 0.3em;
}

/* ---------- layout ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  font-family: var(--font-display);
  font-weight: 700;
  background: var(--primary);
  color: white;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}
.brand-mark.large { width: 3rem; height: 3rem; font-size: 1.3rem; margin-bottom: 0.6rem; }

.brand-text { font-weight: 700; font-family: var(--font-display); font-size: 1.1rem; }

.topnav { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; }
.topnav a { color: var(--muted); text-decoration: none; }
.topnav a:hover { color: var(--owe); }
.whoami { color: var(--ink); font-weight: 600; }

.wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.back-link {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.back-link:hover { color: var(--primary); }

/* ---------- flashes ---------- */

.flashes { margin-bottom: 1.2rem; }
.flash {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}
.flash-success { background: var(--paid-soft); color: var(--paid); }
.flash-error { background: var(--owe-soft); color: var(--owe); }

/* ---------- forms ---------- */

.stack { display: flex; flex-direction: column; gap: 0.9rem; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; font-weight: 600; color: var(--ink); }

input {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.card-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
}

.inline-form { margin-top: 1rem; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}
@media (max-width: 620px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.1rem;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--primary-dark); border: 1px solid var(--border); }
.btn-owe { background: var(--owe); color: white; }
.btn-paid { background: var(--paid); color: white; }
.btn-block { width: 100%; }

.link-danger, .link-muted {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
  font-family: var(--font-body);
}
.link-danger { color: var(--owe); }
.link-muted { color: var(--muted); }
.link-danger:hover, .link-muted:hover { text-decoration: underline; }

/* ---------- auth screen ---------- */

.auth-screen { display: flex; justify-content: center; padding-top: 3rem; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.2rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.auth-card .stack { text-align: left; margin-top: 1.2rem; }

/* ---------- summary strip ---------- */

.summary-strip {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.summary-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.2rem;
  flex: 1;
}
.summary-label { display: block; font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.summary-value { display: block; font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; margin-top: 0.15rem; }
.text-owe { color: var(--owe); }

/* ---------- family / student list ---------- */

.family-list { display: flex; flex-direction: column; gap: 0.6rem; }

.family-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  text-decoration: none;
  color: var(--ink);
}
.family-row:hover { border-color: var(--primary); }
.family-row.row-inactive { opacity: 0.55; }

.stripe-owe { border-left-color: var(--owe); }
.stripe-paid { border-left-color: var(--paid); }
.stripe-credit { border-left-color: var(--credit); }

.family-row-main { display: flex; flex-direction: column; gap: 0.15rem; }
.family-name { font-weight: 700; }

.balance-badge {
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  white-space: nowrap;
}
.balance-badge.large { font-size: 1rem; padding: 0.5rem 1rem; }
.badge-owe { background: var(--owe-soft); color: var(--owe); }
.badge-paid { background: var(--paid-soft); color: var(--paid); }
.badge-credit { background: var(--credit-soft); color: var(--credit); }

.empty {
  color: var(--muted);
  font-style: italic;
  padding: 1rem 0;
}

/* ---------- ledger table ---------- */

.ledger {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.92rem;
}
.ledger th, .ledger td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.ledger th {
  background: var(--bg);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.ledger tr:last-child td { border-bottom: none; }
.num { text-align: right; }

.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  text-transform: capitalize;
}
.tag-owe { background: var(--owe-soft); color: var(--owe); }
.tag-paid { background: var(--paid-soft); color: var(--paid); }
