:root {
  --bg: #f3f4f7;
  --panel: #ffffff;
  --border: #e4e7ec;
  --border-strong: #d3d7e0;
  --text: #1a1f2b;
  --muted: #6b7280;
  --muted-light: #98a1b0;
  --brand: #2f6f4f;
  --brand-dark: #24593f;
  --brand-light: #e9f4ee;
  --accent: #3457d5;
  --danger: #b3261e;
  --danger-light: #fbe1df;
  --warn: #a15c00;
  --warn-light: #fff3d6;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 33, 0.05);
  --shadow-md: 0 2px 10px rgba(20, 24, 33, 0.06), 0 1px 2px rgba(20, 24, 33, 0.04);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; flex-direction: column; height: 100vh; }
.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 224px;
  background: linear-gradient(180deg, #1b2430 0%, #171e28 100%);
  color: #d7dde5;
  padding: 20px 0;
  flex-shrink: 0;
  box-shadow: 1px 0 0 rgba(0,0,0,.05);
  overflow-y: auto;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  color: #fff;
  padding: 0 20px 18px 20px;
  border-bottom: 1px solid #2c374a;
  margin-bottom: 10px;
  letter-spacing: -.01em;
}
.sidebar .brand img { width: 32px; height: 32px; border-radius: 50%; background: #fff; flex-shrink: 0; }
.sidebar .brand small { display:block; font-weight:400; font-size:11px; color:#9aa7ba; margin-top:2px;}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: #c3cbd8;
  font-size: 13.5px;
  border-left: 3px solid transparent;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: .8; }
.sidebar nav a.active .nav-icon, .sidebar nav a:hover .nav-icon { opacity: 1; }
.sidebar nav a:hover {
  background: #232d3f;
  color: #fff;
  text-decoration: none;
}
.sidebar nav a.active {
  background: #26314a;
  color: #fff;
  text-decoration: none;
  border-left-color: var(--brand);
  font-weight: 600;
}
.sidebar .section-label {
  padding: 16px 20px 5px 20px;
  font-size: 10.5px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: #6f7c93;
}
.logout-form { margin-top: 4px; }
.logout-form button {
  all: unset;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: #c3cbd8;
  font-size: 13.5px;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
  transition: color .12s ease;
}
.logout-form button:hover { color: #fff; }

.sidebar-scrim { display: none; }

.main { flex: 1; padding: 28px 36px 60px 36px; max-width: 1677px; overflow-y: auto; min-height: 0; }
.page-title { font-size: 22px; font-weight: 700; margin: 0 0 4px 0; letter-spacing: -.01em; }
.page-sub { color: var(--muted); margin: 0 0 22px 0; font-size: 13px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}
.card h2, .card h3 { margin-top: 0; }
.card h3 { font-size: 14.5px; font-weight: 700; letter-spacing: -.005em; margin-bottom: 12px; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--brand);
  border-radius: var(--radius);
  padding: 15px 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease, transform .15s ease;
}
.kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.kpi-icon { width: 16px; height: 16px; color: var(--muted-light); flex-shrink: 0; }
.kpi .label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi .value { font-size: 23px; font-weight: 700; margin-top: 6px; letter-spacing: -.01em; }
.kpi .value.negative { color: var(--danger); }
.kpi .value.positive { color: var(--brand); }

table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 2px solid var(--border-strong); }
tbody tr:nth-child(even) td { background: #fafbfc; }
tr:hover td { background: #f2f6f4; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-top: 2px solid var(--text); border-bottom: none; background: transparent !important; }

/* -------------------------------------------------------------------------
   Report drill-down - click a line on Trial Balance / P&L / Balance Sheet
   to expand the transactions behind that total in place, QuickBooks-"zoom"
   style, instead of leaving the report to look them up. See
   _report_drilldown.html for the JS and the account_drilldown JSON route
   in app/routers/reports.py.
   ------------------------------------------------------------------------- */
.drilldown-toggle {
  background: none; border: none; padding: 2px; margin: 0 4px 0 -4px; cursor: pointer;
  color: var(--muted-light); vertical-align: middle; border-radius: 4px; line-height: 0;
}
.drilldown-toggle:hover { color: var(--brand); background: var(--brand-light); }
.drilldown-chevron { width: 13px; height: 13px; transition: transform .15s ease; }
.drilldown-toggle.is-open .drilldown-chevron { transform: rotate(90deg); }
tbody tr.drilldown-detail-row td { background: var(--bg); border-bottom: 1px solid var(--border); padding: 12px 11px 14px 34px; }
tr.drilldown-detail-row:hover td { background: var(--bg); }
.drilldown-table { font-size: 12.5px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.drilldown-table th, .drilldown-table td { padding: 6px 10px; }
.drilldown-table tfoot td { font-weight: 600; border-top: 1px solid var(--border); background: var(--bg); }
.drilldown-loading, .drilldown-empty { color: var(--muted); font-size: 12.5px; margin: 2px 0; }
.drilldown-error { color: var(--danger); font-size: 12.5px; margin: 2px 0; }
.drilldown-footer { font-size: 12px; color: var(--muted); margin: 8px 0 0 0; }

/* Financial-statement section/subtotal rows (P&L, Balance Sheet, and similar
   grouped reports) - a clear visual break between groups instead of a plain
   bolded cell sitting in the regular row flow. */
tr.stmt-section td {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--brand-dark);
  background: var(--brand-light) !important;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding-top: 8px;
  padding-bottom: 8px;
}
tr.stmt-subtotal td {
  font-weight: 700;
  border-top: 1px solid var(--border-strong);
  background: #fafbfc !important;
}
tr.stmt-grandtotal td {
  font-weight: 700;
  font-size: 14.5px;
  border-top: 2px solid var(--text);
  background: transparent !important;
}
tr.stmt-line td:first-child { padding-left: 26px; color: var(--text); }

.btn {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(36, 89, 63, .25);
  transition: background .12s ease, box-shadow .12s ease, transform .04s ease;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; box-shadow: 0 2px 6px rgba(36, 89, 63, .3); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border-strong); box-shadow: var(--shadow-sm); }
.btn.secondary:hover { background: #f5f6f8; box-shadow: var(--shadow-sm); }
.btn.danger { background: var(--danger); box-shadow: 0 1px 2px rgba(179, 38, 30, .25); }
.btn.danger:hover { background: #8f1e18; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

form.inline { display: inline; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 13px 20px; max-width: 640px; }
.form-grid.wide { grid-template-columns: 1fr; max-width: 760px; }
/* min-width: 0 overrides a CSS Grid item's default automatic minimum size,
   which otherwise sizes to the min-content width of whatever's inside it -
   for a <select> with long option text (an account picker, say) that can be
   wider than the 1fr share this row is supposed to get, pushing the whole
   form-grid past its max-width and forcing a horizontal scrollbar on the
   card around it instead of just letting the field's own text truncate. */
.form-row { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-row label { font-size: 12.5px; font-weight: 600; color: #4b5563; }
/* Flexbox's default cross-axis "stretch" isn't reliably applied to form
   controls in every browser, so a <select>/<input>/<textarea> here would
   otherwise keep sizing itself to its own content instead of filling the
   row - set explicitly rather than assumed. Anything that needs a smaller,
   fixed width (a handful of inline categorize dropdowns) sets its own
   style="width:...", which wins over this by specificity. */
.form-row > input, .form-row > select, .form-row > textarea { width: 100%; min-width: 0; }
input, select, textarea {
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 111, 79, .13);
}
textarea { resize: vertical; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 100px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge.draft { background: #eceef1; color: #55606e; }
.badge.sent { background: #e3edff; color: #1c4fa3; }
.badge.partial { background: #fff3d6; color: var(--warn); }
.badge.paid { background: #dff3e6; color: var(--brand-dark); }
.badge.overdue { background: #fbe1df; color: var(--danger); }
.badge.void { background: #eee; color: #999; text-decoration: line-through; }
.badge.void::before { display: none; }

.flash { padding: 11px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13.5px; box-shadow: var(--shadow-sm); }
.flash.error { background: var(--danger-light); color: var(--danger); }
.flash.success { background: var(--brand-light); color: var(--brand-dark); }

.section-divider { border: none; border-top: 1px solid var(--border); margin: 22px 0; }
.muted { color: var(--muted); }
.right { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 8px 14px; font-size: 13.5px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--text); font-weight: 600; border-bottom-color: var(--brand); }
.help-text { font-size: 12px; color: var(--muted); margin-top: 2px; }
.line-item-table input, .line-item-table select { width: 100%; }

/* -------------------------------------------------------------------------
   Searchable dropdowns - every <select> on every page (Paid From/Category
   account pickers, Payee, Tax Rate, filters...) is progressively enhanced
   into a type-to-filter combobox at page load (see base.html's script).
   The original <select> is kept in the DOM (display:none) as the real form
   field; .combobox-input is a plain text box standing in for it visually. */
.combobox-wrap { position: relative; display: inline-block; width: auto; }
.form-row > .combobox-wrap, .line-item-table .combobox-wrap { width: 100%; min-width: 0; }
.combobox-native-select { display: none; }
.combobox-input { width: 100%; cursor: text; }
.combobox-input:disabled { cursor: not-allowed; opacity: .6; }
.combobox-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 260px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 4px;
}
.combobox-option { padding: 7px 10px; border-radius: var(--radius-sm); font-size: 13.5px; cursor: pointer; }
.combobox-option:hover, .combobox-option.active { background: var(--brand-light); }
.combobox-optgroup-label {
  padding: 8px 10px 4px 10px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted-light);
}
.combobox-empty { padding: 10px; font-size: 12.5px; color: var(--muted); text-align: center; }
.remove-line { color: var(--danger); cursor: pointer; font-size: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.two-col > * { min-width: 0; } /* let a wide table inside shrink/scroll instead of forcing this column past its 1fr share */
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* -------------------------------------------------------------------------
   Dashboard - a wider, denser layout than the rest of the app (forms and
   statements read better constrained; an overview page benefits from using
   the whole window instead). main-full lifts the shared .main max-width
   just for this page; the grid below reflows at each breakpoint rather
   than leaving empty space on a wide monitor or squeezing on a narrow one.
   ------------------------------------------------------------------------- */
.main.main-full { max-width: none; }
.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 20px;
  align-items: start;
}
.dash-main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.dash-two { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.dash-two > .card, .dash-main > .card { min-width: 0; }
.dash-side { position: sticky; top: 20px; }
.quick-actions { display: flex; flex-direction: column; gap: 8px; }
.quick-actions .btn { text-align: center; }

@media (max-width: 1150px) {
  .dash-grid { grid-template-columns: 1fr; }
  .dash-side { position: static; }
}
@media (max-width: 720px) {
  .dash-two { grid-template-columns: 1fr; }
}

.report-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.email-form { display: none; gap: 8px; align-items: center; margin-bottom: 14px; }
.email-form.open { display: flex; }
.trend-table td.num, .trend-table th.num { min-width: 70px; }

/* -------------------------------------------------------------------------
   Statement / letterhead layout - used by invoice & bill detail pages so
   they read as an actual document rather than a data table with buttons
   glued underneath.
   ------------------------------------------------------------------------- */
.statement {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px 34px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
  overflow-x: auto;
}
.statement-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 26px; flex-wrap: wrap; }
.statement-brand { display: flex; align-items: center; gap: 12px; }
.statement-brand .company-name { font-size: 16.5px; font-weight: 700; letter-spacing: -.01em; }
.statement-brand .company-meta { font-size: 12px; color: var(--muted); white-space: pre-line; margin-top: 2px; }
.statement-doc-type { text-align: right; }
.statement-doc-type .doc-label { font-size: 24px; font-weight: 800; letter-spacing: .01em; color: var(--text); text-transform: uppercase; }
.statement-doc-type .doc-number { font-size: 13px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.statement-doc-type .badge { margin-top: 8px; }

.statement-parties { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 24px; flex-wrap: wrap; padding-bottom: 22px; border-bottom: 1px solid var(--border); }
.statement-party .party-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-light); font-weight: 700; margin-bottom: 5px; }
.statement-party .party-name { font-size: 14px; font-weight: 700; }
.statement-party .party-detail { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.statement-dates { display: flex; gap: 28px; }
.statement-dates .date-item .date-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-light); font-weight: 700; margin-bottom: 5px; }
.statement-dates .date-item .date-value { font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; }

.statement-totals { display: flex; justify-content: flex-end; margin-top: 18px; }
.statement-totals-box { min-width: 280px; }
.statement-totals-box .t-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; }
.statement-totals-box .t-row.muted-row { color: var(--muted); }
.statement-totals-box .t-row .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.statement-totals-box .t-balance {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--brand-light); color: var(--brand-dark);
}
.statement-totals-box .t-balance.settled { background: #eef0f3; color: var(--muted); }
.statement-totals-box .t-balance .label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.statement-totals-box .t-balance .v { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }

.statement-actions { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; }
.statement-memo { margin-top: 16px; font-size: 12.5px; color: var(--muted); }

/* -------------------------------------------------------------------------
   Topbar - persistent app-shell strip housing the mobile sidebar toggle and
   the global search box. Sits above the sidebar/main split so search stays
   reachable from anywhere without scrolling back up a long report.
   ------------------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 58px;
  flex-shrink: 0;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 30;
}
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-strong);
  background: #fff;
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-toggle svg { width: 18px; height: 18px; }
.topbar-search { position: relative; flex: 1; max-width: 480px; }
.topbar-search .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--muted-light); pointer-events: none; }
.topbar-search input {
  width: 100%;
  padding: 8px 14px 8px 36px;
  border-radius: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 13.5px;
}
.topbar-search input:focus { background: #fff; box-shadow: 0 0 0 3px rgba(47, 111, 79, .13); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar-company { font-size: 12.5px; color: var(--muted); font-weight: 600; }

.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 6px;
}
.search-dropdown-empty { padding: 16px 12px; font-size: 13px; color: var(--muted); text-align: center; }
.search-dropdown-group { margin-bottom: 4px; }
.search-dropdown-label {
  padding: 8px 10px 4px 10px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted-light);
}
.search-dropdown-hit, .search-hit {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
}
.search-dropdown-hit:hover, .search-dropdown-hit.active, .search-hit:hover {
  background: var(--brand-light);
  text-decoration: none;
}
.search-dropdown-viewall {
  display: block;
  text-align: center;
  padding: 9px 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brand-dark);
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.search-dropdown-viewall:hover { background: var(--brand-light); text-decoration: none; }
.search-hit-main { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.search-hit-title { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-hit-subtitle { font-size: 12px; color: var(--muted); margin-top: 1px; }
.search-hit-meta { font-size: 11.5px; color: var(--muted-light); margin-top: 1px; font-variant-numeric: tabular-nums; }

.search-group h3 { display: flex; align-items: center; gap: 8px; }
.search-group-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: var(--bg);
  border-radius: 100px;
  padding: 1px 8px;
}
.search-hit-list { display: flex; flex-direction: column; gap: 2px; }
.search-hit-list .search-hit { border: 1px solid transparent; }
.search-hit-list .search-hit:hover { border-color: var(--border); }

.empty-state { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty-state-icon { width: 40px; height: 40px; color: var(--muted-light); margin-bottom: 12px; }
.empty-state p { margin: 4px 0; }

/* -------------------------------------------------------------------------
   Pagination - shared prev/next pager for any list that can grow large.
   ------------------------------------------------------------------------- */
.pagination { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.pagination-info { font-size: 12.5px; color: var(--muted); }
.pagination-controls { display: flex; align-items: center; gap: 10px; }
.pagination-page { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.btn.disabled { opacity: .4; pointer-events: none; }

/* -------------------------------------------------------------------------
   Responsive - collapse the sidebar behind the topbar toggle on narrow
   viewports instead of squeezing a 224px rail onto a phone screen.
   ------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .sidebar-toggle { display: flex; }
  .sidebar {
    position: fixed;
    top: 58px;
    left: 0;
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 58px 0 0 0;
    background: rgba(15, 18, 25, .4);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    z-index: 35;
  }
  .sidebar-scrim.show { opacity: 1; pointer-events: auto; }
  .main { padding: 20px 16px 40px 16px; }
  .topbar-search { max-width: none; }
  .topbar-company { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .no-print, .flash, form:not(.print-keep) { display: none !important; }
  .app-shell, .layout { display: block; height: auto; overflow: visible; }
  .main { padding: 0; max-width: none; overflow: visible; }
  .card, .statement { border: none; padding: 0; margin-bottom: 14px; box-shadow: none; }
  body { background: #fff; }
  a { color: inherit; text-decoration: none; }
  table { font-size: 12px; }
  tr.stmt-section td, tbody tr:nth-child(even) td { background: transparent !important; }
}

/* ---- Dashboard: weekly / monthly totals chart ---------------------------- */
.totals-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.totals-head h3 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 999px; padding: 2px; background: var(--bg); }
.seg-btn { border: 0; background: transparent; padding: 5px 14px; border-radius: 999px; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg-btn.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }
.totals-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 16px; margin: 14px 0 10px; }
.totals-summary > div { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--bg); }
.totals-summary .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.totals-summary strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.totals-summary .negative, .totals-table .negative { color: var(--danger); }
.totals-summary .positive { color: var(--brand); }
.tc-legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tc-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 10px; }
.tc-legend .sw:first-child { margin-left: 0; }
.tc-legend .sw.inc { background: var(--brand); }
.tc-legend .sw.exp { background: #d9826b; }
.tc-legend .sw.net { background: var(--text); height: 3px; }
.tchart { width: 100%; height: auto; display: block; }
.tc-grid { stroke: var(--border); stroke-width: 1; }
.tc-zero { stroke: var(--border-strong); stroke-width: 1.2; }
.tc-axis { font-size: 11px; fill: var(--muted); }
.tc-inc { fill: var(--brand); }
.tc-exp { fill: #d9826b; }
.tc-inc:hover, .tc-exp:hover { opacity: .8; }
.tc-net { fill: none; stroke: var(--text); stroke-width: 1.4; opacity: .75; vector-effect: non-scaling-stroke; }
.tc-netdot { fill: var(--panel); stroke: var(--text); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.totals-details { margin-top: 8px; }
.totals-details summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 4px 0; }
.table-scroll { overflow-x: auto; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 720px) { .totals-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---- Topbar sync pill ------------------------------------------------------ */
.sync-pill-form { display: flex; align-items: center; gap: 8px; margin: 0; }
.sync-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.sync-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-light); }
.sync-pill.ok .dot { background: #1a9a55; }
.sync-pill.error { color: var(--danger); }
.sync-pill.error .dot { background: var(--danger); }
@media (max-width: 720px) { .sync-pill { display: none; } }

/* ---- Clickable dashboard tiles & list filters ------------------------------ */
a.kpi-link { display: block; color: inherit; text-decoration: none; cursor: pointer; }
a.kpi-link:hover { text-decoration: none; box-shadow: var(--shadow-md); transform: translateY(-1px); border-color: var(--brand); }
a.kpi-link:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.filter-tabs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 4px 0 14px; }
.filter-tabs a { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--panel); color: var(--text); font-size: 13px; text-decoration: none; }
.filter-tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.filter-total { margin-left: auto; font-size: 13px; color: var(--muted); }
.filter-total strong { color: var(--text); font-variant-numeric: tabular-nums; }
/* Global creation menu and dashboard insights */
.add-new { position:relative; flex-shrink:0; }
.add-new summary { cursor:pointer; list-style:none; white-space:nowrap; }
.add-new summary::-webkit-details-marker { display:none; }
.add-new-panel { position:absolute; right:0; top:calc(100% + 10px); z-index:100; width:240px; max-height:70vh; overflow:auto; padding:10px; background:#fff; border:1px solid #dce3ed; border-radius:14px; box-shadow:0 16px 45px #172e4926; }
.add-new-panel a { display:block; padding:10px 14px; border-radius:8px; color:#243449; text-decoration:none; }
.add-new-panel a:hover,.add-new-panel a:focus-visible { background:#edf6f1; color:#236747; }
.insight-grid { display:grid; grid-template-columns:1fr 1fr; gap:22px; margin-bottom:24px; }
.health-card h3 .muted { font-size:12px; font-weight:400; }
.balance-insight,.expense-insight { display:block; margin:17px 0; color:inherit; text-decoration:none; }
.balance-insight>span,.expense-insight>span { display:flex; justify-content:space-between; gap:15px; font-size:13px; }
.balance-insight small { color:#69768a; font-size:12px; }
.health-track,.expense-track { height:9px; overflow:hidden; border-radius:8px; background:#e7f1ec; margin:9px 0; }
.health-track>span,.expense-track>span { display:block; height:100%; border-radius:8px; background:#d57f68; }
.expense-track { background:#edf0f6; height:7px; }
.expense-track>span { background:linear-gradient(90deg,#2d7253,#70aa8a); }
#add-new-form { scroll-margin-top:90px; }
#add-new-form:target { outline:2px solid #2d7253; outline-offset:4px; }
[hidden] { display:none !important; }
@media(max-width:1000px) { .topbar-company { display:none; } }
@media(max-width:700px) { .insight-grid { grid-template-columns:1fr; gap:0; } .topbar-right { gap:6px; } .add-new-panel { width:210px; } .sync-pill-form { flex-wrap:wrap; } }
@media print { .add-new { display:none; } }
/* Compact dashboard: prioritize the income and expenses chart. */
.sidebar-toggle { display:flex; }
@media(min-width:901px) { .navigation-hidden .sidebar { display:none; } }
.dashboard-page { padding:22px 28px 40px; }
.dashboard-page .page-sub { margin-bottom:16px; }
.dashboard-page .kpi-primary { grid-template-columns:repeat(3,minmax(0,1fr)); gap:12px; margin-bottom:10px; }
.dashboard-page .kpi-primary .kpi { padding:13px 17px; }
.dashboard-page .kpi-primary .value { font-size:27px; }
.dashboard-page .kpi-secondary { grid-template-columns:repeat(5,minmax(0,1fr)); gap:10px; margin-bottom:18px; }
.dashboard-page .kpi-secondary .kpi { padding:10px 13px; border-top-width:2px; }
.dashboard-page .kpi-secondary .label { font-size:10px; letter-spacing:.025em; }
.dashboard-page .kpi-secondary .value { font-size:19px; margin-top:4px; }
.dashboard-page .kpi-secondary .kpi-icon { width:13px; height:13px; }
.dashboard-page .dash-grid { grid-template-columns:minmax(0,3fr) minmax(260px,1fr); gap:18px; }
.dashboard-page .insight-grid { display:block; margin:0; }
.dashboard-page .health-card { padding:15px 17px; margin-bottom:14px; }
.dashboard-page .health-card h3 { font-size:13px; }
.dashboard-page .balance-insight,.dashboard-page .expense-insight { margin:12px 0; }
.dashboard-page .balance-insight>span,.dashboard-page .expense-insight>span { font-size:12px; }
.dashboard-page .dash-side { position:static; }
.dashboard-page .dash-side>.card { padding:15px 17px; }
.dashboard-page .quick-actions { gap:6px; }
.dashboard-page .quick-actions .btn { padding:7px 10px; font-size:12px; }
.dashboard-page .totals-card { padding:22px 24px; }
.dashboard-page .totals-head h3 { font-size:18px; }
.dashboard-page .dash-two .card { padding:15px; }
.dashboard-page .dash-two table { font-size:12px; }
/* Each summary group fills its row at every desktop width. */
.dashboard-page .kpi-row { width:100%; min-width:0; }
.dashboard-page .kpi { min-width:0; }
.dashboard-page .kpi .value { overflow-wrap:anywhere; }
@media(max-width:1100px) { .dashboard-page .dash-grid { grid-template-columns:minmax(0,2fr) minmax(245px,1fr); } .dashboard-page .dash-two { grid-template-columns:1fr; } }
@media(max-width:800px) { .dashboard-page { padding:18px 16px 35px; } .dashboard-page .dash-grid { grid-template-columns:1fr; } .dashboard-page .kpi-secondary { grid-template-columns:repeat(3,minmax(0,1fr)); } .dashboard-page .totals-card { padding:18px 14px; } }
@media(max-width:480px) { .dashboard-page .kpi-primary { gap:7px; } .dashboard-page .kpi-primary .kpi { padding:10px; } .dashboard-page .kpi-primary .value { font-size:21px; } .dashboard-page .kpi-secondary { grid-template-columns:repeat(2,minmax(0,1fr)); } .dashboard-page .kpi .label { font-size:9px; } .dashboard-page .kpi-icon { display:none; } }

/* Let incomplete rows expand evenly on smaller screens. */
.dashboard-page .kpi-secondary { display:flex; flex-wrap:wrap; }
.dashboard-page .kpi-secondary .kpi { flex:1 1 calc(20% - 10px); }
@media(max-width:800px) { .dashboard-page .kpi-secondary .kpi { flex-basis:calc(33.333% - 10px); } }
@media(max-width:480px) { .dashboard-page .kpi-secondary .kpi { flex-basis:calc(50% - 10px); } }

/* Header shortcuts for full-screen and wide desktop windows. */
.topbar-nav { display:none; }
@media(min-width:1200px) {
  .topbar-nav { display:flex; align-items:center; gap:4px; flex-shrink:0; }
  .topbar-nav a { padding:8px 10px; border-radius:6px; white-space:nowrap; font-size:13px; font-weight:600; color:var(--muted); }
  .topbar-nav a:hover,.topbar-nav a:focus-visible { background:var(--brand-light); color:var(--brand-dark); text-decoration:none; }
  .topbar-nav a[aria-current="page"] { background:var(--brand-light); color:var(--brand-dark); }
  .topbar-search { min-width:180px; }
  .topbar-company { max-width:240px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
}
@media(min-width:1200px) and (max-width:1550px) { .topbar-company { display:none; } .topbar-search { max-width:360px; } }

.account-balance { margin-top:8px; padding:10px 12px; border:1px solid var(--border); border-radius:7px; background:#f6f9f7; font-size:12px; }
.account-balance-row { display:flex; align-items:baseline; justify-content:space-between; gap:12px; margin:3px 0; }
.account-balance-row span { color:var(--muted); }
.account-balance strong { white-space:nowrap; font-variant-numeric:tabular-nums; }
.account-balance .negative { color:var(--danger); }
.account-balance .balance-note { display:block; margin-top:4px; color:var(--muted); font-size:11px; }
.balance-retry { border:0; background:none; color:var(--brand-dark); cursor:pointer; padding:0 0 0 6px; font:inherit; text-decoration:underline; }

.weekly-reminder-banner { display:flex; align-items:center; gap:24px; flex-wrap:wrap; border-left:4px solid var(--brand-dark); }
.weekly-reminder-banner h3, .weekly-reminder-banner p { margin:0; }
.weekly-reminder-banner > div:first-child { flex:1; }
.weekly-reminder-banner p, .weekly-reminder-banner span { color:var(--muted); font-size:12px; }
.weekly-reminder-banner strong, .weekly-reminder-totals strong { display:block; font-size:21px; }
.weekly-reminder-banner svg, .weekly-reminder-heading svg { width:20px; height:20px; vertical-align:middle; }
.weekly-reminder-dialog { width:min(720px, calc(100% - 32px)); max-height:85vh; overflow:auto; padding:24px; border:1px solid var(--border); border-radius:12px; color:inherit; box-shadow:0 24px 80px #0004; }
.weekly-reminder-dialog::backdrop { background:#14253880; }
.weekly-reminder-heading, .weekly-reminder-actions { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; }
.weekly-reminder-heading h2 { margin:0; }
.weekly-reminder-totals { display:grid; grid-template-columns:1fr 1fr; gap:16px; background:#f3f6fa; padding:16px; border-radius:8px; }
.weekly-reminder-list { margin:20px 0; }
.weekly-reminder-item { display:flex; justify-content:space-between; gap:16px; padding:12px 0; border-bottom:1px solid var(--border); text-decoration:none; color:inherit; }
.weekly-reminder-item:hover { background:#f3f6fa; }
.weekly-reminder-item span { display:block; font-size:12px; }
.weekly-reminder-item > div:last-child { text-align:right; white-space:nowrap; }
@media(max-width:600px) { .weekly-reminder-dialog { padding:16px; } .weekly-reminder-totals { grid-template-columns:1fr; } .weekly-reminder-banner { gap:16px; } }
