:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e2e6ef;
  --text: #1f2430;
  --muted: #6b7280;
  --brand: #2451b3;
  --brand-dark: #1b3d8a;
  --green: #1c8a4d;
  --red: #c0392b;
  --shadow: 0 1px 3px rgba(20,30,60,.08), 0 4px 16px rgba(20,30,60,.05);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
button {
  font: inherit; cursor: pointer; border: 1px solid var(--border);
  background: #fff; border-radius: 8px; padding: 8px 12px;
  transition: .12s; color: var(--text);
}
button:hover { border-color: #c7cede; background: #fafbff; }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.primary:hover { background: var(--brand-dark); }
button.ghost { background: transparent; border-color: transparent; }
button.danger { color: var(--red); border-color: #f0c5c0; }
button.small { padding: 4px 8px; font-size: 12px; border-radius: 6px; }
input, select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus { outline: 2px solid #bcd0ff; border-color: var(--brand); }
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }

.app-header {
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 12px 20px; display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.app-header h1 { font-size: 16px; margin: 0; font-weight: 700; }
.app-header .spacer { flex: 1; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); display:inline-block; margin-right:8px;}

.container { max-width: 1180px; margin: 18px auto; padding: 0 16px; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
}
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.period-pill { font-weight: 600; }
.muted { color: var(--muted); }

table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td {
  padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left;
  white-space: nowrap;
}
table.grid th { font-size: 12px; color: var(--muted); font-weight: 600; background:#fbfcfe; }
table.grid tr:hover td { background: #fbfcff; }
table.grid td.num, table.grid th.num { text-align: right; }
/* Editable number fields — make them clearly stand out (low-contrast monitors) */
table.grid input.cell {
  width: 90px; text-align: right; padding: 7px 9px;
  border: 2px solid #8fa8d8; border-radius: 6px;
  background: #eef4ff; color: #13223f; font-weight: 600;
  box-shadow: inset 0 1px 2px rgba(20,40,90,.06);
}
table.grid input.cell:hover { border-color: var(--brand); background: #e6eeff; }
table.grid input.cell:focus {
  outline: 3px solid #bcd0ff; outline-offset: 0;
  border-color: var(--brand); background: #fff;
}
.val-strong { font-weight: 700; }
.to-pay { color: var(--brand-dark); font-weight: 700; }
.paid-yes { color: var(--green); font-weight: 600; }
.chip { font-size: 11px; padding: 2px 7px; border-radius: 999px; background:#eef2fb; color: var(--brand-dark); }

.row-actions { display: flex; gap: 6px; }

.overlay {
  position: fixed; inset: 0; background: rgba(20,30,60,.35);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal {
  background: #fff; border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
}
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--border); display:flex; align-items:center; }
.modal header h2 { margin: 0; font-size: 16px; }
.modal .body { padding: 18px 20px; }
.modal .footer { padding: 14px 20px; border-top: 1px solid var(--border); display:flex; gap:10px; justify-content:flex-end; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 360px; padding: 28px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { margin: 0 0 18px; color: var(--muted); }
.login-card .field { margin-bottom: 14px; }
.err { color: var(--red); font-size: 13px; margin: 8px 0 0; }

.consumer-row { display:flex; align-items:center; gap:10px; padding:8px 0; border-bottom:1px solid var(--border); }
.consumer-row .name { flex:1; font-weight:600; }
.empty { text-align:center; padding: 48px 16px; color: var(--muted); }
.spin { display:inline-block; width:14px; height:14px; border:2px solid #cdd6ea; border-top-color: var(--brand); border-radius:50%; animation: sp .7s linear infinite; vertical-align:-2px; }
@keyframes sp { to { transform: rotate(360deg); } }
.save-flash { color: var(--green); font-size: 12px; }

/* ---- small modal (confirm / prompt) ---- */
.modal.modal-sm { max-width: 420px; }

/* ---- header: clickable brand + "saved" toast ---- */
.brand-link { cursor: pointer; user-select: none; display: inline-flex; align-items: center; }
.brand-link:hover { opacity: .85; }
.saved-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; color: var(--green);
  background: #e8f6ee; border: 1px solid #bfe6cd;
  padding: 4px 10px; border-radius: 999px;
  animation: saved-in .18s ease-out;
}
@keyframes saved-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

/* ---- overview: period cards ---- */
.period-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.period-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 16px; cursor: pointer; transition: .14s;
  display: flex; flex-direction: column; gap: 10px;
}
.period-card:hover { border-color: #bcd0ff; box-shadow: 0 2px 6px rgba(20,30,60,.1), 0 8px 24px rgba(36,81,179,.1); transform: translateY(-1px); }
.period-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.period-card-month { font-size: 15px; font-weight: 700; }
.period-card-meta { font-size: 12px; }
.period-card-stats {
  display: flex; gap: 18px; padding-top: 6px; border-top: 1px solid var(--border);
}
.period-card-stats > div { display: flex; flex-direction: column; gap: 2px; }
.period-card-stats span { font-size: 11px; }
.period-card-stats b { font-size: 14px; }
.period-card-open { font-size: 12px; color: var(--brand); font-weight: 600; }

/* ---- overview: debtors summary button ---- */
button.debt-summary {
  background: #fff5f4; border-color: #f0c5c0; color: var(--red);
}
button.debt-summary:hover { background: #fdecea; border-color: #e8b1aa; }
button.debt-summary b { color: var(--red); }

/* ---- debtors modal rows ---- */
.debtor-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.debtor-main { flex: 1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.debtor-main .name { font-weight: 600; }
.debtor-period { font-size: 11px; color: var(--muted); }
.debtor-owed { font-weight: 700; color: var(--red); white-space: nowrap; }
.debtor-total { font-size: 13px; color: var(--muted); }
.debtor-total strong { color: var(--red); font-size: 15px; }
