:root {
  --brand: #166534;
  --brand-2: #15803d;
  --brand-soft: #dcfce7;
  --brand-ink: #14532d;
  --gold: #ca8a04;
  --bg: #f5f7f3;
  --surface: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --danger: #b91c1c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); font-size: 14px; line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong, b { font-weight: 600; }
a { color: var(--brand-2); }

/* Boot & auth */
.boot { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; gap: 12px; color: var(--muted); }
.boot img { width: 96px; margin: 0 auto; animation: pulse 1.6s ease-in-out infinite; }
.boot.error p { color: var(--danger); max-width: 420px; }
.boot.error img { animation: none; }
@keyframes pulse { 50% { transform: scale(.94); opacity: .7; } }

.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(circle at 20% 10%, #dcfce7 0, transparent 45%), radial-gradient(circle at 90% 90%, #fef9c3 0, transparent 40%), var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 32px 28px; box-shadow: 0 10px 30px rgba(20, 83, 45, .12); display: grid; gap: 14px; }
.auth-card h1 { text-align: center; font-size: 24px; color: var(--brand-ink); }
.auth-card h2 { font-size: 16px; font-weight: 600; }
.auth-logo { width: 88px; margin: 0 auto; }

/* Shell */
.app { display: grid; grid-template-columns: 240px 1fr; height: 100vh; }
.sidebar { background: var(--brand-ink); color: #dcfce7; display: flex; flex-direction: column; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; font-weight: 700; font-size: 18px; color: #fff; }
.brand img { width: 40px; height: 40px; border-radius: 10px; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
nav { padding: 4px 10px 16px; flex: 1; }
.nav-group { text-transform: uppercase; font-size: 11px; letter-spacing: .06em; color: #86efac; opacity: .8; padding: 14px 10px 6px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #dcfce7; text-decoration: none; }
.nav-link:hover { background: rgba(255, 255, 255, .08); }
.nav-link.active { background: #fff; color: var(--brand-ink); font-weight: 600; }
.nav-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }
.userbox { padding: 14px 16px; border-top: 1px solid rgba(255, 255, 255, .12); display: grid; gap: 2px; }
.user-name { color: #fff; font-weight: 600; }
.user-role { font-size: 12px; opacity: .8; margin-bottom: 8px; }
.main { overflow-y: auto; padding: 24px 28px 48px; }

.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-header h1 { font-size: 22px; color: var(--brand-ink); }
.page-header p { margin: 4px 0 0; max-width: 720px; }
.page-actions, .row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.card-title { font-size: 15px; margin-bottom: 10px; }
.card > p { margin-top: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two-col .card { margin: 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #cbd5e1; background: #f9fafb; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { color: var(--danger); border-color: #fecaca; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: transparent; color: inherit; border-color: rgba(255, 255, 255, .3); }
.btn.block { width: 100%; padding: 10px; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 16px; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: #f3f4f6; color: var(--ink); }

/* Tables */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.search { flex: 1; min-width: 200px; max-width: 360px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafafa; }
table.data td { padding: 9px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
table.data tbody tr[tabindex] { cursor: pointer; }
table.data tbody tr[tabindex]:hover { background: #f0fdf4; }
table.data tfoot td { font-weight: 700; background: var(--brand-soft); color: var(--brand-ink); }
table.data.compact td { padding: 6px 8px; }
table.data .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.empty { text-align: center; color: var(--muted); padding: 24px !important; }

.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip-green { background: #dcfce7; color: #166534; }
.chip-blue { background: #dbeafe; color: #1e40af; }
.chip-amber { background: #fef3c7; color: #92400e; }
.chip-red { background: #fee2e2; color: #991b1b; }
.chip-grey { background: #f3f4f6; color: #4b5563; }

/* Forms */
input, select, textarea { font: inherit; color: inherit; border: 1px solid #d1d5db; border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #86efac; outline-offset: 0; border-color: var(--brand-2); }
input:disabled, select:disabled, textarea:disabled { background: #f9fafb; color: #4b5563; }
input.readonly { background: #f3f4f6; color: #4b5563; }
input.computed { font-weight: 700; color: var(--brand-ink); background: var(--brand-soft); text-align: right; font-size: 15px; }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid .wide, .form-grid .form-section { grid-column: 1 / -1; }
.form-section { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--brand-ink); padding-top: 8px; border-top: 1px dashed var(--line); margin-top: 4px; }
.field { display: grid; gap: 4px; align-content: start; }
.field label { font-weight: 600; font-size: 13px; }
.req { color: var(--danger); }
.field-hint { font-size: 12px; color: var(--muted); }
.field-hint:empty, .field-error:empty { display: none; }
.field-error { font-size: 12px; color: var(--danger); font-weight: 500; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.field-money input { text-align: right; }
.datalist-wrap { display: block; }

.contact-rows { display: grid; gap: 8px; margin-bottom: 8px; }
.contact-row { display: grid; grid-template-columns: 28px 1fr 1fr auto; gap: 8px; align-items: center; }
.contact-no { color: var(--muted); font-weight: 600; }

.audit { margin-top: 16px; }
.audit-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 8px; background: #f9fafb; border-radius: 8px; padding: 10px 12px; }
.audit-label { display: block; font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.audit-value { font-size: 13px; font-weight: 500; }

/* Lookup */
.lookup { position: relative; }
.lookup-list { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0; max-height: 260px; overflow-y: auto; margin: 0; padding: 4px;
  list-style: none; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12); }
.lookup-list li { padding: 7px 10px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; }
.lookup-list li:hover, .lookup-list li.active { background: #f0fdf4; }
.lk-label { font-weight: 500; }
.lk-sub { font-size: 12px; color: var(--muted); }
.lookup-empty { color: var(--muted); cursor: default !important; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.large { max-width: 820px; }
.modal.small { max-width: 420px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-header h2 { font-size: 17px; color: var(--brand-ink); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }
.modal-footer .left { margin-right: auto; }

/* Toast */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--brand-ink); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); transition: .25s; }
.toast.show { opacity: 1; transform: none; }
.toast-error { background: var(--danger); }

/* Dashboard */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; border-top: 3px solid var(--brand-2); }
.tile.accent { border-top-color: var(--gold); background: #fffbeb; }
.tile-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile-value { font-size: 22px; font-weight: 700; color: var(--brand-ink); margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Reports */
.card .row { margin-top: 14px; }
.bulk { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.report h2 { font-size: 18px; color: var(--brand-ink); }
.report h3 { font-size: 14px; margin: 20px 0 8px; color: var(--brand-ink); }
.report h4 { font-size: 13px; margin: 14px 0 6px; }
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border-bottom: 2px solid var(--brand-soft); padding-bottom: 10px; margin-bottom: 8px; }
.report-head p { margin: 4px 0 0; }
.report .tiles { margin: 14px 0 0; }
.report .tile { box-shadow: none; border: 1px solid var(--line); }
.callout { margin-top: 10px; padding: 10px 14px; background: var(--brand-soft); border-radius: 8px; color: var(--brand-ink); }

/* Responsive */
/* Tabs inside record forms */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 16px; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand-ink); border-bottom-color: var(--brand); }
.tab-badge { background: var(--brand); color: #fff; border-radius: 999px; font-size: 11px; min-width: 18px; padding: 1px 6px; text-align: center; }
.tab-panel[hidden] { display: none; }

/* Member form: associations */
.assoc-tab { display: grid; gap: 12px; justify-items: start; }
.assoc-tab > p { margin: 0; }
.assoc-rows { display: grid; gap: 10px; width: 100%; }
.assoc-row { display: grid; grid-template-columns: minmax(0, 1fr) 180px 120px auto; gap: 10px; align-items: end; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fafafa; }
.assoc-row.has-error { border-color: var(--danger); }
.assoc-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.assoc-row select { width: 100%; }
.assoc-empty { font-style: italic; }
@media (max-width: 640px) {
  .assoc-row { grid-template-columns: 1fr 1fr auto; }
  .assoc-row .assoc-cell:first-child { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .audit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: 100vh; }
  .sidebar { overflow: visible; }
  .nav-toggle { display: block; }
  .sidebar nav, .sidebar .userbox { display: none; }
  .sidebar.open nav, .sidebar.open .userbox { display: block; }
  .main { padding: 16px 16px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .contact-row { grid-template-columns: 24px 1fr auto; }
  .contact-row input[type=tel] { grid-column: 2; }
}
