/* ============================================================
   Finance — styles
   Clean, modern, light/dark via CSS custom properties.
   One restrained accent (indigo). No build step.
   ============================================================ */

:root {
  /* Surfaces & text — light theme (default) */
  --bg:            #f6f7fb;
  --surface:       #ffffff;
  --surface-2:     #f1f3f9;
  --surface-hover: #f5f6fb;
  --border:        #e4e7ee;
  --border-strong: #d3d8e3;

  --text:          #1b2030;
  --text-2:        #5b6478;
  --text-3:        #8a93a6;

  --accent:        #4f46e5;   /* indigo */
  --accent-soft:   #eef0fe;
  --accent-text:   #ffffff;

  --green:         #15915f;
  --green-soft:    #e3f4ec;
  --amber:         #c2820b;
  --amber-soft:    #fbf1da;
  --red:           #d23b3b;
  --red-soft:      #fbe6e6;

  --shadow-sm: 0 1px 2px rgba(20, 25, 45, .06), 0 1px 3px rgba(20, 25, 45, .05);
  --shadow-md: 0 4px 14px rgba(20, 25, 45, .08);
  --shadow-lg: 0 12px 32px rgba(20, 25, 45, .12);

  --radius:    14px;
  --radius-sm: 9px;
  --radius-lg: 20px;

  --sidebar-w: 280px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg:            #0e1118;
  --surface:       #171b26;
  --surface-2:     #1e2331;
  --surface-hover: #20263500;
  --surface-hover: #212737;
  --border:        #272d3c;
  --border-strong: #333b4d;

  --text:          #e7eaf2;
  --text-2:        #a3acc0;
  --text-3:        #717b91;

  --accent:        #7c8cff;
  --accent-soft:   #1d2236;
  --accent-text:   #0e1118;

  --green:         #3ecd8f;
  --green-soft:    #142a22;
  --amber:         #e0ad4e;
  --amber-soft:    #2c2615;
  --red:           #f06a6a;
  --red-soft:      #2c1818;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 14px rgba(0,0,0,.45);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.55);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .25s ease, color .25s ease;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

button { font-family: inherit; }

::selection { background: var(--accent-soft); }

/* ---------------- App shell ---------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  /* right padding 0 so the sync button's right edge lines up with the accounts
     summary boxes (Loans) below, which sit at the sidebar's content edge. */
  padding: 4px 0 2px 8px;
}
.brand-mark {
  color: var(--accent);
  font-size: 20px;
}
.brand-name {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.sync-btn {
  margin-left: auto;          /* push to the far right of the sidebar content */
  flex: 0 0 auto;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  border-radius: 8px;
  font-size: 17px; line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.sync-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.sync-btn.syncing { color: var(--accent); pointer-events: none; }
.sync-ico { display: inline-block; line-height: 1; }
.sync-btn.syncing .sync-ico { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-weight: 550;
  transition: background-color .15s, color .15s;
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); }
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.nav-ico { width: 18px; text-align: center; opacity: .9; font-size: 15px; }

/* Accounts panel */
.accounts-panel {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.accounts-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.summary-pill {
  min-width: 0;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 9px 6px;
  text-align: center;
  overflow: hidden;
}
.summary-pill .lbl {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-3);
  margin-bottom: 3px;
}
.summary-pill .val {
  display: block;
  font-size: 12px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.inst-group { margin-bottom: 12px; }
.inst-name {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-3);
  font-weight: 650;
  margin: 0 6px 6px;
}
.acct-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
}
.acct-row:hover { background: var(--surface-hover); }
.acct-ico {
  width: 28px; height: 28px;
  flex: 0 0 28px;
  display: grid; place-items: center;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 14px;
}
.acct-meta { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; }
.acct-name {
  display: block; max-width: 100%;
  font-size: 13px; font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.acct-mask { display: block; font-size: 11px; color: var(--text-3); white-space: nowrap; }
.acct-bal { flex: 0 0 auto; font-size: 13px; font-weight: 600; white-space: nowrap; }
.acct-bal.neg { color: var(--red); }

.sidebar-foot { margin-top: auto; padding: 6px 8px 0; }

/* ---------------- Main ---------------- */
.main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 28px 34px 60px;
  max-width: 1200px;
}

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.view-title { font-size: 26px; }

/* Month selector */
.month-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow-sm);
}
.month-select {
  border: none;
  background: transparent;
  color: var(--text);
  font-weight: 650;
  font-size: 15px;
  padding: 6px 8px;
  min-width: 150px;
  text-align: center;
  text-align-last: center;
  cursor: pointer;
  appearance: none;
}
.month-select:focus { outline: none; }

.icon-btn {
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text-2);
  width: 34px; height: 34px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  display: grid; place-items: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------------- Cards / summary ---------------- */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat-card .lbl {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-3);
  font-weight: 600;
}
.stat-card .num {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 6px;
}
.stat-card .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.stat-card.accent .num { color: var(--accent); }
.stat-card .num.pos { color: var(--green); }
.stat-card .num.neg { color: var(--red); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card-title { font-size: 16px; margin-bottom: 14px; }
.card-title-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 10px;
}
.card-title-row .card-title { margin-bottom: 0; }

/* ---------------- Budget table ---------------- */
.budget-card { padding: 6px; }
.budget-table { width: 100%; }

.bt-row {
  display: grid;
  grid-template-columns: minmax(140px, 2.4fr) 110px 110px minmax(120px, 1.6fr);
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
}
/* Grid items default to min-width:auto and won't shrink below their content
   (e.g. the plan <input>'s intrinsic width), which overflowed the fixed tracks.
   Allow every cell to shrink to its track. */
.bt-row > * { min-width: 0; }
.bt-head-cols {
  color: var(--text-3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 650;
  padding-top: 8px; padding-bottom: 8px;
}
.bt-head-cols .num { text-align: right; }

.group-header {
  cursor: pointer;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  margin: 6px 6px 2px;
  padding: 12px 14px;
  user-select: none;
}
.group-header:hover { background: var(--surface-hover); }
.group-header .gh-name {
  display: flex; align-items: center; gap: 8px;
  font-weight: 650; font-size: 14px;
}
.chevron {
  display: inline-block;
  transition: transform .18s ease;
  color: var(--text-3);
  font-size: 12px;
}
.group-header.collapsed .chevron { transform: rotate(-90deg); }
.group-header .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.group-header .num .muted { font-weight: 500; }

.cat-row { border-bottom: 1px solid var(--border); }
.cat-row:last-child { border-bottom: none; }
.cat-row:hover { background: var(--surface-hover); }
.cat-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 14px;
}
.cat-row .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.remaining.neg { color: var(--red); }
.remaining.ok { color: var(--text-2); }

/* inline plan editor */
.plan-input {
  width: 100%;
  min-width: 0;
  text-align: right;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  padding: 5px 8px;
  border-radius: 7px;
  transition: border-color .15s, background .15s;
}
.plan-input:hover { border-color: var(--border-strong); background: var(--surface); }
.plan-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* progress + remaining cell */
.prog-cell { display: flex; flex-direction: column; gap: 5px; align-items: stretch; }
.prog-cell .remaining { text-align: right; font-size: 13px; }
.progress {
  height: 6px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress .bar {
  height: 100%;
  border-radius: 99px;
  background: var(--text-3);          /* gray default (e.g. spent with no fill) */
  transition: width .3s ease, background .2s;
}
.progress .bar.under { background: var(--amber); }   /* under budget  -> yellow */
.progress .bar.equal { background: var(--green); }   /* exactly on budget -> green */
.progress .bar.over  { background: var(--red); }     /* over budget   -> red */

/* ---------------- Filters ---------------- */
.filters {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field.stack { margin-bottom: 14px; }
.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}
/* Generic form controls (filters, settings). Exclude the inline budget plan editor,
   whose 150px min-width here was overriding .plan-input and overflowing its cell. */
select, input[type="text"]:not(.plan-input) {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
  min-width: 150px;
  transition: border-color .15s, box-shadow .15s;
}
select:focus, input[type="text"]:not(.plan-input):focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------------- Transactions table ---------------- */
.table-wrap { overflow-x: auto; }
.tx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  /* Keep columns readable on narrow screens; .table-wrap scrolls horizontally. */
  min-width: 620px;
}
/* Search + uncategorized toggle in the filters bar */
.tx-search-field { flex: 1 1 180px; }
.tx-toggle {
  display: flex; align-items: center; gap: 8px;
  height: 38px;
  font-size: 14px; color: var(--text-2);
  white-space: nowrap;
}
.tx-toggle input[type="checkbox"] { width: 16px; height: 16px; min-width: 0; }

/* Sortable headers */
.tx-table th.sortable { cursor: pointer; user-select: none; }
.tx-table th.sortable:hover { color: var(--text-2); }
.tx-table th.sortable.sorted { color: var(--accent); }
.tx-table th .sort-ind { font-size: 10px; margin-left: 2px; }

/* Bulk-select checkbox column */
.col-check { width: 34px; }
.tx-table td.col-check, .tx-table th.col-check { padding-right: 0; }
.tx-table .col-check input[type="checkbox"] { width: 16px; height: 16px; min-width: 0; cursor: pointer; }

/* Bulk action bar */
.tx-actionbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.tx-actionbar .tx-selcount { font-weight: 650; font-size: 13px; color: var(--accent); }
.tx-actionbar select { min-width: 160px; }

/* Footer summary */
.tx-footer {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  padding: 14px 14px 4px;
  font-size: 13px; color: var(--text-2);
}
.tx-footer .tx-net { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--text); }

/* ---------------- Reconnect banner ---------------- */
.reconnect-banners:not(:empty) { margin-bottom: 18px; display: flex; flex-direction: column; gap: 10px; }
.reconnect-banner {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 12px 14px;
  background: var(--amber-soft);
  border: 1px solid var(--amber);
  border-radius: var(--radius-sm);
}
.reconnect-msg { flex: 1 1 200px; font-weight: 600; font-size: 14px; color: var(--text); min-width: 0; }
.reconnect-banner .reconnect-dismiss { flex: 0 0 auto; }


.tx-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-3);
  font-weight: 650;
  padding: 0 14px 12px;
  border-bottom: 1px solid var(--border);
}
.tx-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tx-table tr:last-child td { border-bottom: none; }
.tx-table tbody tr:hover { background: var(--surface-hover); }
.col-amt, .tx-table td.col-amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.col-date { white-space: nowrap; color: var(--text-2); }
.amt-in { color: var(--green); font-weight: 600; }       /* inflow  (+) */
.amt-out { color: var(--red); }                           /* outflow (−) */
.amt-transfer { color: var(--text-3); font-weight: 600; } /* transfer (⇄) — neither */
.payee-cell { font-weight: 550; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--amber-soft);
  color: var(--amber);
  margin-left: 8px;
  vertical-align: middle;
}
.chip {
  display: inline-block;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--text-2);
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.xfer-arrow { color: var(--accent); font-weight: 700; padding: 0 2px; }

.empty {
  text-align: center;
  color: var(--text-3);
  padding: 40px 20px;
  font-size: 14px;
}

/* ---------------- Reports ---------------- */
.report-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
/* Let chart/stat/settings cards shrink instead of being forced wide by their
   intrinsic content (chart canvases, long numbers). */
.report-grid > *, .settings-grid > *, .cards > * { min-width: 0; }
.chart-card { display: flex; flex-direction: column; min-width: 0; }
.chart-card-wide { grid-column: 1 / -1; }
.chart-title { font-size: 15px; margin-bottom: 14px; color: var(--text); }
.chart-box { position: relative; height: 280px; }
.chart-box-tall { height: 360px; }

/* ---------------- Settings ---------------- */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
  align-items: start;
}
.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-hover); border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; }

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .sub { font-size: 12px; color: var(--text-3); }
.list-row .right { font-variant-numeric: tabular-nums; font-weight: 600; }
.list-row .right.neg { color: var(--red); }
.cat-pill-row { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 6px; }

/* ---------------- Categorization rules ---------------- */
.rules-help { margin: -6px 0 12px; }
.rules-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.rules-add #rulePattern { flex: 1 1 140px; min-width: 0; }
.rules-add select { flex: 0 1 auto; min-width: 0; max-width: 100%; }
.rules-add .btn { flex: 0 0 auto; }
.rule-row .rule-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.rule-pattern { font-weight: 600; word-break: break-word; }
.rule-arrow { color: var(--text-3); }
.rule-cat { color: var(--text-2); word-break: break-word; }
.rule-del {
  flex: 0 0 auto;
  padding: 2px 9px;
  line-height: 1;
  font-size: 16px;
}
.rule-del:hover { border-color: var(--red); color: var(--red); }
.group-label {
  font-size: 12px; font-weight: 650; color: var(--text-2);
  margin: 12px 0 4px;
}
.group-label:first-child { margin-top: 0; }

/* ---------------- Misc ---------------- */
.muted { color: var(--text-3); }
.small { font-size: 12px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: var(--surface);
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 550;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 100;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Mobile ---------------- */
.mobile-topbar { display: none; }
.backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 13, 22, .45);
  z-index: 40;
}

@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 960px) {
  .report-grid, .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
  }
  .mobile-title { font-weight: 700; font-size: 17px; }
  .app-shell { display: block; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 45;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 20px 18px 50px; max-width: none; }
  /* Bulk action bar: let the category select take the row's full width. */
  .tx-actionbar select { flex: 1 1 100%; min-width: 0; }
  .tx-actionbar .btn { flex: 1 1 auto; }
  .bt-row {
    grid-template-columns: minmax(120px, 1.6fr) 96px 90px 1.2fr;
    gap: 8px; padding: 10px;
  }
}

@media (max-width: 540px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .bt-row { grid-template-columns: 1.4fr 84px 1fr; }
  .bt-row .col-spent { display: none; }
}

/* ---------------- Detail drawer ---------------- */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 13, 22, .45);
  z-index: 90;
  opacity: 0;
  transition: opacity .2s ease;
}
.drawer-backdrop.show { opacity: 1; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 420px;
  max-width: 92vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 95;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s ease;
  overflow: hidden;
}
.drawer.open { transform: translateX(0); }
.drawer:focus { outline: none; }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.drawer-title {
  font-size: 18px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.drawer-close { font-size: 22px; }

.drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* drawer form fields reuse .field/.field-label; stack them full width */
.drawer-body .field { width: 100%; }
.drawer-body .field select,
.drawer-body .field input[type="text"] { min-width: 0; width: 100%; }

.drawer-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-3);
  font-weight: 650;
  margin-bottom: -4px;
}

.drawer-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.drawer-stat {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
}
.drawer-stat .lbl {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3); font-weight: 600; display: block;
}
.drawer-stat .val {
  font-size: 17px; font-weight: 700; margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.drawer-stat .val.neg { color: var(--red); }
.drawer-stat .val.pos { color: var(--green); }

.drawer-toggle {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.drawer-toggle .lbl { font-weight: 600; font-size: 14px; }
.drawer-toggle .sub { font-size: 12px; color: var(--text-3); }

/* mini transaction list inside drawers */
.drawer-txlist { display: flex; flex-direction: column; }
.drawer-tx {
  display: flex; align-items: baseline; gap: 10px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.drawer-tx:last-child { border-bottom: none; }
.drawer-tx .tx-date { color: var(--text-3); white-space: nowrap; flex: 0 0 auto; }
.drawer-tx .tx-payee {
  flex: 1 1 auto; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.drawer-tx .tx-amt {
  flex: 0 0 auto; font-variant-numeric: tabular-nums; font-weight: 600;
}
.drawer-tx .tx-amt.amt-in { color: var(--green); }

.drawer-actions {
  display: flex; gap: 10px; margin-top: auto;
  padding-top: 8px;
}
.drawer-actions .btn { flex: 1; justify-content: center; text-align: center; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-text); opacity: .9; }
.btn-danger {
  border-color: var(--red);
  color: var(--red);
  background: transparent;
}
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); color: var(--red); }

.drawer-readonly-note {
  font-size: 12px; color: var(--text-3);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* clickable affordances on openers */
.cat-name.clickable,
.acct-row.clickable { cursor: pointer; }
.cat-name.clickable { position: relative; padding-right: 16px; }
.cat-name.clickable::after {
  content: "›";
  position: absolute; right: 2px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3); opacity: 0;
  transition: opacity .15s;
}
.cat-row:hover .cat-name.clickable::after,
.cat-name.clickable:focus-visible::after { opacity: 1; }
.cat-name.clickable:hover { color: var(--accent); }
.cat-name.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.acct-row.clickable .acct-chevron {
  flex: 0 0 auto; color: var(--text-3); opacity: 0;
  transition: opacity .15s; font-size: 15px;
}
.acct-row.clickable:hover .acct-chevron,
.acct-row.clickable:focus-visible .acct-chevron { opacity: 1; }
.acct-row.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.tx-table tbody tr.clickable { cursor: pointer; }
.tx-table tbody tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

@media (max-width: 540px) {
  .drawer-meta { grid-template-columns: 1fr; }
}

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
