:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e0e2e7;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --paid-bg: #dcfce7;
  --paid-text: #166534;
  --outstanding-bg: #fee2e2;
  --outstanding-text: #991b1b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  padding-top: 14px;
  padding-bottom: 14px;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
}

.topbar nav a {
  margin-right: 18px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}

.topbar nav a:hover { color: var(--primary); }

h1 { margin-top: 0; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.page-header .actions { display: flex; gap: 8px; }

.btn, button, input[type="submit"] {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover, button:hover { background: var(--primary-dark); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  font-size: 0.85rem;
}

.inline-form { display: inline-block; margin: 0; }

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.table th, .table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
  vertical-align: top;
}

.table th {
  background: #fafbfc;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.table tr:last-child td { border-bottom: none; }

.empty, .muted { color: var(--muted); }

a { color: var(--primary); }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 20px;
}

.filters label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: var(--muted);
  gap: 4px;
}

.filters input, .filters select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}

.stat-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  min-width: 180px;
  flex: 1;
}

.stat-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 1.5rem; font-weight: 700; }

.stat-card.stat-paid .stat-value { color: var(--paid-text); }
.stat-card.stat-outstanding .stat-value { color: var(--outstanding-text); }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #eef0f4;
  color: var(--muted);
  margin: 2px 2px;
}

.badge-paid { background: var(--paid-bg); color: var(--paid-text); }
.badge-outstanding { background: var(--outstanding-bg); color: var(--outstanding-text); }

.as-button {
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.period-list { display: flex; flex-wrap: wrap; gap: 2px; max-width: 420px; }

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  max-width: 480px;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.form input, .form select, .form textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
}

.form button { align-self: flex-start; }

.dialog {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  max-width: 360px;
}

.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

.dialog .form { max-width: none; border: none; padding: 20px; }

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  align-items: center;
}

.detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 24px;
}

.detail-list dt { color: var(--muted); font-size: 0.85rem; }
.detail-list dd { margin: 0; }

.error {
  background: var(--outstanding-bg);
  color: var(--outstanding-text);
  padding: 10px 14px;
  border-radius: 6px;
}

h2 { margin-top: 32px; }
