/* Reset + base */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #222;
  background: #f5f6f8;
  line-height: 1.5;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 16px 0 12px; }
h2 { font-size: 16px; margin: 0 0 10px; }

/* Top nav */
.topnav {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 20px;
  background: #1f2937; color: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  flex-wrap: wrap;
}
.topnav .brand { font-weight: 700; font-size: 16px; display: flex; flex-direction: column; gap: 2px; }
.topnav .brand a { color: inherit; text-decoration: none; }
.topnav .brand-sub { font-size: 11px; color: #93c5fd; font-weight: 400; }
.topnav .links { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topnav .links a {
  color: #cbd5e1; padding: 6px 12px; border-radius: 4px;
  font-size: 13px; text-decoration: none;
}
.topnav .links a:hover { background: #374151; color: #fff; }
.topnav .links a.active { background: #2563eb; color: #fff; }
.topnav .user { display: flex; gap: 12px; align-items: center; font-size: 13px; color: #cbd5e1; }
.topnav .user .logout { color: #fca5a5; }

/* Container */
.container { max-width: 1400px; margin: 0 auto; padding: 16px 20px 60px; }

/* Auth */
.auth-card {
  max-width: 360px; margin: 80px auto;
  background: #fff; padding: 28px;
  border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
.auth-card h1 { text-align: center; margin: 0 0 24px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #555; }
.auth-card input {
  padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 4px;
  font-size: 14px;
}
.auth-card input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }

/* Cards */
.card {
  background: #fff; border-radius: 6px;
  padding: 16px; margin-bottom: 16px;
  border: 1px solid #e5e7eb;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

/* KPI cards */
.kpi-row {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.kpi {
  background: #fff; padding: 14px 16px;
  border-radius: 6px; border: 1px solid #e5e7eb;
  border-left: 4px solid #6b7280;
}
.kpi-label { font-size: 12px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.4px; }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi-green { border-left-color: #16a34a; }
.kpi-green .kpi-value { color: #16a34a; }
.kpi-red { border-left-color: #dc2626; }
.kpi-red .kpi-value { color: #dc2626; }
.kpi-blue { border-left-color: #2563eb; }
.kpi-blue .kpi-value { color: #2563eb; }
.kpi-orange { border-left-color: #ea580c; }
.kpi-orange .kpi-value { color: #ea580c; }

/* Tables */
.data {
  width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid #e5e7eb;
}
.data th, .data td {
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid #f0f1f3;
  font-size: 13px;
}
.data th {
  background: #f9fafb; color: #374151;
  font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.data tbody tr:hover { background: #f9fafb; }
.data tfoot td {
  background: #f9fafb; font-weight: 600;
  border-top: 2px solid #d1d5db;
}
.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* Dues matrix specific */
.matrix th, .matrix td { padding: 4px 6px; font-size: 12px; }
.matrix .resident-cell { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-paid { background: #dcfce7; color: #166534; }
.cell-partial { background: #fef9c3; color: #854d0e; }
.cell-unpaid { background: #fee2e2; color: #991b1b; }
.cell-overpaid { background: #dbeafe; color: #1e40af; }
.cell-empty { background: #f3f4f6; color: #9ca3af; }

.row-status-unpaid { background: #fef2f2; }
.row-status-partial { background: #fefce8; }
.row-status-paid { background: #f0fdf4; }

/* Badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f3f4f6; color: #6b7280; }

.legend { display: flex; gap: 6px; margin-top: 10px; }

/* Status colors */
.balance-due { color: #dc2626; font-weight: 600; }
.balance-credit { color: #16a34a; font-weight: 600; }
.pos { color: #16a34a; }
.neg { color: #dc2626; }

/* Filter bar */
.filter-bar {
  display: flex; gap: 10px; align-items: end;
  background: #fff; padding: 10px 14px;
  border-radius: 6px; border: 1px solid #e5e7eb;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-bar label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: #6b7280; }
.filter-bar select {
  padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 4px;
  font-size: 13px; background: #fff;
}

/* Buttons */
.btn {
  padding: 7px 14px; border: 1px solid #d1d5db; background: #fff;
  border-radius: 4px; cursor: pointer; font-size: 13px;
  color: #374151; text-decoration: none; display: inline-block;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn.primary:hover { background: #1d4ed8; }
.btn.ghost { background: transparent; border-color: transparent; color: #6b7280; }

/* Flash messages */
.flash {
  padding: 10px 14px; border-radius: 4px; margin-bottom: 12px;
  font-size: 13px;
}
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-info { background: #dbeafe; color: #1e40af; }

.muted { color: #6b7280; font-style: italic; }

/* Expenses */
.expenses-table .group-header td {
  background: #1f2937; color: #fff; font-weight: 700;
  font-size: 12px; letter-spacing: 0.5px;
}
.expenses-table .cat-header td {
  background: #f3f4f6; font-weight: 600; color: #374151;
}
.expenses-table .tx-row td { font-size: 12px; color: #4b5563; }
.expenses-table .indent2 { padding-left: 24px; }
.expenses-table .fee-row td { color: #9ca3af; font-style: italic; font-size: 11px; }

/* Income statement */
.statement { max-width: 720px; margin: 0 auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.statement-section { margin: 18px 0 8px; font-size: 13px; }
.statement-section.income { color: #16a34a; }
.statement-section.expense { color: #dc2626; }
.statement-line { display: flex; justify-content: space-between; padding: 4px 0; }
.statement-line.indent { padding-left: 20px; color: #6b7280; }
.statement-line.total { border-top: 1px solid #d1d5db; padding-top: 6px; font-weight: 700; }
.statement-line.grand-total {
  border-top: 3px double #1f2937; border-bottom: 3px double #1f2937;
  padding: 10px 0; margin: 12px 0; font-size: 16px;
}
.statement-line.grand-total.positive { color: #16a34a; }
.statement-line.grand-total.negative { color: #dc2626; }
.statement hr { border: none; border-top: 1px solid #e5e7eb; margin: 16px 0; }

/* Admin */
.admin-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: 20px 0; }
.admin-card {
  background: #fff; padding: 16px; border: 1px solid #e5e7eb; border-radius: 6px;
  text-decoration: none; color: #222; display: block;
  transition: box-shadow 0.15s, transform 0.15s;
}
.admin-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); transform: translateY(-1px); text-decoration: none; }
.admin-card-label { font-size: 12px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.4px; }
.admin-card-value { font-size: 28px; font-weight: 700; margin: 4px 0; color: #1f2937; }
.admin-card-desc { font-size: 12px; color: #6b7280; }

.form-stack { display: flex; flex-direction: column; gap: 12px; max-width: 720px; }
.form-stack label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #555; }
.form-stack input, .form-stack textarea, .form-stack select {
  padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 14px;
}
.form-row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #555; }
.form-row input, .form-row select, .form-row textarea {
  padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 13px;
}

.alloc-edit input, .alloc-edit select { padding: 4px 6px; font-size: 12px; }
.alloc-chip {
  display: inline-block; padding: 2px 6px; margin: 1px 2px;
  background: #f3f4f6; border-radius: 3px; font-size: 11px;
}
.alloc-chip .num { font-weight: 600; margin-left: 4px; color: #1f2937; }

/* Import flow */
.upload-form { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.upload-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #6b7280; }
.upload-form input[type="file"], .upload-form input[type="number"], .upload-form select {
  padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 13px; background: #fff;
}
.import-review th, .import-review td { padding: 4px 6px; font-size: 12px; }
.import-review select, .import-review input[type="number"] {
  padding: 3px 6px; border: 1px solid #d1d5db; border-radius: 3px; font-size: 12px; background: #fff;
}
.row-duplicate { background: #fef2f2; }
.row-duplicate td { color: #991b1b; }
.action-bar { display: flex; gap: 8px; padding: 12px 0; flex-wrap: wrap; }
.btn.danger { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.btn.danger:hover { background: #fecaca; }
.small { font-size: 11px; }

/* Flat statement */
.flat-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.flat-header form.inline { display: flex; gap: 12px; align-items: end; }
.identity { display: flex; gap: 24px; padding: 12px 16px; flex-wrap: wrap; }
