:root {
  --chrome-bg: #1e2228;
  --chrome-bg-2: #242a31;
  --chrome-bg-3: #2b323a;
  --chrome-line: rgba(255, 255, 255, .09);
  --chrome-line-strong: rgba(255, 255, 255, .14);
  --chrome-text: #e9ecef;
  --chrome-muted: #a9b2bd;
  --accent: #7db7ff;
  --accent-rgb: 125,183,255;
  --accent-2: #9b7dff;
  --danger: #f07178;
  --good: #5ad6a0;
  --warn: #f7c66b;
  --sheet-bg: #ffffff;
  --sheet-text: #111827;
  --sheet-muted: #6b7280;
  --grid: #d4d8df;
  --grid-strong: #aeb6c2;
  --header-bg: #eef1f5;
  --header-text: #1f2937;
  --select: #3785c1;
  --select-soft: rgba(55, 133, 193, .11);
  --row-h: 25px;
  --font: Roboto, Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: #171a1f;
  color: var(--chrome-text);
  font-family: var(--font);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button,
input,
select,
textarea { font-family: var(--font); font-size: 13px; }
button,
select,
input[type="date"],
input[type="number"],
input[type="text"],
textarea {
  min-height: 25px;
  line-height: 20px;
  border: 1px solid var(--chrome-line-strong);
  border-radius: 4px;
  background: rgba(0, 0, 0, .22);
  color: var(--chrome-text);
  outline: none;
}
input[type="text"], input[type="number"], input[type="date"], select, textarea { padding: 2px 6px; }
button {
  padding: 2px 8px;
  cursor: pointer;
  background: rgba(0, 0, 0, .22);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.035);
}
button:hover,
button:focus-visible,
input:focus,
select:focus,
textarea:focus {
  border-color: rgba(var(--accent-rgb), .72);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), .16);
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  border-bottom: 1px solid rgba(0,0,0,.58);
  background: var(--chrome-bg);
  box-shadow: 0 4px 5px rgba(0,0,0,.14), 0 1px 10px rgba(0,0,0,.12);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand-line {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .1px;
  color: #f2f5f8;
}
.app-version {
  display: inline-block;
  font-size: 11px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: .15px;
  color: var(--chrome-muted);
}
.topbar-controls,
.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.field-inline { display: inline-flex; align-items: center; gap: 5px; color: var(--chrome-muted); font-size: 12px; }
.field-inline input { height: 25px; width: 130px; }
.toolbar {
  padding: 5px 10px;
  border-bottom: 1px solid rgba(0,0,0,.56);
  background: var(--chrome-bg-2);
  position: sticky;
  top: 40px;
  z-index: 25;
}
.toolbar button { height: 24px; min-height: 24px; padding: 2px 7px; }
.toolbar-sep { width: 1px; height: 21px; background: var(--chrome-line-strong); margin: 0 2px; }
.toolbar-picker { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--chrome-muted); }
.toolbar-picker input[type="color"] { width: 28px; height: 23px; padding: 1px; background: rgba(0,0,0,.18); }
.formula-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 360px;
  min-width: 230px;
  color: var(--chrome-muted);
}
.formula-wrap span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--chrome-line);
  border-radius: 4px;
  background: rgba(0,0,0,.18);
  font-style: italic;
  color: var(--accent);
}
#formulaBar {
  flex: 1 1 auto;
  height: 25px;
  min-width: 180px;
  background: #fff;
  color: #111827;
  border-color: #9da7b3;
  line-height: 20px;
}
#formulaBar:disabled { background: #e8ebef; color: #818891; }
.selected-hint { color: var(--chrome-muted); font-size: 12px; white-space: nowrap; }

.sheet-wrap {
  flex: 1;
  overflow: auto;
  padding: 0;
  background: #ffffff;
}
.treasury-sheet {
  font-family: var(--font);
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--sheet-bg);
  color: var(--sheet-text);
  min-width: 0;
  width: max-content;
  box-shadow: none;
}
.treasury-sheet th,
.treasury-sheet td {
  border: 1px solid var(--grid);
  height: var(--row-h);
  min-height: var(--row-h);
  padding: 2px 5px;
  vertical-align: middle;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  background: #fff;
  color: #111827;
}
.treasury-sheet th {
  position: sticky;
  top: 0;
  z-index: 8;
  background: var(--header-bg);
  color: var(--header-text);
  font-weight: 600;
  text-align: center;
  user-select: none;
}
.treasury-sheet th[data-column] { position: sticky; }
.column-letter {
  display: block;
  font-size: 10px;
  line-height: 11px;
  color: #64748b;
  font-weight: 700;
}
.column-title {
  display: block;
  font-size: 11px;
  line-height: 13px;
  color: var(--header-text);
  overflow: hidden;
  text-overflow: ellipsis;
}
.corner-header { background: #e2e8f0; }
.row-header-cell {
  text-align: center;
  background: #f1f5f9;
  color: #64748b;
  font-size: 11px;
  user-select: none;
}
.col-resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
}
.col-resize-handle:hover { background: rgba(55,133,193,.25); }
.is-resizing-column { cursor: col-resize; user-select: none; }

.col-row-header { width: 38px; text-align: center; background: #eef1f5; color: #475569; }
.col-date { width: 84px; text-align: center; }
.col-color { width: 10px; padding: 0; min-width: 10px; max-width: 18px; }
.col-item-name { width: 215px; }
.col-amount { width: 64px; text-align: right; }
.col-running-total { width: 76px; text-align: right; }
.col-gap { width: 18px; background: #fff; }
.col-tracker { width: 150px; }
.col-note-1, .col-note-2, .col-note-3, .col-note-4, .col-note-5 { width: 190px; }

.treasury-sheet td { cursor: crosshair; }
.treasury-sheet td.cell-editable { cursor: crosshair; }
.treasury-sheet td:focus { outline: none; }
.cell-selected {
  position: relative;
  box-shadow: inset 0 0 0 2px var(--select);
  z-index: 3;
}
.cell-selected::after {
  display: none;
}

.row-selected td {
  box-shadow: inset 0 1px 0 rgba(55, 133, 193, .22), inset 0 -1px 0 rgba(55, 133, 193, .22);
}
.row-selected .row-header-cell {
  background: #dbeafe;
  color: #1e3a8a;
}
.color-cell { cursor: pointer; }
.color-swatch { display: block; width: 100%; height: calc(var(--row-h) - 1px); border-radius: 0; }
.amount-cell, .running-cell { text-align: right; font-variant-numeric: tabular-nums; }
.amount-negative { color: #b42318; }
.amount-positive { color: #087443; }
.gap-cell { background: #fff; cursor: crosshair; }
.tracker-empty { color: transparent; }
.tracker-pill { color: #334155; }
.tracker-pill strong { color: #0f172a; }
.date-past { text-decoration: line-through; color: #6b7280; }
.date-repeat-hidden { color: transparent; text-decoration: none; }
.row-weekly-pay td { font-weight: 700; background: #f5f7fb; }
.row-recurring td { background: #fbfdff; }
.row-net-total td {
  background: #f1f5f9;
  font-weight: 700;
  border-top: 2px solid var(--grid-strong);
}
.net-extra-label { text-align: right; color: #1f2937; }
.week-spacer td {
  height: 14px;
  min-height: 14px;
  background: #ffffff;
  border: 0;
  padding: 0;
}
.loading-cell { text-align: center; color: #4b5563; padding: 22px; }

.context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 220px;
  padding: 5px;
  background: #252b33;
  border: 1px solid var(--chrome-line-strong);
  border-radius: 7px;
  box-shadow: 0 12px 30px rgba(0,0,0,.38);
}
.context-menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  box-shadow: none;
  border-radius: 4px;
  color: var(--chrome-text);
  min-height: 24px;
  padding: 4px 9px;
  white-space: nowrap;
}
.context-menu kbd {
  font: inherit;
  font-size: 10px;
  color: var(--chrome-muted);
  background: transparent;
  border: 0;
  padding: 0;
  margin-left: auto;
}
.context-right { display: inline-flex; align-items: center; gap: 10px; margin-left: auto; }
.context-menu button:hover,
.context-submenu:hover > .context-submenu-label { background: rgba(var(--accent-rgb), .16); }
.context-menu button:disabled { opacity: .42; cursor: default; }
.context-menu button:disabled:hover { background: transparent; }
.context-menu hr { border: 0; border-top: 1px solid var(--chrome-line); margin: 4px 0; }
.context-submenu { position: relative; }
.context-submenu-label { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.context-submenu-panel {
  display: none;
  position: absolute;
  left: calc(100% + 4px);
  top: -5px;
  min-width: 230px;
  padding: 5px;
  background: #252b33;
  border: 1px solid var(--chrome-line-strong);
  border-radius: 7px;
  box-shadow: 0 12px 30px rgba(0,0,0,.38);
}
.context-submenu:hover > .context-submenu-panel,
.context-submenu:focus-within > .context-submenu-panel { display: block; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  z-index: 1200;
  background: #111827;
  color: #fff;
  border: 1px solid var(--chrome-line-strong);
  border-radius: 7px;
  padding: 8px 12px;
  box-shadow: 0 10px 22px rgba(0,0,0,.32);
  transition: .16s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.panel-dialog {
  width: min(980px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  border: 1px solid var(--chrome-line-strong);
  border-radius: 10px;
  padding: 0;
  background: #222830;
  color: var(--chrome-text);
  box-shadow: 0 18px 60px rgba(0,0,0,.55);
}
.panel-dialog::backdrop { background: transparent; backdrop-filter: none; }
.dialog-shell { margin: 0; display: flex; flex-direction: column; max-height: calc(100vh - 28px); }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 11px;
  background: #1f242b;
  border-bottom: 1px solid var(--chrome-line);
  cursor: move;
  user-select: none;
}
.dialog-head button { min-width: 28px; font-size: 18px; line-height: 18px; }
.dialog-grid {
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(300px, 1.1fr);
  gap: 12px;
  padding: 11px;
  overflow: auto;
}
.dialog-grid section {
  background: rgba(0,0,0,.18);
  border: 1px solid var(--chrome-line);
  border-radius: 8px;
  padding: 10px;
}
.dialog-grid h3 { margin: 0 0 8px; font-size: 13px; color: #f4f6f8; }
.dialog-grid label { display: grid; gap: 3px; margin-bottom: 7px; color: var(--chrome-muted); font-size: 12px; }
.dialog-grid input, .dialog-grid select, .dialog-grid textarea { width: 100%; }
.dialog-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.compact-dialog-shell .dialog-grid { grid-template-columns: minmax(430px, 1fr) minmax(260px, .7fr); }
.compact-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(105px, 1fr));
  gap: 6px 8px;
}
.compact-form-grid .wide { grid-column: span 3; }
.check-row { display: flex; grid-template-columns: none; align-items: center; gap: 6px; }
.check-row input { width: auto; }
.hint-line { display: block; color: var(--chrome-muted); margin: 6px 0; line-height: 1.25; }
.simple-list { display: grid; gap: 6px; max-height: 370px; overflow: auto; }
.list-card {
  border: 1px solid var(--chrome-line);
  border-radius: 7px;
  padding: 7px;
  background: rgba(0,0,0,.19);
  cursor: pointer;
}
.list-card:hover { border-color: rgba(var(--accent-rgb), .45); background: rgba(var(--accent-rgb), .09); }
.list-card strong { display: block; color: #fff; }
.list-card small { display: block; color: var(--chrome-muted); margin-top: 2px; }
.link-box { margin-top: 10px; display: grid; gap: 7px; }
.link-box p { margin: 0; color: var(--chrome-muted); }

.color-popup-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}
.color-popup {
  width: 250px;
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 9px;
  border: 1px solid var(--chrome-line-strong);
  background: #242a31;
  color: var(--chrome-text);
  box-shadow: 0 16px 46px rgba(0,0,0,.48);
}
.color-popup input[type="color"] { width: 100%; height: 42px; padding: 2px; }
.color-popup-actions { display: flex; gap: 6px; justify-content: flex-end; }

.color-popup-rich { width: 330px; }
.color-popup-title { display: grid; gap: 2px; cursor: move; user-select: none; }
.color-popup-title small { color: var(--chrome-muted); font-size: 11px; }
.color-preview-row {
  display: grid;
  grid-template-columns: 34px 1fr 44px;
  gap: 7px;
  align-items: center;
}
.color-preview {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  border: 1px solid var(--chrome-line-strong);
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.color-preview-row input[data-color-hex] {
  height: 30px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-transform: lowercase;
}
.color-preview-row input[data-color-native] {
  width: 44px;
  height: 30px;
  padding: 1px;
}
.color-preview-row input.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(240,113,120,.16); }
.color-swatch-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 5px;
}
.preset-swatch {
  min-height: 24px;
  height: 24px;
  padding: 0;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,.2);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.15), 0 1px 2px rgba(0,0,0,.22);
  background: var(--swatch-color, transparent);
}
.preset-swatch:hover { transform: translateY(-1px); border-color: rgba(255,255,255,.55); }
.color-action-spacer { flex: 1; }



.compact-bill-dialog {
  width: min(820px, calc(100vw - 28px));
}
.compact-bill-dialog .dialog-head { padding: 7px 9px; }
.compact-bill-dialog .dialog-grid {
  grid-template-columns: minmax(430px, 1fr) minmax(250px, .62fr);
  gap: 8px;
  padding: 8px;
}
.compact-bill-dialog .dialog-grid section { padding: 8px; }
.compact-bill-dialog .dialog-grid h3 { margin-bottom: 5px; }
.bill-form-grid {
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 5px 7px;
}
.bill-form-grid label { margin-bottom: 0; }
.bill-form-grid label:has(#billName),
.bill-form-grid label:has(#billNotes) { grid-column: span 3; }
.compact-bill-dialog textarea { min-height: 48px; }
.compact-bill-dialog .simple-list { max-height: 270px; }

@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .toolbar { top: 82px; }
  .dialog-grid, .compact-dialog-shell .dialog-grid { grid-template-columns: 1fr; }
  .compact-form-grid { grid-template-columns: 1fr 1fr; }
  .compact-form-grid .wide { grid-column: span 2; }
}

.treasury-sheet td.col-date {
  border-top-color: transparent;
  border-bottom-color: transparent;
}

.net-extra-label {
  font-weight: 400;
  font-style: italic;
}

.toolbar button.is-active {
  border-color: rgba(var(--accent-rgb), .9);
  background: rgba(var(--accent-rgb), .22);
  color: #fff;
}
.note-header-menu {
  position: fixed;
}
.row-transposed td {
  color: #64748b;
  text-decoration: line-through;
  background: #f3f4f6;
}


/* v0.15 interaction/layout refinements */
.app-shell { padding-left: 10px; padding-right: 10px; box-sizing: border-box; }
.sheet-wrap { margin-left: 0; margin-right: 0; overflow-x: auto; overflow-y: auto; background: #fff; max-width: 100%; }
.treasury-sheet { table-layout: fixed; min-width: max-content; }
.treasury-sheet thead th { height: 32px; }
.column-letter { display: block; line-height: 14px; font-size: 11px; opacity: .82; }
.column-title { display: block; line-height: 15px; font-size: 11px; }
.toolbar .icon-btn { width: 28px; min-width: 28px; padding: 2px 0; display: inline-flex; align-items: center; justify-content: center; }
.toolbar .icon-btn .fa { font-size: 13px; }
.toolbar .icon-picker { min-width: auto; }
.toolbar select { max-width: 82px; }
.row-selected td { background: #dbeafe; box-shadow: inset 0 1px 0 #60a5fa, inset 0 -1px 0 #60a5fa; }
.row-selected .row-header-cell { background: #93c5fd; color: #0f172a; font-weight: 700; }
.cell-selected { background: inherit; outline: 2px solid #1d4ed8; outline-offset: -2px; box-shadow: inset 0 0 0 1px #ffffff; }
.col-amount, .col-running-total, .amount-cell, .running-cell { text-align: center; }
.amount-negative { color: #b42318; }
.amount-positive { color: #087443; }
.treasury-sheet th.col-gap { background: var(--header-bg); color: var(--header-text); }
.treasury-sheet td.col-gap, .gap-cell { background: #fff; }
.running-reset-cell { font-weight: 700; background: #fff7ed; }
.tracker-cell { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tracker-pill { color: #334155; }
.net-extra-label { font-style: italic; font-weight: 400; }


/* v0.16 spreadsheet interaction refinements */
.app-shell { padding-left: 10px; padding-right: 10px; }
.sheet-wrap {
  width: calc(100vw - 20px);
  max-width: calc(100vw - 20px);
  overflow-x: scroll;
  overflow-y: auto;
  scrollbar-gutter: stable both-edges;
  border-left: 1px solid var(--grid);
  border-right: 1px solid var(--grid);
}
.column-letter {
  min-height: 17px;
  line-height: 15px;
  padding-bottom: 3px;
  margin-bottom: 4px;
  border-bottom: 4px solid #fff;
}
.treasury-sheet thead th { height: 38px; }
.column-title { line-height: 14px; }
.row-selected td {
  background-color: inherit;
  box-shadow: inset 0 0 0 9999px rgba(37, 99, 235, .18), inset 2px 0 0 #2563eb, inset -2px 0 0 #2563eb;
}
.row-selected .row-header-cell {
  background: #93c5fd;
  color: #0f172a;
  font-weight: 800;
}
.row-select-start td { border-top: 2px solid #2563eb; }
.row-select-end td { border-bottom: 2px solid #2563eb; }
.row-select-middle td { border-top-color: var(--grid); border-bottom-color: var(--grid); }
.row-select-end td:last-child { position: relative; }
.row-select-end td:last-child::after {
  content: '⠿';
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2563eb;
  color: #fff;
  font-size: 10px;
  border-radius: 3px 0 0 0;
  cursor: move;
  z-index: 5;
}
.cell-selected {
  background-color: inherit;
  outline: 2px solid #1d4ed8;
  outline-offset: -2px;
  box-shadow: inset 0 0 0 1px #ffffff;
}
.move-handle-cell,
.gap-cell { cursor: move; text-align: center; color: #64748b; }
.move-handle-cell::before { content: '⋮⋮'; font-size: 12px; letter-spacing: -2px; opacity: .75; }
.row-drop-target td { outline: 2px dashed #f59e0b; outline-offset: -2px; }
body.is-drag-selecting .treasury-sheet td { cursor: cell; }
body.is-formula-picking .treasury-sheet td { cursor: crosshair; }
body.is-row-moving .treasury-sheet td { cursor: move; }
.toolbar-popup-wrap { position: relative; display: inline-flex; }
.format-popup {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  z-index: 500;
  min-width: 118px;
  padding: 6px;
  background: #252b33;
  border: 1px solid var(--chrome-line-strong);
  border-radius: 7px;
  box-shadow: 0 12px 30px rgba(0,0,0,.38);
  display: flex;
  gap: 5px;
}
.format-popup[hidden] { display: none; }
.format-popup button { min-width: 28px; height: 26px; padding: 2px 6px; }
.border-popup { width: 275px; display: grid; gap: 7px; }
.border-side-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.border-side-grid label { display: grid; grid-template-columns: 44px 42px 1fr; gap: 4px; align-items: center; color: var(--chrome-muted); font-size: 11px; }
.border-side-grid input { width: 42px; min-height: 24px; }
.border-side-grid select { min-height: 24px; }
.border-color-row { display: grid; grid-template-columns: 44px 1fr; gap: 6px; align-items: center; color: var(--chrome-muted); font-size: 11px; }
.border-color-row input { width: 100%; min-height: 26px; }
.popup-actions { display: flex; justify-content: flex-end; gap: 6px; }
[data-bill-field][hidden] { display: none; }
.context-menu.range-context::before {
  content: 'Selected range';
  display: block;
  padding: 4px 7px 5px;
  color: var(--chrome-muted);
  font-size: 11px;
  border-bottom: 1px solid var(--chrome-line);
  margin-bottom: 4px;
}

/* v0.17: Negative/positive amounts must not alter cell fill colors. */
.amount-negative,
.amount-positive,
.amount-cell.amount-negative,
.amount-cell.amount-positive,
.running-cell.amount-negative,
.running-cell.amount-positive {
  background-color: transparent;
}
.row-selected .amount-negative,
.row-selected .amount-positive {
  background-color: #dbeafe;
}


/* v0.18 redo: do not auto-style amount/running cells by positive/negative value at all. */
.treasury-sheet td.amount-cell,
.treasury-sheet td.running-cell {
  background-image: none;
}
.treasury-sheet td.amount-cell.amount-negative,
.treasury-sheet td.amount-cell.amount-positive,
.treasury-sheet td.running-cell.amount-negative,
.treasury-sheet td.running-cell.amount-positive {
  background: inherit;
  background-color: inherit;
}
.treasury-sheet tr:not(.row-selected) td.amount-cell.amount-negative,
.treasury-sheet tr:not(.row-selected) td.amount-cell.amount-positive,
.treasury-sheet tr:not(.row-selected) td.running-cell.amount-negative,
.treasury-sheet tr:not(.row-selected) td.running-cell.amount-positive {
  background: #ffffff;
  background-color: #ffffff;
}


/* v0.20 startup/layout/formula fixes */
.toolbar {
  align-items: center;
}
.formula-wrap {
  order: -10;
  flex: 0 0 100%;
  width: 100%;
  min-width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
}
.fx-menu-wrap { position: relative; display: inline-flex; }
.fx-button {
  width: 34px;
  min-width: 34px;
  height: 25px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.fx-symbol { font-style: italic; font-weight: 700; color: var(--accent); letter-spacing: -.5px; }
.fx-menu {
  min-width: 150px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.fx-menu[hidden] { display: none; }
.fx-menu button { text-align: left; justify-content: flex-start; width: 100%; }
#formulaBar { width: 100%; min-width: 0; }
.sheet-wrap {
  width: calc(100vw - 30px);
  max-width: calc(100vw - 30px);
  padding: 5px;
  margin: 0;
  overflow-x: scroll;
  overflow-y: auto;
  background: #fff;
}
.treasury-sheet { margin: 0; }
.treasury-sheet thead th {
  position: sticky;
  z-index: 12;
}
.treasury-sheet thead tr.column-letter-row th {
  top: 0;
  height: 18px;
  min-height: 18px;
  padding: 1px 4px;
  font-size: 10px;
  line-height: 14px;
}
.treasury-sheet thead tr.header-separator-row th {
  top: 18px;
  height: 7px;
  min-height: 7px;
  padding: 0;
  background: #fff;
  border-left: 1px solid var(--grid);
  border-right: 1px solid var(--grid);
  border-top: 0;
  border-bottom: 0;
}
.treasury-sheet thead tr.column-title-row th {
  top: 25px;
  height: 24px;
  min-height: 24px;
  padding: 2px 5px;
}
.column-letter, .column-title {
  margin: 0;
  padding: 0;
  border: 0;
  min-height: 0;
}
/* Remove row-only selection fill and prevent amount/running value from changing fills. */
.row-selected td,
.row-selected .row-header-cell {
  background-color: inherit;
  box-shadow: none;
}
.treasury-sheet td.amount-cell,
.treasury-sheet td.running-cell,
.treasury-sheet td.amount-cell.amount-negative,
.treasury-sheet td.amount-cell.amount-positive,
.treasury-sheet td.running-cell.amount-negative,
.treasury-sheet td.running-cell.amount-positive,
.treasury-sheet tr.row-weekly-pay td.amount-cell,
.treasury-sheet tr.row-weekly-pay td.running-cell,
.treasury-sheet tr.row-recurring td.amount-cell,
.treasury-sheet tr.row-recurring td.running-cell,
.treasury-sheet tr.row-net-total td.amount-cell,
.treasury-sheet tr.row-net-total td.running-cell {
  background: #ffffff;
  background-color: #ffffff;
  background-image: none;
}
.treasury-sheet tr.row-net-total td.col-date,
.treasury-sheet tr.row-net-total td.date-repeat-hidden {
  background: #ffffff;
  background-color: #ffffff;
}

.topbar-icon-btn { min-width: 30px; height: 26px; padding: 2px 8px; }
.settings-dialog { width: min(560px, calc(100vw - 28px)); }
.settings-grid { grid-template-columns: 1fr; }
.settings-section { max-width: none; }
.settings-note { margin: 0 0 9px; color: var(--chrome-muted); font-size: 12px; line-height: 1.35; }
.settings-note code { color: #f2f5f8; background: rgba(0,0,0,.28); border: 1px solid var(--chrome-line); border-radius: 4px; padding: 1px 4px; }
.danger-btn { background: linear-gradient(180deg, rgba(211,74,74,.42), rgba(136,35,35,.56)); border-color: rgba(255,118,118,.52); color: #ffecec; }
.danger-btn:not(:disabled):hover { background: linear-gradient(180deg, rgba(226,86,86,.56), rgba(151,40,40,.68)); }
.danger-btn:disabled { opacity: .42; cursor: not-allowed; }

/* v0.23 selection/background stabilization */
.sheet-wrap {
  position: relative;
}
.treasury-sheet tr.row-selected td,
.treasury-sheet tr.row-selected .row-header-cell,
.treasury-sheet tr.row-select-start td,
.treasury-sheet tr.row-select-middle td,
.treasury-sheet tr.row-select-end td {
  background-color: inherit;
  box-shadow: none;
  border-top-width: 1px;
  border-bottom-width: 1px;
  border-top-color: var(--grid);
  border-bottom-color: var(--grid);
}
.treasury-sheet td.cell-selected {
  outline: 0;
  outline-offset: 0;
  box-shadow: none;
  position: relative;
  z-index: 2;
}
.treasury-sheet td.range-selected-fill {
  background-image: linear-gradient(rgba(37, 99, 235, .13), rgba(37, 99, 235, .13));
  cursor: cell;
}
body.is-drag-selecting .treasury-sheet td.range-selected-fill {
  background-image: linear-gradient(rgba(37, 99, 235, .22), rgba(37, 99, 235, .22));
}
.mt-selection-overlay {
  position: absolute;
  border: 2px solid #2563eb;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 30;
  box-shadow: 0 0 0 1px rgba(255,255,255,.92), 0 0 0 3px rgba(37,99,235,.12);
}
.mt-selection-overlay[hidden] { display: none; }
.mt-selection-handle {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 8px;
  height: 8px;
  background: #2563eb;
  border: 1px solid #fff;
  border-radius: 2px;
  box-sizing: border-box;
}
.row-select-end td:last-child::after { display: none; }
.treasury-sheet tr.row-weekly-pay td.col-date,
.treasury-sheet tr.row-weekly-pay td.col-note-1,
.treasury-sheet tr.row-net-total td.col-date,
.treasury-sheet tr.row-net-total td.col-note-1,
.treasury-sheet tr.row-net-total td.col-note-2,
.treasury-sheet tr.row-net-total td.col-note-3,
.treasury-sheet tr.row-net-total td.col-note-4,
.treasury-sheet tr.row-net-total td.col-note-5 {
  background: #ffffff;
  background-color: #ffffff;
  background-image: none;
}
.treasury-sheet td.amount-cell,
.treasury-sheet td.running-cell,
.treasury-sheet td.amount-cell.amount-negative,
.treasury-sheet td.amount-cell.amount-positive,
.treasury-sheet td.running-cell.amount-negative,
.treasury-sheet td.running-cell.amount-positive {
  background: #ffffff;
  background-color: #ffffff;
  background-image: none;
}
.move-handle-cell::before {
  letter-spacing: -1px;
}

/* v0.24 sheet left-spacing fix */
.sheet-wrap {
  scrollbar-gutter: auto;
  padding: 5px;
}
.treasury-sheet {
  margin-left: 0;
  margin-right: 0;
}

/* v0.27 header/version and selection handle cleanup */
.brand-line { display: inline-flex; align-items: baseline; gap: 8px; }
.brand-line .brand-title { font-size: 20px; font-weight: 700; }
.brand-line .app-version { font-size: 11px; font-weight: 400; line-height: 1; opacity: .8; }
.treasury-sheet td.cell-selected::after { display: none; content: none; }
.treasury-sheet thead tr.column-letter-row th { position: sticky; }
.treasury-sheet thead tr.column-title-row .col-resize-handle { display: none; }
.treasury-sheet thead tr.column-letter-row .col-resize-handle { display: block; }

/* v0.28: keep app version inline beside the Treasury title */
.brand-block {
  display: flex;
  align-items: baseline;
  min-width: max-content;
}
.brand-line {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  flex-wrap: nowrap;
  gap: 7px;
  white-space: nowrap;
}
.brand-line .brand-title {
  display: inline-block;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
}
.brand-line .app-version {
  display: inline-block;
  align-self: baseline;
  font-size: 11px;
  font-weight: 400;
  line-height: 1;
  opacity: .75;
  margin-left: 0;
}

.row-drop-target-before td { box-shadow: inset 0 2px 0 rgba(var(--accent-rgb), .95); }
.row-drop-target-after td { box-shadow: inset 0 -2px 0 rgba(var(--accent-rgb), .95); }
.panel-dialog.is-dragging-popup, .color-popup.is-dragging-popup { opacity: .98; }

/* v0.39 row-entry selection/move cleanup */
.treasury-sheet td.row-header-cell {
  cursor: pointer;
  user-select: none;
}
.treasury-sheet tr.row-selected td.row-header-cell,
.treasury-sheet tr.row-selected td.row-header-cell:hover {
  cursor: move;
}
.treasury-sheet tr.row-cut-pending td {
  opacity: .48;
  filter: grayscale(.15);
}
.treasury-sheet tr.row-cut-pending td.row-header-cell::after {
  content: "cut";
  display: block;
  font-size: 8px;
  line-height: 1;
  opacity: .8;
}
.context-menu button:disabled,
.context-menu .context-submenu:has(button:disabled) > .context-submenu-label {
  opacity: .42;
  cursor: default;
}

/* v0.41 paste/selection/color polish */
.treasury-sheet thead tr.header-separator-row th {
  border-left-color: transparent;
  border-right-color: transparent;
  border-left-width: 0;
  border-right-width: 0;
}
.treasury-sheet tr.row-selected td {
  background-image: linear-gradient(rgba(37, 99, 235, .10), rgba(37, 99, 235, .10));
  box-shadow: none;
  border-top-color: var(--grid);
  border-bottom-color: var(--grid);
}
.treasury-sheet tr.row-selected td.col-date {
  border-top-color: var(--grid);
  border-bottom-color: var(--grid);
}
.treasury-sheet tr.row-selected td.row-header-cell {
  background-color: #dbeafe;
  background-image: linear-gradient(rgba(37, 99, 235, .18), rgba(37, 99, 235, .18));
  color: #1e3a8a;
  font-weight: 700;
}
.treasury-sheet td.range-selected-fill {
  background-color: inherit;
  background-image: linear-gradient(rgba(37, 99, 235, .16), rgba(37, 99, 235, .16));
  background-blend-mode: multiply;
}
.treasury-sheet td.cell-selected {
  background-color: inherit;
  background-image: inherit;
}
.move-handle-cell::before { font-size: 10px; letter-spacing: -1px; opacity: .55; }
.treasury-sheet td { cursor: default; }
.treasury-sheet td.cell-editable, body.is-drag-selecting .treasury-sheet td { cursor: cell; }
.treasury-sheet td.row-header-cell { cursor: pointer; }
.treasury-sheet tr.row-selected td.row-header-cell:hover { cursor: move; }
.align-icon {
  display: inline-grid;
  gap: 2px;
  width: 16px;
  height: 14px;
  align-content: center;
}
.align-icon::before,
.align-icon::after,
.align-icon span {
  content: '';
  display: block;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}
.align-icon::before { width: 14px; }
.align-icon::after { width: 10px; }
.align-icon-left { justify-items: start; }
.align-icon-center { justify-items: center; }
.align-icon-right { justify-items: end; }
.submenu-sep {
  border: 0;
  border-top: 1px solid var(--chrome-line);
  margin: 4px 0;
}
.color-popup-backdrop { background: transparent; backdrop-filter: none; }
.color-popup-rich { width: min(360px, calc(100vw - 24px)); }
.color-popup-title { cursor: move; }
.color-preview-row,
.color-option-row {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  align-items: center;
  gap: 7px;
}
.color-option-row { grid-template-columns: 1fr 1fr; margin-top: 7px; }
.color-preview-row label,
.color-option-row label {
  display: grid;
  gap: 3px;
  color: var(--chrome-muted);
  font-size: 11px;
}
.color-preview { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--chrome-line-strong); }
.color-group-label { margin: 9px 0 4px; color: var(--chrome-muted); font-size: 11px; }
.existing-entry-colors { min-height: 24px; }
.color-empty-note { color: var(--chrome-muted); font-size: 11px; padding: 4px; }
.color-popup-actions [data-color-ok] { font-weight: 700; }

/* v0.42 terminology, selection color, cursor, and picker cleanup */
:root {
  --accent: #0b7cff;
  --accent-rgb: 11, 124, 255;
  --select: #0b7cff;
  --select-soft: rgba(11, 124, 255, .18);
  --header-bg: #d9ebff;
  --header-text: #0b2545;
}
.treasury-sheet thead th,
.treasury-sheet .col-row-header,
.treasury-sheet td.row-header-cell {
  background-color: #d9ebff;
  color: #0b2545;
}
.treasury-sheet td.range-selected-fill {
  background-image: linear-gradient(rgba(0, 112, 255, .22), rgba(0, 112, 255, .22));
  background-blend-mode: multiply;
}
.mt-selection-overlay {
  border-color: #006eff;
  box-shadow: 0 0 0 1px rgba(255,255,255,.95), 0 0 0 3px rgba(0,112,255,.18);
}
.mt-selection-handle { background: #006eff; }
.treasury-sheet tr.row-selected td {
  background-image: linear-gradient(rgba(0, 112, 255, .14), rgba(0, 112, 255, .14));
  box-shadow: none;
}
.treasury-sheet tr.row-selected td.row-header-cell {
  background-color: #8cc8ff;
  background-image: linear-gradient(rgba(0, 112, 255, .18), rgba(0, 112, 255, .18));
}
/* Keep cursor icons normal-sized and restore the F/gap move affordance. */
.move-handle-cell,
.gap-cell,
.treasury-sheet tr.row-selected td.row-header-cell:hover,
body.is-row-moving .treasury-sheet td {
  cursor: move;
}
.move-handle-cell::before {
  content: '⋮⋮';
  display: inline-block;
  font-size: 9px;
  line-height: 9px;
  letter-spacing: -2px;
  transform: scale(.78);
  opacity: .72;
}
.treasury-sheet td { cursor: default; }
.treasury-sheet td.cell-editable, body.is-drag-selecting .treasury-sheet td { cursor: cell; }
.treasury-sheet td.row-header-cell { cursor: pointer; }
.context-submenu-panel button[data-context-command="clear-entries"] span::before { content: ''; }
.color-picker-popup { width: min(460px, calc(100vw - 24px)); }
.color-picker-main { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 8px; align-items: center; }
.color-picker-grid { display: grid; grid-template-columns: repeat(4, minmax(62px, 1fr)); gap: 7px; }
.color-picker-popup label { display: grid; gap: 3px; color: var(--chrome-muted); font-size: 11px; }
.color-picker-popup input[type="number"] { width: 100%; min-width: 0; }
.color-picker-popup input[type="color"] { height: 30px; }
.color-popup-rich .color-preview-row { grid-template-columns: 34px 1fr 1fr; }
.color-popup-rich .color-option-row { display: none; }
.color-popup-title small { display: none; }
.color-swatch { background-color: #ffffff; }

/* v0.42 final interaction overrides */
.treasury-sheet td.move-handle-cell,
.treasury-sheet td.gap-cell,
.treasury-sheet tr.row-selected td.row-header-cell:hover,
body.is-row-moving .treasury-sheet td {
  cursor: move;
}
.treasury-sheet td.move-handle-cell::before,
.treasury-sheet td.gap-cell::before {
  content: '⋮⋮';
  display: inline-block;
  width: 10px;
  height: 12px;
  font-size: 9px;
  line-height: 10px;
  letter-spacing: -2px;
  transform: scale(.72);
  transform-origin: center;
  opacity: .7;
}
.align-icon {
  position: relative;
  display: inline-block;
  width: 16px;
  height: 14px;
  background: none;
}
.align-icon::before,
.align-icon::after { content: none; }
.align-icon-left {
  background-image: linear-gradient(currentColor,currentColor),linear-gradient(currentColor,currentColor),linear-gradient(currentColor,currentColor);
  background-size: 15px 2px, 10px 2px, 13px 2px;
  background-position: 0 2px, 0 6px, 0 10px;
  background-repeat: no-repeat;
}
.align-icon-center {
  background-image: linear-gradient(currentColor,currentColor),linear-gradient(currentColor,currentColor),linear-gradient(currentColor,currentColor);
  background-size: 15px 2px, 10px 2px, 13px 2px;
  background-position: center 2px, center 6px, center 10px;
  background-repeat: no-repeat;
}
.align-icon-right {
  background-image: linear-gradient(currentColor,currentColor),linear-gradient(currentColor,currentColor),linear-gradient(currentColor,currentColor);
  background-size: 15px 2px, 10px 2px, 13px 2px;
  background-position: right 2px, right 6px, right 10px;
  background-repeat: no-repeat;
}

/* Performance, row clipboard, and entry popup maintenance fixes */
.color-picker-button {
  width: auto;
  min-width: 0;
  display: inline-grid;
  grid-template-columns: auto 9px;
  gap: 3px;
  align-items: center;
  padding-inline: 5px;
}
.color-picker-button .color-chip {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  border: 1px solid rgba(15,23,42,.35);
  display: inline-block;
}
#fxMenuToggle.fx-button {
  width: auto;
  min-width: 0;
  flex: 0 0 auto;
  padding-left: 0;
  padding-right: 0;
}
#fxMenuToggle .fx-symbol { display: inline-block; width: auto; }
.custom-color-picker-popup { width: min(440px, calc(100vw - 24px)); }
.custom-picker-top { display: grid; grid-template-columns: 46px 1fr; gap: 10px; align-items: center; }
.custom-color-preview { width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); box-shadow: inset 0 0 0 1px rgba(255,255,255,.5); }
.custom-gradient-field {
  position: relative;
  height: 150px;
  border-radius: 12px;
  border: 1px solid var(--line);
  overflow: hidden;
  cursor: crosshair;
}
.custom-gradient-field [data-gradient-thumb] {
  position: absolute;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  margin-top: -6px;
  border-radius: 999px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(15,23,42,.8);
  pointer-events: none;
}
.color-slider-row label { display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 8px; }
.color-slider-row input[type="range"] { width: 100%; }
.color-picker-popup input[type="color"] { display: none; }
.context-submenu.is-disabled-submenu > .context-submenu-panel { display: none; }
.context-submenu.is-disabled-submenu > .context-submenu-label { opacity: .42; cursor: default; }
.treasury-sheet td.move-handle-cell::before,
.treasury-sheet td.gap-cell::before {
  width: 6px;
  height: 9px;
  font-size: 7px;
  line-height: 7px;
  letter-spacing: -2px;
  transform: scale(.55);
}
.treasury-sheet td.move-handle-cell,
.treasury-sheet td.gap-cell { cursor: move; }

.entries-list-dialog { width: min(650px, calc(100vw - 28px)); }
.entries-list-grid { grid-template-columns: 1fr; }
.entry-list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.entry-list-head h3 { margin: 0; }
.entry-settings-dialog { width: min(760px, calc(100vw - 28px)); }
.entry-settings-form { padding: 11px; overflow: auto; }
.entry-settings-section { background: rgba(0,0,0,.18); border: 1px solid var(--chrome-line); border-radius: 8px; padding: 10px; }
.entry-settings-section h3 { margin: 0 0 8px; font-size: 13px; color: #f4f6f8; }
.entry-settings-grid label { margin-bottom: 0; }
.entry-settings-grid [hidden] { display: none; }
.entry-payment-progress { align-self: end; color: var(--chrome-muted); font-size: 12px; padding: 5px 0; }
@media (max-width: 760px) {
  .entry-settings-grid { grid-template-columns: 1fr 1fr; }
  .entry-settings-grid .wide { grid-column: span 2; }
}

/* v0.47 entry settings cleanup, dark dropdowns, swatch sizing */
select,
select option,
select optgroup {
  color-scheme: dark;
  background: #242a31;
  color: var(--chrome-text);
}
select:disabled,
select option:disabled {
  color: var(--chrome-muted);
  background: #20252c;
}
input[type="date"],
input[type="number"],
input[type="text"],
textarea {
  color-scheme: dark;
}

.color-popup-rich { width: 302px; }
.color-popup-rich .color-swatch-grid {
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.color-popup-rich .preset-swatch {
  height: 24px;
  min-height: 24px;
}
.color-group-label {
  margin: 1px 0 -2px;
  color: var(--chrome-muted);
  font-size: 11px;
  line-height: 1.1;
}
.color-popup-rich .existing-entry-colors {
  min-height: 80px;
  align-content: start;
  max-height: 128px;
  overflow: auto;
  padding-right: 2px;
}
.color-empty-note {
  grid-column: 1 / -1;
  color: var(--chrome-muted);
  font-size: 11px;
  align-self: center;
}

.entry-settings-dialog {
  width: min(620px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 28px));
}
.entry-settings-dialog .dialog-shell {
  max-height: min(760px, calc(100vh - 28px));
}
.entry-settings-form {
  padding: 10px;
  overflow: auto;
}
.entry-settings-section {
  padding: 10px;
}
.entry-settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 10px;
  align-items: end;
}
.entry-settings-grid .wide,
.entry-settings-row-gap {
  grid-column: 1 / -1;
}
.entry-settings-row-gap {
  height: 5px;
  border-bottom: 1px solid rgba(255,255,255,.055);
  margin-bottom: 2px;
}
.entry-settings-grid label {
  display: grid;
  gap: 3px;
  color: var(--chrome-muted);
  font-size: 12px;
  min-width: 0;
}
.entry-settings-grid input,
.entry-settings-grid select,
.entry-color-control {
  width: 100%;
}
.entry-color-control {
  display: flex;
  align-items: center;
  gap: 6px;
}
.entry-color-swatch-button {
  min-width: 40px;
  width: 40px;
  height: 25px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 2px;
  vertical-align: middle;
}
.entry-color-swatch-button .color-chip {
  width: 24px;
  height: 14px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,.28);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18);
}
.entry-settings-dialog .hint-line:empty {
  display: none;
}
@media (max-width: 640px) {
  .entry-settings-grid { grid-template-columns: 1fr; }
  .entry-settings-grid .wide,
  .entry-settings-row-gap { grid-column: 1 / -1; }
}


/* v0.47 popup stacking, selection overlay, and entry settings sizing */
.topbar { z-index: 700; }
.toolbar { z-index: 650; }
.mt-selection-overlay { z-index: 20; }
.treasury-sheet th { z-index: 18; }
.context-menu { z-index: 1200; }
.toast { z-index: 5000; }
.panel-dialog { z-index: 1400; }
.color-popup-backdrop { z-index: 1450; }
.format-popup { z-index: 900; }

.entry-settings-grid [data-entry-field="amount"] {
  max-width: 165px;
  justify-self: start;
  width: 100%;
}
.entry-settings-grid [data-entry-field="amount"] input {
  width: 138px;
  max-width: 100%;
}
.entry-settings-grid [data-entry-field="color"] {
  justify-self: start;
  min-width: 140px;
}
.entry-settings-grid [data-entry-field="color"] .entry-color-control {
  width: auto;
}
.entry-settings-color-backdrop {
  align-items: center;
  justify-content: center;
}
.entry-settings-dialog .entry-settings-color-backdrop {
  position: fixed;
  inset: 0;
}

/* v0.49 tighter Entry Settings layout */
.entry-settings-dialog {
  width: min(430px, calc(100vw - 28px));
  max-height: min(820px, calc(100vh - 28px));
}
.entry-settings-dialog .dialog-shell {
  max-height: min(820px, calc(100vh - 28px));
}
.entry-settings-form {
  padding: 8px;
}
.entry-settings-section {
  padding: 9px;
}
.entry-settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 9px;
}
.entry-settings-grid .entry-settings-row-gap {
  grid-column: 1 / -1;
  height: 4px;
  margin: 1px 0 0;
}
.entry-settings-grid label[data-entry-field="title"],
.entry-settings-grid label[data-entry-field="amount"],
.entry-settings-grid label[data-entry-field="current-balance"],
.entry-settings-grid label[data-entry-field="starting-balance"] {
  grid-column: auto;
  width: 100%;
  max-width: none;
  justify-self: stretch;
}
.entry-settings-grid label[data-entry-field="title"] input,
.entry-settings-grid label[data-entry-field="amount"] input,
.entry-settings-grid label[data-entry-field="current-balance"] input,
.entry-settings-grid label[data-entry-field="starting-balance"] input {
  width: 100%;
  max-width: 100%;
}
.entry-settings-grid label[data-entry-field="amount"] {
  white-space: nowrap;
}
.entry-settings-grid .entry-field-title {
  white-space: nowrap;
  display: inline-block;
}
.entry-type-with-color {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  width: 100%;
}
.entry-type-with-color #entryTypeSelect {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
}
.entry-type-with-color .entry-color-swatch-button {
  flex: 0 0 auto;
  margin-left: 2px;
}
.entry-color-swatch-button[hidden] {
  display: none;
}
.entry-settings-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
  margin-top: 9px;
}
.entry-actions-primary,
.entry-actions-secondary {
  display: flex;
  gap: 6px;
  align-items: center;
}
.entry-actions-secondary {
  justify-content: flex-end;
  flex-wrap: wrap;
}
.entry-actions-secondary button {
  font-size: 11px;
  padding-inline: 8px;
}
.entry-settings-dialog .hint-line {
  display: none;
}
@media (max-width: 470px) {
  .entry-settings-dialog { width: calc(100vw - 18px); }
  .entry-settings-grid { grid-template-columns: 1fr; }
  .entry-settings-grid label[data-entry-field="title"],
  .entry-settings-grid label[data-entry-field="amount"],
  .entry-settings-grid label[data-entry-field="current-balance"],
  .entry-settings-grid label[data-entry-field="starting-balance"] {
    grid-column: 1 / -1;
  }
  .entry-settings-actions { align-items: stretch; flex-direction: column; }
  .entry-actions-primary,
  .entry-actions-secondary { justify-content: flex-end; }
}

/* v0.50: make the Column F row drag handles usable again. */
.treasury-sheet td.move-handle-cell,
.treasury-sheet td.gap-cell {
  cursor: move;
  min-width: 20px;
  width: 20px;
  padding-left: 1px;
  padding-right: 1px;
  text-align: center;
  vertical-align: middle;
}
.treasury-sheet td.move-handle-cell::before,
.treasury-sheet td.gap-cell::before {
  content: '⋮⋮';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 18px;
  font-size: 17px;
  line-height: 15px;
  letter-spacing: -3px;
  transform: none;
  transform-origin: center;
  opacity: .9;
  color: var(--chrome-muted);
}
.treasury-sheet td.move-handle-cell:hover::before,
.treasury-sheet td.gap-cell:hover::before {
  opacity: 1;
  color: var(--chrome-text);
}


/* v0.51: keep copy-over only inside Entry Settings, and force loan balances onto one compact row. */
.entry-settings-grid .entry-balance-pair {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 9px;
  align-items: end;
}
.entry-settings-grid .entry-balance-pair[hidden] {
  display: none;
}
.entry-settings-grid .entry-balance-pair label {
  grid-column: auto;
  width: 100%;
  max-width: none;
}
.entry-settings-grid .entry-balance-pair label[hidden] {
  display: none;
}
.entry-settings-grid .entry-balance-pair input {
  width: 100%;
  max-width: 100%;
}
@media (max-width: 470px) {
  .entry-settings-grid .entry-balance-pair {
    grid-template-columns: 1fr;
  }
}


/* v0.52: keep color-chip swatches centered before focus/click layout recalculation. */
.entry-color-swatch-button,
.color-picker-button,
button:has(> .color-chip) {
  align-items: center;
}
.entry-color-swatch-button > .color-chip,
.color-picker-button > .color-chip,
button > .color-chip {
  flex: 0 0 auto;
  display: block;
  margin-block: auto;
  align-self: center;
}

/* v0.54+: entry settings color swatch is its own flex button; do not inherit toolbar color-picker grid layout. */
#entryColorSchemeSwatch.entry-color-swatch-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-width: 40px;
  height: 25px;
  min-height: 25px;
  padding: 0;
  line-height: 0;
  vertical-align: middle;
}
#entryColorSchemeSwatch.entry-color-swatch-button > .color-chip {
  display: block;
  flex: 0 0 auto;
  align-self: center;
  width: 24px;
  height: 14px;
  margin: 0;
  position: static;
  transform: none;
}
.toolbar button.color-picker-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.toolbar button.color-picker-button > .color-chip {
  flex: 0 0 auto;
  align-self: center;
  margin: 0;
  transform: none;
}



/* v0.57 CSS cleanup: use colgroup CSS variables instead of stamping widths on header cells. */
:root {
  --mt-col-row-header: 38px;
  --mt-col-date: 84px;
  --mt-col-color: 10px;
  --mt-col-entry-name: 215px;
  --mt-col-amount: 64px;
  --mt-col-running-total: 76px;
  --mt-col-gap: 18px;
  --mt-col-note: 190px;
  --mt-popup-z-base: 1400;
  --mt-selection-z: 18;
}
.treasury-sheet {
  width: max-content;
  min-width: max-content;
}
.treasury-sheet col {
  width: var(--mt-col-width);
}
.treasury-sheet th[data-column],
.treasury-sheet td[data-column] {
  width: auto;
  min-width: 0;
  max-width: none;
}
.treasury-sheet .col-row-header { width: var(--mt-col-row-header); }
.treasury-sheet .col-date { width: var(--mt-col-date); }
.treasury-sheet .col-color { width: var(--mt-col-color); min-width: var(--mt-col-color); max-width: 18px; }
.treasury-sheet .col-entry-name { width: var(--mt-col-entry-name); }
.treasury-sheet .col-amount { width: var(--mt-col-amount); }
.treasury-sheet .col-running-total { width: var(--mt-col-running-total); }
.treasury-sheet .col-gap { width: var(--mt-col-gap); }
.treasury-sheet .col-note-1,
.treasury-sheet .col-note-2,
.treasury-sheet .col-note-3,
.treasury-sheet .col-note-4,
.treasury-sheet .col-note-5 { width: var(--mt-col-note); }
.format-popup[hidden],
.fx-menu[hidden],
[data-bill-field][hidden],
.entry-settings-grid [hidden],
.entry-settings-grid .entry-balance-pair[hidden],
.entry-settings-grid .entry-balance-pair label[hidden],
.mt-selection-overlay[hidden],
.context-menu[hidden],
.entry-color-swatch-button[hidden] {
  display: none;
}
.entry-color-swatch-button,
.color-picker-button,
button:has(> .color-chip) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.entry-color-swatch-button > .color-chip,
.color-picker-button > .color-chip,
button > .color-chip {
  flex: 0 0 auto;
  align-self: center;
  margin: 0;
}
