:root {
  color-scheme: light;
  --page: #f7f6f3;
  --side: #f1f0ed;
  --surface: #ffffff;
  --surface-soft: #faf9f7;
  --surface-hover: #ebe8e3;
  --ink: #151515;
  --muted: #6f6b66;
  --line: #e5e1db;
  --accent: #ff5a3d;
  --accent-soft: #f1e9e5;
  --accent-ink: #674238;
  --active: #e4e0db;
  --input: #ffffff;
  --cash-expense: #f5c4c8;
  --cash-income: #cfeadc;
  --positive: #1f8a5b;
  --negative: #b84b43;
  --warning: #9a6a17;
  --shadow: 0 10px 28px rgba(28, 25, 23, 0.08);
  --shadow-soft: 0 8px 22px rgba(28, 25, 23, 0.06);
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 24px;
  --space-6: 32px;
  --weight-medium: 560;
  --weight-semibold: 620;
  --weight-bold: 700;
}

body[data-theme="dark"] {
  color-scheme: dark;
  --page: #121212;
  --side: #181716;
  --surface: #1f1e1c;
  --surface-soft: #262420;
  --surface-hover: #302d28;
  --ink: #f5f2ec;
  --muted: #b5aea4;
  --line: #3a362f;
  --accent: #ff6b4f;
  --accent-soft: #3a2924;
  --accent-ink: #ffd2c6;
  --active: #34312c;
  --input: #181716;
  --cash-expense: #5b3035;
  --cash-income: #294c3d;
  --positive: #72d5a6;
  --negative: #ff8d88;
  --warning: #e3bc6d;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 360px);
  display: grid;
  gap: 16px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
  font-size: 1.6rem;
}

.login-card label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: var(--weight-bold);
}

.login-error {
  min-height: 1.3em;
  margin: 0;
  color: var(--negative);
  font-weight: var(--weight-bold);
}

button,
input,
select,
textarea {
  font: inherit;
  line-height: 1.35;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
h4,
strong,
th {
  font-weight: var(--weight-semibold);
}

h1,
h2,
h3,
h4,
p {
  overflow-wrap: anywhere;
}

.app-shell {
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--side);
  padding: var(--space-4) 12px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 15px;
  font-weight: var(--weight-bold);
}

.sidebar h1 {
  margin: 1px 0 0;
  font-size: 16px;
  line-height: 1.1;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0;
  text-transform: uppercase;
}

.tabs {
  display: grid;
  gap: var(--space-1);
}

.tab,
.text-button,
.secondary-button,
.primary-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  font-weight: var(--weight-medium);
}

.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  background: transparent;
  color: var(--ink);
  padding: 0 12px;
  text-align: left;
  font-size: 14px;
  line-height: 1.25;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.tab.active {
  background: var(--active);
}

.tab:hover,
.secondary-button:hover,
.text-button:hover {
  background: var(--surface-hover);
}

.sidebar-spacer {
  flex: 1;
  min-height: 16px;
}

.user-panel,
.quick-stats,
.panel,
.metric,
.entry-form,
.inline-form,
.report-card,
.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.user-panel {
  position: relative;
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3);
}

.user-panel h2 {
  margin: 0;
  font-size: 15px;
}

.account-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 18px;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px;
  color: var(--ink);
  text-align: left;
}

.account-caret {
  display: grid;
  place-items: center;
  color: var(--muted);
  line-height: 1;
}

.account-menu {
  position: absolute;
  z-index: 20;
  top: auto;
  bottom: calc(100% - 4px);
  right: 12px;
  left: 12px;
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 6px;
  box-shadow: var(--shadow);
}

.account-menu[hidden] {
  display: none;
}

.account-menu button {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  padding: 0 10px;
  text-align: left;
  font-weight: var(--weight-medium);
}

.account-menu button:hover:not(:disabled) {
  background: var(--surface-hover);
}

.account-menu button.danger {
  color: var(--negative);
}

.account-menu button:disabled {
  cursor: default;
  opacity: 0.5;
}

.account-card:hover {
  background: var(--input);
}

.account-card strong,
.account-card small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-avatar,
.profile-avatar {
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 999px;
  background: #222;
  background-position: center;
  background-size: cover;
  color: #fff;
  font-weight: var(--weight-bold);
}

.account-avatar {
  width: 42px;
  height: 42px;
  font-size: 14px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-header h2,
.section-header h3,
.panel h3,
.report-card h3 {
  margin: 0;
}

.muted,
small {
  color: var(--muted);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: var(--weight-medium);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  color: var(--ink);
  min-height: 42px;
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 90, 61, 0.12);
}

textarea {
  resize: vertical;
}

.quick-stats {
  display: grid;
  gap: 0;
  overflow: hidden;
  padding: 0;
}

.quick-stats-header {
  background: var(--surface-soft);
}

.quick-stats div {
  display: grid;
  gap: 5px;
  border-bottom: 1px solid var(--line);
  padding: var(--space-3);
}

.quick-stats div:last-child {
  border-bottom: 0;
}

.quick-stats span,
.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: var(--weight-medium);
  line-height: 1.35;
}

.quick-stats-header span {
  color: var(--ink);
  font-size: 14px;
  font-weight: var(--weight-semibold);
}

.quick-stats-header small {
  font-size: 12px;
}

.quick-stats strong {
  font-size: 20px;
  line-height: 1.2;
}

.quick-stats strong.positive {
  color: var(--positive);
}

.quick-stats strong.negative {
  color: var(--negative);
}

main {
  min-width: 0;
  padding: var(--space-4) var(--space-5) var(--space-6);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 56px;
  margin: calc(var(--space-4) * -1) calc(var(--space-5) * -1) var(--space-6);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--page) 92%, transparent);
  padding: 12px var(--space-5);
  backdrop-filter: blur(10px);
}

.topbar h2 {
  margin: 2px 0 0;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.35;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-5);
}

.page-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

.page-heading h2 {
  margin: 5px 0 0;
  font-size: clamp(27px, 3.2vw, 42px);
  line-height: 1.12;
  letter-spacing: 0;
}

.period-control {
  min-width: 180px;
}

.metric-grid,
.content-grid,
.report-grid,
.allocation-layout {
  display: grid;
  gap: var(--space-4);
}

.metric-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric {
  display: grid;
  gap: var(--space-2);
  min-height: 114px;
  padding: var(--space-4);
}

.metric strong {
  font-size: 27px;
  line-height: 1.18;
  letter-spacing: 0;
}

.metric:nth-child(3) {
  border-color: #d7d0c8;
  background: var(--surface-soft);
}

.content-grid {
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, 0.9fr);
  margin-top: var(--space-4);
}

.allocation-panel {
  grid-column: 1 / -1;
}

.allocation-layout {
  grid-template-columns: minmax(320px, 0.75fr) minmax(0, 1.25fr);
}

.allocation-history-panel {
  margin-top: var(--space-4);
}

.allocation-history-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(180px, 240px) minmax(160px, 210px) auto;
  gap: var(--space-3);
  align-items: center;
  margin-top: var(--space-4);
}

.allocation-history-toolbar .search {
  max-width: none;
}

.allocation-history-results {
  margin: var(--space-2) 0 0;
  font-size: 13px;
}

.allocation-history-more {
  display: grid;
  place-items: center;
  border-top: 1px solid var(--line);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
}

.allocation-history-more[hidden] {
  display: none;
}

.allocation-summary,
.allocation-rules,
.allocation-queue,
.allocation-history {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.allocation-queue {
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  align-items: start;
}

.allocation-history {
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  align-items: start;
}

.allocation-hero {
  display: grid;
  gap: var(--space-1);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: var(--space-4);
}

.allocation-hero strong {
  font-size: 28px;
  line-height: 1.15;
}

.allocation-mini-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}

.allocation-mini-grid div,
.allocation-rule,
.allocation-card,
.allocation-history-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: var(--space-3);
}

.allocation-mini-grid span,
.allocation-rule small,
.allocation-card p {
  color: var(--muted);
}

.allocation-mini-grid span,
.allocation-mini-grid strong,
.allocation-rule-main strong,
.allocation-rule-main small {
  display: block;
}

.allocation-rule {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--space-3);
}

.allocation-rule:hover {
  background: var(--input);
}

.allocation-rule-main {
  min-width: 0;
}

.allocation-rule-main strong,
.allocation-rule-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.allocation-percent-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  min-height: 30px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  padding: 0 11px;
  font-size: 13px;
  font-weight: var(--weight-semibold);
}

.allocation-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.allocation-rule.editing {
  grid-template-columns: minmax(160px, 0.8fr) minmax(180px, 1fr) 92px auto;
  align-items: end;
}

.allocation-rule.editing:hover {
  background: var(--surface-soft);
}

.allocation-rule.editing label {
  min-width: 0;
}

.danger-link {
  color: var(--negative);
}

.allocation-add-form {
  display: grid;
  grid-template-columns: minmax(160px, 0.9fr) minmax(180px, 1fr) 90px auto;
  gap: var(--space-3);
  align-items: end;
  border-top: 1px solid var(--line);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
}

.allocation-card,
.allocation-history-row {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
}

.allocation-card-head,
.allocation-history-head,
.allocation-split div {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
}

.allocation-card-head,
.allocation-history-head {
  align-items: start;
}

.allocation-card-head h3,
.allocation-card-head p,
.allocation-description {
  margin: 0;
}

.allocation-card-category,
.allocation-history-category {
  display: grid;
  gap: 8px;
}

.allocation-card-category > span,
.allocation-history-category > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: var(--weight-medium);
}

.allocation-card .category-picker,
.allocation-history-row .category-picker {
  min-width: 0;
}

.allocation-card .category-trigger,
.allocation-history-row .category-trigger {
  min-height: 34px;
  background: var(--input);
}

.allocation-split {
  display: grid;
  gap: var(--space-2);
}

.allocation-split.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.allocation-split div {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 9px 10px;
}

.allocation-split span,
.allocation-split small {
  color: var(--muted);
}

.allocation-history-buckets {
  display: grid;
  gap: 6px;
}

.allocation-history-row[role="button"] {
  cursor: pointer;
}

.allocation-history-row[role="button"]:hover {
  background: var(--input);
}

.allocation-history-row[role="button"]:focus-visible {
  outline: 3px solid rgba(255, 90, 61, 0.22);
  outline-offset: 2px;
}

.allocation-history-row span,
.allocation-history-buckets span {
  display: block;
}

.allocation-history-buckets span {
  overflow: hidden;
  border-top: 1px solid var(--line);
  padding-top: 6px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.warning-chip {
  background: color-mix(in srgb, var(--warning) 18%, var(--surface));
  color: var(--warning);
}

.transaction-allocation-panel {
  display: grid;
  gap: var(--space-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  margin-top: var(--space-3);
  padding: var(--space-3);
}

.transaction-allocation-panel[hidden] {
  display: none;
}

.entry-allocation-lines {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.entry-allocation-meta {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
}

.entry-allocation-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  min-height: 38px;
  padding: 8px var(--space-2);
}

.entry-allocation-line span,
.entry-allocation-line small {
  color: var(--muted);
}

.panel,
.entry-form,
.inline-form,
.report-card {
  padding: var(--space-5);
}

.accounts-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(0, 1.2fr);
  gap: var(--space-4);
}

.account-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.wide-account {
  grid-column: span 2;
}

.account-form .primary-button {
  grid-column: span 2;
}

.accounts-list {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.vendor-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: var(--space-3);
}

.vendor-card.editing {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}

.vendor-logo {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: var(--weight-bold);
}

.vendor-main {
  min-width: 0;
}

.vendor-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-3);
}

.vendor-title-row h3,
.vendor-title-row p {
  margin: 0;
}

.vendor-title-row p,
.vendor-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.vendor-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px var(--space-3);
  margin-top: var(--space-2);
}

.vendor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: var(--active);
  color: var(--ink);
  padding: 0 10px;
  font-size: 12px;
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.status-active {
  background: color-mix(in srgb, var(--positive) 18%, var(--surface));
  color: var(--positive);
}

.status-review {
  background: color-mix(in srgb, var(--warning) 18%, var(--surface));
  color: var(--warning);
}

.status-paused {
  background: color-mix(in srgb, var(--muted) 16%, var(--surface));
}

.icon-text-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  color: var(--ink);
  padding: 0 10px;
  font-weight: var(--weight-medium);
}

.activity-list,
.bar-list,
.category-list {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.activity-item,
.category-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: var(--space-3);
}

.activity-item strong,
.activity-item span {
  display: block;
}

.amount.expense,
.decision-cut {
  color: var(--negative);
}

.amount.income,
.decision-keep {
  color: var(--positive);
}

.decision-review {
  color: var(--warning);
}

.bar-row {
  display: grid;
  gap: 8px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: 14px;
  font-weight: var(--weight-medium);
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-hover);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}

.wide {
  grid-column: span 3;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.primary-button,
.secondary-button,
.text-button,
.icon-button,
.danger-button {
  min-height: 40px;
  padding: 0 var(--space-4);
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: #e9482f;
}

.danger-button {
  border: 0;
  border-radius: 8px;
  background: var(--negative);
  color: #fff;
  font-weight: var(--weight-medium);
}

.secondary-button,
.text-button {
  border: 1px solid var(--line);
  background: var(--input);
  color: var(--ink);
}

.icon-button {
  width: 38px;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
}

.search {
  max-width: 340px;
}

#new-entry-from-transactions {
  min-width: 112px;
}

.receipt-upload-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  border: 1px dashed color-mix(in srgb, var(--accent) 55%, var(--line));
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: var(--space-4);
  padding: var(--space-5);
  box-shadow: var(--shadow-soft);
}

.receipt-upload-panel.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.receipt-upload-panel h3,
.receipt-upload-panel p,
.receipt-status {
  margin: 0;
}

.receipt-upload-panel h3 {
  line-height: 1.35;
}

.receipt-upload-panel p {
  line-height: 1.55;
}

.receipt-status {
  min-height: 20px;
  margin: -4px 0 var(--space-3);
  font-size: 13px;
  line-height: 1.4;
}

.receipt-dialog {
  width: min(980px, calc(100vw - 40px));
}

.receipt-review-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: var(--space-5);
}

.receipt-preview {
  display: grid;
  align-content: start;
  gap: var(--space-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: var(--space-3);
}

.receipt-preview img {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border-radius: 6px;
  background: var(--input);
}

.receipt-fields,
.receipt-line-items {
  display: grid;
  gap: 14px;
}

.receipt-money-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.receipt-line-items {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.receipt-line-item {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.receipt-line-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.receipt-line-item:first-of-type {
  padding-top: 0;
}

.cashflow-head,
.cashflow-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.cashflow-head h2,
.cashflow-subhead h3 {
  margin: 0;
  line-height: 1.2;
}

.segmented-control,
.mini-tabs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.segmented-control button,
.mini-tabs span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 0 14px;
  color: var(--muted);
  font-weight: var(--weight-medium);
  line-height: 1;
}

.segmented-control button.active,
.mini-tabs span:first-child {
  background: var(--active);
  color: var(--ink);
}

.cash-chart-card,
.cash-breakdown-card,
.cash-summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.cash-chart-card {
  overflow: auto;
  margin-bottom: var(--space-5);
  padding: var(--space-5);
}

.cash-chart {
  display: block;
  width: 100%;
  min-width: 760px;
  height: auto;
}

.cash-chart line {
  stroke: var(--line);
  stroke-width: 1;
}

.cash-chart .grid-line {
  stroke: var(--surface-hover);
}

.cash-chart .expense-bar {
  fill: var(--cash-expense);
}

.cash-chart .income-bar {
  fill: var(--cash-income);
}

.cash-chart polyline {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cash-chart circle {
  fill: var(--ink);
}

.cash-chart text {
  fill: var(--muted);
  font-size: 12px;
}

.cash-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.cash-summary-card {
  display: grid;
  place-items: center;
  gap: var(--space-2);
  min-height: 100px;
  padding: var(--space-4);
}

.cash-summary-card strong {
  font-size: 23px;
  line-height: 1.18;
}

.cash-summary-card strong.negative {
  color: var(--negative);
}

.cash-summary-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0;
  text-transform: uppercase;
}

.cash-breakdown-card {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
  overflow: hidden;
  padding: var(--space-5);
}

.cash-breakdown-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  min-height: 46px;
  overflow: hidden;
  border-radius: 8px;
  padding: 0 var(--space-3);
}

.cash-breakdown-bar {
  position: absolute;
  inset: 3px auto 3px 0;
  z-index: 0;
  border-radius: 8px;
  background: var(--cash-expense);
}

#cash-income-breakdown .cash-breakdown-bar {
  background: var(--cash-income);
}

.cash-breakdown-row span,
.cash-breakdown-row strong {
  position: relative;
  z-index: 1;
}

.cash-breakdown-row strong {
  justify-self: end;
}

.cash-empty {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 190px;
  color: var(--muted);
  text-align: center;
}

.cash-empty strong {
  color: var(--ink);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 15px var(--space-4);
  text-align: left;
  vertical-align: top;
  line-height: 1.45;
}

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.transaction-row {
  cursor: pointer;
}

.transaction-row:hover td,
.transaction-row:focus-visible td {
  background: var(--surface-soft);
}

.transaction-row:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: -3px;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  padding: 0 10px;
  font-size: 12px;
  font-weight: var(--weight-medium);
}

.inline-form {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.category-picker {
  position: relative;
  min-width: 220px;
}

.category-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 0 12px;
  color: var(--ink);
  font-weight: var(--weight-medium);
  text-align: left;
  line-height: 1.25;
}

.category-trigger:hover {
  border-color: var(--line);
  background: var(--input);
}

.category-caret {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  line-height: 1;
  transform: translateY(-1px);
}

.category-menu {
  position: fixed;
  z-index: 1000;
  max-width: calc(100vw - 24px);
  max-height: 520px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.category-search {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  min-height: 43px;
}

.category-menu-list {
  max-height: 414px;
  overflow: auto;
  padding: 6px 0;
}

.category-menu-group {
  display: grid;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  padding: 6px 8px 8px;
}

.category-menu-group:last-child {
  border-bottom: 0;
}

.category-menu-group h4 {
  margin: 5px 8px;
  color: var(--muted);
  font-size: 12px;
}

.category-menu-group button,
.create-category-link {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  padding: 0 8px;
  text-align: left;
}

.category-menu-group button:hover {
  background: var(--surface-soft);
}

.create-category-link {
  border-top: 1px solid var(--line);
  border-radius: 0;
  color: #007ca8;
  font-weight: var(--weight-medium);
}

.category-empty {
  margin: 0;
  padding: 16px;
  color: var(--muted);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.plain-icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 20px;
}

.plain-icon-button:hover {
  background: var(--surface-soft);
}

.icon-name-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
}

.emoji-current {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px 0 0 8px;
  background: var(--input);
  font-size: 20px;
}

.icon-name-row input {
  border-left: 0;
  border-radius: 0 8px 8px 0;
}

.emoji-picker {
  display: grid;
  position: fixed;
  z-index: 1100;
  gap: 10px;
  max-height: min(620px, calc(100vh - 32px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  box-shadow: var(--shadow);
}

.emoji-picker[hidden] {
  display: none;
}

.emoji-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.emoji-tabs button,
.emoji-grid button {
  display: grid;
  place-items: center;
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 19px;
}

.emoji-tabs button:hover,
.emoji-tabs button.active,
.emoji-grid button:hover {
  background: var(--accent-soft);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  max-height: 430px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  scrollbar-width: none;
}

.emoji-grid::-webkit-scrollbar {
  display: none;
}

.add-group-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.category-pill button,
.row-actions button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  min-height: 34px;
  padding: 0 10px;
  color: var(--ink);
  font-weight: var(--weight-medium);
}

.report-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.report-card {
  display: grid;
  gap: 14px;
}

.report-line {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  border-bottom: 1px solid var(--line);
  padding-bottom: var(--space-2);
}

.report-line:last-child {
  border-bottom: 0;
}

.settings-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: var(--space-4);
}

.settings-menu,
.settings-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.settings-menu {
  align-self: start;
  display: grid;
  gap: var(--space-1);
  padding: var(--space-3);
}

.settings-menu h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.settings-menu button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 0 12px;
  text-align: left;
  font-weight: var(--weight-medium);
}

.settings-menu button.active {
  background: #d9f2f3;
  color: #087383;
}

.settings-menu button:disabled {
  cursor: default;
  opacity: 0.55;
}

.settings-panel {
  overflow: hidden;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  border-bottom: 1px solid var(--line);
  padding: var(--space-4) var(--space-5);
}

.settings-head h2 {
  margin: 3px 0 0;
  font-size: 20px;
  line-height: 1.25;
}

.profile-form {
  display: grid;
  gap: var(--space-5);
  padding: var(--space-5);
}

.profile-photo-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.profile-avatar {
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  background-color: #6f42c1;
  font-size: 18px;
}

.picture-button {
  display: inline-grid;
  place-items: center;
  width: fit-content;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0 12px;
  color: var(--ink);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

#profile-picture {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.profile-grid small {
  font-weight: 500;
}

.login-preview {
  display: grid;
  border: 1px solid #d8e7df;
  border-radius: 8px;
  background: #f2faf5;
  padding: 14px;
}

.login-preview strong,
.login-preview span {
  display: block;
}

.login-preview span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

dialog::backdrop {
  background: rgba(34, 31, 28, 0.28);
}

dialog h2 {
  margin-top: 0;
  line-height: 1.2;
}

dialog form {
  display: grid;
  gap: var(--space-4);
}

.confirm-dialog {
  width: min(460px, calc(100vw - 32px));
}

.confirm-dialog form {
  gap: var(--space-3);
}

.confirm-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--negative);
  font-size: 20px;
  font-weight: var(--weight-bold);
}

.confirm-dialog h2 {
  margin: 4px 0 6px;
}

.confirm-dialog .form-actions {
  justify-content: stretch;
}

.confirm-dialog .form-actions button {
  flex: 1;
}

#entry-dialog {
  width: min(1240px, calc(100vw - 48px));
  max-height: calc(100vh - 40px);
  overflow: hidden;
  padding: var(--space-5);
}

#entry-dialog .entry-form {
  border: 0;
  box-shadow: none;
  max-height: calc(100vh - 104px);
  overflow: auto;
  padding: 0;
  padding-right: var(--space-2);
  scrollbar-width: thin;
}

#entry-dialog .dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
}

#entry-dialog .form-grid {
  gap: var(--space-3) var(--space-5);
}

#entry-dialog .entry-work-note {
  grid-column: span 2;
}

#entry-dialog .entry-payment-note {
  grid-column: span 1;
}

#entry-dialog input,
#entry-dialog select,
#entry-dialog textarea {
  padding-top: 10px;
  padding-bottom: 10px;
}

#entry-dialog textarea {
  min-height: 52px;
}

#entry-dialog .form-actions {
  margin-top: var(--space-4);
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .tabs {
    grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  }

  .tab {
    justify-content: center;
    text-align: center;
  }

  .sidebar-spacer {
    display: none;
  }

  .metric-grid,
  .content-grid,
  .report-grid,
  .cash-summary-grid,
  .accounts-layout,
  .allocation-layout,
  .settings-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .allocation-queue {
    grid-template-columns: 1fr;
  }

  .allocation-history {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .allocation-history-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .wide {
    grid-column: span 2;
  }
}

@media (max-width: 720px) {
  main {
    padding: var(--space-3) 12px var(--space-5);
  }

  .topbar {
    display: grid;
    align-items: start;
    margin-right: -12px;
    margin-left: -12px;
    padding-right: 12px;
    padding-left: 12px;
  }

  .tabs,
  .metric-grid,
  .content-grid,
  .report-grid,
  .cash-summary-grid,
  .accounts-layout,
  .allocation-layout,
  .allocation-mini-grid,
  .allocation-queue,
  .allocation-history,
  .allocation-split.compact,
  .allocation-history-toolbar,
  .account-form,
  .settings-layout,
  .profile-grid,
  .form-grid,
  .inline-form {
    grid-template-columns: 1fr;
  }

  .page-heading,
  .page-actions,
  .cashflow-head,
  .receipt-upload-panel {
    display: grid;
    align-items: stretch;
  }

  .page-heading {
    gap: var(--space-3);
    margin-bottom: var(--space-4);
  }

  .page-heading h2 {
    font-size: 30px;
    line-height: 1.14;
  }

  .wide {
    grid-column: auto;
  }

  .wide-account,
  .account-form .primary-button {
    grid-column: auto;
  }

  .vendor-card {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .vendor-card.editing {
    grid-template-columns: 1fr;
  }

  .vendor-card .icon-text-button {
    grid-column: 1 / -1;
  }

  .vendor-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .allocation-rule,
  .allocation-add-form,
  .allocation-card-head,
  .allocation-history-row {
    display: grid;
  }

  .allocation-rule,
  .allocation-add-form {
    grid-template-columns: 1fr;
  }

  .allocation-rule.editing {
    grid-template-columns: 1fr;
  }

  .allocation-rule-main strong,
  .allocation-rule-main small {
    white-space: normal;
  }

  .allocation-percent-pill {
    justify-self: start;
  }

  .allocation-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .panel,
  .entry-form,
  .inline-form,
  .report-card,
  .cash-breakdown-card,
  .cash-chart-card {
    padding: var(--space-4);
  }

  .allocation-history-buckets {
    min-width: 0;
    text-align: left;
  }

  .receipt-review-layout,
  .receipt-money-grid {
    grid-template-columns: 1fr;
  }

  .search {
    max-width: none;
  }

  #entry-dialog {
    width: min(100vw - 24px, 720px);
    max-height: calc(100vh - 24px);
    padding: var(--space-4);
  }

  #entry-dialog .entry-form {
    max-height: calc(100vh - 72px);
    padding-right: 0;
  }

  #entry-dialog .entry-work-note,
  #entry-dialog .entry-payment-note {
    grid-column: auto;
  }

  .entry-allocation-lines {
    grid-template-columns: 1fr;
  }

  .form-actions {
    display: grid;
  }
}
