:root {
  color-scheme: light;
  --page: #f2f5f5;
  --surface: #ffffff;
  --surface-quiet: #e9efef;
  --ink: #172225;
  --muted: #627277;
  --line: #cfd9da;
  --accent: #176b70;
  --accent-dark: #123c43;
  --accent-soft: #dceff0;
  --blue: #235d9f;
  --amber: #9a5b0a;
  --amber-soft: #fff2d6;
  --red: #a33a3a;
  --red-soft: #fde7e5;
  --green: #26734d;
  --green-soft: #e2f3e9;
  --shadow: 0 1px 2px rgb(20 46 50 / 8%);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--page); }
body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font: 16px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; min-height: 42px; }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid rgb(35 93 159 / 28%);
  outline-offset: 2px;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.25rem; line-height: 1.2; }
h2 { font-size: 1.25rem; line-height: 1.25; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px max(20px, calc((100vw - 1240px) / 2));
  color: #fff;
  background: var(--accent-dark);
}
.brand-block, .header-actions, .section-heading, .toolbar-actions, .business-actions {
  display: flex;
  align-items: center;
}
.brand-block { gap: 12px; }
.brand-block p { color: #c8dbdd; font-size: 0.875rem; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgb(255 255 255 / 35%);
  border-radius: 7px;
  color: var(--accent-dark);
  background: #d8eced;
  font-weight: 800;
}
.header-actions, .toolbar-actions, .business-actions { gap: 10px; }
.header-actions, .business-actions { flex-wrap: wrap; justify-content: flex-end; }
.button {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 15px;
  font-weight: 700;
  cursor: pointer;
}
.button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.app-header .button.primary { color: var(--accent-dark); background: #d8eced; border-color: #d8eced; }
.button.secondary { color: var(--accent-dark); background: var(--surface); border-color: var(--line); }
.button.danger { color: var(--red); background: var(--surface); border-color: #deb6b2; }
.app-header .button.secondary { color: #fff; background: transparent; border-color: rgb(255 255 255 / 35%); }
.button:disabled { cursor: not-allowed; opacity: 0.52; }

.login-page {
  min-height: 100vh;
  background: #e8eeee;
}
.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}
.login-form {
  display: grid;
  gap: 18px;
  width: min(400px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgb(18 60 67 / 12%);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.login-brand h1 { font-size: 1.5rem; }
.login-form label { display: grid; gap: 7px; color: var(--accent-dark); font-weight: 700; }
.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
}
.login-form .button { width: 100%; }
.login-error { padding: 10px 12px; border-radius: 6px; color: var(--red); background: var(--red-soft); font-size: 0.875rem; }

.payment-band {
  padding: 22px max(20px, calc((100vw - 1240px) / 2));
  background: var(--surface);
}
.checking-band {
  padding: 18px max(20px, calc((100vw - 1240px) / 2)) 22px;
  background: #f7f9f9;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.section-heading { justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.section-heading.compact { margin-bottom: 14px; }
.eyebrow { color: var(--muted); font-size: 0.8125rem; font-weight: 750; text-transform: uppercase; }
.reminder-key, .work-note { color: var(--muted); font-size: 0.875rem; }
.payment-list, .checking-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(285px, 100%), 1fr));
  gap: 12px;
}
.payment-list { grid-auto-rows: 238px; }
.checking-list { grid-auto-rows: minmax(0, auto); }
.home-title-card {
  --payment-card-bg: var(--surface-quiet);
  position: relative;
  isolation: isolate;
  height: 100%;
  overflow: hidden;
  transition: box-shadow 140ms ease, transform 140ms ease, opacity 140ms ease;
}
.home-title-card > * { position: relative; z-index: 1; }
.home-title-card:has(.home-card-menu[open]) { z-index: 20; overflow: visible; }
.home-title-card > .payment-title-row, .home-title-card > .checking-title-row { z-index: 5; }
.home-title-card:hover { box-shadow: inset 0 0 0 1px rgb(18 60 67 / 12%), 0 3px 10px rgb(18 60 67 / 8%); }
.home-title-card.dragging { opacity: 0.45; transform: scale(0.985); }
.home-title-card.title-card-business { --payment-card-bg: #f2eee2; border-left-color: #8b682d; }
.home-title-card.title-card-work { --payment-card-bg: #e5f0f6; border-left-color: #356d8a; }
.home-title-card.title-card-gmr::after {
  position: absolute;
  z-index: 0;
  top: 50%;
  left: 50%;
  width: 164px;
  height: 164px;
  background: url("/assets/gmr-logo.png") center / contain no-repeat;
  content: "";
  opacity: 0.11;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.home-title-card.title-card-personal::after {
  position: absolute;
  z-index: 0;
  inset: 0;
  background: url("/assets/personal-watermark.jpg") center / cover no-repeat;
  content: "";
  opacity: 0.14;
  pointer-events: none;
}
.payment-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 11px;
  min-width: 0;
  min-height: 238px;
  padding: 14px 16px 15px;
  background: var(--payment-card-bg);
  border-left: 4px solid var(--accent);
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px rgb(18 60 67 / 5%);
}
.payment-item.is-soon { --payment-card-bg: var(--amber-soft); border-left-color: var(--amber); }
.payment-item.is-near { --payment-card-bg: #ffe7bd; border-left-color: #bb6706; }
.payment-item.is-urgent, .payment-item.is-overdue { --payment-card-bg: var(--red-soft); border-left-color: var(--red); }
.payment-item.is-cleared { border-left-color: var(--green); }
.payment-title-row { display: flex; align-items: flex-start; gap: 9px; min-width: 0; }
.home-card-drag-handle { flex: 0 0 auto; margin-top: 1px; color: var(--muted); font-size: 1.15rem; line-height: 1.25; cursor: grab; }
.home-card-drag-handle:active { cursor: grabbing; }
.payment-name { flex: 1 1 auto; min-width: 0; font-size: 1.0625rem; line-height: 1.3; overflow-wrap: anywhere; }
.home-card-menu { position: relative; z-index: 4; flex: 0 0 auto; }
.home-card-menu summary {
  display: grid;
  width: 30px;
  height: 26px;
  place-items: center;
  padding: 0 0 7px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-size: 1.125rem;
  font-weight: 800;
  line-height: 1;
  list-style: none;
  cursor: pointer;
}
.home-card-menu summary::-webkit-details-marker { display: none; }
.home-card-menu summary:hover, .home-card-menu[open] summary { border-color: rgb(23 107 112 / 20%); background: rgb(255 255 255 / 62%); }
.home-card-menu-popover {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  right: 0;
  width: max-content;
  min-width: 174px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  box-shadow: 0 8px 20px rgb(18 60 67 / 16%);
}
.home-card-menu-popover button {
  width: 100%;
  min-height: 34px;
  padding: 6px 9px;
  border: 0;
  border-radius: 3px;
  color: var(--ink);
  background: transparent;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}
.home-card-menu-popover button:hover { color: var(--red); background: var(--red-soft); }
.payment-highlight { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.payment-highlight > span, .payment-schedule > span:first-child, .payment-facts span { color: var(--muted); font-size: 0.75rem; font-weight: 650; text-transform: uppercase; }
.payment-amount { flex: 0 0 auto; color: var(--ink); font-size: 1.25rem; line-height: 1.2; white-space: nowrap; }
.payment-schedule { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; padding: 9px 0; border-top: 1px solid rgb(98 114 119 / 22%); border-bottom: 1px solid rgb(98 114 119 / 22%); }
.payment-schedule strong { white-space: nowrap; }
.payment-status { color: var(--ink); font-size: 0.8125rem; font-weight: 700; text-transform: none; }
.payment-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.payment-facts div { min-width: 0; }
.payment-facts span, .payment-facts strong { display: block; }
.payment-facts strong { margin-top: 2px; font-size: 0.875rem; line-height: 1.35; overflow-wrap: anywhere; }

.checking-item {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 10px;
  min-width: 0;
  padding: 14px 16px;
  background: var(--payment-card-bg);
  border-left: 4px solid var(--accent);
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px rgb(18 60 67 / 7%);
}
.checking-item.title-card-gmr::after { width: 136px; height: 136px; }
.checking-title-row, .checking-balance, .checking-footer { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.checking-title-row { gap: 9px; }
.checking-title-copy { display: grid; flex: 1 1 auto; gap: 5px; min-width: 0; }
.checking-title-row h3 { min-width: 0; font-size: 1.0625rem; line-height: 1.3; overflow-wrap: anywhere; }
.checking-balance { align-items: baseline; }
.checking-balance span, .checking-footer div span { color: var(--muted); font-size: 0.75rem; font-weight: 650; text-transform: uppercase; }
.checking-balance strong { flex: 0 0 auto; font-size: 1.25rem; line-height: 1.2; white-space: nowrap; }
.checking-footer { align-items: end; padding-top: 10px; border-top: 1px solid rgb(98 114 119 / 22%); }
.checking-footer div span, .checking-footer div strong { display: block; }
.checking-footer div strong { margin-top: 2px; font-size: 0.875rem; }
.checking-footer > span { max-width: 52%; color: var(--muted); font-size: 0.8125rem; text-align: right; overflow-wrap: anywhere; }
.shortage-dot { flex: 0 0 auto; width: 9px; height: 9px; margin-top: 3px; border-radius: 50%; }
.shortage-dot-mild { background: var(--muted); }
.shortage-dot-soon { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.checking-item.has-shortage-urgent { --payment-card-bg: var(--red-soft); border-left-color: var(--red); }
.home-title-filler {
  border: 1px dashed transparent;
  background: transparent;
  box-shadow: none;
}
.payment-list .home-title-filler { min-height: 238px; }
.checking-list .home-title-filler { min-height: 44px; }
.home-title-filler::after { display: none; }
.home-title-filler .home-card-drag-handle {
  position: absolute;
  top: 14px;
  left: 16px;
  opacity: 0.12;
  transition: opacity 140ms ease;
}
.home-title-filler:hover {
  border-color: rgb(98 114 119 / 22%);
  box-shadow: none;
}
.home-title-filler:hover .home-card-drag-handle,
.home-title-filler.dragging .home-card-drag-handle { opacity: 0.75; }

.context-tabs {
  display: flex;
  gap: 2px;
  padding: 0 max(20px, calc((100vw - 1240px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.context-tab {
  position: relative;
  appearance: none;
  min-width: 120px;
  min-height: 52px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-weight: 750;
  cursor: pointer;
}
.context-tab::after {
  position: absolute;
  right: 14px;
  bottom: -1px;
  left: 14px;
  height: 3px;
  background: transparent;
  content: "";
}
.context-tab.is-active { color: var(--accent-dark); }
.context-tab.is-active::after { background: var(--accent); }
.business-subtabs, .work-view-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  margin: -4px 0 18px;
  border-bottom: 1px solid var(--line);
}
.business-subtab, .work-view-tab {
  appearance: none;
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}
.business-subtab.is-active, .work-view-tab.is-active { color: var(--accent-dark); border-bottom-color: var(--accent); }
.work-view-tabs { margin-top: 0; }

.work-period-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.work-period-tabs {
  display: flex;
  flex: 1 1 auto;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
}
.work-period-tab {
  appearance: none;
  flex: 0 0 auto;
  min-width: 140px;
  min-height: 54px;
  padding: 7px 12px 8px;
  border: 1px solid transparent;
  border-bottom: 3px solid transparent;
  border-radius: 5px 5px 0 0;
  color: var(--muted);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.work-period-tab span, .work-period-tab small { display: block; }
.work-period-tab span { max-width: 190px; overflow: hidden; color: inherit; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.work-period-tab small { color: var(--muted); font-size: 0.75rem; }
.work-period-tab.is-active { color: var(--accent-dark); background: var(--accent-soft); border-color: var(--line); border-bottom-color: var(--accent); }
.work-period-actions { flex: 0 0 auto; padding-bottom: 6px; }

.app-main { width: min(1240px, calc(100vw - 40px)); margin: 0 auto; padding: 28px 0 48px; }
.context-overview, .work-panel, .connections-panel {
  margin-bottom: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.context-overview, .work-panel { padding: 20px; }
.summary-metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.metric { min-width: 0; padding: 14px 16px; }
.metric + .metric { border-left: 1px solid var(--line); }
.metric-label { color: var(--muted); font-size: 0.8125rem; }
.metric-value { margin-top: 2px; font-size: 1.25rem; font-weight: 760; }
.account-list { display: grid; gap: 10px; }
.account-row {
  display: grid;
  grid-template-columns: minmax(210px, 1.35fr) repeat(2, minmax(125px, 0.72fr)) minmax(360px, 2fr);
  gap: 14px;
  align-items: center;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.account-name { align-self: center; min-width: 0; }
.account-name strong, .account-name span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-name span, .field-label, .connection-meta { color: var(--muted); font-size: 0.8125rem; }
.account-name .account-kind { margin: 3px 0 1px; color: var(--accent); font-size: 0.75rem; font-weight: 750; text-transform: uppercase; }
.account-name-row { display: flex; align-items: center; gap: 6px; }
.account-name-row strong { min-width: 0; }
.rename-account { appearance: none; flex: 0 0 auto; border: none; background: none; padding: 0; color: var(--accent); font-size: 0.75rem; font-weight: 700; cursor: pointer; }
.rename-account:hover { text-decoration: underline; }
.drag-handle { flex: 0 0 auto; color: var(--muted); font-size: 0.9375rem; cursor: grab; }
.account-row.dragging { opacity: 0.5; }
.business-subtab[draggable="true"] { cursor: grab; }
.business-subtab.dragging { opacity: 0.5; }
.account-value { align-self: center; }
.account-value strong, .account-value span { display: block; }
.account-value span { color: var(--muted); font-size: 0.8125rem; }
.field-stack { display: grid; gap: 5px; }
.field-stack select, .field-stack input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  background: var(--surface);
  padding: 0 10px;
}
.field-stack input[readonly] { color: var(--accent-dark); background: var(--accent-soft); cursor: default; }
.account-controls { display: grid; align-content: center; gap: 10px; min-width: 0; }
.payment-settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.classification-fields { display: flex; align-items: end; flex-wrap: wrap; gap: 10px 14px; min-width: 0; }
.classification-fields > * { flex: 1 1 145px; min-width: 0; }
.use-fields { display: grid; align-content: end; min-height: 42px; }
.use-checkboxes { display: flex; flex-wrap: wrap; gap: 10px; }
.use-checkbox { display: flex; align-items: center; gap: 4px; font-size: 0.8125rem; color: var(--ink); white-space: nowrap; }
.use-checkbox input { accent-color: var(--accent); }
.context-badge { color: var(--muted); font-size: 0.8125rem; }
.transaction-context {
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  background: var(--surface);
  padding: 2px 6px;
  font-size: 0.8125rem;
}
.empty-state {
  padding: 30px 18px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-quiet);
  border: 1px dashed #b9c7c8;
  border-radius: 6px;
}
.empty-state strong { display: block; margin-bottom: 4px; color: var(--ink); }

.work-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) repeat(2, minmax(155px, 0.8fr)) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--surface-quiet);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.work-control { display: grid; gap: 5px; color: var(--muted); font-size: 0.875rem; }
.work-control input, .work-control select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  background: var(--surface);
  padding: 0 10px;
}
.work-control input[readonly] { color: var(--accent-dark); background: var(--accent-soft); cursor: default; }
.sheet-wrap { overflow-x: auto; border: 1px solid #111; border-radius: 3px; background: #fff; }
.sheet-table { width: 100%; min-width: 1000px; border-collapse: collapse; table-layout: fixed; }
.sheet-table th, .sheet-table td { height: 39px; border: 1px solid #111; }
.sheet-table th {
  height: 42px;
  padding: 8px 9px;
  color: #111;
  background: #fff;
  font-size: 0.9375rem;
  text-align: left;
}
.sheet-table thead tr:nth-child(2) th { border-top-width: 4px; font-size: 1rem; text-align: center; }
.sheet-table thead tr:nth-child(2) th:first-child { width: 84px; }
.sheet-table thead tr:nth-child(2) th:nth-child(2) { width: 120px; text-align: left; }
.sheet-table thead tr:nth-child(2) th:nth-child(3) { width: 260px; }
.sheet-table thead tr:nth-child(2) th:nth-child(4) { width: 240px; }
.sheet-table thead tr:nth-child(2) th:nth-child(5) { width: 170px; }
.sheet-table thead tr:nth-child(2) th:nth-child(6) { width: 140px; }
.sheet-meta-row th { height: 36px; font-size: 1rem; font-weight: 500; }
.sheet-meta-row th:last-child { text-align: right; }
.sheet-table td:first-child { text-align: center; color: var(--muted); }
.exclude-work-item {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  margin-right: 3px;
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
  vertical-align: middle;
}
.exclude-work-item:hover { color: var(--red); }
.is-pending-row .pending-badge { margin-left: 4px; }
.sheet-input {
  width: 100%;
  min-height: 43px;
  border: 0;
  border-radius: 0;
  padding: 7px 9px;
  color: var(--ink);
  background: transparent;
}
.sheet-input[type="number"] { padding-right: 10px; }
.sheet-input:focus { position: relative; outline: 2px solid var(--blue); outline-offset: -2px; }
.amount-input { text-align: right; }
.sheet-empty-row td { height: 36px; }
.sheet-total-row td { border-bottom-width: 4px; }
.sheet-total-row td:last-child, .sheet-summary-total td:nth-child(4) { padding: 6px 10px; text-align: right; font-weight: 800; }
.sheet-spacer-row td { height: 38px; border-color: #aeb8ba; }
.sheet-summary-heading td:nth-child(3) { padding: 6px; font-size: 1rem; font-weight: 750; text-transform: uppercase; }
.sheet-summary-row td:nth-child(3) { padding: 6px; font-weight: 650; }
.sheet-summary-row td:nth-child(4) { padding: 6px 10px; text-align: right; }
.sheet-summary-total td:nth-child(4) { border-top-width: 2px; }
.work-note { margin-top: 10px; }
.work-save-status {
  align-self: center;
  min-width: 54px;
  color: var(--muted);
  font-size: 0.8125rem;
  text-align: right;
}
.work-save-status[data-state="saving"] { color: var(--accent); }
.work-save-status[data-state="error"] { color: var(--red); }

.transaction-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
.transaction-table { width: 100%; min-width: 1050px; border-collapse: collapse; table-layout: fixed; }
.transaction-table th, .transaction-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.transaction-table th { color: #fff; background: var(--accent-dark); font-size: 0.875rem; }
.transaction-table th:first-child { width: 110px; }
.transaction-table th:nth-child(2) { width: 180px; }
.transaction-table th:nth-child(3) { width: 140px; }
.transaction-table th:nth-child(5) { width: 120px; text-align: right; }
.transaction-table th:nth-child(6) { width: 130px; }
.transaction-table th:last-child { width: 205px; }
.transaction-table tr:last-child td { border-bottom: 0; }
.transaction-table td span { display: block; color: var(--muted); font-size: 0.8125rem; }
.transaction-amount { text-align: right !important; font-variant-numeric: tabular-nums; }
.transaction-disposition { width: 100%; min-height: 38px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); padding: 0 8px; }
.transaction-ineligible { color: var(--muted); font-size: 0.875rem; }

.transactions-panel { margin-bottom: 20px; overflow: hidden; }
.transactions-panel summary { padding: 16px 18px; font-weight: 750; cursor: pointer; }
.transactions-filters { display: flex; flex-wrap: wrap; gap: 12px; padding: 0 18px 16px; }
.context-transaction-table { width: 100%; min-width: 700px; border-collapse: collapse; table-layout: fixed; }
.context-transaction-table th, .context-transaction-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.context-transaction-table th { color: #fff; background: var(--accent-dark); font-size: 0.875rem; }
.context-transaction-table th:first-child { width: 100px; }
.context-transaction-table th:nth-child(2) { width: 200px; }
.context-transaction-table th:nth-child(4) { width: 120px; text-align: right; }
.context-transaction-table th:nth-child(5) { width: 100px; }
.context-transaction-table th:last-child { width: 130px; }
.context-transaction-table tr:last-child td { border-bottom: 0; }
.context-transaction-table td span { display: block; color: var(--muted); font-size: 0.8125rem; }
.pending-badge, .posted-badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.pending-badge { color: var(--amber); background: #fbeed4; }
.posted-badge { color: var(--muted); background: var(--surface-quiet); }

.transaction-dialog {
  width: min(1040px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 24px 80px rgb(15 31 35 / 28%);
}
.transaction-dialog::backdrop { background: rgb(16 31 34 / 52%); }
.dialog-header, .dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 18px; }
.dialog-header { border-bottom: 1px solid var(--line); }
.dialog-footer { border-top: 1px solid var(--line); color: var(--muted); }
.dialog-close {
  width: 42px;
  min-height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  background: var(--surface);
  font-size: 1.5rem;
  cursor: pointer;
}
.import-filters {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) repeat(2, minmax(145px, 0.65fr)) minmax(210px, 1.2fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px 18px;
  background: var(--surface-quiet);
  border-bottom: 1px solid var(--line);
}
.import-results-wrap { max-height: 470px; overflow: auto; }
.import-results-table { width: 100%; min-width: 760px; border-collapse: collapse; table-layout: fixed; }
.import-results-table th, .import-results-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.import-results-table th { position: sticky; top: 0; z-index: 1; color: #fff; background: var(--accent-dark); font-size: 0.875rem; }
.import-results-table th:first-child { width: 52px; text-align: center; }
.import-results-table th:nth-child(2) { width: 110px; }
.import-results-table th:nth-child(3) { width: 190px; }
.import-results-table th:last-child { width: 120px; text-align: right; }
.import-results-table td:first-child { text-align: center; }
.import-results-table td span { display: block; color: var(--muted); font-size: 0.8125rem; }
.import-results-table input[type="checkbox"] { width: 20px; min-height: 20px; accent-color: var(--accent); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.settings-panel { padding: 20px; }
.settings-account-list { display: grid; gap: 10px; margin-top: 14px; }
.settings-account-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.settings-account-row .toolbar-actions { flex-wrap: wrap; }
.settings-sync-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent-dark);
  background: var(--surface);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
}
.settings-sync-toggle input { width: 18px; min-height: 18px; margin: 0; accent-color: var(--accent); }
.settings-sync-toggle.is-disabled { color: var(--muted); background: var(--surface-quiet); cursor: not-allowed; }
.settings-subsection-heading { margin-top: 28px; }
.email-match-panel { display: grid; gap: 14px; margin-top: 14px; }
.email-match-status { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.email-match-business { max-width: 280px; }
.email-match-candidates { display: grid; gap: 10px; }
.email-match-candidates h3 { font-size: 1rem; }
.email-match-candidate {
  display: grid;
  gap: 8px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.email-match-guess { display: grid; gap: 2px; font-size: 0.875rem; }
.email-match-guess span:last-child { color: var(--muted); }
.connections-panel { overflow: hidden; }
.connections-panel summary { padding: 16px 18px; font-weight: 750; cursor: pointer; }
.connections-list { display: grid; border-top: 1px solid var(--line); }
.connection-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}
.connection-row:last-child { border-bottom: 0; }
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 0.8125rem;
  font-weight: 700;
}
.status-badge.error { color: var(--red); background: var(--red-soft); }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 15px;
  color: #fff;
  background: var(--accent-dark);
  border-radius: 6px;
  box-shadow: 0 12px 30px rgb(0 0 0 / 18%);
  z-index: 10;
}

@media (max-width: 980px) {
  .summary-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(3), .metric:nth-child(5) { border-left: 0; border-top: 1px solid var(--line); }
  .account-row, .account-row.non-credit { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .account-row { min-height: 0; }
  .account-name { grid-column: 1 / -1; }
  .account-controls { grid-column: 1 / -1; }
  .work-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .work-period-bar { align-items: stretch; flex-direction: column; padding-bottom: 10px; }
  .work-period-actions { align-self: flex-end; padding-bottom: 0; }
  .import-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .login-form { padding: 24px 20px; }
  .app-header { align-items: stretch; flex-direction: column; padding: 14px 16px; }
  .brand-block p { display: none; }
  .header-actions { justify-content: stretch; gap: 6px; }
  .header-actions .button { flex: 1 1 130px; min-height: 40px; padding: 0 10px; }
  .payment-band, .checking-band { padding: 18px 16px; }
  .home-title-filler { display: none; }
  .reminder-key { display: none; }
  .context-tabs { position: sticky; top: 0; z-index: 5; padding: 0 8px; }
  .context-tab { flex: 1; min-width: 0; }
  .app-main { width: calc(100vw - 20px); padding-top: 12px; }
  .context-overview, .work-panel { padding: 15px; }
  .section-heading { align-items: stretch; flex-direction: column; }
  .business-actions, .toolbar-actions { width: 100%; }
  .business-actions > *, .toolbar-actions > * { flex: 1; }
  .summary-metrics { grid-template-columns: 1fr 1fr; }
  .metric { padding: 12px; }
  .metric-value { font-size: 1.0625rem; }
  .account-row, .account-row.non-credit { grid-template-columns: 1fr; }
  .account-name { grid-column: auto; }
  .account-controls { grid-column: auto; }
  .payment-settings { grid-template-columns: 1fr; }
  .work-controls { grid-template-columns: 1fr; }
  .work-period-actions { align-self: stretch; }
  .import-filters { grid-template-columns: 1fr; }
  .dialog-footer { align-items: stretch; flex-direction: column; }
  .dialog-footer .toolbar-actions { width: 100%; }
  .dialog-footer .button { flex: 1; }
  .connection-row { align-items: flex-start; flex-direction: column; }
}
