:root {
  color-scheme: light;
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #ece8dd;
  --text: #1b211d;
  --muted: #6d766e;
  --line: #dcd7c8;
  --green: #17785f;
  --green-soft: #d9eee6;
  --amber: #c8891d;
  --red: #b94d3e;
  --shadow: 0 18px 45px rgba(39, 50, 42, .12);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111611;
  --surface: #1a211b;
  --surface-2: #253025;
  --text: #edf4ea;
  --muted: #aeb8aa;
  --line: #334033;
  --green: #77d6ae;
  --green-soft: #193729;
  --amber: #f0c15b;
  --red: #ff8a76;
  --shadow: 0 18px 45px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, rgba(23,120,95,.14), transparent 34rem), var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input, select { font: inherit; }
.app-shell { width: min(100%, 520px); margin: 0 auto; padding: 18px 14px 92px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.eyebrow { margin: 0 0 4px; color: var(--green); font-size: .72rem; font-weight: 800; letter-spacing: .08em; }
h1 { margin: 0; font-size: clamp(1.5rem, 6vw, 2.15rem); line-height: 1.02; }
h2 { margin: 0; font-size: 1rem; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.logout-button { width: auto; min-width: 58px; padding: 0 13px; font-size: .78rem; font-weight: 850; }

.hero-card {
  min-height: 154px;
  padding: 22px;
  border-radius: 28px;
  background: linear-gradient(135deg, #173f32, #17785f 62%, #b5d35d);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.label { display: block; font-size: .78rem; opacity: .8; font-weight: 700; text-transform: uppercase; }
.hero-card strong { display: block; margin-top: 4px; font-size: clamp(2.4rem, 13vw, 4rem); line-height: .95; }
.hero-meta { display: flex; justify-content: space-between; align-items: end; gap: 12px; }
.pill { display: inline-flex; align-items: center; min-height: 30px; padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,.18); font-size: .82rem; font-weight: 800; }
.pill.negative { background: rgba(185,77,62,.22); }
.pill.positive { background: rgba(20,145,99,.28); }

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin: 14px -2px 16px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
}
.tab { min-height: 38px; border: 0; border-radius: 13px; background: transparent; color: var(--muted); font-size: .75rem; font-weight: 800; }
.tab.active { background: var(--text); color: var(--surface); }

.group-card { gap: 10px; }
.group-toggle {
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.group-summary { display: grid; gap: 3px; justify-items: end; white-space: nowrap; }
.group-summary span { color: var(--green); font-size: .72rem; font-weight: 850; }
.group-students { display: grid; gap: 8px; margin-top: 2px; }
.group-student {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.group-student strong { display: block; line-height: 1.2; }
.group-student span { display: block; margin-top: 2px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.group-student.paid { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); background: color-mix(in srgb, var(--green-soft) 74%, var(--surface)); }
.group-student.unpaid { border-color: color-mix(in srgb, var(--red) 46%, var(--line)); background: color-mix(in srgb, var(--red) 10%, var(--surface)); }
.group-student.unpaid .student-payment, .group-student.unpaid .student-payment span { color: var(--red); }
.group-student.paid .student-payment, .group-student.paid .student-payment span { color: var(--green); }
.student-payment { text-align: right; white-space: nowrap; }

.view { display: none; }
.view.active { display: block; }
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi, .panel, .item { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.kpi { padding: 16px; }
.kpi span { display:block; color: var(--muted); font-size: .78rem; font-weight: 700; }
.kpi strong { display:block; margin-top: 8px; font-size: 1.25rem; }
.kpi.warning strong { color: var(--amber); }
.panel { margin-top: 12px; padding: 16px; }
.panel-head { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; margin-bottom: 14px; }
.panel-head span { color: var(--muted); font-size: .78rem; font-weight: 700; text-align: right; }
.danger-soft { border-color: color-mix(in srgb, var(--red) 40%, var(--line)); }
.warning-soft { border-color: color-mix(in srgb, var(--amber) 45%, var(--line)); }

.toolbar { display:grid; gap:8px; grid-template-columns: 1fr; margin-bottom: 12px; }
input, select { width:100%; min-height: 44px; border:1px solid var(--line); border-radius: 15px; background: var(--surface); color: var(--text); padding: 0 12px; }
.list { display:grid; gap: 10px; }
.list.tight { gap: 8px; }
.item { padding: 14px; display:grid; gap: 8px; }
.item-main { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
.item-title { font-weight: 850; line-height: 1.2; }
.item-sub { color: var(--muted); font-size: .84rem; margin-top: 3px; }
.amount { font-weight: 900; white-space: nowrap; }
.amount.income { color: var(--green); }
.amount.expense, .amount.pending { color: var(--red); }
.tags { display:flex; flex-wrap:wrap; gap:6px; }
.tag { padding: 4px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .72rem; font-weight: 800; }
.tag.ok { color: var(--green); background: var(--green-soft); }
.tag.warn { color: var(--amber); background: color-mix(in srgb, var(--amber) 18%, transparent); }

.bars { display:grid; gap:10px; }
.bar-row { display:grid; grid-template-columns: 78px 1fr auto; align-items:center; gap:10px; font-size:.8rem; }
.bar-label { color: var(--muted); font-weight: 750; overflow:hidden; text-overflow: ellipsis; white-space:nowrap; }
.bar-track { height: 11px; border-radius: 999px; background: var(--surface-2); overflow:hidden; }
.bar-fill { height:100%; border-radius:inherit; background: linear-gradient(90deg, var(--green), #b5d35d); min-width: 3px; }
.bar-fill.expense { background: linear-gradient(90deg, var(--amber), var(--red)); }
.bar-value { font-weight:850; }
.empty { color: var(--muted); text-align:center; padding:22px; border:1px dashed var(--line); border-radius:18px; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-shell { width: min(100%, 430px); }
.login-card {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.login-mark {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #173f32, #17785f 62%, #b5d35d);
  color: #fff;
  font-size: 1.7rem;
  font-weight: 950;
  box-shadow: var(--shadow);
}
.login-copy { margin: 0 0 18px; color: var(--muted); font-weight: 750; }
.login-form { display: grid; gap: 12px; }
.login-form label { display: grid; gap: 6px; color: var(--muted); font-size: .82rem; font-weight: 800; }
.login-form input { min-height: 48px; }
.login-submit {
  min-height: 50px;
  border: 0;
  border-radius: 16px;
  background: var(--text);
  color: var(--surface);
  font-weight: 900;
  cursor: pointer;
}
.login-error { display: none; margin: 0; color: var(--red); font-size: .84rem; font-weight: 800; }
.login-error.visible { display: block; }
.login-foot { display: block; margin-top: 16px; color: var(--muted); line-height: 1.4; }

@media (min-width: 760px) {
  .app-shell { width: min(100%, 1060px); padding: 28px 24px; }
  main { display: block; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .toolbar { grid-template-columns: 1fr 190px; }
  .list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #movementList { grid-template-columns: 1fr; }
  .tabs { max-width: 720px; }
}
