:root {
  --navy: #0b2a4a;
  --navy-2: #143862;
  --gold: #b8860b;
  --gold-soft: #f7eed1;
  --ink: #1b2735;
  --muted: #6b7785;
  --line: #e5e9ee;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --green: #1b7a4b;
  --green-soft: #e3f4ec;
  --red: #b32424;
  --red-soft: #fce7e7;
  --amber: #b56500;
  --amber-soft: #fdefda;
  --blue: #1f4d8c;
  --blue-soft: #e3edf9;
  --purple: #5e3a99;
  --purple-soft: #ede5fa;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* ===== Layout ===== */
.shell { display: grid; grid-template-columns: 240px 1fr; height: 100vh; overflow: hidden; }
.sidebar {
  background: var(--navy);
  color: #cfd9e6;
  padding: 18px 0;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar .brand {
  padding: 0 22px 22px;
  border-bottom: 1px solid #1a3e64;
}
.sidebar .brand .name {
  color: #fff; font-weight: 700; font-size: 16px;
  letter-spacing: -0.01em;
}
.sidebar .brand .sub {
  color: var(--gold); font-size: 11px;
  letter-spacing: 0.1em; text-transform: uppercase;
  margin-top: 2px; font-weight: 700;
}
.sidebar .group-title {
  font-size: 10.5px; letter-spacing: 0.12em;
  text-transform: uppercase; color: #8aa1bd;
  padding: 18px 22px 8px;
}
.sidebar nav button {
  background: transparent; border: 0;
  color: #cfd9e6;
  text-align: left; width: 100%;
  padding: 9px 22px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px;
  border-left: 3px solid transparent;
}
.sidebar nav button:hover { background: #103452; color: #fff; }
.sidebar nav button.active {
  background: #0a2440;
  border-left-color: var(--gold);
  color: #fff; font-weight: 600;
}
.sidebar nav .ic {
  width: 18px; height: 18px; display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 14px; opacity: 0.85;
}
.sidebar .bottom {
  margin-top: auto;
  padding: 18px 22px;
  border-top: 1px solid #1a3e64;
  font-size: 11.5px;
  color: #8aa1bd;
}
.sidebar .user {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px;
}
.sidebar .user .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--gold); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.sidebar .user .who { color: #fff; font-size: 13px; }
.sidebar .user .role { color: #8aa1bd; font-size: 11px; }

.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px 28px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar .ttl { font-size: 17px; font-weight: 600; color: var(--navy); }
.topbar .crumb { color: var(--muted); font-size: 12px; }
.topbar .actions { display: flex; gap: 10px; align-items: center; }
.topbar .entity-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--gold-soft); color: var(--amber);
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.topbar .entity-pill::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--gold);
}
.viewport { flex: 1; overflow: auto; padding: 24px 28px; }

/* ===== Common ===== */
.h1 { font-size: 22px; font-weight: 700; color: var(--navy); margin: 0 0 4px; letter-spacing: -0.01em; }
.h-sub { color: var(--muted); margin: 0 0 18px; font-size: 13.5px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 6px;
  border: 1px solid var(--line); background: #fff;
  font-size: 13px; font-weight: 500;
  transition: all 0.12s ease;
}
.btn:hover { background: #f5f7fa; }
.btn.primary {
  background: var(--navy); color: #fff; border-color: var(--navy);
}
.btn.primary:hover { background: var(--navy-2); }
.btn.gold {
  background: var(--gold); color: #fff; border-color: var(--gold);
}
.btn.gold:hover { background: #a07509; }
.btn.danger {
  background: #fff; color: var(--red); border-color: #f1c4c4;
}
.btn.danger:hover { background: var(--red-soft); }
.btn.sm { padding: 4px 10px; font-size: 12px; }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 16px 18px;
}
.kpi .lbl { font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 26px; font-weight: 700; color: var(--navy); margin-top: 4px; letter-spacing: -0.01em; }
.kpi .delta { font-size: 12px; color: var(--green); margin-top: 4px; }
.kpi .delta.neg { color: var(--red); }

.row2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 16px;
}
.panel-h {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.panel-h h3 {
  margin: 0; font-size: 15px; color: var(--navy); font-weight: 600;
}
.panel-h .more {
  color: var(--muted); font-size: 12px;
}

table.data {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.data th, table.data td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line);
}
table.data th {
  color: var(--muted); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  background: #fafbfc;
  position: sticky; top: 0;
}
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover { background: #f7faff; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.muted { color: var(--muted); }

.pill {
  display: inline-block;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.02em;
}
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.red   { background: var(--red-soft);   color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue  { background: var(--blue-soft);  color: var(--blue); }
.pill.purple{ background: var(--purple-soft);color: var(--purple); }
.pill.grey  { background: #eef0f3; color: #4a5360; }

.searchbar {
  display: flex; gap: 8px; margin-bottom: 14px; align-items: center;
}
.searchbar input {
  flex: 1; padding: 8px 12px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff;
}
.searchbar input:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
.searchbar select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }

.metric-row { display: flex; gap: 22px; padding: 8px 0 14px; }
.metric-row .m { display: flex; flex-direction: column; }
.metric-row .m .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.metric-row .m .v { font-size: 17px; font-weight: 700; color: var(--navy); }

/* aging bars */
.aging { display: grid; grid-template-columns: 70px 1fr 90px; gap: 10px; align-items: center; padding: 8px 0; }
.aging .lbl { font-size: 13px; color: var(--ink); }
.aging .bar { height: 10px; background: #eef0f3; border-radius: 999px; overflow: hidden; }
.aging .bar > div { height: 100%; border-radius: 999px; }
.aging .amt { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--ink); text-align: right; }

/* === Account drawer === */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(11,42,74,0.4);
  z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%;
  width: 880px; max-width: 100%;
  background: #fff; box-shadow: -10px 0 30px rgba(0,0,0,0.1);
  z-index: 51; transform: translateX(100%);
  transition: transform 0.22s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-h {
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--navy); color: #fff;
}
.drawer-h .who { font-size: 17px; font-weight: 600; }
.drawer-h .sub { color: #aac0d8; font-size: 12.5px; margin-top: 2px; }
.drawer-h .x { background: transparent; color: #fff; border: 0; font-size: 22px; }
.drawer-tabs {
  display: flex; gap: 4px; padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}
.drawer-tabs button {
  background: transparent; border: 0; padding: 14px 14px 12px;
  font-size: 13px; color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.drawer-tabs button.active {
  color: var(--navy); border-bottom-color: var(--gold); font-weight: 600;
}
.drawer-body {
  flex: 1; overflow: auto; padding: 22px 24px;
}
.kv { display: grid; grid-template-columns: 160px 1fr; row-gap: 8px; column-gap: 14px; font-size: 13.5px; }
.kv .k { color: var(--muted); }
.kv .v { color: var(--ink); }
.section-h {
  font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
  margin: 22px 0 10px;
}
.timeline { position: relative; padding-left: 18px; }
.timeline::before {
  content: ''; position: absolute; left: 5px; top: 4px; bottom: 0;
  width: 2px; background: var(--line);
}
.timeline .ev {
  position: relative; padding-bottom: 14px;
}
.timeline .ev::before {
  content: ''; position: absolute; left: -16px; top: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #fff; border: 2px solid var(--gold);
}
.timeline .ev .when { font-size: 11.5px; color: var(--muted); }
.timeline .ev .what { font-size: 13.5px; color: var(--ink); margin-top: 1px; }
.timeline .ev .by   { font-size: 11.5px; color: var(--muted); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,42,74,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff; border-radius: 10px;
  width: 540px; max-width: 92%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  overflow: hidden;
}
.modal-h {
  padding: 16px 22px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-h h3 { margin: 0; color: var(--navy); font-size: 16px; }
.modal-b { padding: 18px 22px; }
.modal-f { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: #fafbfc; }
.modal label { display: block; font-size: 12.5px; color: var(--muted); margin: 8px 0 4px; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.modal textarea { min-height: 80px; }
.modal .calc {
  background: #fafbfc; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; margin: 10px 0;
  font-size: 13px;
}
.modal .calc-row { display: flex; justify-content: space-between; padding: 3px 0; }
.modal .calc-row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; font-weight: 700; color: var(--navy); }

/* Toast */
.toast-wrap { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--navy); color: #fff;
  padding: 10px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 10px 24px rgba(0,0,0,0.18);
  min-width: 220px;
  animation: slideIn 0.18s ease;
}
.toast.ok::before { content: '✓ '; color: #7ce0a4; font-weight: 700; }
.toast.err::before { content: '! '; color: #ff8a8a; font-weight: 700; }
@keyframes slideIn { from { transform: translateY(-8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Homeowner portal mode */
.ho-shell {
  background: linear-gradient(180deg, #f4f7fb 0%, #fafbfc 200px);
  min-height: 100vh;
  font-family: -apple-system, "SF Pro Text", system-ui, sans-serif;
}
.ho-top {
  background: var(--navy); color: #fff;
  padding: 16px 32px;
  display: flex; justify-content: space-between; align-items: center;
}
.ho-top .brand { font-weight: 700; }
.ho-top .brand .sub { color: var(--gold); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; }
.ho-top .who { font-size: 13px; }
.ho-page { max-width: 920px; margin: 0 auto; padding: 32px 24px 64px; }
.ho-card {
  background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 22px 26px; margin-bottom: 16px;
}
.ho-bal {
  display: flex; justify-content: space-between; align-items: flex-end;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px; margin-bottom: 18px;
}
.ho-bal .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.ho-bal .num { font-size: 38px; font-weight: 700; color: var(--navy); letter-spacing: -0.01em; }
.ho-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.role-toggle {
  display: flex; background: #eef0f3; border-radius: 8px; padding: 3px;
}
.role-toggle button {
  background: transparent; border: 0; padding: 6px 14px;
  font-size: 12.5px; border-radius: 6px; color: var(--muted);
}
.role-toggle button.active { background: #fff; color: var(--navy); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
