:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #1a2230;
  --muted: #66738a;
  --border: #e3e8ef;
  --accent: #1e7a46;      /* SA green */
  --accent-2: #d4a017;    /* gold */
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
  --radius: 12px;
}
:root[data-theme="dark"] {
  --bg: #0f141b;
  --panel: #1a212b;
  --panel-2: #141a22;
  --text: #e6ebf2;
  --muted: #93a1b5;
  --border: #2a333f;
  --accent: #2fa35f;
  --accent-2: #e0b437;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

* { 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);
  line-height: 1.5;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--panel);
  border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 12px;
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 32px; }
.brand h1 { margin: 0; font-size: 20px; }
.tagline { margin: 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs {
  display: flex; gap: 4px; padding: 0 16px; background: var(--panel);
  border-bottom: 1px solid var(--border); overflow-x: auto;
  position: sticky; top: 0; z-index: 30;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: none; background: none; padding: 12px 16px; font-size: 14px;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
  white-space: nowrap; font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main { padding: 24px; max-width: 1200px; margin: 0 auto;
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
.panel { display: none; }
.panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 20px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: 16px; }
.head-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.stat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.accent { border-top: 3px solid var(--accent); }
.stat.gold { border-top: 3px solid var(--accent-2); }

/* buttons */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
  font-weight: 500; transition: .15s;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn.link { border: none; background: none; color: var(--accent); padding: 4px; }

/* tables */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--panel-2); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.ok { background: rgba(46,163,95,.15); color: var(--accent); }
.badge.good { background: rgba(46,163,95,.15); color: var(--accent); }
.badge.warn { background: rgba(212,160,23,.18); color: var(--accent-2); }
.badge.bad { background: rgba(192,57,43,.15); color: var(--danger); }
.neg { color: var(--danger); font-weight: 600; }
.pos { color: var(--accent); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 28px; font-size: 14px; }

/* progress */
.progress { height: 16px; background: var(--panel-2); border-radius: 20px; overflow: hidden; border: 1px solid var(--border); }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0; transition: width .5s ease; }
.progress-legend { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; color: var(--muted); }

/* forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input, select {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel-2); color: var(--text); font-size: 14px; font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form label.check input { width: auto; }
small.muted { font-weight: 400; }

/* breakdown */
.breakdown { display: flex; flex-direction: column; gap: 2px; }
.breakdown .row { display: flex; justify-content: space-between; padding: 10px 4px; border-bottom: 1px solid var(--border); font-size: 14px; }
.breakdown .row.total { font-weight: 700; font-size: 16px; border-bottom: none; border-top: 2px solid var(--border); margin-top: 4px; padding-top: 14px; }
.breakdown .row .lbl { color: var(--muted); }

/* statement */
.statement { font-size: 14px; }
.statement h3 { margin: 0 0 4px; }
.stmt-meta { color: var(--muted); font-size: 13px; margin-bottom: 16px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10,15,22,.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal-overlay[hidden] { display: none; }
.toast[hidden] { display: none; }
.modal {
  background: var(--panel); border-radius: var(--radius); width: 100%; max-width: 480px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3); max-height: 90vh; overflow-y: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 8px;
  font-size: 14px; box-shadow: var(--shadow); z-index: 60; animation: fade .2s ease;
}

/* yearly summary table */
#yearlyTable .rowlbl { font-weight: 600; color: var(--muted); white-space: nowrap; }
#yearlyTable tr.strong td { font-weight: 700; }
#yearlyTable tr.strong { background: var(--panel-2); }

/* proof of payment */
.pop-state { min-height: 20px; font-size: 13px; }
.pop-state .btn.link { padding: 2px 4px; }

/* import status */
.import-status { margin-top: 12px; padding: 10px 14px; border-radius: 8px; font-size: 13px; background: var(--panel-2); border: 1px solid var(--border); }
.import-status.ok { border-color: var(--accent); color: var(--accent); }
.import-status.err { border-color: var(--danger); color: var(--danger); }

/* inset cards */
.card.inset { background: var(--panel-2); margin-top: 16px; }
.card.inset h3 { margin: 0 0 12px; font-size: 15px; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.map-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }

/* review table */
table.review td.desc { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }
table.review tr.dup { background: rgba(212,160,23,.08); }
table.review select { padding: 5px 8px; font-size: 12px; }

/* suggestion */
.suggest p { margin-top: 0; }
.suggest-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 14px 0; }
.suggest-grid > div { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.suggest-grid .label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.suggest-grid .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.suggest-grid .sub { font-size: 12px; color: var(--muted); }

/* polls */
.poll { border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 14px; }
.poll.closed { opacity: .85; }
.poll-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.poll-head h3 { margin: 0; font-size: 15px; }
.poll-opt { margin-bottom: 12px; }
.poll-opt-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.poll-bar { height: 10px; background: var(--panel-2); border-radius: 20px; overflow: hidden; border: 1px solid var(--border); margin-bottom: 6px; }
.poll-bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s ease; }
textarea { padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); color: var(--text); font-size: 14px; font-family: inherit; resize: vertical; }

@media print {
  .topbar, .tabs, .head-tools, .card-head button, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; }
  .panel { display: none !important; }
  #tab-reports { display: block !important; }
}

/* ---------- Phase 2 additions ---------- */
.login-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--bg); z-index: 40; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 380px; }
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand .logo { font-size: 40px; }
.login-brand h1 { font-size: 20px; margin: 8px 0 2px; }
.who { font-size: 13px; color: var(--muted); padding: 0 6px; }
.badge.pending { background: rgba(212,160,23,.18); color: var(--accent-2); }
.badge.confirmed { background: rgba(46,163,95,.15); color: var(--accent); }

/* role-based visibility: body carries role-admin or role-member */
body.role-member [data-role="admin"] { display: none !important; }
body.role-admin [data-role="member"] { display: none !important; }

.login-screen[hidden], #app[hidden] { display: none !important; }

/* ---------- Phase 3: properties, meetings, ideas, insights ---------- */
.prop { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; background: var(--panel-2); }
.prop-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.prop-head h3 { margin: 0; font-size: 16px; }
.prop-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-top: 12px; }
.prop-grid .label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.prop-grid .v { font-size: 16px; font-weight: 600; margin-top: 2px; }

.mtg { display: flex; gap: 14px; align-items: flex-start; border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 10px; }
.mtg.past { opacity: .6; }
.mtg-when { min-width: 140px; }
.mtg-when .d { font-weight: 700; }
.mtg-body { flex: 1; }
.mtg-body h3 { margin: 0 0 4px; font-size: 15px; }

.idea { border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.idea-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.idea-head h3 { margin: 0; font-size: 15px; }
.comments { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.cmt { font-size: 13px; padding: 6px 10px; background: var(--panel-2); border-radius: 8px; }
.cmt-add { display: flex; gap: 8px; margin-top: 8px; }
.cmt-add input { flex: 1; }

.insights .insight-body { margin-top: 12px; line-height: 1.6; font-size: 14px; }
.insights h3, .insights h4 { margin: 14px 0 4px; }
.insight-body { white-space: normal; }

/* rich rendered markdown (AI verdict / insights) */
.insight-body h2 { font-size: 17px; margin: 18px 0 6px; }
.insight-body h3 { font-size: 15px; margin: 14px 0 5px; }
.insight-body h4, .insight-body h5 { font-size: 13.5px; margin: 12px 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.insight-body p { margin: 8px 0; }
.insight-body ul, .insight-body ol { margin: 6px 0 10px; padding-left: 22px; }
.insight-body li { margin: 3px 0; }
.insight-body code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.insight-body hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.insight-body a { color: var(--accent); }
.insight-body .tbl-wrap { overflow-x: auto; margin: 10px 0; }
.insight-body table { border-collapse: collapse; width: 100%; font-size: 13px; }
.insight-body th, .insight-body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.insight-body thead th { background: var(--panel-2); font-weight: 600; }

/* collapsible AI verdict card (dashboard + ideas board) */
.verdict-card { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); margin-bottom: 16px; overflow: hidden; }
.verdict-card > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; padding: 14px 16px; font-weight: 600; }
.verdict-card > summary::-webkit-details-marker { display: none; }
.verdict-card > summary .v-title { flex: 1; }
.verdict-card > summary .v-del { font-weight: 500; color: var(--danger); }
.verdict-card > summary::after { content: "▾ show"; color: var(--muted); font-weight: 400; font-size: 12px; white-space: nowrap; }
.verdict-card[open] > summary::after { content: "▴ hide"; }
.verdict-card[open] > summary { border-bottom: 1px solid var(--border); }
.verdict-card .v-title { color: var(--accent); }
.verdict-card .insight-body, .verdict-card .sources, .verdict-card .v-note { padding: 0 16px; }
.verdict-card .insight-body { padding-top: 12px; padding-bottom: 12px; line-height: 1.6; font-size: 14px; }
.verdict-card .v-note { padding-top: 10px; }
.verdict-card .sources { padding-bottom: 14px; font-size: 12px; color: var(--muted); }
.verdict-card .sources ul { margin: 4px 0 0; padding-left: 18px; }

.verdict-card .v-actions { padding: 0 16px 14px; }
.verdict-card .v-meta { text-align: right; }

/* AI staleness nudge (admin prompt to refresh) */
.ai-nudge { display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); font-size: 13px; color: var(--muted); }
.ai-nudge.stale { border-color: var(--gold, #b8860b); background: rgba(184,134,11,.10); color: inherit; font-weight: 500; }
.v-actions { margin-top: 12px; }

/* admin/member preview banner */
.preview-banner { background: var(--gold, #b8860b); color: #fff; padding: 8px 16px; font-size: 13px; text-align: center; }
.preview-banner .btn.link { color: #fff; text-decoration: underline; font-weight: 600; }

/* rentals & income */
.tenant { display: grid; grid-template-columns: 1.4fr .8fr 1.2fr auto; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; font-size: 13px; }
@media (max-width: 720px) { .tenant { grid-template-columns: 1fr; } }
.rsub { margin: 16px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.rsub-row { display: flex; justify-content: space-between; align-items: center; }
.insights .sources { margin-top: 14px; font-size: 12px; color: var(--muted); }
.insights .sources ul { margin: 4px 0 0; padding-left: 18px; }

/* idea viewing + checklist */
.idea.off { opacity: .65; }
.idea-actions { display: flex; gap: 8px; margin: 10px 0 6px; flex-wrap: wrap; }
.checklist { max-height: 55vh; overflow-y: auto; margin-bottom: 8px; }
.chk-row { display: grid; grid-template-columns: 1fr 108px 1fr; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.chk-row select, .chk-row input { padding: 5px 8px; font-size: 12px; }
@media (max-width: 640px) { .chk-row { grid-template-columns: 1fr; gap: 4px; } }

/* password show/hide */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 40px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; font-size: 16px; line-height: 1; padding: 6px; opacity: .65; }
.pw-toggle:hover { opacity: 1; }

/* ---------- Desktop niceties ---------- */
@media (min-width: 1000px) {
  main { padding: 28px 24px; }
  .stat .value { font-size: 26px; }
}

/* ---------- Tablet ---------- */
@media (max-width: 820px) {
  main { padding: 18px; }
  .card { padding: 16px; }
  .topbar { padding: 12px 16px; }
}

/* ---------- Phone ---------- */
@media (max-width: 600px) {
  main { padding: 12px; }
  .card { padding: 14px; margin-bottom: 14px; border-radius: 10px; }

  /* compact header: keep brand small, let actions wrap on their own row */
  .topbar { padding: 10px 12px; gap: 8px; }
  .brand { gap: 10px; }
  .logo { font-size: 24px; }
  .brand h1 { font-size: 16px; }
  .tagline { display: none; }
  .who { width: 100%; order: 5; padding: 0; }
  .topbar-actions { gap: 6px; width: 100%; justify-content: flex-start; }
  .topbar-actions .btn { padding: 8px 10px; }
  #yearSelect { min-width: 104px; }

  /* bigger tap targets for tabs */
  .tab { padding: 12px 12px; font-size: 13px; }

  /* stack stats one per row for readability, keep them compact */
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .stat { padding: 13px; }
  .stat .value { font-size: 19px; }
  .stat .label { font-size: 11px; }

  .card-head { margin-bottom: 12px; }
  .card-head h2 { font-size: 15px; }
  .head-tools { width: 100%; }
  .head-tools .btn { flex: 1; }

  /* 16px inputs stop iOS Safari from zooming in on focus */
  input, select, textarea { font-size: 16px; }

  /* meetings stack cleanly */
  .mtg { flex-direction: column; gap: 6px; }
  .mtg-when { min-width: 0; }

  /* verdict summary wraps instead of squashing */
  .verdict-card > summary { flex-wrap: wrap; gap: 4px 10px; }
  .verdict-card .v-meta { text-align: left; }

  /* bottom-sheet style modal — easier to reach with a thumb */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; max-height: 88vh; border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom); }
  .modal-actions { position: sticky; bottom: 0; background: var(--panel); padding-bottom: 4px; }
  .modal-actions .btn { flex: 1; padding: 11px; }

  .breakdown .row.total { font-size: 15px; }
  .toast { left: 12px; right: 12px; transform: none; text-align: center; bottom: max(16px, env(safe-area-inset-bottom)); }
}

/* very small phones: single-column stats */
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
}
