/* ============================================================
   Tokens — warm paper page, white cards. Primary surfaces are
   cards: hairline border, 12px radius, a whisper of shadow
   (--shadow-card). Never nest a card inside a card. Overlays use
   --shadow-pop, kept deliberately light. Chart series colors are
   validated (see dataviz palette method) and stay semantic:
   green = money in, orange = money out. The JS reads --card for
   chart tooltip backgrounds.
   ============================================================ */
:root {
  color-scheme: light dark;

  --page: #f4f3f0;
  --card: #ffffff;
  --ink: #1b1a17;
  --ink-2: #504e48;
  --muted: #85837c;
  --hairline: #e8e6e0;
  --baseline: #cbc9c1;
  --hover: rgba(27, 26, 23, 0.045);

  --accent: #262520;
  --accent-hover: #34332d;
  --accent-ink: #f6f5f2;
  --accent-soft: #e7e5de;

  --series-in: #1baf7a;
  --series-out: #eb6834;
  --series-net: #0f7a5a;
  --track-out: #f9e2d6;

  /* Categorical slots for agent dashboards — fixed order, validated on
     this surface (dataviz method); never cycle past slot 8, fold to Other. */
  --cat-1: #2a78d6;
  --cat-2: #eb6834;
  --cat-3: #1baf7a;
  --cat-4: #eda100;
  --cat-5: #e87ba4;
  --cat-6: #008300;
  --cat-7: #4a3aa7;
  --cat-8: #e34948;

  --delta-good: #006300;
  --delta-bad: #b8322d;
  --danger: #b8322d;

  --ctl-h: 34px;
  --radius: 12px;
  --radius-sm: 8px;

  --shadow-card: 0 1px 2px rgba(27, 26, 23, 0.05);
  --shadow-pop: 0 4px 16px rgba(27, 26, 23, 0.07), 0 1px 3px rgba(27, 26, 23, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0f0f0e;
    --card: #1a1a19;
    --ink: #ecebe8;
    --ink-2: #b1afa9;
    --muted: #8a8881;
    --hairline: #2a2927;
    --baseline: #3d3c39;
    --hover: rgba(236, 235, 232, 0.05);

    --accent: #dcdad4;
    --accent-hover: #cbc9c3;
    --accent-ink: #1b1a17;
    --accent-soft: #2b2a26;

    --series-in: #199e70;
    --series-out: #d95926;
    --series-net: #26a077;
    --track-out: #392b23;

    --cat-1: #3987e5;
    --cat-2: #d95926;
    --cat-3: #199e70;
    --cat-4: #c98500;
    --cat-5: #d55181;
    --cat-6: #008300;
    --cat-7: #9085e9;
    --cat-8: #e66767;

    --delta-good: #2eb856;
    --delta-bad: #e66767;
    --danger: #e66767;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-pop: 0 4px 16px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.25);
  }
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-optical-sizing: auto;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* No rubber-band bounce at the end of a scroll. The page pins the vertical
   axis only, so a trackpad swipe can still navigate back; scroll regions
   pin both axes, which also stops them chaining into the page underneath. */
html, body { overscroll-behavior-y: none; }
:is(#subs-frame, .widget-table-frame, .chat-messages, .chat-history) {
  overscroll-behavior: none;
}

.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

:is(button, input, select, a):focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  outline-offset: 1px;
}

/* ============================================================
   Controls — every control in the filter row and forms is
   exactly var(--ctl-h) tall.
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: var(--ctl-h);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  border-radius: var(--radius-sm);
  padding: 0 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.13s ease;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { height: 28px; padding: 0 11px; font-size: 12.5px; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost { background: var(--card); color: var(--ink); border-color: var(--baseline); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); }

.range-pills {
  display: flex;
  align-items: center;
  gap: 2px;
  height: var(--ctl-h);
  padding: 3px;
  background: var(--card);
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
}
.pill {
  height: 100%;
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  padding: 0 11px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.13s ease, color 0.13s ease;
}
.pill:hover { background: var(--hover); color: var(--ink); }
.pill.active { background: var(--accent); color: var(--accent-ink); }

.scope-group { display: flex; align-items: center; gap: 8px; }
.scope-menu { position: relative; }
.scope-btn { font-weight: 500; min-width: 160px; justify-content: space-between; }
#scope-btn-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scope-btn .chev { color: var(--muted); flex: none; }

.menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  min-width: 240px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 4px;
  box-shadow: var(--shadow-pop);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}
.menu-item { text-decoration: none; }
.menu-item:hover { background: var(--hover); }
.menu-item.selected { background: var(--accent-soft); }
.menu-item svg { color: var(--muted); flex: none; }
.group-display-icon {
  display: grid;
  place-items: center;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  font-size: 14px;
}
.group-display-icon img {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  object-fit: cover;
}
.menu-mask { margin-left: auto; padding-left: 14px; color: var(--muted); font-size: 12px; }

.accounts-menu { position: relative; }
.accounts-panel {
  left: auto;
  right: 0;
  width: min(380px, calc(100vw - 40px));
  padding: 10px 0 8px;
}
.accounts-panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px 8px;
}
.accounts-panel-head .panel-count { margin-left: 0; }
.accounts-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.accounts-panel .empty { padding: 24px 14px; }
.accounts-panel .bill-consent { margin: 10px 14px 6px; }

.custom-range { display: flex; align-items: center; gap: 8px; }
.custom-range input[type="date"] {
  height: var(--ctl-h);
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  padding: 0 10px;
}

/* ============================================================
   Layout — one surface; sections divided by hairlines.
   ============================================================ */
/* The extra bottom padding lives on .page, not body: inside the shell it
   gives content breathing room (and clears the floating chat drawer)
   without extending the document past the sidebar into dead scroll. */
.page {
  max-width: 1360px;
  margin: 0 auto;
  padding: clamp(20px, 3vw, 36px) clamp(20px, 4vw, 44px) 72px;
  display: flex;
  flex-direction: column;
}

.section { margin-top: 32px; }

.split {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  column-gap: 48px;
  align-items: start;
}
.split-main, .split-side { min-width: 0; }
.activity-section { container: dashboard-activity / inline-size; }
@container dashboard-activity (max-width: 1080px) {
  .activity-section .split { grid-template-columns: 1fr; }
  .activity-section .split-side { margin-top: 28px; }
}
@media (max-width: 1020px) {
  .split { grid-template-columns: 1fr; }
  .split-side { margin-top: 28px; }
}

/* ============================================================
   Filter row
   ============================================================ */
.filter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.range-sep { color: var(--muted); }
.range-caption { font-size: 12.5px; color: var(--muted); margin-left: auto; }
.row-actions { display: flex; gap: 8px; }

/* ============================================================
   Section headings
   ============================================================ */
.card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0 0 12px;
}
.card-head h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  margin: 0;
}

.panel-count { margin-left: auto; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.head-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* Tiny icon buttons that appear on row hover (rename, approve, reject). */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn.active { background: var(--accent); color: var(--accent-ink); }
.row-tools { display: inline-flex; gap: 2px; opacity: 0; transition: opacity 0.12s ease; }
tr:hover .row-tools,
li:hover .row-tools,
.row-tools:focus-within { opacity: 1; }

/* In-place rename: no layout shift, just a thin underline while editing. */
.editing {
  outline: none;
  box-shadow: 0 1px 0 var(--ink);
  cursor: text;
}

/* Rules dropdown */
.menu-note { margin: 4px 6px 8px; font-size: 12px; color: var(--muted); }

/* Rules page */
.rule-page-list { list-style: none; margin: 0; padding: 0; }
.rule-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; }
.rule-row:hover { background: var(--hover); }
.rule-row + .rule-row { border-top: 1px solid var(--hairline); }
.rule-row-kind { flex: 0 0 auto; }
.rule-row-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.rule-row-match {
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rule-row-effect { font-size: 12.5px; color: var(--ink-2); }
.rule-row-count { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* New-rule modal: live backfill preview */
.rule-modal { width: min(560px, calc(100vw - 40px)); }
.rule-modal .modal-field-label { margin-top: 12px; }
.rule-modal-grid { display: grid; grid-template-columns: 1fr 160px; gap: 10px; }
.rule-inline-field { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.rule-inline-field .field-label { margin: 0; flex: none; }
.rule-dropdown { position: relative; flex: 1; min-width: 0; }
.rule-dropdown-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  height: var(--ctl-h);
  padding: 0 11px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.rule-dropdown-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rule-dropdown-btn .chev { color: var(--muted); flex: none; }
.rule-dropdown-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rule-dropdown-menu {
  left: 0;
  right: 0;
  width: auto;
  min-width: 0;
  max-height: 240px;
  overflow-y: auto;
  overflow-x: hidden;
}
.rule-dropdown-menu .menu-item { min-width: 0; }
.rule-dropdown-menu .rule-scope-item-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rule-cat-wrap { position: relative; flex: 1; min-width: 0; }
.rule-cat-wrap .modal-input { width: 100%; }
.rule-cat-menu {
  left: 0;
  right: 0;
  width: auto;
  min-width: 0;
  max-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
}
.rule-cat-menu .menu-item {
  display: block;
  line-height: 32px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rule-existing { margin-bottom: 14px; }
.rule-existing-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.rule-existing-list li + li { border-top: 1px solid var(--hairline); }
.rule-existing-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.rule-existing-item:hover { background: var(--hover); }
.rule-existing-item.selected { background: var(--accent-soft); }
.rule-existing-item .tag { flex: none; }
.rule-existing-effect {
  color: var(--ink-2);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rule-delete-btn { margin-right: auto; color: var(--danger); }
/* Quiet recurring-charge hint on dashboard transaction rows. */
.tx-sub-mark {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  color: var(--muted);
  opacity: 0.75;
}
.rule-action-list { display: flex; flex-direction: column; gap: 8px; }
.rule-action-row { display: flex; align-items: center; gap: 8px; }
.rule-action-row .rule-select { flex: 0 0 auto; height: var(--ctl-h); }
.rule-action-row .modal-input { flex: 1; min-width: 0; width: auto; }
.rule-action-remove { flex: none; }
.rule-add-action { margin-top: 8px; display: inline-flex; align-items: center; gap: 5px; }
.rule-modal-accounts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.rule-modal-accounts .rule-select { width: 100%; height: var(--ctl-h); }
.rule-preview-head {
  display: flex;
  align-items: baseline;
  margin-top: 16px;
}
.rule-preview-head .field-label { margin-bottom: 6px; }
.rule-preview-frame {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  max-height: 170px;
  overflow: auto;
}
.rule-preview-list { list-style: none; margin: 0; padding: 0; }
.rule-preview-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 12px;
  font-size: 12.5px;
}
.rule-preview-list li + li { border-top: 1px solid var(--hairline); }
.rule-preview-date { color: var(--muted); white-space: nowrap; }
.rule-preview-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rule-preview-account {
  color: var(--muted);
  max-width: 32%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rule-preview-amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.rule-preview-more { color: var(--muted); }
.rule-preview-note { margin: 0; padding: 14px 12px; font-size: 12.5px; color: var(--muted); }
.rule-select {
  appearance: none;
  font: inherit;
  font-size: 12.5px;
  height: 28px;
  padding: 0 24px 0 9px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  background-color: var(--card);
  color: var(--ink);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%237e8288' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-ink);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  font-weight: 550;
  color: var(--ink-2);
  background: var(--card);
  border: 1px solid var(--baseline);
  cursor: pointer;
}
.chip:hover { color: var(--ink); }
.chip::after { content: "✕"; font-size: 10px; color: var(--muted); }

.empty { padding: 40px 0; text-align: center; color: var(--muted); }
.empty .btn { margin: 10px auto 0; }

/* ============================================================
   Stat strip — one white card per number
   ============================================================ */
.stat-strip {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 12px;
}
@media (max-width: 1020px) { .stat-strip { grid-template-columns: 1fr 1fr; } }

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px 14px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.kpi-value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }
.kpi-value.hero { font-size: 34px; letter-spacing: -0.03em; }
.kpi-delta { font-size: 12.5px; font-weight: 550; color: var(--muted); min-height: 1.2em; }
.kpi-delta .up { color: var(--delta-good); }
.kpi-delta .down { color: var(--delta-bad); }

/* ============================================================
   Charts — tabs above, one white card holds the active panel
   ============================================================ */
.tab-row {
  display: flex;
  gap: 20px;
}
.tab {
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  padding: 8px 1px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.13s ease;
}
.tab:hover { color: var(--ink-2); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

.tab-panel {
  margin-top: 14px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 10px 16px 14px;
}

.chart { width: 100%; height: 320px; padding-top: 8px; }
#chart-sankey { height: 360px; }

.loading .chart, .loading .kpi-value, .loading .buckets, .loading .tx-table { opacity: 0.55; transition: opacity 0.15s; }

/* ============================================================
   Buckets
   ============================================================ */
.buckets {
  list-style: none;
  margin: 0;
  padding: 12px 4px 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bucket-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) 2fr auto;
  align-items: center;
  gap: 14px;
  padding: 5px 10px;
  margin: 0 -10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s ease;
}
.bucket-row:hover { background: var(--hover); }
.bucket-row.active { background: var(--accent-soft); }
.bucket-name {
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bucket-track { height: 8px; border-radius: 999px; background: var(--track-out); overflow: hidden; }
.bucket-fill { height: 100%; background: var(--series-out); }
.bucket-amount { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ============================================================
   Transactions
   ============================================================ */
.table-frame {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
#tx-frame {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}
.tx-table {
  width: 100%;
  min-width: 720px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}
.tx-table th:nth-child(1) { width: 110px; }
.tx-table th:nth-child(3) { width: 160px; }
.tx-table th:nth-child(4) { width: 130px; }
.tx-table td { padding: 9px 14px; }
.tx-table tr + tr td { border-top: 1px solid var(--hairline); }
.tx-table tbody tr { transition: background 0.12s ease; }
.tx-table tbody tr:hover { background: var(--hover); }

.tx-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 12px;
}
.pager-info { font-size: 12.5px; color: var(--muted); }
.pager-btns { display: flex; gap: 6px; }

.tx-date { color: var(--muted); font-size: 12px; white-space: nowrap; width: 1%; }
.tx-name { font-weight: 550; font-size: 13.5px; }
.manual-override::after {
  content: "•";
  margin-left: 5px;
  color: var(--accent);
}
.tx-account { color: var(--muted); font-size: 12px; }
.tx-identity-cell {
  overflow: hidden;
}
.tx-row-details {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.tx-vendor {
  display: inline-flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 34ch;
}
.tx-vendor .tx-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.transaction-logo.tx-table-logo {
  display: inline-grid;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  margin-right: 8px;
  vertical-align: middle;
  border-radius: 6px;
}
.tx-category { text-align: right; white-space: nowrap; }
.tx-amount {
  position: sticky;
  right: 0;
  z-index: 2;
  text-align: right;
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  width: 1%;
  padding-left: 16px;
  font-variant-numeric: tabular-nums;
  background: var(--card);
}
.tx-table th:last-child {
  right: 0;
  z-index: 4;
  text-align: right;
  background: var(--card);
}
#tx-frame.is-overflowing .tx-amount,
#tx-frame.is-overflowing .tx-table th:last-child {
  box-shadow: -12px 0 16px -16px color-mix(in srgb, var(--ink) 35%, transparent);
}
.tx-table tbody tr:hover .tx-amount { background: var(--hover); }
.amount-in { color: var(--delta-good); }

.tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  padding: 1.5px 8px;
  border-radius: 4px;
  border: 1px solid var(--baseline);
  color: var(--ink-2);
  background: transparent;
}
.tag-business { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.tag-pending { color: var(--muted); border-color: var(--hairline); }
.tag-overdue { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.bill-line { margin-top: 2px; }
.bill-consent { margin-top: 12px; }

@media (max-width: 700px) {
  .tx-table th:nth-child(1) { width: 92px; }
  .tx-table th:nth-child(4) { width: 100px; }
}

.standalone-filters { gap: 10px; }
.transaction-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 340px;
  min-width: min(340px, 100%);
  height: var(--ctl-h);
  color: var(--muted);
}
.transaction-search svg {
  position: absolute;
  left: 11px;
  pointer-events: none;
}
.transaction-search input[type="search"] {
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 0 11px 0 34px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}
.transaction-search input[type="search"]::placeholder { color: var(--muted); opacity: 1; }
.transaction-search:focus-within { color: var(--ink-2); }
.transaction-search input[type="search"]::-webkit-search-cancel-button { cursor: pointer; opacity: 0.55; }
.standalone-filters .rule-select {
  height: var(--ctl-h);
  padding-inline: 11px 30px;
  background-position: right 11px center;
  font-size: 13px;
}
.interactive-table { table-layout: fixed; }
.interactive-table th:nth-child(1) { width: 120px; }
.interactive-table th:nth-child(2) { width: 36%; }
.interactive-table th:nth-child(4) { width: 130px; }
.interactive-table th:nth-child(5) { width: 130px; }
.interactive-table td { height: 54px; padding-block: 8px; overflow: hidden; }
.interactive-table[data-density="compact"] td { height: 40px; padding-block: 3px; }
.interactive-table[data-density="spacious"] td { height: 68px; padding-block: 15px; }
.truncate-cell, .transaction-primary, .transaction-secondary {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.transaction-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.transaction-logo {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  overflow: hidden;
  background: var(--hover);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.transaction-logo img { width: 100%; height: 100%; object-fit: cover; }
.transaction-text { display: flex; flex-direction: column; min-width: 0; }
.transaction-primary { font-weight: 550; }
.transaction-secondary { color: var(--muted); font-size: 11.5px; }
.editable-tag, .editable-category, .transaction-primary { cursor: text; }
.tag.manual-override { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }

/* Transfers — like accounts and subscriptions, each section is one white
   frame; rows divide with hairlines instead of stacking separate cards. */
.transfer-row {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 11px 16px 12px;
}
.transfer-row + .transfer-row { border-top: 1px solid var(--hairline); }
.transfer-row-top { display: flex; align-items: center; gap: 14px; }
.transfer-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.transfer-name {
  font-weight: 550;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.transfer-route {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.transfer-arrow { color: var(--muted); }
.transfer-amount { font-weight: 600; font-size: 13.5px; white-space: nowrap; text-align: right; }
.transfer-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.transfer-note { font-size: 12.5px; color: var(--muted); }
.transfer-purpose {
  flex: 0 1 300px;
  min-width: 0;
  height: 28px;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  padding: 0 9px;
}
.transfer-purpose::placeholder { color: var(--muted); opacity: 1; }
.transfer-purpose:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
}
@media (max-width: 700px) {
  .transaction-search { flex-basis: 100%; }
  .standalone-filters .rule-select { flex: 1 1 0; min-width: 0; }
  .standalone-filters .range-caption { flex-basis: 100%; margin-left: 0; }
  .interactive-table th:nth-child(3), .interactive-table td:nth-child(3),
  .interactive-table th:nth-child(4), .interactive-table td:nth-child(4) { display: none; }
}

/* ============================================================
   Subscriptions
   ============================================================ */
#subs-frame { max-height: 400px; overflow-y: auto; scrollbar-width: thin; }
.subs-list { list-style: none; margin: 0; padding: 0 14px; }
.subs-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.subs-row + .subs-row { border-top: 1px solid var(--hairline); }
.subscription-icon {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  padding: 0;
  overflow: visible;
  border: 0;
  border-radius: 8px;
  background: var(--hover);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}
.subscription-icon:hover,
.subscription-icon:focus-visible { box-shadow: 0 0 0 1px var(--baseline); }
.subscription-icon::after {
  content: "✎";
  position: absolute;
  right: -4px;
  bottom: -4px;
  display: none;
  place-items: center;
  width: 14px;
  height: 14px;
  border: 1px solid var(--baseline);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink-2);
  font-size: 9px;
  line-height: 1;
}
.subscription-icon:hover::after,
.subscription-icon:focus-visible::after { display: grid; }
.subscription-icon-value {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: inherit;
}
.subscription-icon-value img { width: 100%; height: 100%; object-fit: cover; }
.subs-info { flex: 1; min-width: 0; }
.subs-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 550;
  font-size: 13.5px;
  min-width: 0;
}
.subs-title {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subs-name .tag { flex: none; }
.subs-meta { display: block; font-size: 12px; color: var(--muted); }
.subs-amount { text-align: right; }
.subs-amount .num { display: block; font-weight: 600; font-size: 14px; }
.subs-amount .subs-meta { white-space: nowrap; }
.subs-total { padding: 8px 2px 0; font-size: 12px; color: var(--muted); text-align: right; }

/* ============================================================
   Accounts
   ============================================================ */
.account-list { list-style: none; margin: 0; padding: 0 14px; }
.account-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
}
.account-row + .account-row { border-top: 1px solid var(--hairline); }

.account-icon { flex: none; display: grid; place-items: center; width: 20px; color: var(--ink-2); }

.account-info { flex: 1; min-width: 0; }
.account-name { display: block; font-weight: 550; font-size: 13.5px; }
.account-meta {
  display: block;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-meta-row { display: flex; align-items: center; gap: 4px; }
.account-meta-provider { overflow: hidden; text-overflow: ellipsis; }
.account-group-icon {
  display: grid;
  place-items: center;
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
  font-size: 11px;
}
.account-group-icon img {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  object-fit: cover;
}
.account-reconnect { margin-top: 6px; }
.account-edit-btn,
.group-edit-btn {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--baseline);
}
.account-edit-btn { margin-left: 2px; }
.account-balance { text-align: right; }
.account-balance .num { display: block; font-weight: 600; font-size: 14px; }
.amount-owed { color: var(--ink-2); }

/* ============================================================
   Modal
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 16, 14, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  width: min(440px, calc(100vw - 40px));
  padding: 26px;
  box-shadow: var(--shadow-pop);
}
.modal h2 { margin: 0 0 6px; font-size: 17px; letter-spacing: -0.01em; }
.modal-sub { margin: 0 0 18px; color: var(--ink-2); font-size: 13.5px; }
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.segmented {
  display: flex;
  gap: 2px;
  height: var(--ctl-h);
  padding: 3px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
}
.seg-option {
  flex: 1;
  height: 100%;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-2);
  border: none;
  cursor: pointer;
}
.seg-option.active { background: var(--accent); color: var(--accent-ink); }

.modal-error {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
  font-size: 13px;
  word-break: break-word;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal-input {
  display: block;
  width: 100%;
  height: var(--ctl-h);
  padding: 0 11px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}
.modal-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.modal-field-label { margin-top: 16px; }
.field-optional { font-weight: 450; }

/* Dashboard icon picker */
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin: 4px 0 14px;
}
.emoji-option {
  height: 36px;
  font-size: 17px;
  line-height: 1;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.emoji-option:hover { background: var(--hover); }
.emoji-option.active { background: var(--accent-soft); }
.icon-modal-row { display: flex; gap: 8px; }
.icon-modal-row input[type="text"] {
  flex: 1;
  min-width: 0;
  height: var(--ctl-h);
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  padding: 0 11px;
}
.group-icon-editor {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.group-icon-preview-column {
  display: flex;
  flex: 0 0 64px;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}
.group-icon-preview {
  display: grid;
  place-items: center;
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  overflow: hidden;
  border: 1px solid var(--baseline);
  border-radius: 12px;
  background: var(--hover);
  font-size: 12px;
  color: var(--muted);
}
.group-icon-preview-value {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 26px;
}
.group-icon-preview-value img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.group-icon-fields { flex: 1; min-width: 0; }
.group-emoji-grid {
  grid-template-columns: repeat(8, 1fr);
  margin-top: 0;
  margin-bottom: 8px;
}
.group-emoji-grid .emoji-option { height: 28px; font-size: 15px; }
.group-icon-reset {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}
.group-icon-reset:hover { color: var(--ink); }
.group-icon-reset:disabled { color: var(--muted); opacity: 0.7; cursor: default; }
.account-modal-group-row { display: flex; align-items: center; gap: 8px; }
.account-modal-group-row .rule-select { flex: 1; min-width: 0; }

/* ============================================================
   Chat
   ============================================================ */
.chat-drawer {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 40;
  width: min(400px, calc(100vw - 36px));
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-pop);
}
.chat-drawer.collapsed { width: auto !important; }
/* Expanded is a full-screen takeover inside the page margins. */
.chat-drawer.expanded { top: 18px; left: 18px; width: auto !important; }
/* min-height: 0 lets the messages area stay bounded so it can scroll. */
.chat-drawer.expanded .chat-body { height: auto !important; flex: 1; min-height: 0; }

.chat-head { display: flex; align-items: center; gap: 2px; padding-right: 10px; }
.chat-drawer.collapsed :is(.chat-expand, .chat-history-btn, .chat-new-btn, .chat-grip) { display: none; }
.chat-expand[aria-pressed="true"] { color: var(--ink); }

/* Corner dots: grab the top-left edge to resize the open drawer. */
.chat-grip {
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 20px;
  cursor: nwse-resize;
  /* Exactly three dots in the corner — enough to read as a handle. */
  background-image:
    radial-gradient(circle at 7px 7px, var(--baseline) 1px, transparent 1.5px),
    radial-gradient(circle at 13px 7px, var(--baseline) 1px, transparent 1.5px),
    radial-gradient(circle at 7px 13px, var(--baseline) 1px, transparent 1.5px);
  background-repeat: no-repeat;
  z-index: 2;
}
.chat-grip:hover {
  background-image:
    radial-gradient(circle at 7px 7px, var(--muted) 1px, transparent 1.5px),
    radial-gradient(circle at 13px 7px, var(--muted) 1px, transparent 1.5px),
    radial-gradient(circle at 7px 13px, var(--muted) 1px, transparent 1.5px);
}

.chat-history {
  position: absolute;
  inset: 0;
  background: var(--card);
  overflow-y: auto;
  z-index: 3;
  padding: 8px;
}
.chat-history-row { position: relative; display: flex; align-items: center; gap: 2px; }
.chat-history-item {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.chat-history-item:hover { background: var(--hover); }
.chat-history-kebab {
  flex: none;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
}
.chat-history-row:hover .chat-history-kebab,
.chat-history-kebab:focus-visible,
.chat-history-kebab[aria-expanded="true"] { opacity: 1; }
.chat-history-kebab:hover { background: var(--hover); color: var(--ink); }
.chat-history-menu { top: 30px; right: 4px; left: auto; min-width: 150px; }
.menu-item.danger { color: var(--danger); }
.chat-history-rename {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--baseline);
  border-radius: 4px;
  padding: 1px 6px;
  width: 100%;
  min-width: 0;
}
.chat-history-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-history-date { color: var(--muted); font-size: 12px; flex: none; }
.chat-history-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 0; }

.chat-toggle {
  flex: 1;
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 4px 11px 16px;
  background: transparent;
  border: none;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.chat-spark { color: var(--accent); margin-right: 2px; }
.chat-toggle-chevron { color: var(--muted); transition: transform 0.2s; }
.chat-drawer.collapsed .chat-toggle-chevron { transform: rotate(180deg); }

.chat-body {
  position: relative;
  display: flex;
  flex-direction: column;
  height: min(460px, 60vh);
  border-top: 1px solid var(--hairline);
}
.chat-drawer.collapsed .chat-body { display: none; }

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  scrollbar-width: thin;
}
.chat-msg {
  max-width: 88%;
  padding: 8px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  overflow-wrap: break-word;
}
.chat-msg-user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; white-space: pre-wrap; }

/* Ephemeral widget previews render as restrained cards — sized like an
   inline image, click to open the full-size modal. Inline slots
   ({{preview:id}} markers) stay hidden until their payload mounts,
   including expired markers in old threads. */
.chat-preview { width: 100%; padding: 2px 0 6px; }
.chat-inline-preview:not([data-mounted]) { display: none; }
.chat-inline-preview[data-mounted] { margin: 10px 0; }
.chat-preview-card {
  display: block;
  width: 380px;
  max-width: 100%;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 10px 12px 8px;
  cursor: zoom-in;
  transition: border-color 0.13s ease;
}
.chat-preview-card:hover { border-color: var(--baseline); }
.chat-preview-card .widget-title { font-size: 12px; padding-bottom: 4px; }
.chat-preview-card .widget-chart { height: 170px !important; }
.chat-preview-card .widget-table-frame { max-height: 200px; }
.chat-preview-stat { display: flex; flex-direction: column; gap: 3px; }

.preview-modal { width: min(880px, calc(100vw - 48px)); padding: 20px 22px; }
.preview-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
}
.preview-modal-head h2 { margin: 0; font-size: 15px; }
.preview-modal .widget-chart { height: min(56vh, 460px); }
.preview-modal .widget-table-frame { max-height: 56vh; }

/* Markdown inside assistant replies */
.chat-msg-assistant :is(p, ul, ol, table, pre, blockquote) { margin: 0 0 8px; }
.chat-msg-assistant > :last-child { margin-bottom: 0; }
.chat-msg-assistant :is(ul, ol) { padding-left: 18px; }
.chat-msg-assistant li { margin: 2px 0; }
.chat-msg-assistant h1, .chat-msg-assistant h2, .chat-msg-assistant h3,
.chat-msg-assistant h4 { font-size: 13.5px; margin: 10px 0 4px; }
.chat-msg-assistant code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--hover);
  border-radius: 4px;
  padding: 1px 5px;
}
.chat-msg-assistant pre {
  background: var(--hover);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 8px 10px;
  overflow-x: auto;
}
.chat-msg-assistant pre code { background: none; padding: 0; }
.chat-msg-assistant table { border-collapse: collapse; font-size: 12.5px; }
.chat-msg-assistant th, .chat-msg-assistant td {
  border: 1px solid var(--hairline);
  padding: 4px 9px;
  text-align: left;
}
.chat-msg-assistant th { font-weight: 600; }
.chat-msg-assistant a { color: inherit; }
.chat-msg-assistant blockquote {
  border-left: 2px solid var(--baseline);
  padding-left: 10px;
  color: var(--ink-2);
}
.chat-msg-assistant { align-self: flex-start; background: var(--hover); border-bottom-left-radius: 4px; }
.chat-msg.chat-status { color: var(--muted); }
.chat-msg-error {
  align-self: flex-start;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
}

.chat-input-row { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--hairline); }
.chat-input-row input {
  flex: 1;
  min-width: 0;
  height: var(--ctl-h);
  font: inherit;
  font-size: 13.5px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--baseline);
  background: var(--card);
  color: var(--ink);
}
.chat-input-row input::placeholder { color: var(--muted); }
.chat-input-row input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
}

/* ============================================================
   Shell — sidebar + content on the same flat surface
   ============================================================ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  flex: none;
  position: sticky;
  top: 0;
  width: 208px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 12px 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
/* Full-color art, not an ink-painted mask: the mark keeps its own orange
   and black in both schemes instead of inverting. */
.brand-mark {
  display: inline-block;
  flex: none;
  height: 24px;
  aspect-ratio: 1527 / 2368;
  background: url("../img/bucket-mark.bac05a9820c4.png") no-repeat center / contain;
}
.auth-brand .brand-mark { height: 32px; }
.sidebar .brand { padding: 2px 10px 20px; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.13s ease, color 0.13s ease;
}
.side-link svg { flex: none; color: var(--muted); }
.side-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  cursor: pointer;
  overflow: hidden;
}
.side-icon:hover { background: var(--hover); }
.side-icon img { display: block; width: 16px; height: 16px; border-radius: 4px; object-fit: cover; }
.side-emoji { font-size: 13px; line-height: 1; }
/* Mixed-scope dashboards: the touched groups' icons, overlapped. */
.side-icon-stack {
  width: auto;
  min-width: 18px;
  display: inline-flex;
  align-items: center;
  overflow: visible;
}
.side-icon-stack img,
.side-icon-stack .side-emoji {
  width: 15px;
  height: 15px;
  font-size: 11px;
  line-height: 15px;
  text-align: center;
}
.side-icon-stack img { box-shadow: 0 0 0 1.5px var(--page); }
.side-icon-stack img + img,
.side-icon-stack .side-emoji + .side-emoji,
.side-icon-stack img + .side-emoji,
.side-icon-stack .side-emoji + img { margin-left: -5px; }
.side-label {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-link:hover { background: var(--hover); color: var(--ink); }
.side-link:hover svg { color: var(--ink-2); }
.side-link.active { background: var(--accent-soft); color: var(--ink); }
.side-link.active svg { color: var(--ink); }
.side-group {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 18px 10px 4px;
}
.side-group-scope {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-group-icon { flex: none; font-size: 11px; line-height: 1; }
img.side-group-icon { width: 13px; height: 13px; border-radius: 3px; object-fit: cover; display: block; }

.side-foot {
  margin-top: auto;
  border-top: 1px solid var(--hairline);
  padding-top: 10px;
}

.user-menu { position: relative; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.user-chip:hover { background: var(--hover); }
.user-avatar {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
  display: flex;
  align-items: center;
  justify-content: center;
}
.user-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-chip .chev { flex: none; color: var(--muted); }
.user-popover {
  top: auto;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 0;
}
.user-popover form { display: contents; }
.side-user {
  padding: 0 10px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-foot form { margin: 0; }

.shell-main { flex: 1; min-width: 0; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: static;
    width: auto;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-right: none;
    border-bottom: 1px solid var(--hairline);
  }
  .sidebar .brand { padding: 0 10px 0 0; }
  .side-nav { flex-direction: row; }
  .side-link { width: auto; }
  .side-foot { margin-top: 0; margin-left: auto; flex-direction: row; align-items: center; border-top: none; padding-top: 0; }
  .side-user { display: none; }
}

/* ============================================================
   Forms — shared field styles (settings, auth)
   ============================================================ */
.form-field { margin-bottom: 16px; }
.form-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}
.form-field :is(input, select) {
  width: 100%;
  height: var(--ctl-h);
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  padding: 0 11px;
}
.form-field select {
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%237e8288' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.form-field input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
}
.form-field .helptext {
  display: block;
  margin-top: 5px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}
.form-field .helptext ul { margin: 4px 0 0; padding-left: 16px; }

.errorlist {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  font-size: 12.5px;
  color: var(--danger);
}
form > .errorlist { margin: 0 0 14px; }

.messages {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  font-size: 13px;
  color: var(--ink-2);
}
.messages li {
  padding: 9px 13px;
  background: var(--card);
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
}
.messages li + li { margin-top: 6px; }

/* ============================================================
   Settings page
   ============================================================ */
.settings-page { max-width: 560px; }
.page-head { padding-bottom: 24px; }
.page-head h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }

.settings-section {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 20px 22px 26px;
}
.settings-section + .settings-section { margin-top: 16px; }
.settings-section .card-head { padding-bottom: 6px; }
.settings-status { margin: 0 0 18px; font-size: 13px; color: var(--muted); }
.settings-note { margin: 0; font-size: 13px; color: var(--ink-2); }
.settings-form { max-width: 420px; }
.settings-form .btn { margin-top: 4px; }

/* ============================================================
   Standalone pages (rules, subscriptions)
   ============================================================ */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.page-sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); max-width: 560px; }
.label-hint { font-weight: 500; color: var(--muted); }
.form-row { display: flex; gap: 10px; }
.form-row .form-field { flex: 1; min-width: 0; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 14px;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
.data-table td { padding: 8px 14px; vertical-align: middle; }
.data-table tbody tr + tr td { border-top: 1px solid var(--hairline); }
.data-table tbody tr { transition: background 0.12s ease; }
.data-table tbody tr:hover { background: var(--hover); }
.data-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cell-muted { color: var(--muted); }
.cell-date { white-space: nowrap; color: var(--ink-2); }
.cell-nowrap { white-space: nowrap; }
.cell-actions { text-align: right; white-space: nowrap; width: 1%; }
.cell-primary { width: 99%; }
.cell-stack { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cell-clip {
  display: block;
  max-width: 30ch;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-strong { font-weight: 550; cursor: text; }
.cell-meta { font-size: 12px; color: var(--muted); }
.cell-note { color: var(--muted); font-size: 12.5px; }
.cell-note .cell-clip { max-width: 36ch; }
.inline-rename {
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--ink);
  outline: none;
  padding: 0;
  min-width: 140px;
}

/* ============================================================
   Auth — centered white card on the paper page
   ============================================================ */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px 10vh;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 30px 28px;
}
.auth-brand { display: flex; align-items: center; margin-bottom: 28px; }
.auth-card h1 { margin: 0 0 6px; font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }
.auth-sub { margin: 0 0 24px; font-size: 13.5px; color: var(--ink-2); }
.auth-submit { width: 100%; justify-content: center; margin-top: 4px; }
.auth-alt { margin: 22px 0 0; font-size: 13px; color: var(--muted); text-align: center; }
.auth-alt a { color: var(--ink); }

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

/* ============================================================
   Agent dashboards — 12-col grid of bordered, flat widgets
   ============================================================ */
/* One compact header line: the agent supplies the words, not the layout. */
.dash-head { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.dash-head h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }
.dash-desc {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-controls {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.dash-controls:empty { display: none; }
.dash-range-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.widget-grid {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}
/* Every widget is one white card. Table widgets are the exception: their
   scrolling frame IS the card (title stays above it), so cards never nest. */
.widget {
  grid-column: span 6;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 14px 16px 16px;
}
.widget:has(.widget-table-frame) {
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
}
.widget--third { grid-column: span 4; }
.widget--half { grid-column: span 6; }
.widget--two_thirds { grid-column: span 8; }
.widget--full { grid-column: span 12; }
@media (max-width: 1020px) {
  .widget, .widget--third, .widget--half, .widget--two_thirds, .widget--full { grid-column: span 12; }
}

.widget-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  padding-bottom: 8px;
}
.widget-body { flex: 1; min-height: 0; }
.widget-chart { width: 100%; height: 260px; }
/* Consecutive stats pack into one row of small cards. */
.widget-stat-strip {
  grid-column: span 12;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.widget-stat-strip .widget { flex: 1; min-width: 170px; }
.widget--stat { padding: 16px 18px 14px; }
.widget--stat .widget-body { display: flex; flex-direction: column; gap: 3px; }
.widget-note { font-size: 12px; color: var(--muted); padding-top: 8px; }
.widget-error { font-size: 12.5px; color: var(--danger); padding: 10px 0; overflow-wrap: anywhere; }
.widget-empty { color: var(--muted); font-size: 13px; padding: 24px 0; text-align: center; }

/* Like the home page: title sits above, the frame is the card. */
.widget-table-frame {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: auto;
  max-height: 340px;
}
/* border-collapse: separate keeps the header's bottom border attached to
   the sticky th cells while the body scrolls beneath them. */
.widget-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.widget-table th, .tx-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  padding: 9px 14px;
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  background: var(--card);
}
.widget-table td { padding: 9px 14px; }
.widget-table tbody tr + tr td { border-top: 1px solid var(--hairline); }
.widget-table td.num, .widget-table th.num, .tx-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.widget-table .group-row td { cursor: pointer; font-weight: 550; }
.widget-table .group-row:hover td { background: var(--hover); }
.group-chevron {
  display: inline-block;
  color: var(--muted);
  font-size: 10px;
  transition: transform 0.12s ease;
}
.group-row.open .group-chevron { transform: rotate(90deg); }
.group-count { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 4px; }

.widget-md { font-size: 13.5px; line-height: 1.55; color: var(--ink-2); }
.widget-md h1, .widget-md h2, .widget-md h3 { font-size: 13.5px; font-weight: 650; color: var(--ink); margin: 10px 0 4px; }
.widget-md p { margin: 6px 0; }
.widget-md ul, .widget-md ol { margin: 6px 0; padding-left: 20px; }
.widget-md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--accent-soft); padding: 1px 4px; border-radius: 4px; }

.dash-empty { margin-top: 48px; text-align: center; color: var(--muted); }
.dash-empty p { max-width: 52ch; margin: 6px auto; }
