/* AllFinancials — dashboard styles. Adopted from the Turns design language. */
:root {
  --bg: #f8f9fa;
  --bg-card: #fff;
  --text: #2c3e50;
  --text-muted: #95a5a6;
  --border: #ecf0f1;
  --border-hover: #d5dbdb;
  --primary: #2c3e50;
  --primary-hover: #34495e;
  --primary-bg: #f0f4f8;
  --success: #27ae60;
  --success-bg: #f0fdf4;
  --warning: #f39c12;
  --warning-bg: #fffbeb;
  --danger: #e74c3c;
  --danger-bg: #fef2f2;
  --danger-hover: #c0392b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 { font-size: 20px; font-weight: 600; color: var(--text); }
header nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius);
  transition: background 0.15s;
}
header nav a:hover { background: var(--border); color: var(--text); }
main { padding: 24px; max-width: 1200px; margin: 0 auto; }

a.btn,
button.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
button.btn { font-family: inherit; }
.btn:hover { background: var(--primary-hover); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--border); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

/* User bar above the rollup ----------------------------------------------- */
.user-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.user-name { font-weight: 500; color: var(--text); }
.user-email { color: var(--text-muted); }
.user-bar a { color: var(--primary); text-decoration: none; }
.user-bar a:hover { text-decoration: underline; }
.badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

/* Top-line summary cards -------------------------------------------------- */
.topline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin: 16px 0 24px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  transition: box-shadow 0.15s;
}
.card:hover { box-shadow: var(--shadow-hover); }
.card-pos { border-top: 3px solid var(--success); }
.card-neg { border-top: 3px solid var(--danger); }
.card-neutral { border-top: 3px solid var(--text-muted); }
.card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.card-value {
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* Per-entity rollup table ------------------------------------------------- */
.entities { margin-top: 24px; }
.entities h3 { margin-bottom: 12px; font-size: 16px; font-weight: 600; }
.rollup-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.rollup-table th,
.rollup-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.rollup-table thead th {
  background: var(--bg);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.rollup-table tbody tr:last-child td { border-bottom: none; }
.rollup-table tbody tr:hover { background: var(--bg); }
.rollup-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.error {
  background: var(--danger-bg);
  border-left: 3px solid var(--danger);
  padding: 16px;
  border-radius: var(--radius);
  color: var(--text);
}

.footer {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 16px;
}
.loading { color: var(--text-muted); font-style: italic; }

/* Tab bar ----------------------------------------------------------------- */
.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 0 0 24px;
}
.tab {
  padding: 10px 16px;
  text-decoration: none;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Uploader ---------------------------------------------------------------- */
.uploader {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.uploader h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.uploader-header {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  gap: 8px;
}
.form-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 8px 0;
}
.form-row input[type=file] {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.hint { color: var(--text-muted); font-size: 13px; margin: 8px 0; }
.error-inline { color: var(--danger); }
.ok { color: var(--success); }

/* Sequential upload progress -------------------------------------------- */
.upload-current-status {
  display: inline-block;
  background: var(--primary-bg);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  margin-left: 8px;
}
.upload-results {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  font-size: 13px;
  max-height: 240px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.upload-results li {
  padding: 2px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.upload-result-ok { color: var(--success); }
.upload-result-warn { color: var(--danger); }

/* Rules tab ---------------------------------------------------------------- */
.rule-form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 16px;
}
.rule-form-grid label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: block;
}
.rule-form-grid input,
.rule-form-grid select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
}
.rule-form-grid input:focus,
.rule-form-grid select:focus { outline: none; border-color: var(--primary); }
.rule-form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}
.rules-list { margin-top: 24px; }
.rules-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 13px;
}
.rules-table th,
.rules-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.rules-table thead th {
  background: var(--bg);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.rules-table tbody tr:last-child td { border-bottom: none; }
.rules-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.rule-pattern {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Documents table --------------------------------------------------------- */
.documents { margin-top: 16px; }
.docs-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.docs-table th,
.docs-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 14px;
}
.docs-table thead th {
  background: var(--bg);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.docs-table tbody tr:last-child td { border-bottom: none; }
.docs-table tbody tr:hover { background: var(--bg); }
.docs-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.filename { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
.status-uploaded { background: var(--warning-bg); color: var(--warning); }
.status-parsed { background: var(--primary-bg); color: var(--primary); }
.status-associatedwithentity { background: var(--primary-bg); color: var(--primary); }
.status-applied { background: var(--success-bg); color: var(--success); }
.status-archived { background: var(--danger-bg); color: var(--danger); }

/* (button styles for both `a.btn` and `button.btn` are defined at the top) */

/* Modal ------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  width: 520px;
  max-width: 92vw;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.modal h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal label {
  display: block;
  margin: 12px 0;
  font-size: 13px;
  font-weight: 500;
}
.modal input,
.modal select {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
}
.modal input:focus,
.modal select:focus { outline: none; border-color: var(--primary); }
.modal fieldset {
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.modal fieldset[disabled] { opacity: 0.5; }
.modal legend { font-size: 12px; color: var(--text-muted); padding: 0 6px; font-weight: 600; }
.modal details summary {
  cursor: pointer;
  color: var(--primary);
  padding: 8px 0;
  font-size: 13px;
  font-weight: 500;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Entity detail view ------------------------------------------------------ */
.tab-context {
  background: transparent;
  border-bottom-color: transparent !important;
  color: var(--primary) !important;
  cursor: default;
  font-weight: 600;
}
.entity-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.entity-link:hover { text-decoration: underline; }
.back-link { color: var(--text-muted); text-decoration: none; font-size: 13px; }
.back-link:hover { color: var(--primary); text-decoration: underline; }
.entity-header h2 { margin: 8px 0 4px; font-size: 24px; font-weight: 600; }
.entity-header h2 small {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.6em;
  margin-left: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.gl-balances, .journal-ledger { margin-top: 24px; }
.gl-balances h3, .journal-ledger h3 { font-size: 16px; font-weight: 600; }
.gl-balances h3 small,
.journal-ledger h3 small {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.7em;
  margin-left: 8px;
}
.gl-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text);
}
.gl-related-party td:first-child::before {
  content: '⚑ ';
  color: var(--warning);
  font-weight: bold;
}
.gifi {
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
}
.journal-table .memo { max-width: 380px; }
.tag-pill {
  display: inline-block;
  background: var(--warning-bg);
  color: var(--warning);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.7rem;
  margin-left: 0.3em;
}

/* GL balances row interactions */
.gl-balances-table tbody tr {
  cursor: pointer;
  transition: background-color 0.08s ease;
}
.gl-balances-table tbody tr:hover {
  background: var(--primary-bg);
}
.gl-row-active {
  background: var(--primary-bg) !important;
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* JE filter bar */
.je-filters {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  margin-top: 24px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.je-filters label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  gap: 4px;
}
.je-filters input {
  padding: 6px 10px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 9rem;
  font-family: inherit;
}
.je-filters input[type="search"] { min-width: 16rem; }
.je-filters input:focus { outline: none; border-color: var(--primary); }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 0;
  text-decoration: underline;
  font-family: inherit;
  font-weight: 500;
}
.link-btn:hover { color: var(--primary-hover); }
.gl-balances h3 .link-btn { margin-left: 8px; font-size: 12px; }

/* JE actions cell + suspense highlight */
.je-actions { white-space: nowrap; }
.je-actions .link-btn { margin-right: 8px; padding: 2px 0; }
.je-suspense { background: var(--warning-bg); }
.je-suspense:hover { background: #fef3c7; }

/* Inline reclassify form */
.je-reclassify-row td {
  background: var(--primary-bg);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.reclassify-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.reclassify-form label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  gap: 4px;
}
.reclassify-form select,
.reclassify-form input {
  padding: 6px 10px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 11rem;
  font-family: inherit;
}
.reclassify-form select { min-width: 18rem; }
.reclassify-form select:focus,
.reclassify-form input:focus { outline: none; border-color: var(--primary); }
.reclassify-status.err { color: var(--danger); }

.rule-apply-toggle {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-size: 13px;
}

/* Cell tones for the rollup entity table */
.pos-cell { color: var(--success); }
.neg-cell { color: var(--danger); }

/* Entity-detail summary card --------------------------------------------- */
.entity-summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-top: 16px;
}
.entity-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 20px;
  margin-bottom: 16px;
}
.entity-summary-figure { display: flex; flex-direction: column; gap: 4px; }
.entity-summary-figure-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.entity-summary-figure-value {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.entity-summary-figure-value.muted { color: var(--text-muted); font-size: 14px; font-weight: 500; }
.entity-summary-figure-value.pos { color: var(--success); }
.entity-summary-figure-value.neg { color: var(--danger); }
.entity-summary-actions {
  display: flex;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* Profile fields (legal name, address, jurisdiction, etc.) */
.entity-profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px 24px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}
.entity-profile-field { display: flex; flex-direction: column; gap: 2px; }
.entity-profile-field-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.entity-profile-field-value {
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
  word-break: break-word;
}

/* Cap table (corporations) */
.entity-cap-table,
.entity-cra-programs,
.entity-notes-panel { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.entity-cap-table h4,
.entity-cra-programs h4,
.entity-notes-panel h4 { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.entity-cap-table table,
.entity-cra-programs table { box-shadow: none; border: 1px solid var(--border); }
.entity-cap-table th,
.entity-cra-programs th { font-size: 11px; }
.entity-cap-table td,
.entity-cra-programs td { font-size: 13px; }

/* Description tagline at the top of the entity card */
.entity-description {
  font-size: 13px;
  color: var(--text-muted);
  padding: 0 0 14px 0;
  margin: -4px 0 16px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
}

/* Notes panel — markdown-rendered free-form */
.entity-notes-body { font-size: 13px; color: var(--text); line-height: 1.6; }
.entity-notes-body h5 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 12px 0 4px;
}
.entity-notes-body h5:first-child { margin-top: 0; }
.entity-notes-body p { margin: 0 0 8px; }
.entity-notes-body ul { margin: 0 0 8px; padding-left: 20px; }
.entity-notes-body li { margin: 2px 0; }

/* CRA program accounts editor in modal */
.cra-program-edit-table { font-size: 13px; }
.cra-program-edit-table input,
.cra-program-edit-table select {
  width: 100%;
  padding: 4px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
}
.cra-program-edit-table input:focus,
.cra-program-edit-table select:focus { outline: none; border-color: var(--primary); }
.cra-program-edit-table td { padding: 6px 8px; }

/* Status pills for CRA program rows reuse existing status- classes */
.status-active { background: var(--success-bg); color: var(--success); }
.status-closed { background: var(--bg); color: var(--text-muted); }
.status-suspended { background: var(--warning-bg); color: var(--warning); }

/* Fieldset cleanup inside the edit modal */
.modal fieldset .rollup-table { box-shadow: none; }
.modal textarea {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  margin-top: 6px;
  resize: vertical;
  line-height: 1.5;
}
.modal textarea:focus { outline: none; border-color: var(--primary); }

/* Entity toggle column on the rollup table */
.entity-toggle-cell { width: 40px; }
.entity-row-excluded { opacity: 0.4; }
.entity-row-excluded a.entity-link { color: var(--text-muted); }
.entity-row-excluded td.num { text-decoration: line-through; }
.entities h3 .link-btn { margin-left: 12px; font-size: 12px; font-weight: 500; }

/* Inter-entity money-flow diagram (Sankey-ish) */
.inter-entity-flows {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-top: 24px;
  box-shadow: var(--shadow);
}
.inter-entity-flows h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.inter-entity-flows h3 small {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.7em;
  margin-left: 8px;
}
.flow-svg {
  display: block;
  margin: 16px 0;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 8px;
}
.flow-band path {
  fill: none;
  stroke: var(--danger);
  stroke-opacity: 0.35;
  transition: stroke-opacity 0.15s;
}
.flow-band:hover path {
  stroke-opacity: 0.7;
}
.flow-node rect {
  fill: var(--bg-card);
  stroke: var(--primary);
  stroke-width: 1.5;
}
.flow-node-target rect { fill: var(--primary-bg); }
.flow-node-name {
  font-size: 13px;
  font-weight: 600;
  fill: var(--text);
  font-family: 'SF Pro Display', -apple-system, sans-serif;
}
.flow-node-amount {
  font-size: 11px;
  fill: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-family: 'SF Pro Display', -apple-system, sans-serif;
}
.flow-node-transit rect {
  fill: var(--warning-bg);
  stroke: var(--warning);
}
.flow-table { margin-top: 16px; font-size: 13px; }
.flow-table th, .flow-table td { padding: 8px 12px; }
.flow-table tr:hover td { background: var(--bg); }
.flow-table td:nth-child(2) { color: var(--text-muted); text-align: center; padding: 0; }

/* Cash-trajectory waterfall (entity detail) */
.run-rate-waterfall { margin-top: 16px; }
.run-rate-waterfall h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.waterfall-svg {
  display: block;
  margin: 12px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}
.waterfall-bar { rx: 2; }
.waterfall-pos { fill: var(--success); fill-opacity: 0.8; }
.waterfall-neg { fill: var(--danger); fill-opacity: 0.8; }
.waterfall-tick { stroke: var(--text); stroke-width: 1.5; }
.waterfall-step { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.waterfall-zero-line { stroke: var(--text-muted); stroke-width: 1; }
.waterfall-label {
  font-size: 10px;
  fill: var(--text-muted);
  text-anchor: middle;
  font-family: 'SF Pro Display', -apple-system, sans-serif;
  font-variant-numeric: tabular-nums;
}
.waterfall-axis-tick line { stroke: var(--border); stroke-width: 1; }
.waterfall-axis-label {
  font-size: 10px;
  fill: var(--text-muted);
  text-anchor: end;
  font-variant-numeric: tabular-nums;
  font-family: 'SF Pro Display', -apple-system, sans-serif;
}

/* Spend breakdown bars (entity detail) */
.spend-breakdown { margin-top: 24px; }
.spend-breakdown h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.spend-breakdown h3 small {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.7em;
  margin-left: 8px;
}
.spend-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}
.spend-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.spend-row:last-child { border-bottom: none; }
.spend-row-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.spend-row-name { color: var(--text); font-weight: 500; }
.spend-row-direction {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: var(--radius);
}
.spend-row-direction.spend-pos { background: var(--success-bg); color: var(--success); }
.spend-row-direction.spend-neg { background: var(--danger-bg); color: var(--danger); }
.spend-row-occurrences { color: var(--text-muted); font-size: 11px; margin-left: auto; }
.spend-row-bar-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
}
.spend-row-bar {
  height: 14px;
  border-radius: 3px;
  min-width: 1px;
  transition: width 0.2s;
}
.spend-bar-pos { background: var(--success); opacity: 0.7; }
.spend-bar-neg { background: var(--danger); opacity: 0.7; }
.spend-row-amount {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}

/* Efficiency snapshot panel (rollup) */
.efficiency-panel { margin-top: 24px; }
.efficiency-panel h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.efficiency-panel h3 small {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.7em;
  margin-left: 8px;
}
.efficiency-table .efficiency-bar-cell {
  width: 18%;
  padding: 8px 4px;
}
.efficiency-bar {
  height: 10px;
  border-radius: 2px;
  background: var(--text-muted);
  min-width: 1px;
  transition: width 0.2s;
}
.efficiency-bar-pos { background: var(--success); opacity: 0.75; }
.efficiency-bar-neg { background: var(--danger); opacity: 0.75; }
.efficiency-bar-warn { background: var(--warning); opacity: 0.85; }
.efficiency-bar-muted { background: var(--primary); opacity: 0.4; }
.efficiency-pos-text { color: var(--success); }
.efficiency-neg-text { color: var(--danger); }
.efficiency-muted-text { color: var(--text-muted); }

/* JE filter checkbox (suspense-only) */
.je-filter-checkbox {
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
  font-size: 12px;
  font-weight: 500;
  text-transform: none !important;
  letter-spacing: normal !important;
  color: var(--text) !important;
  cursor: pointer;
  user-select: none;
  padding-bottom: 4px;
}
.je-filter-checkbox input { margin: 0; }

/* Spend breakdown row hover (clickable) */
.spend-row-clickable {
  cursor: pointer;
  margin: 0 -12px;
  padding: 12px;
  border-radius: var(--radius);
  transition: background 0.12s;
}
.spend-row-clickable:hover {
  background: var(--bg);
}
.spend-row-clickable:hover .spend-row-bar { opacity: 1; }

/* Suggested-rules panel on the Rules tab */
.rule-suggestions {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.rule-suggestions h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.rule-suggestions h3 small {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.7em;
  margin-left: 8px;
}
.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.suggestion-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.suggestion-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-hover);
}
.suggestion-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.suggestion-amount {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.suggestion-direction {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: var(--radius);
}
.suggestion-count { color: var(--text-muted); font-size: 12px; margin-left: auto; }
.suggestion-memo {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text);
  background: var(--bg-card);
  padding: 8px 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
  word-break: break-word;
}
.suggestion-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Live regex match preview in the rule editor */
.rule-pattern-preview {
  display: block;
  font-size: 12px;
  margin-top: 4px;
  font-style: italic;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: pre-line;
}
.rule-pattern-preview[data-tone="pos"] { color: var(--success); font-style: normal; }
.rule-pattern-preview[data-tone="neg"] { color: var(--danger); font-style: normal; }

/* Entity-detail run-rate panel */
.entity-run-rate { margin-top: 24px; }
.entity-run-rate h3 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.run-rate-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  gap: 24px;
  align-items: start;
}
.run-rate-figs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.run-rate-spark {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-height: 90px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.spark-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
}
.spark-bar {
  width: 100%;
  min-height: 1px;
  border-radius: 2px;
}
.spark-pos { background: var(--success); }
.spark-neg { background: var(--danger); }
.spark-neutral { background: var(--border-hover); }
.spark-label {
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* Recurring-obligations table */
.recurring-obligations { margin-top: 24px; }
.recurring-obligations h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.recurring-outflow td:nth-child(2) { color: var(--danger); font-weight: 500; }
.recurring-inflow td:nth-child(2) { color: var(--success); font-weight: 500; }
.recurring-table .memo { max-width: 360px; }

/* Documents filter bar */
.docs-filter-bar {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.docs-filter-bar label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  gap: 6px;
}
.docs-filter-bar select {
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  min-width: 16rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
}
.docs-filter-bar select:focus { outline: none; border-color: var(--primary); }

/* Deprecated CoA rows (shown in the CoA modal) */
.coa-deprecated td { opacity: 0.55; font-style: italic; }
