:root {
  --bg: #f5f6f8;
  --surface: #fff;
  --text: #1d2330;
  --muted: #6a7282;
  --border: #dde1e7;
  --primary: #2b5fa8;
  --primary-text: #fff;
  --danger: #b3261e;
  --paid: #1e7d45;
  --paid-bg: #e3f4e9;
  --partial: #8a5a00;
  --partial-bg: #fdf1d8;
  --unpaid: #b3261e;
  --unpaid-bg: #fbe5e3;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2 { margin: 0 0 .6em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
[hidden] { display: none !important; }

button, .button {
  font: inherit;
  padding: .45em .9em;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  white-space: nowrap;
}
button:hover, .button:hover { border-color: #b8bfca; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.danger { color: var(--danger); }
button.link { border: none; background: none; color: var(--primary); padding: 0; }
button.small { padding: .2em .6em; font-size: .88em; }

input, select, textarea {
  font: inherit;
  padding: .4em .55em;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
label { display: block; margin-bottom: .7em; font-size: .9em; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: .2em; color: var(--text); }
label.inline { display: inline-flex; align-items: center; gap: .4em; margin: 0; }
label.inline input[type=checkbox] { width: auto; margin: 0; }
.year-input { width: 6em; }
.fee-input { max-width: 10em; display: block; }

.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: .3em 0; }
.spacer { flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2em 1.4em;
  margin-bottom: 1.2em;
  max-width: 560px;
}

/* Login */
.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login .card { width: 100%; max-width: 340px; }
.login button { width: 100%; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 1.2em; flex-wrap: wrap;
  padding: .7em 1.2em;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; }
.topbar nav { display: flex; gap: .3em; flex-wrap: wrap; }
.tab { border-color: transparent; background: none; }
.tab.active { background: var(--bg); border-color: var(--border); font-weight: 600; }
.user { margin-left: auto; display: flex; gap: .8em; align-items: center; color: var(--muted); }

.content { padding: 1.2em; max-width: 1200px; margin: 0 auto; }
.toolbar { display: flex; gap: .6em; align-items: center; flex-wrap: wrap; margin-bottom: 1em; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }

/* Tables */
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
table.data.narrow { width: auto; min-width: 360px; }
table.data th, table.data td { padding: .5em .7em; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { background: #fafbfc; font-size: .85em; color: var(--muted); font-weight: 600; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #fafbfc; }
table.data tfoot td { font-weight: 600; border-top: 2px solid var(--border); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.actions { text-align: right !important; white-space: nowrap; }
.actions button + button { margin-left: .3em; }
tr.inactive td { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 2em !important; }

.badge { display: inline-block; padding: .1em .55em; border-radius: 999px; font-size: .82em; font-weight: 600; }
.badge.paid { color: var(--paid); background: var(--paid-bg); }
.badge.partial { color: var(--partial); background: var(--partial-bg); }
.badge.unpaid { color: var(--unpaid); background: var(--unpaid-bg); }
.badge.inactive { color: var(--muted); background: var(--bg); }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8em; margin-bottom: 1em; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .7em 1em; }
.stat .label { font-size: .82em; color: var(--muted); }
.stat .value { font-size: 1.35em; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Dialogs */
dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.3em 1.5em;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  color: var(--text);
  background: var(--surface);
}
dialog#history-dialog { width: min(760px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(20, 25, 35, .45); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .9em; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 .9em; }
.method { display: block; font-size: .85em; color: var(--muted); }
fieldset.people { border: 1px solid var(--border); border-radius: 8px; padding: .6em 1em .9em; margin: 0 0 .9em; }
fieldset.people legend { font-size: .9em; color: var(--muted); padding: 0 .3em; }
.person { padding: .5em 0; border-bottom: 1px dashed var(--border); margin-bottom: .6em; }
.person-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4em; font-size: .92em; }
.person-head .muted { font-weight: normal; }
button.link.danger { color: var(--danger); }
.dialog-actions { display: flex; gap: .5em; margin-top: 1em; align-items: center; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: .6em 1.1em; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

@media (max-width: 720px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  table.data { display: block; overflow-x: auto; }
  .user { margin-left: 0; }
}

@media print {
  .topbar, .toolbar, .no-print, .toast { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; }
  table.data { border: none; }
}
