* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ========================================
   CSS Variables for Light/Dark Mode
   ======================================== */

:root {
  /* Soft Slate Theme (Default) */
  --bg-gradient-start: #f6f8f6;
  --bg-gradient-end: #e1ece9;
  --bg-primary: #fffefb;
  --bg-secondary: #f5f8f6;
  --bg-tertiary: #e9f0ed;

  --text-primary: #172826;
  --text-secondary: #53635f;
  --text-tertiary: #0f766e;
  --text-muted: #66736f;

  --border-color: #d7e0dd;
  --border-color-hover: #b8c7c3;

  --btn-primary-bg: var(--brand-primary-hover);
  --btn-primary-hover: var(--brand-primary-dark);
  --btn-primary-text: #ffffff;
  --btn-secondary-bg: #eef3f1;
  --btn-secondary-hover: #e1ebe7;

  --success-color: #0f8a6f;
  --warning-color: #a16207;
  --danger-color: #d24f45;

  /* The hero keeps its deep green in both themes; its alarm state has its
     own terracotta, borrowed from no member's colour */
  --hero-start: #0b7468;
  --hero-end: #07584f;
  --hero-attention-start: #b4503f;
  --hero-attention-end: #8e3d30;

  --shadow-sm: 0 1px 2px rgba(23, 40, 38, 0.08);
  --shadow-md: 0 12px 30px rgba(23, 40, 38, 0.1);
  --shadow-lg: 0 20px 48px rgba(23, 40, 38, 0.14);

  --brand-primary: #0f8a7b;
  --brand-primary-hover: #0b7468;
  --brand-primary-light: #d7f3ee;
  --brand-primary-dark: #07584f;
  --brand-primary-50: #edf8f5;
  --section-household: #4f6f94;
  --section-household-light: #e3ebf7;
  --section-rose: #b95f7a;
  --section-rose-light: #f7e5ec;
  --section-jason: #b7791f;
  --section-jason-light: #f7ecd8;
  --accent-primary: var(--brand-primary);
}

/* Dark Mode Colors */
[data-theme="dark"] {
  --bg-gradient-start: #202827;
  --bg-gradient-end: #30342e;
  --bg-primary: #29302f;
  --bg-secondary: #333b39;
  --bg-tertiary: #404946;

  --text-primary: #f7f5ef;
  --text-secondary: #d2d8d2;
  --text-tertiary: #9ee7d7;
  --text-muted: #a6b0ab;

  --border-color: #4a5552;
  --border-color-hover: #61706b;

  --btn-primary-bg: var(--brand-primary);
  --btn-primary-hover: var(--brand-primary-hover);
  --btn-primary-text: #0b2f2a;
  --btn-secondary-bg: #35403d;
  --btn-secondary-hover: #404c49;

  --success-color: #34d399;
  --warning-color: #f6b44b;
  --danger-color: #f87171;

  --hero-start: #0b7468;
  --hero-end: #07584f;
  --hero-attention-start: #b4503f;
  --hero-attention-end: #8e3d30;

  --shadow-sm: 0 1px 2px 0 rgba(8, 12, 11, 0.22);
  --shadow-md: 0 10px 28px rgba(8, 12, 11, 0.26);
  --shadow-lg: 0 20px 46px rgba(8, 12, 11, 0.34);

  --brand-primary: #33c8b5;
  --brand-primary-hover: #69dbc9;
  --brand-primary-light: rgba(51, 200, 181, 0.18);
  --brand-primary-dark: #baf7ec;
  --brand-primary-50: rgba(51, 200, 181, 0.1);
  --section-household: #9bb9e7;
  --section-household-light: rgba(155, 185, 231, 0.18);
  --section-rose: #ee9ab6;
  --section-rose-light: rgba(238, 154, 182, 0.18);
  --section-jason: #f3c36b;
  --section-jason-light: rgba(243, 195, 107, 0.18);
}

/* One focus ring for the whole app: the browser's default is replaced with the
   brand ring here, and nowhere does a rule switch it off */
:focus-visible {
  outline: 3px solid var(--brand-primary);
  outline-offset: 2px;
}

/* Read by assistive tech, invisible to everyone else */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* The first Tab press on the page offers a jump past the header */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  z-index: 10000;
  padding: 10px 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  text-decoration: none;
  font-weight: 600;
}
.skip-link:focus {
  top: 12px;
}
/* Landing on the content after the skip link should not ring the whole page */
#main:focus-visible {
  outline: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background:
    linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  min-height: 100vh;
  padding: 20px;
  color: var(--text-primary);
  transition: background 0.3s ease, color 0.3s ease;
}

.container {
  max-width: 900px;
  margin: 0 auto;
}

/* Header */
header {
  background: var(--bg-primary);
  padding: 24px 30px;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  margin-bottom: 24px;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
}

header:hover {
  box-shadow: var(--shadow-lg);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 48px;
  height: 48px;
  color: var(--btn-primary-bg);
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.logo:hover {
  transform: scale(1.05);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-text h1 {
  color: var(--text-primary);
  font-size: 1.75rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin: 0;
  font-weight: 500;
}

.header-period {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

h1 {
  color: var(--text-tertiary);
  font-size: 2rem;
  margin-bottom: 10px;
}

.budget-period {
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  display: inline-block;
  margin: 0 auto;
}

.budget-period-notes {
  display: none;
  align-items: center;
  gap: 6px;
  max-width: 300px;
}

.budget-period-notes.visible {
  display: flex;
}

.budget-notes-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.budget-notes-edit-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  flex-shrink: 0;
}

.budget-notes-edit-btn:hover {
  opacity: 1;
  color: var(--text-primary);
}

.budget-notes-input {
  font-size: 0.85rem;
  padding: 4px 8px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 240px;
  font-style: italic;
}

.budget-notes-input:focus {
  border-color: var(--btn-primary-bg);
  box-shadow: 0 0 0 2px rgba(100, 116, 139, 0.15);
}

.btn-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--border-color);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.btn-header svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-header:hover {
  background: var(--bg-tertiary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.btn-header:active {
  transform: translateY(0);
}

.btn-header-primary {
  background: var(--btn-primary-bg);
  color: #ffffff;
  border-color: rgba(15, 138, 123, 0.32);
}

.btn-header-primary:hover {
  background: var(--btn-primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(15, 138, 123, 0.22);
}

.funds-summary {
  background: linear-gradient(135deg, #fbfdfb 0%, #e4eeeb 100%);
  padding: 20px;
  border-radius: 12px;
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: stretch;
  gap: 16px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
}

.funds-summary:has(.funds-value.zero) {
  background: linear-gradient(135deg, #f3fbf8 0%, #d8f3ee 100%);
  box-shadow: 0 18px 40px rgba(15, 138, 123, 0.12);
}

.funds-arrow {
  font-size: 1.5rem;
  color: var(--text-muted);
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

.funds-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(215, 224, 221, 0.72);
  border-radius: 10px;
  transition: all 0.2s ease;
  text-align: center;
}

.funds-item:hover {
  transform: translateY(-2px);
  background: #ffffff;
}

.funds-remaining {
  background: #ffffff;
  border: 2px solid rgba(15, 138, 123, 0.28);
}

.funds-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 600;
}

.funds-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 5px;
}

.funds-value.positive {
  color: var(--warning-color);
}

.funds-value.zero {
  color: var(--success-color);
}

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

.funds-value.neutral {
  color: var(--text-primary);
}

.funds-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 4px;
  font-style: italic;
}

/* Buttons */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 48px;
  box-shadow: var(--shadow-sm);
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border: 1px solid rgba(15, 138, 123, 0.32);
}

.btn-primary:hover {
  transform: translateY(-2px);
  background: var(--btn-primary-hover);
  box-shadow: 0 12px 26px rgba(15, 138, 123, 0.24);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-tertiary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.9rem;
  min-height: auto;
}

/* Main Content */
main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

section {
  background: var(--bg-primary);
  padding: 28px;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
}

section:hover {
  box-shadow: var(--shadow-lg);
}

h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 24px;
  letter-spacing: -0.01em;
}

/* Add Expense Form */
.add-expense-section form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.floating-label {
  position: relative;
  margin-top: 8px;
}

.form-group.floating-label input,
.form-group.floating-label select {
  padding: 18px 12px 8px 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.2s ease;
}

.form-group.floating-label input:focus,
.form-group.floating-label select:focus {
  border-color: var(--btn-primary-bg);
}

.form-group.floating-label label {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: 400;
  pointer-events: none;
  transition: all 0.2s ease;
  background: var(--bg-primary);
  padding: 0 4px;
}

/* Float label when input is focused or has value */
.form-group.floating-label input:focus + label,
.form-group.floating-label input:not(:placeholder-shown) + label,
.form-group.floating-label select:focus + label,
.form-group.floating-label select:valid + label {
  top: 0;
  transform: translateY(-50%);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--btn-primary-bg);
}

/* Handle select specifically */
.form-group.floating-label select:not(:invalid) + label {
  top: 0;
  transform: translateY(-50%);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--btn-primary-bg);
}

label {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9rem;
}

input, select {
  padding: 12px 14px;
  border: 2px solid var(--border-color);
  border-radius: 10px;
  font-size: 1rem;
  transition: border-color 0.2s, background 0.3s ease, color 0.3s ease;
  min-height: 48px;
  background: var(--bg-primary);
  color: var(--text-primary);
}

input:focus, select:focus {
  border-color: var(--text-tertiary);
}

/* Categories Grid */
/* Budget sections */
.budget-section {
  margin-bottom: 35px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.budget-section:last-child {
  border-bottom: none;
}

.section-header {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 3px solid var(--text-tertiary);
  word-wrap: break-word;
}

/* Color-Coded Budget Sections */
.section-group {
  margin-bottom: 0;
  border-left: 3px solid var(--border-color);
  padding-left: 1rem;
  transition: border-color 0.3s ease;
}
.section-group[data-section="household"] { border-left-color: var(--section-household); }
.section-group[data-section="rose"] { border-left-color: var(--section-rose); }
.section-group[data-section="jason"] { border-left-color: var(--section-jason); }
.section-group .section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  font-size: 1rem;
}
.section-group[data-section="household"] .section-header { color: var(--section-household); }
.section-group[data-section="rose"] .section-header { color: var(--section-rose); }
.section-group[data-section="jason"] .section-header { color: var(--section-jason); }

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
  margin-bottom: 0;
}

/* The three sections stack full width; each section's cards sit two across
   on a laptop and one across on a phone */
.section-stack {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.section-stack .categories-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
}
.section-stack .envelope-skeleton {
  width: 100%;
}

#budget-content > .funds-summary { margin-bottom: 16px; }

/* A reload keeps the numbers on screen, dimmed, until the fresh ones land */
.funds-summary.is-loading {
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.category-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.25s ease, background 0.25s ease;
  overflow: hidden;
  word-wrap: break-word;
  box-shadow: var(--shadow-sm);
}

.category-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--btn-primary-bg);
}

.category-card .overflow-menu-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}

.category-card .overflow-menu-btn:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

.category-card .overflow-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  z-index: 100;
  min-width: 150px;
  overflow: hidden;
  animation: menuFadeIn 0.15s ease;
}

.category-card .overflow-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-primary);
  text-align: left;
  transition: background 0.1s ease;
}

.category-card .overflow-menu-item:hover {
  background: var(--bg-secondary);
}

/* Wrapper for overflow button+menu positioning */
.category-header > div:last-child {
  position: relative;
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.category-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
  flex: 1;
  min-width: 0;
}

.category-notes {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 12px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.category-progress {
  margin: 12px 0;
}

.progress-bar {
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

.progress-fill.safe {
  background: linear-gradient(90deg, #0f8a7b, #34c3af);
}

.progress-fill.warning {
  background: linear-gradient(90deg, var(--warning-color), #e7b85d);
}

.progress-fill.overspent {
  background: linear-gradient(90deg, var(--danger-color), #fb8f8f);
}

/* Progress Bar Animation */
@keyframes progressFill {
  from { width: 0; }
}
.progress-fill {
  animation: progressFill 0.8s ease-out;
}
.progress-fill.overspent {
  animation: progressPulse 2s ease-in-out infinite;
}
@keyframes progressPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Also support .progress-bar-fill class */
.progress-bar-fill {
  animation: progressFill 0.8s ease-out;
  transition: background-color 0.3s ease;
}
.progress-bar-fill.overspent {
  animation: progressPulse 2s ease-in-out infinite;
}

.progress-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: right;
}

.category-amounts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.95rem;
}

.amount-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.amount-label {
  color: var(--text-secondary);
  flex-shrink: 0;
}

.amount-value {
  font-weight: 600;
  text-align: right;
  word-wrap: break-word;
}

.remaining {
  font-size: 1.2rem;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 2px solid var(--border-color);
}

.remaining.positive {
  color: var(--success-color);
}

.remaining.warning {
  color: #f59e0b;
}

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

/* Section subtotals */
.section-subtotal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 16px;
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
}

.subtotal-label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
  min-width: 100px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.subtotal-amounts {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  font-size: 0.95rem;
}

.subtotal-item {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.subtotal-item.positive {
  color: var(--success-color);
}

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

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

/* Modal Animation Keyframes */
@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: modalFadeIn 0.2s ease;
}

.modal .modal-content {
  animation: modalSlideUp 0.3s ease;
}

.modal-content {
  background: var(--bg-primary);
  padding: 30px;
  border-radius: 12px;
  max-width: 900px;
  width: 95%;
  max-height: 95vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: background 0.3s ease;
  position: relative; /* anchors the .modal-x close button */
}

.modal-content::-webkit-scrollbar {
  width: 8px;
}

.modal-content::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb {
  background: var(--btn-primary-bg);
  border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
  background: var(--btn-primary-hover);
}

.modal-content h2 {
  margin-bottom: 20px;
}

/* Enhanced Modal Header */
.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--border-color);
}

.modal-header-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text); /* dark text on the dark theme's mint */
  border-radius: 8px;
  flex-shrink: 0;
}

.modal-header-icon svg {
  width: 20px;
  height: 20px;
}

.modal-header-content {
  flex: 1;
}

.modal-header-content h2 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--text-primary);
}

.modal-header-content p {
  margin: 4px 0 0 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Template selection */
.template-selection {
  background: var(--bg-secondary);
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 20px;
  border: 2px solid var(--border-color);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.template-selection h3 {
  font-size: 1rem;
  margin: 0 0 10px 0;
  color: var(--text-primary);
}

.template-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.template-buttons .btn {
  flex: 1;
  padding: 10px 15px;
  font-size: 0.9rem;
}

.template-dropdown {
  width: 100%;
  padding: 10px;
  border: 2px solid var(--border-color-hover);
  border-radius: 6px;
  font-size: 0.95rem;
  margin-top: 10px;
  background: var(--bg-primary);
}

/* Form sections for reset budget */
.form-section {
  margin-bottom: 25px;
  padding: 15px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 2px solid var(--border-color);
}

/* A member's rows are a fieldset; the legend is its heading, on the card like before */
fieldset.form-section {
  min-width: 0;
  margin-inline: 0;
}

legend.section-label {
  float: left;
  width: 100%;
  padding: 0 0 6px;
}

legend.section-label + * {
  clear: both;
}

.section-label {
  display: block;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--btn-primary-bg);
  word-wrap: break-word;
}

.categories-input-section {
  margin-bottom: 10px;
}

.category-input-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 2fr) auto;
  gap: 8px;
  margin-bottom: 10px;
  align-items: center;
}

.category-input-row input,
.category-input-row select {
  min-width: 0;
  width: 100%;
}

.category-option-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
}

.category-option-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.edit-modal-early-pay {
  font-size: 0.9rem;
  color: var(--text-primary);
  padding: 4px 0;
}

.cat-row-controls {
  display: flex;
  gap: 3px;
  align-items: center;
  flex-shrink: 0;
}

.btn-remove-category,
.btn-reorder-category {
  background: none;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  min-height: auto;
  padding: 0;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
}

.btn-remove-category {
  border: 1px solid var(--danger-color);
  color: var(--danger-color);
  font-size: 1.1rem;
  font-weight: bold;
}

.btn-remove-category:hover {
  background: var(--danger-color);
  color: white;
}

.btn-reorder-category {
  border: 1px solid var(--text-muted, #888);
  color: var(--text-muted, #888);
  font-size: 0.65rem;
}

.btn-reorder-category:hover {
  background: var(--text-muted, #888);
  color: white;
}

.allocation-summary {
  background: var(--bg-secondary);
  padding: 15px;
  border-radius: 8px;
  margin: 15px 0;
  border: 2px solid var(--border-color);
  overflow: hidden;
}

.allocation-summary.over-budget {
  background: #f9dddd;
  border-color: #efb4b4;
}

.allocation-summary.under-budget {
  background: #f7ecd8;
  border-color: #e7c98d;
}

.validation-success {
  margin-top: 12px;
  padding: 12px;
  background: #d7f3ee;
  border: 2px solid #a7ddd3;
  border-radius: 6px;
  color: #07584f;
  font-weight: 700;
  text-align: center;
}

.validation-info {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-secondary);
  font-weight: 600;
  text-align: center;
}

.validation-warning {
  margin-top: 12px;
  padding: 12px;
  background: #f7ecd8;
  border: 2px solid #e7c98d;
  border-radius: 6px;
  color: #71480f;
  font-weight: 700;
  text-align: center;
}

.validation-error {
  margin-top: 12px;
  padding: 12px;
  background: #f9dddd;
  border: 2px solid #efb4b4;
  border-radius: 6px;
  color: #8f2626;
  font-weight: 700;
  text-align: center;
}

.allocation-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 0.95rem;
  flex-wrap: wrap;
}

.allocation-row:last-child {
  margin-bottom: 0;
  padding-top: 8px;
  border-top: 2px solid var(--border-color);
  font-weight: 700;
  font-size: 1.05rem;
}

.allocation-value.positive {
  color: var(--success-color);
}

.allocation-value.zero {
  color: var(--text-tertiary);
  font-weight: 700;
}

.allocation-value.negative {
  color: #8f2626;
  font-weight: 700;
}
[data-theme="dark"] .allocation-value.negative { color: #fca5a5; }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  position: sticky;
  bottom: 0;
  background: var(--bg-primary);
  padding: 12px 0 4px;
  z-index: 1;
}

.modal-actions .btn {
  flex: 1;
}

/* Mobile Responsive */
/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  /* Every sheet's action row clears the home indicator; in the Start Fresh
     wizard, Go Live comes first and full width (the other sheets keep their
     order until Release 3 reviews them together) */
  .modal-actions {
    flex-wrap: wrap;
    padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  }
  #reset-modal .modal-actions .btn-primary {
    flex: 1 1 100%;
    order: -1;
  }

  header {
    padding: 16px;
  }

  .header-top {
    flex-direction: column;
    gap: 16px;
    margin-bottom: 12px;
  }

  .header-brand {
    justify-content: center;
  }

  .header-period {
    margin-bottom: 12px;
  }

  .header-actions {
    justify-content: center;
    flex-wrap: wrap;
  }

  .btn-header {
    flex: 1 1 auto;
    min-width: 110px;
    justify-content: center;
  }

  .brand-text h1 {
    font-size: 1.5rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  section {
    padding: 20px;
  }

  .funds-summary {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .funds-arrow {
    transform: rotate(90deg);
    font-size: 1.2rem;
  }



  .template-cat-row {
    grid-template-columns: 1fr;
    gap: 8px;
    position: relative;
  }

  /* Name and amount on one line, the note under them, the option and the
     row buttons on a third: a row reads as one thing */
  .category-input-row {
    grid-template-columns: minmax(0, 1fr) 110px;
    grid-template-areas: "name amount" "notes notes" "opts controls";
    gap: 8px;
    position: relative;
  }
  .category-input-row .cat-name { grid-area: name; }
  .category-input-row .cat-amount { grid-area: amount; }
  .category-input-row .cat-notes { grid-area: notes; }
  .category-input-row .category-option-label { grid-area: opts; }
  .category-input-row .cat-row-controls { grid-area: controls; justify-self: end; }

  /* Keep the row buttons in normal flow on phones. Floating them over the
     first field hid half the category name and put the (unconfirmed) delete
     button exactly where you tap to edit the name; on template rows, which
     are not position:relative, they escaped the row entirely and stacked on
     the modal's close button. */
  .cat-row-controls {
    position: static;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
  }

  .btn-remove-category,
  .btn-reorder-category {
    width: 36px;
    height: 36px;
  }

  .modal .modal-content {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    margin: 0;
    width: 100%;
    max-width: 100%;
    padding: 20px;
    animation: slideUpFromBottom 0.3s ease;
  }

  @keyframes slideUpFromBottom {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  .template-buttons {
    flex-direction: column;
  }

  .form-section {
    padding: 12px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.3rem;
  }

  .section-header {
    font-size: 1.1rem;
  }

  .category-card {
    padding: 15px;
  }

  .funds-value {
    font-size: 1.3rem;
  }

  .btn {
    padding: 10px 18px;
    font-size: 0.95rem;
  }
}

/* Confirmation dialog */
.confirmation-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-primary);
  padding: 25px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 2000;
  max-width: 450px;
  width: 90%;
}

.confirmation-dialog h3 {
  margin: 0 0 15px 0;
  color: var(--text-primary);
  font-size: 1.2rem;
}

.confirmation-dialog p {
  margin: 0 0 20px 0;
  color: var(--text-secondary);
  line-height: 1.6;
}

.confirmation-dialog .warning {
  background: #f9dddd;
  border: 2px solid #efb4b4;
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 20px;
  color: #8f2626;
  font-weight: 600;
}

.confirmation-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.confirmation-actions .btn {
  min-width: 100px;
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1999;
}

/* The confirmation sits above every dialog that can ask it, including the
   hand-built ones at 2000; only the Money Date card and toasts are higher */
.overlay.confirmation-overlay { z-index: 2999; }
.confirmation-dialog { z-index: 3000; }

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.category-card {
  animation: fadeIn 0.3s ease-out;
}

/* Animations */
@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* Edit Allocation Modal */
.edit-allocation-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-primary);
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 2000;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.edit-allocation-modal h3 {
  margin: 0 0 20px 0;
  color: var(--text-primary);
  font-size: 1.3rem;
  border-bottom: 2px solid var(--btn-primary-bg);
  padding-bottom: 10px;
}

.edit-allocation-info {
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 20px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 0.95rem;
}

.info-row:not(:last-child) {
  border-bottom: 1px solid var(--border-color);
}

.info-value {
  font-weight: 700;
  color: var(--text-primary);
}

.info-value.zero {
  color: var(--success-color);
}

.info-value.warning {
  color: var(--warning-color);
}

.info-value.danger {
  color: #8f2626;
}
[data-theme="dark"] .info-value.danger { color: #fca5a5; }

.edit-allocation-btn {
  width: 100%;
  margin-top: 12px;
  background: var(--btn-primary-bg);
  color: white;
}

.edit-allocation-btn:hover {
  background: var(--btn-primary-hover);
}

#edit-validation-message {
  margin: 15px 0;
  min-height: 45px;
}

/* Mobile Responsive for Edit Modal */
@media (max-width: 768px) {
  .edit-allocation-modal {
    padding: 20px;
    width: 95%;
  }

  .edit-allocation-modal h3 {
    font-size: 1.1rem;
  }
}

/* ========================================
   Settings Modal & Backup Styles
   ======================================== */

.settings-modal-content {
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
}

/* Long settings panels must scroll without collapsing the tab navigation. */
#settings-modal .settings-modal-content > * {
  flex-shrink: 0;
}

.settings-section {
  margin-bottom: 30px;
}

.settings-section h3 {
  color: var(--text-tertiary);
  font-size: 1.2rem;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 10px;
}

.settings-section h4 {
  color: var(--text-tertiary);
  font-size: 1rem;
  margin-bottom: 15px;
}

/* Backup Status Card */
.backup-status-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 15px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
}

.status-row:last-child {
  border-bottom: none;
}

.status-label {
  font-weight: 600;
  color: var(--text-tertiary);
  font-size: 0.95rem;
}

.status-value {
  color: var(--text-primary);
  font-size: 0.95rem;
}

#backup-status-indicator {
  font-weight: 600;
}

/* Backup Browser */
.backup-browser {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
}

.backup-list {
  max-height: 300px;
  overflow-y: auto;
}

.loading-text {
  text-align: center;
  color: var(--text-secondary);
  padding: 20px;
  margin: 0;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
}

/* Individual Backup Items */
.backup-item {
  display: flex;
  align-items: center;
  padding: 12px 15px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  margin-bottom: 10px;
  background: var(--bg-secondary);
  transition: all 0.2s ease;
  gap: 10px;
}

.backup-item:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-color-hover);
}

.backup-info {
  flex: 1;
}

.backup-date {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 5px;
}

.backup-details {
  font-size: 0.85rem;
  color: var(--text-tertiary);
}

/* Backup Browser Header */
.backup-browser-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.backup-browser-header h4 {
  margin: 0;
}

/* Select All Checkbox */
.backup-select-all {
  padding: 10px 15px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  margin-bottom: 10px;
}

.backup-select-all .checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-tertiary);
}

.backup-select-all input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Backup Item with Checkbox */
.backup-checkbox {
  display: flex;
  align-items: center;
  margin-right: 12px;
}

.backup-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Backup Actions */
.backup-actions {
  display: flex;
  gap: 8px;
}

.btn-delete-backup {
  background: transparent;
  color: var(--danger-color);
  border: 1px solid var(--danger-color);
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-delete-backup:hover {
  background: var(--danger-color);
  color: white;
}

/* Delete Selected Button */
#delete-selected-btn {
  font-size: 0.85rem;
  padding: 6px 12px;
}

#delete-selected-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Dark mode for backup delete UI */
[data-theme="dark"] .btn-delete-backup {
  color: #f87171;
  border-color: #f87171;
}

[data-theme="dark"] .btn-delete-backup:hover {
  background: #f87171;
  color: #0f172a;
}

.btn-restore {
  background: var(--btn-primary-bg);
  color: white;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s ease;
  white-space: nowrap;
  margin-left: 15px;
}

.btn-restore:hover {
  background: var(--btn-primary-hover);
}

.btn-restore:active {
  background: var(--btn-secondary-bg);
}

/* Theme Toggle */
.theme-toggle-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
}

.theme-toggle-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

/* ========================================
   History Modal & Period Cards
   ======================================== */

.history-modal-content {
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
}

.compare-modal-content {
  max-width: 1000px;
  max-height: 90vh;
  overflow-y: auto;
}

.comparison-container {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 30px;
  margin-top: 20px;
  align-items: start;
}

.comparison-period {
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: 10px;
  padding: 20px;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.comparison-period h3 {
  margin: 0 0 10px 0;
  font-size: 1.2rem;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 10px;
}

.comparison-period .period-dates {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.comparison-divider {
  width: 2px;
  background: var(--border-color);
  align-self: stretch;
}

.comparison-stats {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.comparison-stats .stat-item {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  transition: background 0.3s ease;
}

.comparison-details-toggle {
  margin-top: 30px;
  text-align: center;
  padding: 20px 0;
  border-top: 2px solid var(--border-color);
}

.comparison-details-toggle .btn {
  padding: 12px 24px;
  font-size: 1rem;
}

.category-comparison-container {
  margin-top: 20px;
  animation: slideDown 0.3s ease-out;
}

.comparison-section {
  margin-bottom: 30px;
}

.comparison-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 15px;
  padding: 10px 15px;
  background: var(--bg-secondary);
  border-left: 4px solid var(--btn-primary-bg);
  border-radius: 4px;
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-secondary);
  border-radius: 8px;
  overflow: hidden;
}

.comparison-table thead {
  background: var(--bg-tertiary);
}

.comparison-table th {
  padding: 12px;
  text-align: left;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border-color);
}

.comparison-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.comparison-table tbody tr:last-child td {
  border-bottom: none;
}

.comparison-table tbody tr:hover {
  background: var(--bg-tertiary);
}

.comparison-table .cat-name {
  font-weight: 600;
  color: var(--text-primary);
}

.comparison-table .diff-increase {
  color: var(--danger-color);
  font-weight: 600;
}

.comparison-table .diff-decrease {
  color: var(--success-color);
  font-weight: 600;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-top: 20px;
}

.period-card {
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: 10px;
  padding: 20px;
  transition: all 0.2s ease;
  cursor: pointer;
}

.period-card:hover {
  border-color: var(--border-color-hover);
  box-shadow: var(--shadow-md);
}

.period-summary:focus {
  outline: 2px solid var(--btn-primary-bg);
  outline-offset: 2px;
  border-radius: 8px;
}

.period-card.current {
  border-color: var(--success-color);
  background: var(--bg-tertiary);
}

.period-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.period-dates-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.period-dates {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.period-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-icon-export,
.btn-icon-compare {
  background: var(--btn-primary-bg);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-icon-compare {
  background: var(--btn-secondary-bg);
}

.btn-icon-export:hover,
.btn-icon-compare:hover {
  background: var(--btn-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-icon-compare:hover {
  background: var(--btn-secondary-hover);
}

.btn-icon-export:active,
.btn-icon-compare:active {
  transform: translateY(0);
}

.period-badge {
  background: var(--success-color);
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

.period-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-value.positive {
  color: var(--success-color);
}

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

.expand-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 10px;
  font-style: italic;
}

.period-details {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 2px solid var(--border-color);
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.period-breakdown {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-breakdown {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 15px;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.section-summary {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  padding: 8px;
  background: var(--bg-secondary);
  border-radius: 6px;
}

.category-breakdown {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 12px;
  padding: 10px;
  background: var(--bg-primary);
  border-radius: 6px;
  font-size: 0.9rem;
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.category-row:hover {
  border-color: var(--border-color-hover);
  box-shadow: var(--shadow-sm);
}

.category-row .category-name {
  font-weight: 600;
  color: var(--text-primary);
}

.category-row .category-value {
  text-align: right;
  color: var(--text-secondary);
}

.category-row .category-value.allocated {
  color: var(--text-primary);
}

.category-row .category-value.spent {
  color: var(--warning-color);
}

.category-row .category-value.remaining {
  font-weight: 600;
}

.category-row .category-value.remaining.positive {
  color: var(--success-color);
}

.category-row .category-value.remaining.negative {
  color: var(--danger-color);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-left: 4px solid;
  border-radius: 8px;
  padding: 16px 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  max-width: 400px;
  pointer-events: auto;
  animation: toastSlideIn 0.3s ease;
  transition: all 0.3s ease;
}

/* The class names showToast sets: toast-success, toast-error, toast-info */
.toast.toast-success {
  border-left: 4px solid var(--success-color);
}

.toast.toast-error {
  border-left: 4px solid var(--danger-color);
}

.toast.toast-info {
  border-left: 4px solid var(--btn-primary-bg);
}

.toast-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.toast-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toast-title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.toast-message {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: pre-line;
}

.confirmation-message {
  white-space: pre-line;
}

/* On a phone a toast sits at the top, never over a sheet's close button */
@media (max-width: 768px) {
  .toast-container {
    top: 12px;
    left: 16px;
    right: 16px;
    align-items: stretch;
  }
  .toast {
    min-width: 0;
    max-width: none;
    padding: 12px 14px;
  }
}

.toast.removing {
  animation: slideOutRight 0.3s ease-out forwards;
}

@keyframes slideInRight {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(400px);
    opacity: 0;
  }
}

@keyframes toastSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.toast.toast-success {
  border-left-color: var(--brand-primary);
  background: var(--brand-primary-50);
}

.toast-action {
  margin-left: auto;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.toast-action:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ========================================
   Email Configuration Styles
   ======================================== */

.email-status-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 15px 20px;
  margin-bottom: 20px;
}

.email-status-card .status-value.configured {
  color: var(--success-color);
  font-weight: 600;
}

.email-status-card .status-value.not-configured {
  color: var(--warning-color);
  font-weight: 600;
}

.email-instructions {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.email-instructions h4 {
  color: #1d4ed8;
  margin-top: 0;
  margin-bottom: 15px;
}

.email-instructions ol {
  margin: 0;
  padding-left: 20px;
  color: #1e40af;
}

.email-instructions li {
  margin-bottom: 10px;
  line-height: 1.5;
}

.email-instructions a {
  color: #2563eb;
  text-decoration: underline;
}

.email-instructions a:hover {
  color: #1d4ed8;
}

.email-config-form {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
}

.email-config-form .form-group {
  margin-bottom: 15px;
}

.email-config-form .form-group:last-of-type {
  margin-bottom: 20px;
}

.email-config-actions {
  display: flex;
  gap: 10px;
}

.email-config-actions .btn {
  flex: 1;
}

/* Dark mode email config */
[data-theme="dark"] .email-instructions {
  background: #1e3a5f;
  border-color: #2563eb;
}

[data-theme="dark"] .email-instructions h4 {
  color: #60a5fa;
}

[data-theme="dark"] .email-instructions ol {
  color: #93c5fd;
}

[data-theme="dark"] .email-instructions a {
  color: #93c5fd;
}

/* ========================================
   Email Template Editor Styles
   ======================================== */

.section-description {
  color: var(--text-tertiary);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.template-selector {
  margin-bottom: 20px;
}

.template-editor {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
}

.template-info {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border-color);
}

.template-info h4 {
  color: var(--text-primary);
  margin-bottom: 5px;
  font-size: 1.1rem;
}

.template-description {
  color: var(--text-tertiary);
  font-size: 0.9rem;
  margin: 0;
}

.placeholders-section {
  margin-bottom: 20px;
}

.placeholders-section h5 {
  color: var(--text-tertiary);
  font-size: 0.85rem;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.placeholders-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.placeholder-tag {
  background: var(--border-color);
  color: var(--text-primary);
  padding: 4px 10px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.placeholder-tag:hover {
  background: var(--btn-primary-bg);
  color: white;
  border-color: var(--btn-primary-bg);
}

.template-editor .form-group {
  margin-bottom: 15px;
}

.template-editor .form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.template-editor input[type="text"],
.template-editor textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.95rem;
  box-sizing: border-box;
}

.template-editor textarea {
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.85rem;
  resize: vertical;
  min-height: 200px;
}

.template-editor input[type="text"]:focus,
.template-editor textarea:focus {
  border-color: var(--btn-primary-bg);
}

.template-preview-section {
  margin: 20px 0;
  padding: 15px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.template-preview-section h5 {
  color: var(--text-tertiary);
  font-size: 0.85rem;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.preview-subject {
  font-weight: 600;
  color: var(--text-primary);
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  margin-bottom: 10px;
  min-height: 20px;
}

.preview-subject:empty::before {
  content: 'Subject preview will appear here';
  color: var(--text-muted);
  font-weight: normal;
  font-style: italic;
}

.preview-body {
  padding: 15px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  min-height: 100px;
  max-height: 300px;
  overflow-y: auto;
  color: var(--text-primary);
}

.preview-body:empty::before {
  content: 'Click "Preview" to see rendered template';
  color: var(--text-muted);
  font-style: italic;
}

.template-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.template-actions .btn {
  flex: 1;
  min-width: 100px;
}

.btn-danger-outline {
  background: transparent;
  color: var(--danger-color);
  border: 2px solid var(--danger-color);
}

.btn-danger-outline:hover {
  background: var(--danger-color);
  color: white;
}

/* Dark mode for template editor */
[data-theme="dark"] .template-editor input[type="text"],
[data-theme="dark"] .template-editor textarea {
  background: #0f172a;
}

[data-theme="dark"] .template-preview-section {
  background: #0f172a;
}

[data-theme="dark"] .btn-danger-outline {
  color: #f87171;
  border-color: #f87171;
}

[data-theme="dark"] .btn-danger-outline:hover {
  background: #f87171;
  color: #0f172a;
}

/* Responsive Settings Modal */
@media (max-width: 768px) {
  .settings-modal-content {
    width: 95%;
    max-height: 95vh;
    padding: 20px;
  }

  .settings-section h3 {
    font-size: 1.1rem;
  }

  .backup-status-card {
    padding: 15px;
  }

  .status-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }

  .backup-item {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .btn-restore {
    margin-left: 0;
    width: 100%;
  }

  .backup-list {
    max-height: 250px;
  }

  /* Template editor responsive */
  .template-actions {
    flex-direction: column;
  }

  .template-actions .btn {
    width: 100%;
  }

  .placeholders-list {
    gap: 5px;
  }

  .placeholder-tag {
    font-size: 0.8rem;
    padding: 3px 8px;
  }

  .template-editor textarea {
    min-height: 150px;
  }

  /* History modal responsive */
  .history-modal-content {
    padding: 20px;
  }

  .period-card {
    padding: 15px;
  }

  .period-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .period-dates {
    font-size: 1rem;
  }

  .period-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .period-dates-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .period-actions {
    width: 100%;
    flex-direction: column;
  }

  .btn-icon-export,
  .btn-icon-compare {
    width: 100%;
    justify-content: center;
  }

  .compare-modal-content {
    padding: 20px;
  }

  .comparison-container {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .comparison-divider {
    display: none;
  }

  .comparison-details-toggle .btn {
    width: 100%;
  }

  .category-comparison-container {
    overflow-x: auto;
  }

  .comparison-table {
    font-size: 0.85rem;
  }

  .comparison-table th,
  .comparison-table td {
    padding: 8px;
    white-space: nowrap;
  }

  .category-row {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
  }

  .category-row .category-name {
    font-size: 1rem;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
  }

  .category-row .category-value {
    display: flex;
    justify-content: space-between;
    text-align: left;
  }

  .category-row .category-value::before {
    font-weight: 600;
    color: var(--text-secondary);
  }

  .category-row .category-value.allocated::before {
    content: 'Allocated: ';
  }

  .category-row .category-value.spent::before {
    content: 'Spent: ';
  }

  .category-row .category-value.remaining::before {
    content: 'Remaining: ';
  }

  .section-summary {
    flex-direction: column;
    gap: 6px;
  }
}

/* ========================================
   Search Modal Styles
   ======================================== */

.search-modal-content {
  max-width: 900px;
}

.search-filters {
  margin-bottom: 20px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 15px;
}

.filter-group label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.filter-group input,
.filter-group select {
  padding: 10px 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.2s ease;
}

.filter-group input:focus,
.filter-group select:focus {
  border-color: var(--btn-primary-bg);
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-bottom: 15px;
}

.filter-actions {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.filter-actions button {
  flex: 1;
  padding: 10px;
  margin-bottom: 0;
}

/* Search Summary */
.search-summary {
  display: flex;
  gap: 30px;
  padding: 15px 20px;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: 10px;
  margin-bottom: 20px;
}

.summary-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.summary-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Search Results */
.search-results {
  min-height: 300px;
  max-height: 500px;
  overflow-y: auto;
  padding: 10px;
  background: var(--bg-secondary);
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

.search-results::-webkit-scrollbar {
  width: 8px;
}

.search-results::-webkit-scrollbar-track {
  background: var(--bg-primary);
  border-radius: 4px;
}

.search-results::-webkit-scrollbar-thumb {
  background: var(--btn-primary-bg);
  border-radius: 4px;
}

.placeholder-text {
  text-align: center;
  color: var(--text-secondary);
  padding: 60px 20px;
  font-size: 1rem;
}

.error-text {
  text-align: center;
  color: var(--danger-color);
  padding: 60px 20px;
  font-size: 1rem;
}

/* Search Results List */
.search-results-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.search-date-group {
  background: var(--bg-primary);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.search-date-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.search-date {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.search-date-total {
  font-weight: 700;
  color: var(--btn-primary-bg);
  font-size: 1.05rem;
}

.search-transactions {
  display: flex;
  flex-direction: column;
}

.search-transaction {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.2s ease;
}

.search-transaction:last-child {
  border-bottom: none;
}

.search-transaction:hover {
  background: var(--bg-secondary);
}

.search-txn-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.search-txn-category {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.search-txn-description {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-style: italic;
}

.search-txn-author {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.search-txn-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 15px;
}

.search-txn-amount {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 1.05rem;
}

.search-txn-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.search-transaction:hover .search-txn-actions {
  opacity: 1;
}

.btn-icon {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-secondary);
  border-color: var(--border-color);
}

.btn-delete-txn:hover {
  color: var(--danger-color, #e74c3c);
}

/* Inline edit form for transactions */
.search-transaction.editing {
  padding: 10px 15px;
}

.edit-txn-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.edit-txn-fields {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.edit-txn-fields select,
.edit-txn-fields input {
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
}

.edit-txn-category {
  flex: 1;
  min-width: 120px;
}

.edit-txn-amount {
  width: 100px;
}

.edit-txn-description {
  flex: 2;
  min-width: 140px;
}

.edit-txn-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .search-modal-content {
    max-width: 95%;
    padding: 20px;
  }

  .filter-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .filter-actions {
    flex-direction: column;
  }

  .filter-actions button {
    width: 100%;
  }

  .search-summary {
    flex-direction: column;
    gap: 15px;
  }

  .search-results {
    max-height: 400px;
  }

  .search-transaction {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .search-txn-right {
    align-self: flex-end;
    margin-left: 0;
  }

  .search-txn-actions {
    opacity: 1;
  }

  .edit-txn-fields {
    flex-direction: column;
  }

  .edit-txn-amount {
    width: 100%;
  }
}

/* ==================
   User Menu Styles
   ================== */

.btn-user {
  position: relative;
}

.user-menu-dropdown {
  position: fixed;
  top: 60px;
  right: 20px;
  background: var(--bg-primary);
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  min-width: 200px;
  z-index: 1000;
  overflow: hidden;
}

.user-menu-header {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-menu-header span:first-child {
  font-weight: 600;
  color: var(--text-primary);
}

.user-role-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  background: var(--section-household-light);
  color: #2f4d70;
  border-radius: 9999px;
  text-transform: capitalize;
}

.user-role-badge.admin {
  background: var(--section-jason-light);
  color: #71480f;
}

.user-menu-divider {
  height: 1px;
  background: var(--border-color);
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-primary);
  text-align: left;
  transition: background 0.15s;
}

.user-menu-item:hover {
  background: var(--bg-tertiary);
}

.user-menu-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.user-menu-logout {
  color: #dc2626;
}

.user-menu-logout:hover {
  background: #f9dddd;
}

/* Loading overlay for auth check */
.auth-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.auth-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==================
   User Management Styles
   ================== */

.user-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  gap: 15px;
}

.user-item:hover {
  background: var(--bg-tertiary);
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.user-name {
  font-weight: 600;
  color: var(--text-primary);
}

.user-email {
  font-size: 0.85rem;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem;
  padding: 2px 8px;
  background: var(--section-household-light);
  color: #2f4d70;
  border-radius: 9999px;
  text-transform: capitalize;
  display: inline-block;
  margin-top: 4px;
}

.user-role.admin {
  background: var(--section-jason-light);
  color: #71480f;
}

.user-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.user-actions button {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.user-actions .btn-danger {
  background: #f9dddd;
  color: #8f2626;
  border: 1px solid #efb4b4;
}

.user-actions .btn-danger:hover {
  background: #f5c7c7;
}

.form-help {
  display: block;
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* Mobile responsive for user management */
@media (max-width: 600px) {
  .user-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .user-actions {
    width: 100%;
    margin-top: 10px;
  }

  .user-actions button {
    flex: 1;
  }
}

/* ==================
   Notifications Styles
   ================== */

.btn-notifications {
  position: relative;
}

.notifications-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--danger-color);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.notifications-panel {
  position: fixed;
  top: 60px;
  right: 80px;
  background: var(--bg-primary);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  width: 380px;
  max-width: calc(100vw - 40px);
  max-height: 500px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notifications-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-color);
}

.notifications-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.btn-text {
  background: none;
  border: none;
  color: var(--brand-primary);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.btn-text:hover {
  background: var(--bg-tertiary);
}

.notifications-list {
  flex: 1;
  overflow-y: auto;
  max-height: 380px;
}

.notifications-loading,
.notifications-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-tertiary);
}

.notification-item {
  padding: 15px 20px;
  border-bottom: 1px solid var(--bg-tertiary);
  cursor: pointer;
  transition: background 0.15s;
}

.notification-item:hover {
  background: var(--bg-secondary);
}

.notification-item.unread {
  background: rgba(122, 167, 255, 0.1);
  border-left: 3px solid var(--brand-primary);
}

.notification-item.unread:hover {
  background: rgba(122, 167, 255, 0.15);
}

.notification-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.notification-message {
  color: var(--text-tertiary);
  font-size: 0.85rem;
  line-height: 1.4;
  margin-bottom: 6px;
}

.notification-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.notifications-footer {
  padding: 10px 15px;
  border-top: 1px solid var(--border-color);
  text-align: center;
}

/* Mobile responsive for notifications */
@media (max-width: 480px) {
  .notifications-panel {
    right: 10px;
    width: calc(100vw - 20px);
  }
}

/* ========================================
   Notification Preferences
   ======================================== */

.notification-prefs-list {
  max-height: 400px;
  overflow-y: auto;
}

.notification-pref-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  border-bottom: 1px solid var(--border-color);
}

.notification-pref-item:last-child {
  border-bottom: none;
}

.notification-pref-info {
  flex: 1;
  margin-right: 20px;
}

.notification-pref-name {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.notification-pref-description {
  font-size: 0.85rem;
  color: var(--text-tertiary);
}

.notification-pref-toggles {
  display: flex;
  gap: 20px;
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-group label {
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color-hover);
  transition: 0.3s;
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--brand-primary);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

/* ========================================
   Modal Variants
   ======================================== */

.modal-medium .modal-content {
  max-width: 500px;
}

.modal-large .modal-content {
  max-width: 700px;
}

.modal-description {
  color: var(--text-tertiary);
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 20px;
  margin-top: 20px;
  border-top: 1px solid var(--border-color);
}

.form-divider {
  height: 1px;
  background: var(--border-color);
  margin: 24px 0;
}

.form-message {
  padding: 12px 16px;
  border-radius: 8px;
  margin-top: 16px;
  font-size: 0.9rem;
}

.form-message.error {
  background: #f9dddd;
  color: #8f2626;
  border: 1px solid #efb4b4;
}

.form-message.success {
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
}

[data-theme="dark"] .form-message.error {
  background: rgba(220, 38, 38, 0.1);
  border-color: rgba(220, 38, 38, 0.3);
}

[data-theme="dark"] .form-message.success {
  background: rgba(22, 163, 74, 0.1);
  border-color: rgba(22, 163, 74, 0.3);
}

.form-row {
  display: flex;
  gap: 15px;
}

.form-row .form-group {
  flex: 1;
}

.checkbox-group {
  display: flex;
  align-items: center;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--brand-primary);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--border-color);
}

.btn-small {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.btn-small svg {
  margin-right: 6px;
  vertical-align: middle;
}

/* ========================================
   Tab Bar
   ======================================== */


.tab-bar {
  display: flex;
  gap: 0;
  background: var(--bg-primary);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  position: sticky;
  top: 10px;
  z-index: 150;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  box-shadow: var(--shadow-sm);
}

.tab-btn svg {
  flex-shrink: 0;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  animation: tabFadeIn 0.3s ease;
}

@keyframes tabFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   Charts
   ======================================== */

.chart-wrapper {
  position: relative;
  height: 280px;
}

.chart-wrapper-small {
  height: 200px;
}

/* Dark Mode Card Hover Shadows */
[data-theme="dark"] .category-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Exclude-from-saved icon */
.exclude-saved-icon {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  color: var(--text-secondary);
  opacity: 0.6;
  vertical-align: middle;
}

/* ========================================
   Tab Bar and Charts Responsive
   ======================================== */

@media (max-width: 768px) {
  /* The label stays under the icon: three icons alone are a guessing game */
  .tab-btn {
    flex-direction: column;
    gap: 2px;
    padding: 6px 4px;
    font-size: 0.7rem;
    line-height: 1.1;
  }

  .tab-btn span {
    display: block;
  }

  .chart-wrapper {
    height: 200px;
  }
}

@keyframes menuFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   Link and Danger Buttons
   ======================================== */

.btn-link {
  background: none;
  border: none;
  color: var(--brand-primary-dark);
  font-size: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
  font-weight: 600;
}

/* Danger button variant */
.btn.btn-danger {
  background: var(--danger-color);
  color: white;
  border-color: var(--danger-color);
}

.btn.btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
}

/* ========================================
   Mobile Overflow Menu
   ======================================== */

.mobile-menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mobile-menu-toggle svg {
  width: 22px;
  height: 22px;
}

.mobile-menu-toggle:hover {
  background: var(--bg-tertiary);
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex;
  }

  .header-actions {
    display: none;
    flex-direction: column;
    width: 100%;
    gap: 6px;
  }

  .header-actions.open {
    display: flex;
  }

  .header-actions .btn-header {
    min-width: unset;
    width: 100%;
    justify-content: flex-start;
  }
}

/* ========================================
   Loading Spinner Overlay
   ======================================== */

.app-loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  transition: opacity 0.3s ease;
}

.app-loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.app-loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.app-loading-text {
  color: white;
  margin-top: 16px;
  font-size: 1rem;
  font-weight: 500;
}

/* ========================================
   Settings Tabs
   ======================================== */

.settings-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 24px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.settings-tab-btn {
  padding: 10px 16px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s ease;
}

.settings-tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-secondary);
}

.settings-tab-btn.active {
  color: var(--btn-primary-bg);
  border-bottom-color: var(--btn-primary-bg);
}

.settings-tab-content {
  display: none;
}

.settings-tab-content.active {
  display: block;
}

/* ========================================
   Funds Summary Redesign
   ======================================== */

.funds-summary-redesigned {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.funds-card {
  background: var(--bg-primary);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
  border: 1px solid var(--border-color);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.funds-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.funds-card-label {
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.funds-card-amount {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}
.funds-card.remaining .funds-card-amount { color: var(--brand-primary); }
.funds-card.remaining.warning .funds-card-amount { color: #f59e0b; }
.funds-card.remaining.danger .funds-card-amount { color: var(--danger-color); }
@media (max-width: 640px) {
  .funds-summary-redesigned {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  .funds-card-amount { font-size: 1.4rem; }
}
[data-theme="dark"] .funds-card:hover {
  box-shadow: 0 4px 16px rgba(52, 211, 153, 0.1);
}

/* ========================================
   Categories Section Header
   ======================================== */

.categories-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.categories-section-header h2 {
  margin: 0;
}

.categories-section-header .budget-lens-bar {
  margin-bottom: 0;
}

.categories-section-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ========================================
   Period pill: the dates, the days left and a thin bar in one line
   ======================================== */

.budget-period-pill {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.75rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.budget-period-pill .budget-period {
  font-weight: 600;
  color: var(--text-primary);
}
.budget-countdown {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.budget-countdown .countdown-number {
  font-weight: 700;
  color: var(--brand-primary);
}
.budget-countdown.ending-soon .countdown-number {
  color: var(--danger-color);
}
.budget-countdown .countdown-bar {
  width: 72px;
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  overflow: hidden;
}
.budget-countdown .countdown-bar-fill {
  height: 100%;
  background: var(--brand-primary);
  border-radius: 3px;
  transition: width 0.5s ease;
}
.budget-countdown.ending-soon .countdown-bar-fill {
  background: var(--danger-color);
}

/* ========================================
   FAB (Floating Action Button) - Mobile Only
   ======================================== */

.fab-add-expense {
  display: none;
  position: fixed;
  bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  right: 1.5rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--brand-primary);
  color: white;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
  z-index: 100;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  align-items: center;
  justify-content: center;
}
.fab-add-expense:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
}
.fab-add-expense:active { transform: scale(0.95); }
@media (max-width: 768px) {
  .fab-add-expense { display: flex; }
  /* The Budget tab's hero has its own Add expense; elsewhere the page ends above the button */
  body[data-tab="budget"] .fab-add-expense { display: none; }
  main { padding-bottom: calc(56px + 3rem + env(safe-area-inset-bottom, 0px)); }
}
[data-theme="dark"] .fab-add-expense {
  box-shadow: 0 4px 12px rgba(52, 211, 153, 0.3);
}

/* ========================================
   Command Palette
   ======================================== */

.command-palette {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
  animation: modalFadeIn 0.15s ease;
}
.command-palette.active { display: flex; }
.command-palette-box {
  background: var(--bg-primary);
  border-radius: 12px;
  width: 90%;
  max-width: 520px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  animation: modalSlideUp 0.2s ease;
}
.command-palette-input {
  width: 100%;
  padding: 1rem 1.25rem;
  border: none;
  border-bottom: 1px solid var(--border-color);
  font-size: 1rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  box-sizing: border-box;
}
.command-palette-input::placeholder { color: var(--text-muted); }
.command-palette-results {
  max-height: 300px;
  overflow-y: auto;
  padding: 0.5rem;
}
.command-result-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  color: var(--text-primary);
}
.command-result-item:hover,
.command-result-item.selected {
  background: var(--brand-primary-50);
}
.command-result-item .command-icon {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  background: var(--bg-secondary);
  font-size: 0.9rem;
}
.command-result-item .command-label { font-weight: 500; }
.command-result-item .command-shortcut {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
}
.command-palette-hint {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  text-align: center;
}

/* ========================================
   Recent Category Pills (Fast Entry)
   ======================================== */

.recent-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.recent-pill {
  padding: 0.375rem 0.75rem;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.recent-pill:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
  background: var(--brand-primary-50);
}

/* ========================================
   Empty State Illustrations
   ======================================== */

.empty-state-illustrated {
  text-align: center;
  padding: 3rem 1.5rem;
}
.empty-state-illustrated svg {
  width: 120px; height: 120px;
  margin-bottom: 1.5rem;
  opacity: 0.6;
}
.empty-state-illustrated h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}
.empty-state-illustrated p {
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 300px;
  margin: 0 auto 1.25rem;
}

/* ========================================
   Budget Cockpit
   ======================================== */

.cockpit-summary {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(0, 1.4fr);
  gap: 0;
  overflow: hidden;
  padding: 0;
}

.cockpit-summary:has(.funds-value.zero),
.funds-summary.cockpit-summary {
  background: var(--bg-primary);
}

.cockpit-hero {
  background: linear-gradient(145deg, var(--hero-start) 0%, var(--hero-end) 100%);
  color: #ffffff;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.4rem;
  min-height: 210px;
}

.cockpit-summary.needs-attention .cockpit-hero {
  background: linear-gradient(145deg, var(--hero-attention-start) 0%, var(--hero-attention-end) 100%);
}

.cockpit-kicker,
.safe-to-spend-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.95;
}

.safe-to-spend-value {
  font-size: 2.5rem;
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: 0;
  word-break: break-word;
}

.safe-to-spend-subcopy {
  font-size: 0.94rem;
  line-height: 1.4;
  opacity: 0.9;
}

.cockpit-action {
  align-self: flex-start;
  margin-top: 0.65rem;
  background: #ffffff;
  color: #07584f;
  border-color: rgba(255, 255, 255, 0.72);
}

.cockpit-action:hover:not(:disabled) {
  background: #f7faf8;
  color: #07584f;
}

.cockpit-action:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.cockpit-detail-panel {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
}

.cockpit-metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.cockpit-metric {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.9rem;
  min-width: 0;
}

.cockpit-metric-label {
  display: block;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.3rem;
}

.cockpit-metric strong {
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.cockpit-metric strong.negative {
  color: var(--danger-color);
}

.cockpit-attention {
  background: var(--brand-primary-50);
  border: 1px solid var(--brand-primary-light);
  border-radius: 8px;
  color: var(--brand-primary-dark);
  font-weight: 700;
  line-height: 1.45;
  padding: 0.85rem 1rem;
}

.cockpit-attention.needs-review {
  background: #f7ecd8;
  border-color: #e7c98d;
  color: #71480f;
}

.cockpit-loading {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem;
  color: var(--text-secondary);
}

.loading-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--brand-primary);
  animation: pulse 1.2s ease-in-out infinite;
}

.budget-error-panel {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem;
  background: #f9dddd;
  color: #8f2626;
}

.budget-error-panel strong,
.budget-error-panel p {
  display: block;
  margin-top: 0.25rem;
}

.budget-error-panel p {
  color: #8f2626;
  font-size: 0.9rem;
  line-height: 1.45;
}

.budget-error-kicker {
  display: block;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.envelope-skeleton {
  min-height: 130px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: linear-gradient(90deg, var(--bg-secondary), var(--bg-tertiary), var(--bg-secondary));
  background-size: 200% 100%;
  animation: skeletonSweep 1.5s ease-in-out infinite;
}

@keyframes skeletonSweep {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.envelope-card {
  --category-spend-pct: 0%;
  --category-spend-soft: rgba(15, 138, 123, 0.07);
  --category-spend-strong: rgba(15, 138, 123, 0.18);
  border-radius: 8px;
  padding: 18px;
  background:
    linear-gradient(
      100deg,
      var(--category-spend-soft) 0%,
      var(--category-spend-strong) var(--category-spend-pct),
      transparent var(--category-spend-pct),
      transparent 100%
    ),
    var(--bg-primary);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-height: 190px;
  isolation: isolate;
  position: relative;
}

.envelope-card.spend-close {
  --category-spend-soft: rgba(161, 98, 7, 0.08);
  --category-spend-strong: rgba(231, 184, 93, 0.24);
}

/* Fully spent (spent equals assigned, remaining $0.00) is the plan working: the
   card green, carried across the whole card. Only overspending is red. */
.envelope-card.spend-spent {
  --category-spend-soft: rgba(15, 138, 123, 0.12);
  --category-spend-strong: rgba(15, 138, 123, 0.26);
}

.envelope-card.spend-over {
  --category-spend-soft: rgba(210, 79, 69, 0.1);
  --category-spend-strong: rgba(239, 68, 68, 0.26);
}

[data-theme="dark"] .envelope-card {
  --category-spend-soft: rgba(52, 211, 153, 0.1);
  --category-spend-strong: rgba(52, 211, 153, 0.24);
}

[data-theme="dark"] .envelope-card.spend-close {
  --category-spend-soft: rgba(246, 180, 75, 0.12);
  --category-spend-strong: rgba(246, 180, 75, 0.28);
}

[data-theme="dark"] .envelope-card.spend-spent {
  --category-spend-soft: rgba(52, 211, 153, 0.16);
  --category-spend-strong: rgba(52, 211, 153, 0.32);
}

[data-theme="dark"] .envelope-card.spend-over {
  --category-spend-soft: rgba(248, 113, 113, 0.14);
  --category-spend-strong: rgba(248, 113, 113, 0.32);
}

.envelope-card.envelope-overspent {
  border-color: #efb4b4;
}

.envelope-header {
  align-items: flex-start;
  flex-wrap: nowrap;
  margin-bottom: 0;
}

.envelope-title-block {
  min-width: 0;
}

.envelope-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  position: relative;
}

.envelope-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(130px, auto);
  align-items: end;
  gap: 0.75rem;
}

.envelope-primary-amount {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}

.envelope-primary-amount strong {
  font-size: 1.45rem;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.envelope-primary-amount.positive strong {
  color: var(--success-color);
}

.envelope-primary-amount.warning strong {
  color: var(--warning-color);
}

.envelope-primary-amount.negative strong {
  color: var(--danger-color);
}

.envelope-money-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.envelope-money-grid div {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 0.55rem;
}

.envelope-money-grid span {
  display: block;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.2rem;
}

.envelope-money-grid strong {
  color: var(--text-primary);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.envelope-section-header {
  border-bottom: 1px solid var(--border-color);
  justify-content: space-between;
  padding-bottom: 0.75rem;
}

.envelope-section-header h3 {
  color: inherit;
  font-size: 1rem;
  margin: 0;
}

.envelope-section-header span {
  color: var(--text-muted);
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 0.15rem;
}

.section-balance {
  text-align: right;
}

.section-balance strong {
  display: block;
  font-size: 1rem;
}

.section-balance.positive strong {
  color: var(--success-color);
}

.section-balance.negative strong {
  color: var(--danger-color);
}

.family-activity {
  align-items: center;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  display: inline-flex;
  gap: 0.55rem;
  min-height: 32px;
  padding: 0.25rem 0.6rem;
}

.family-activity-label {
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 700;
}

.activity-avatars {
  display: inline-flex;
  gap: 0.25rem;
}

@media (max-width: 760px) {
  .cockpit-summary {
    grid-template-columns: 1fr;
  }

  .cockpit-hero {
    min-height: auto;
  }

  .safe-to-spend-value {
    font-size: 2rem;
  }

  .envelope-body {
    grid-template-columns: 1fr;
  }

  /* Three tiles stay in one row on a phone: the type scales with the width
     so an amount never breaks across two lines */
  .cockpit-metrics-grid {
    gap: 0.5rem;
  }
  .cockpit-metric {
    padding: 0.6rem 0.45rem;
  }
  .cockpit-metric-label {
    font-size: clamp(0.6rem, 2.9vw, 0.76rem);
    letter-spacing: 0.03em;
  }
  .cockpit-metric strong {
    font-size: clamp(0.8rem, 3.6vw, 1rem);
    white-space: nowrap;
    letter-spacing: -0.01em;
  }

  .budget-error-panel {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* ========================================
   Milestone Celebration & Confetti
   ======================================== */

.celebration-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 9999;
}
@keyframes confettiFall {
  0% { transform: translateY(-100%) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
.confetti-piece {
  position: absolute;
  width: 10px; height: 10px;
  top: -10px;
  animation: confettiFall 3s ease-in forwards;
}
.milestone-badge {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: var(--bg-primary);
  border-radius: 16px;
  padding: 2rem;
  text-align: center;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
  z-index: 10000;
  pointer-events: auto;
  animation: badgePop 0.5s ease forwards;
}
@keyframes badgePop {
  0% { transform: translate(-50%, -50%) scale(0); }
  50% { transform: translate(-50%, -50%) scale(1.1); }
  100% { transform: translate(-50%, -50%) scale(1); }
}
.milestone-badge h2 {
  font-size: 1.5rem; margin-bottom: 0.5rem; color: var(--text-primary);
}
.milestone-badge p { color: var(--text-muted); margin-bottom: 1rem; }
.milestone-badge .milestone-icon { font-size: 3rem; margin-bottom: 1rem; }

/* ========================================
   Streak Counter
   ======================================== */

.streak-counter {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  background: var(--brand-primary-50);
  color: var(--brand-primary);
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* ========================================
   Header Tools Dropdown
   ======================================== */

.header-tools-dropdown { position: relative; }
.tools-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--bg-primary);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-color);
  padding: 0.375rem;
  min-width: 180px;
  display: none;
  z-index: 200;
  animation: modalSlideUp 0.15s ease;
}
.tools-menu.open { display: block; }
.tools-menu-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-primary);
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  transition: background 0.15s ease;
}

/* An item that is not on offer (the loans goal once it is tracked) takes no room: display:flex above would beat [hidden] */
.tools-menu-item[hidden] { display: none; }
.tools-menu-item:hover { background: var(--bg-secondary); }
.tools-menu-item svg { width: 16px; height: 16px; opacity: 0.7; }

/* ========================================
   Search Progressive Disclosure
   ======================================== */

.search-advanced-toggle {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0;
  color: var(--brand-primary);
  font-size: 0.85rem;
  cursor: pointer;
  background: none;
  border: none;
  margin-top: 0.5rem;
}
.search-advanced-toggle svg {
  width: 16px; height: 16px;
  transition: transform 0.2s ease;
}
.search-advanced-toggle.expanded svg { transform: rotate(180deg); }
.search-advanced-fields {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.search-advanced-fields.expanded { max-height: 500px; }

/* ========================================
   Inline Validation Error Styles
   ======================================== */

.field-error {
  color: var(--danger-color);
  font-size: 0.82rem;
  font-weight: 500;
  margin-top: 4px;
  display: none;
}

.field-error.visible {
  display: block;
}

input.invalid,
select.invalid {
  border-color: var(--danger-color) !important;
}

/* ========================================
   Touch Target Improvements
   ======================================== */

/* Modal close buttons - ensure minimum 44x44px touch target */
.modal-close,
.modal-content .close-btn,
.modal .close,
button[aria-label="Close"] {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Modal close X button - left-aligned in header */
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Small icon buttons - ensure minimum touch target */
.btn-remove-category,
.btn-reorder-category {
  min-width: 28px;
  min-height: 28px;
}

/* Budget notes edit button - increase touch target */
.budget-notes-edit-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Notification badge buttons */
.btn-text {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ========================================
   Reduced Motion Support
   ======================================== */

/* ========================================
   Static Category (Saved) — Form Row
   ======================================== */

.static-category {
  position: relative;
  border-left: 3px solid var(--success-color);
}

.static-category .cat-name {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.static-badge {
  display: inline-flex;
  align-items: center;
  background: var(--success-color);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}


/* ========================================
   Behavioral Reinforcement Features
   ======================================== */

/* Feature 3: Cooling-Off Nudge */
.cooling-off-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
  animation: modalFadeIn 0.2s ease;
}

.cooling-off-card {
  background: var(--bg-primary);
  border-radius: 16px;
  padding: 30px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  animation: slideUpCard 0.3s ease;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

@keyframes slideUpCard {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.cooling-off-card .cooling-off-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.cooling-off-card h3 {
  margin: 0 0 8px 0;
  color: var(--text-primary);
}

.cooling-off-card p {
  margin: 0 0 20px 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

.cooling-off-actions {
  display: flex;
  gap: 10px;
}

.cooling-off-actions .btn {
  flex: 1;
}

/* Recovery framing for an envelope over its limit */
.amount-row.recovery-framing {
  background: rgba(161, 98, 7, 0.08);
  border-radius: 6px;
  padding: 4px 6px;
  margin-top: 4px;
}

.amount-row.recovery-framing .amount-label {
  color: var(--warning-color);
  font-weight: 600;
  font-size: 0.8rem;
}

.amount-row.recovery-framing .amount-value {
  color: var(--warning-color);
  font-size: 0.8rem;
}

/* Money Date Check-in */
.money-date-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-secondary);
  border: 2px solid var(--brand-primary);
  border-radius: 16px;
  padding: 24px;
  max-width: 420px;
  width: 90%;
  z-index: 10001;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.money-date-card > h3 {
  margin: 0 0 8px 0;
  font-size: 1.2rem;
  text-align: center;
}

.money-date-card > p {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin: 0 0 16px 0;
}

.money-date-section {
  margin-bottom: 12px;
}

.money-date-section h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 0 0 6px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.money-date-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 3px 0;
}

.money-date-empty {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 4px 0;
}

.money-date-streak {
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--brand-primary);
  padding: 8px;
  background: var(--bg-primary);
  border-radius: 8px;
}

/* Feature 18: Family Activity */
.family-activity {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}

.activity-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  background: var(--success-color);
  border: 2px solid transparent;
  cursor: default;
}

.activity-dot.stale {
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  border: 2px dashed var(--border-color);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==================
   Recurring Transactions
   ================== */

.recurring-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-height: 400px;
  overflow-y: auto;
}

.recurring-item {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  transition: all 0.2s ease;
}

.recurring-item:hover {
  border-color: var(--brand-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.recurring-item-paused {
  opacity: 0.65;
}

.recurring-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.recurring-description {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 1.05rem;
}

.recurring-paused-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: rgba(251, 191, 36, 0.12);
  color: #b45309;
  border: 1px solid rgba(251, 191, 36, 0.35);
  vertical-align: middle;
}

[data-theme="dark"] .recurring-paused-badge {
  color: #fbbf24;
}

.recurring-details {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.recurring-detail {
  display: flex;
  align-items: center;
  gap: 5px;
}

.recurring-detail strong {
  color: var(--text-primary);
}

.recurring-amount {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--brand-primary);
  white-space: nowrap;
}

.recurring-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.recurring-actions button {
  padding: 6px 12px;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* Mobile Responsive for Recurring */
@media (max-width: 768px) {
  .recurring-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .recurring-amount {
    align-self: flex-end;
    margin-top: -10px;
  }

  .recurring-actions {
    width: 100%;
    justify-content: stretch;
  }

  .recurring-actions button {
    flex: 1;
  }
}

.date-outside-period-warning {
  display: block;
  margin-top: 6px;
  color: #b45309;
  font-size: 0.82rem;
}

[data-theme="dark"] .date-outside-period-warning {
  color: #fbbf24;
}

.edit-txn-date {
  min-width: 130px;
}

/* ==================
   Budget Time Lenses
   ================== */

.budget-lens-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 4px;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
@media (max-width: 480px) {
  /* Four options as a 2×2 grid: nothing hides off the edge of the screen */
  .budget-lens-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    overflow: visible;
  }
  .lens-btn { white-space: normal; padding: 8px 6px; }
}

.lens-btn {
  border: none;
  background: transparent;
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.lens-btn:hover {
  color: var(--text-primary);
}

.lens-btn.active {
  background: var(--bg-primary);
  color: var(--brand-primary-dark);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.lens-summary {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 18px;
}

.lens-summary-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.lens-summary-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.lens-range {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.lens-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.lens-summary-grid > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lens-summary-grid span {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.lens-summary-grid strong {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.lens-summary-grid strong.negative,
.lens-row-amounts strong.negative {
  color: #dc2626;
}

.lens-caption {
  margin: 12px 0 0;
  font-size: 0.83rem;
  color: var(--text-muted);
}

.lens-section {
  margin-bottom: 18px;
}

.lens-section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.lens-section-header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.lens-section-totals {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.lens-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 2fr minmax(170px, auto);
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--bg-primary);
}

.lens-row.lens-over {
  border-color: rgba(220, 38, 38, 0.4);
}

.lens-row-name {
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lens-row-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--bg-secondary);
  overflow: hidden;
}

.lens-row-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--brand-primary);
}

.lens-over .lens-row-fill {
  background: #dc2626;
}

.lens-row-amounts {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.lens-row-amounts strong {
  color: var(--text-primary);
  font-size: 0.88rem;
}

@media (max-width: 640px) {
  .lens-row {
    grid-template-columns: 1fr auto;
  }
  .lens-row-bar {
    display: none;
  }
}

/* ==================
   Category Drill-Down
   ================== */

.category-detail-header {
  padding: 4px 0 14px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 14px;
}

.category-detail-caption {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.category-detail-remaining-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.category-detail-remaining {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--brand-primary-dark);
}

.category-detail-remaining.negative {
  color: #dc2626;
}

.category-detail-pill {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.pill-ok { background: rgba(15, 138, 123, 0.12); color: var(--brand-primary-dark); }
.pill-watch { background: rgba(251, 191, 36, 0.15); color: #b45309; }
.pill-over { background: rgba(220, 38, 38, 0.12); color: #b91c1c; }

[data-theme="dark"] .pill-watch { color: #fbbf24; }
[data-theme="dark"] .pill-over { color: #fca5a5; }

/* Soft status tints with values a dark screen can read */
[data-theme="dark"] .cockpit-attention.needs-review { background: rgba(246, 180, 75, 0.14); border-color: rgba(246, 180, 75, 0.45); color: #f6d28c; }
[data-theme="dark"] .validation-success { background: rgba(52, 211, 153, 0.14); border-color: rgba(52, 211, 153, 0.4); color: #9ee7d7; }
[data-theme="dark"] .validation-warning,
[data-theme="dark"] .allocation-summary.under-budget { background: rgba(246, 180, 75, 0.14); border-color: rgba(246, 180, 75, 0.4); color: #f6d28c; }
[data-theme="dark"] .validation-error,
[data-theme="dark"] .allocation-summary.over-budget,
[data-theme="dark"] .confirmation-dialog .warning,
[data-theme="dark"] .budget-error-panel { background: rgba(248, 113, 113, 0.14); border-color: rgba(248, 113, 113, 0.4); color: #fca5a5; }

.category-detail-progress {
  height: 10px;
  border-radius: 5px;
  background: var(--bg-secondary);
  overflow: hidden;
  margin: 10px 0;
}

.category-detail-progress-fill {
  height: 100%;
  border-radius: 5px;
  background: var(--brand-primary);
  transition: width 0.2s ease;
}

.category-detail-progress-fill.over {
  background: #dc2626;
}

.category-detail-metrics {
  display: flex;
  gap: 18px;
}

.category-detail-metric {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.category-detail-metric span {
  font-size: 0.74rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.category-detail-metric strong {
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
}

.category-detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.category-detail-transactions {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.category-detail-txn {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
}

.category-detail-txn-main {
  min-width: 0;
  overflow-wrap: anywhere;
}

.category-detail-txn-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.category-detail-txn-actions .btn {
  min-height: 36px;
}

.category-detail-txn.editing {
  display: block;
  border-color: var(--brand-primary);
}

.category-detail-txn .edit-txn-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(100px, 0.65fr);
}

.category-detail-txn .edit-txn-fields input,
.category-detail-txn .edit-txn-fields select {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.category-detail-txn .edit-txn-description,
.category-detail-txn .edit-txn-date {
  grid-column: 1 / -1;
}

.category-detail-txn .edit-txn-buttons .btn {
  min-height: 36px;
}

.category-detail-txn-desc {
  font-weight: 600;
  font-size: 0.9rem;
}

.category-detail-txn-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.category-detail-txn-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.category-detail-empty {
  text-align: center;
  padding: 22px 10px;
  color: var(--text-muted);
}

.category-detail-empty-icon {
  font-size: 1.6rem;
  margin-bottom: 6px;
}

.category-detail-empty-title {
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.category-detail-empty-text {
  font-size: 0.85rem;
}

/* Section sort toggle */
.section-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.section-sort-btn {
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.section-sort-btn:hover {
  color: var(--text-primary);
  border-color: var(--brand-primary);
}

.section-sort-btn.active {
  background: rgba(15, 138, 123, 0.1);
  color: var(--brand-primary);
  border-color: var(--brand-primary);
}

/* ==================
   Budget Insights
   ================== */

/* To review: one list for everything that wants a decision */
.review-list {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 14px 8px;
  margin-bottom: 16px;
}
.review-list[hidden] { display: none; }
.review-row { border-radius: 8px; }
.review-row.is-open { background: var(--bg-secondary); }
.review-note .insight-row { cursor: default; color: var(--text-secondary); }
.review-note .insight-row:hover { background: transparent; }
.review-error .insight-row { color: var(--danger-color); }
.review-caret { font-size: 1rem; }
.review-row.is-open .review-caret { transform: rotate(90deg); }
.review-detail {
  padding: 0 6px 12px 34px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.review-detail[hidden] { display: none; }
.review-body { margin: 0; font-size: 0.9rem; line-height: 1.5; color: var(--text-primary); }
.review-detail-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.review-go { font-size: 0.85rem; font-weight: 700; }
.review-quiet { font-size: 0.85rem; color: var(--text-muted); text-decoration: none; }
.review-quiet:hover { color: var(--text-secondary); text-decoration: underline; }

.insights-title {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.insight-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  padding: 8px 6px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-size: 0.88rem;
  color: var(--text-primary);
}

.insight-row:hover {
  background: var(--bg-secondary);
}

.insight-icon {
  flex-shrink: 0;
}

.insight-text {
  flex: 1;
  min-width: 0;
}

.insight-action {
  flex-shrink: 0;
  font-weight: 600;
  color: var(--brand-primary-dark);
  font-size: 0.82rem;
  white-space: nowrap;
}

/* ==================
   Activity Ledger Tab
   ================== */

.activity-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 14px;
}

.activity-summary-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.activity-summary-main strong {
  font-size: 1.05rem;
}

.activity-summary-main span {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.activity-summary-scope {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.activity-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.activity-filters input[type="text"] {
  flex: 2;
  min-width: 160px;
}

.activity-filters select,
.activity-filters input[type="date"] {
  flex: 1;
  min-width: 120px;
}

.activity-day-group {
  margin-bottom: 14px;
}

.activity-day-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 6px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.activity-day-subtotal {
  font-variant-numeric: tabular-nums;
}

.activity-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  margin-bottom: 6px;
}

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

.activity-row-desc {
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activity-row-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.activity-row-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.activity-row-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.activity-row.editing {
  display: block;
}

.activity-more-wrap {
  text-align: center;
  margin-top: 8px;
}

/* Household members modal */
.member-row {
  display: grid;
  grid-template-columns: 80px 1fr 44px;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.member-row label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.member-row input[type="color"] {
  width: 40px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-primary);
  cursor: pointer;
}

/* Drafts tray banner */

/* ========================================
   Modal ✕ close button + Budget Templates
   ======================================== */

.modal-x {
  position: sticky;
  top: 0;
  align-self: flex-end;
  margin: -18px -18px 0 0;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  z-index: 5;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.modal-x:hover {
  background: var(--bg-tertiary, var(--bg-secondary));
  color: var(--text-primary);
  transform: scale(1.08);
}

@keyframes modal-x-pulse {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.35); }
  60% { transform: scale(0.95); }
}

.modal-x-pulse {
  animation: modal-x-pulse 0.6s ease;
}

.templates-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.templates-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.template-list-item {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.template-version-item {
  display: block;
}

.template-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.template-list-name {
  font-weight: 600;
  color: var(--text-primary);
}

.template-list-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.template-default-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-primary, #4a90d9);
  color: #fff;
  vertical-align: middle;
}

.template-list-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.template-editor-section {
  margin-bottom: 18px;
}

.template-cat-row {
  display: grid;
  grid-template-columns: 2fr 1fr 2fr auto;
  gap: 8px;
  margin-bottom: 10px;
  align-items: center;
}

.template-cat-row input {
  min-width: 0;
}

.template-editor-total {
  text-align: right;
  color: var(--text-secondary);
  margin: 10px 0 4px;
}

.template-version-detail {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-secondary);
  font-size: 0.9rem;
}

.template-version-line {
  padding: 2px 0;
  color: var(--text-primary);
}

.template-version-section {
  color: var(--text-secondary);
  font-size: 0.85em;
}

/* ========================================
   Add-to-Template Row Picker
   ======================================== */

.modal-layered {
  z-index: 1100; /* above the Start Fresh wizard (.modal is 1000) */
}

.template-picker-content {
  max-width: 560px;
}

.btn-add-to-template {
  background: none;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  min-height: auto;
  padding: 0;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 1px solid var(--accent-primary, #0f8a7b);
  color: var(--accent-primary, #0f8a7b);
  font-size: 0.9rem;
  font-weight: bold;
}

.btn-add-to-template:hover {
  background: var(--accent-primary, #0f8a7b);
  color: white;
}

.template-picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px 14px;
  background: none;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.template-picker-item:hover {
  border-color: var(--accent-primary, #0f8a7b);
  background: var(--bg-secondary);
}

.picker-checklist-hint {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 12px 0 8px;
}

#picker-row-checklist {
  max-height: 40vh;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 12px;
}

.picker-check-section {
  margin-bottom: 10px;
}

.picker-check-heading {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin: 6px 0 4px;
}

.picker-check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 2px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.picker-check-row input[type="checkbox"] {
  flex-shrink: 0;
  width: auto;
  min-height: auto;
}

.template-picker-item:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Phone layout for the template editor rows.
   This block must come AFTER the base .template-cat-row rule above: both
   selectors have the same specificity, so source order decides which wins.
   The earlier max-width block (with .category-input-row) is overridden by
   that base rule and cannot collapse these to one column on its own. */
@media (max-width: 768px) {
  .template-cat-row {
    grid-template-columns: 1fr;
    gap: 8px;
    position: relative;
  }
}

/* ==== Receipt scanner (2.12.0) ==== */
.receipt-scan-btn {
  margin-left: auto;
  white-space: nowrap;
  align-self: flex-start;
}

.receipt-panel {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-secondary);
  padding: 10px 12px;
  margin-bottom: 14px;
}

.receipt-panel-main {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.receipt-thumb {
  width: 64px;
  height: 84px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  flex-shrink: 0;
}

.receipt-panel-body {
  flex: 1;
  min-width: 0;
}

.receipt-status {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.receipt-status.is-error {
  color: var(--danger-color, #b42318);
}

.receipt-status.is-busy::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border: 2px solid var(--border-color-hover);
  border-top-color: var(--text-tertiary);
  border-radius: 50%;
  animation: receipt-spin 0.8s linear infinite;
  vertical-align: -1px;
}

@keyframes receipt-spin {
  to { transform: rotate(360deg); }
}

.receipt-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 0.85rem;
  color: var(--text-primary);
  margin-top: 4px;
}

.receipt-facts .receipt-fact-label {
  color: var(--text-muted);
  margin-right: 3px;
}

.receipt-proposal {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.receipt-proposal .receipt-rationale {
  display: block;
  margin-top: 2px;
}

.receipt-confidence {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  margin-left: 4px;
}

.receipt-alternatives {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.receipt-chip {
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}

.receipt-chip:hover {
  border-color: var(--border-color-hover);
}

.receipt-panel-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

.drafts-receipt-badge {
  margin-right: 4px;
}

.receipt-viewer-content {
  max-width: 520px;
}

.receipt-viewer-body {
  max-height: 70vh;
  overflow: auto;
  display: flex;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: 8px;
}

.receipt-viewer-img {
  max-width: 100%;
  height: auto;
  display: block;
}

.btn-receipt-txn {
  font-size: 14px;
}

/* ==== Receipt scanner phase 3 ==== */
/* These open on top of the Add Expense modal, which comes later in the DOM */
#receipt-split-modal,
#receipt-viewer-modal {
  z-index: 1001;
}

.receipt-split-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 45vh;
  overflow-y: auto;
  margin-bottom: 12px;
}

.receipt-split-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
}

.receipt-split-item .receipt-split-desc {
  font-size: 0.9rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receipt-split-item .receipt-split-amount {
  font-weight: 600;
  color: var(--text-primary);
}

.receipt-split-item select {
  grid-column: 1 / -1;
  width: 100%;
}

.receipt-split-summary {
  font-size: 0.9rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
}

.receipt-split-summary .receipt-split-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.receipt-split-summary .receipt-split-row.is-total {
  font-weight: 600;
  color: var(--text-primary);
}

.settings-help {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.api-token-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.api-token-value-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.api-token-value-row input {
  flex: 1;
}

.api-token-new {
  border: 1px solid var(--border-color-hover);
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.api-token-value {
  flex: 1;
  font-size: 0.8rem;
  word-break: break-all;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 6px 8px;
  user-select: all;
}

.api-token-help {
  margin-top: 14px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.api-token-help summary {
  cursor: pointer;
  color: var(--text-primary);
}

.api-token-help code {
  font-size: 0.8rem;
  word-break: break-all;
}

/* Heads-up entries: a note on an envelope, no money */
.heads-up-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--primary-dark, #2f6f62);
  background: var(--primary-light, rgba(67, 148, 131, 0.14));
  border: 1px solid currentColor;
}
.heads-up-toggle {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-weight: 400;
  cursor: pointer;
}
.heads-up-toggle input[type="checkbox"] {
  flex: 0 0 auto;
  width: auto;
  min-height: 0;
  margin: 3px 0 0;
}
.heads-up-toggle span { flex: 1 1 auto; line-height: 1.35; }

/* Local finance reconciliation */
.reconciliation-muted { color: var(--text-secondary); font-size: .86rem; line-height: 1.5; }
.tools-menu-count { margin-left: auto; font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
#reconciliation-open.has-attention .tools-menu-count { color: var(--warning-color); font-weight: 700; }
.reconciliation-modal-content { max-width: 720px; max-height: 90vh; overflow-y: auto; }
.reconciliation-modal-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.reconciliation-modal-heading h2 { margin: 0; }
.reconciliation-intro { color: var(--text-secondary); margin: 12px 0; line-height: 1.5; }
.reconciliation-summary { padding: 14px; border-radius: 8px; background: var(--bg-secondary); margin-bottom: 14px; line-height: 1.6; }
.reconciliation-candidates { display: grid; gap: 16px; margin-top: 18px; }
.reconciliation-card { border: 1px solid var(--border-color); border-radius: 10px; padding: 18px; overflow-wrap: anywhere; }
.reconciliation-card h3 { font-size: 1.05rem; margin-bottom: 8px; color: var(--text-primary); }
.reconciliation-facts { font-weight: 600; margin-bottom: 10px; }
.reconciliation-reason { color: var(--text-secondary); line-height: 1.5; margin-bottom: 10px; }
.reconciliation-warning { border-left: 3px solid var(--warning-color); padding: 9px 12px; background: var(--bg-secondary); font-size: .9rem; line-height: 1.5; margin: 10px 0; }
.reconciliation-controls { display: flex; flex-direction: column; gap: 9px; border: 0; margin-top: 14px; min-width: 0; }
.reconciliation-controls label, .bridge-rule-form > label { font-size: .9rem; font-weight: 600; }
.reconciliation-controls select, .bridge-rule-form select, .bridge-rule-form input[type="text"] { width: 100%; min-width: 0; padding: 10px; border: 1px solid var(--border-color); border-radius: 6px; background: var(--bg-primary); color: var(--text-primary); font: inherit; }
.reconciliation-controls .btn { align-self: flex-start; }
.reconciliation-match-label, .reconciliation-ignore { margin-top: 10px; }
.reconciliation-checkbox { display: flex; align-items: flex-start; gap: 10px; line-height: 1.5; }
.reconciliation-checkbox input[type="checkbox"] { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 3px; accent-color: var(--brand-primary); }
.reconciliation-inline-message { margin: 12px 0; line-height: 1.5; overflow-wrap: anywhere; }
.reconciliation-error { color: var(--danger-color); }
.reconciliation-empty { color: var(--text-secondary); padding: 18px 0; line-height: 1.6; }
.reconciliation-controls:disabled { opacity: .65; }
#bank-content :focus-visible, #bank-inbox :focus-visible, #bank-review :focus-visible, #settings-bridge :focus-visible { outline: 3px solid var(--brand-primary); outline-offset: 3px; }
.reconciliation-controls legend { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#reconciliation-more { margin-top: 16px; }
.bridge-settings-block { border-top: 1px solid var(--border-color); margin-top: 22px; padding-top: 22px; }
.bridge-settings-block > p, .bridge-settings-block > label { margin-bottom: 12px; }
.bridge-rule-form { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.bridge-rule-form > .btn { align-self: flex-start; }
.bridge-list { margin-top: 16px; }
.bridge-list-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border-color); }
.bridge-list-row > div { min-width: 0; overflow-wrap: anywhere; }
.bridge-list-row > button { flex: 0 0 auto; }
.bridge-list-row > .bank-account-choice { flex: 0 1 260px; min-width: 0; max-width: 100%; }
#bank-accounts-refresh { margin-top: 14px; }
@media (max-width: 560px) { #bank-accounts-list .bridge-list-row { flex-direction: column; } .bridge-list-row > .bank-account-choice { flex: 0 0 auto; width: 100%; } }
.bridge-pairing-result { padding: 14px; border: 1px solid var(--border-color); background: var(--bg-secondary); border-radius: 8px; margin-top: 14px; }
.bridge-pairing-row { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; }
#bridge-pairing-code { font-size: 1.05rem; overflow-wrap: anywhere; user-select: all; }
/* .reconciliation-checkbox sets display: flex, so the approval safeguards need this to stay hidden until they apply */
#settings-bridge [hidden], #bank-content [hidden], #bank-inbox [hidden], #bank-review [hidden] { display: none !important; }
@media (max-width: 520px) {
  .reconciliation-card { padding: 14px; }
  .reconciliation-modal-heading h2 { font-size: 1.3rem; }
  .reconciliation-controls .btn { width: 100%; }
}

/* Local Bridge first-run guidance */
.bridge-setup-guide { margin-top: 18px; padding: 16px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-secondary); }
.bridge-setup-guide > summary { font-weight: 650; cursor: pointer; line-height: 1.5; }
.bridge-setup-guide > p { margin-top: 12px; }
.bridge-setup-steps { padding-left: 24px; margin: 20px 0 0; }
.bridge-setup-steps > li { margin-bottom: 24px; padding-left: 4px; }
.bridge-setup-steps > li:last-child { margin-bottom: 0; }
.bridge-setup-steps h4 { margin-bottom: 8px; }
.bridge-setup-steps p { line-height: 1.55; margin: 10px 0; }
.bridge-setup-steps a { color: var(--text-tertiary); text-decoration: underline; text-underline-offset: 3px; }
.bridge-command { padding: 12px; margin: 10px 0; overflow-x: auto; border: 1px solid var(--border-color); border-radius: 6px; background: var(--bg-primary); color: var(--text-primary); font-size: .8rem; line-height: 1.6; }
.bridge-command code { user-select: all; }
@media (max-width: 520px) {
  .bridge-setup-guide { padding: 12px; }
  .bridge-setup-steps { padding-left: 18px; }
  .bridge-copy-command { width: 100%; }
}
.reconciliation-quick-categories { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.reconciliation-period-chooser { margin: 10px 0 4px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.reconciliation-period-chooser .reconciliation-period-label { margin: 0; flex: 1 1 100%; }
.reconciliation-period-chooser select { max-width: 100%; }
.reconciliation-quick-categories .btn { white-space: normal; text-align: left; }
.reconciliation-history { margin-top: 24px; border-top: 1px solid var(--border-color); padding-top: 18px; }
.reconciliation-history > summary, .reconciliation-audit > summary, .bridge-memory-guide > summary { cursor: pointer; font-weight: 650; line-height: 1.5; }
.reconciliation-history-row, .reconciliation-result-row, .bridge-memory-row { border-bottom: 1px solid var(--border-color); padding: 16px 0; line-height: 1.6; overflow-wrap: anywhere; }
.reconciliation-history-row > .btn { margin-bottom: 8px; }
#reconciliation-run-detail { margin-top: 14px; }
#reconciliation-detail-summary { padding: 16px 0; line-height: 1.6; }
#reconciliation-detail-summary h3 { margin-bottom: 8px; }
.reconciliation-audit, .bridge-memory-guide { margin-top: 18px; }
.reconciliation-audit-entry { padding: 12px 0; border-bottom: 1px solid var(--border-color); line-height: 1.6; }
.reconciliation-audit-change { display: block; font-size: .9rem; color: var(--text-secondary); }
.reconciliation-refund-options { padding: 12px 0; }
.reconciliation-refund-options > summary { cursor: pointer; font-weight: 650; line-height: 1.5; }
.reconciliation-refund-options > div { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.reconciliation-source-status { display: inline-block; margin-bottom: 10px; padding: 3px 9px; border: 1px solid var(--border-color); border-radius: 999px; font-size: .78rem; font-weight: 650; color: var(--text-secondary); }
.reconciliation-source-status.is-pending { border-color: var(--warning-color); color: var(--text-primary); background: var(--bg-secondary); }
.reconciliation-suggestion { margin: 12px 0; padding: 13px; border: 1px solid var(--border-color); border-left: 3px solid var(--brand-primary); border-radius: 6px; background: var(--bg-secondary); line-height: 1.5; }
.reconciliation-suggestion > p { margin-top: 6px; }
.reconciliation-expense-finder { padding: 14px 0; border-top: 1px solid var(--border-color); margin-top: 12px; }
.reconciliation-expense-finder > summary { cursor: pointer; font-weight: 650; line-height: 1.5; }
.reconciliation-expense-finder > div, .reconciliation-expense-confirmation, .reconciliation-linked-update { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.reconciliation-expense-finder input[type="search"] { width: 100%; min-width: 0; padding: 10px; border: 1px solid var(--border-color); border-radius: 6px; background: var(--bg-primary); color: var(--text-primary); font: inherit; }
.reconciliation-linked-update { border-top: 1px solid var(--border-color); padding-top: 14px; }
.reconciliation-ignored-add { border-top: 1px solid var(--border-color); padding: 14px 0; margin-top: 12px; }
.reconciliation-ignored-add > summary { cursor: pointer; font-weight: 650; line-height: 1.5; }
.reconciliation-ignored-add > div { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

/* Reviewed budget effects retain signed amounts throughout the ledger. */
.category-credit-badge { display: inline-block; font-size: .75rem; color: var(--text-secondary, #59636f); margin-right: .35rem; }
.reconciliation-movement-form { display: grid; gap: .65rem; padding-top: .85rem; border-top: 1px solid var(--border-color, #d9dfe4); }
.reconciliation-movement-form h4 { margin: 0; }
.reconciliation-effect-preview { padding: .75rem; border-radius: .5rem; background: var(--bg-secondary, #f3f6f7); line-height: 1.5; }

/* ── Claude spend (Settings) ─────────────────────────────────────────────── */
.ai-spend-status { margin: 0 0 8px; color: var(--text-primary); }
.ai-spend-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }
.ai-spend-chart { margin: 8px 0 16px; }
.ai-spend-window { margin-bottom: 16px; }
.ai-spend-window h4 { margin: 0 0 6px; font-size: 0.95rem; color: var(--text-primary); }
.ai-spend-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.ai-spend-table th, .ai-spend-table td { padding: 6px 8px; border-bottom: 1px solid var(--border-color); color: var(--text-primary); }
.ai-spend-table th { color: var(--text-secondary); font-weight: 600; }
.ai-spend-notes { margin: 8px 0 0 18px; padding: 0; color: var(--text-secondary); font-size: 0.9rem; }
.settings-tab-btn[hidden] { display: none; }
#settings-ai-spend [hidden] { display: none !important; }

/* ── Start Fresh suggestions ─────────────────────────────────────────────── */
.suggestion-bar { margin: 8px 0 16px; padding: 10px 12px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--bg-secondary); }
.suggestion-status { margin: 0 0 8px; font-size: 0.9rem; color: var(--text-primary); }
.suggestion-bar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.suggestion-balance, .suggestion-leftover { margin: 8px 0 0; font-size: 0.9rem; color: var(--text-secondary); }
.category-input-row .cat-suggestion { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: -2px 0 6px; font-size: 0.85rem; color: var(--text-secondary); }
.category-input-row .cat-suggestion[hidden] { display: none; }
.cat-suggestion-chip { padding: 1px 6px; border-radius: 999px; background: var(--bg-tertiary, var(--bg-secondary)); font-size: 0.75rem; }
.cat-suggestion-use { padding: 2px 8px; }
.cat-suggestion-why { background: none; border: none; padding: 0; color: var(--brand-primary-dark); cursor: pointer; font-size: 0.85rem; }
.cat-suggestion-basis { flex-basis: 100%; margin: 0; color: var(--text-secondary); }
.cat-suggestion-basis[hidden] { display: none; }
.suggestion-accuracy-body h3 { margin: 14px 0 6px; font-size: 1rem; }
.suggestion-accuracy-body table { margin-bottom: 8px; }
#suggestion-bar [hidden] { display: none !important; }

/* ── Goals (Budget tab): two quiet cards under the summary ── */
.goals-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.goals-strip[hidden] { display: none; }
.goal-card { display: flex; flex-direction: column; gap: 8px; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 10px; padding: 14px 16px; color: var(--text-primary); }
.goal-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.goal-card-eyebrow { font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.goal-card-figure { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; }
.goal-card-figure strong { font-size: 1.25rem; font-weight: 800; }
.goal-card-figure span { font-size: 0.88rem; color: var(--text-secondary); }
.goal-card .progress-bar { margin: 0; }
.goal-card-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 0.82rem; color: var(--text-secondary); }
.goal-card-link { font-size: 0.82rem; font-weight: 600; white-space: nowrap; text-decoration: none; }
/* The Finance Health Check (v2.43.0) */
.finance-health { margin-bottom: 16px; }
.finance-health-card .goal-card-link { align-self: flex-start; }
.finance-health-pill { font-size: 0.78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; background: var(--bg-tertiary); color: var(--text-secondary); }
.finance-health-pill.tone-ok { background: var(--brand-primary-light); color: var(--brand-primary-dark); }
.finance-health-pill.tone-bad { background: color-mix(in srgb, var(--danger-color) 16%, var(--bg-primary)); color: var(--hero-attention-end); }
[data-theme="dark"] .finance-health-pill.tone-bad { color: var(--danger-color); }
.finance-health-pill.tone-warn { background: color-mix(in srgb, var(--warning-color) 16%, var(--bg-primary)); color: var(--warning-color); }
[data-theme="dark"] .finance-health-pill.tone-ok { background: color-mix(in srgb, var(--brand-primary) 30%, var(--bg-primary)); color: var(--text-tertiary); }
.finance-health-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.finance-health-tiles > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; background: var(--bg-secondary); border-radius: 8px; padding: 8px 10px; }
.finance-health-tiles small { font-size: 0.72rem; color: var(--text-muted); line-height: 1.3; }
.finance-health-tiles strong { font-size: 0.98rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.finance-health-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 0.9rem; color: var(--text-secondary); padding: 3px 0; }
.finance-health-row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.finance-health-row small { display: block; font-size: 0.76rem; color: var(--text-muted); }
.finance-health-row.is-sub { font-size: 0.8rem; padding-left: 14px; color: var(--text-muted); }
.finance-health-row.is-strong, .finance-health-row.is-total { font-weight: 700; color: var(--text-primary); }
.finance-health-row.is-total { border-top: 1px solid var(--border-color); margin-top: 6px; padding-top: 9px; }
.finance-health-side > .finance-health-row.is-total:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.finance-health-value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.finance-health-note { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.45; margin: 0; }
.finance-health-side { border: 1px solid var(--border-color); border-radius: 10px; padding: 12px 14px; margin-top: 12px; display: flex; flex-direction: column; gap: 2px; }
.finance-health-side h3 { font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 6px; }
.finance-health-list { margin-top: 12px; border-top: 1px solid var(--border-color); padding-top: 10px; }
.finance-health-list summary { font-weight: 600; cursor: pointer; }
.finance-health-list .finance-health-note { margin: 6px 0; }
@media (max-width: 420px) { .finance-health-tiles { grid-template-columns: minmax(0, 1fr); } }
/* .form-group is a flex box, which outranks the browser's own rule for hidden */
#expense-check-group[hidden] { display: none; }
.expense-check-number { margin: 8px 0 0 26px; }
.expense-check-number label { display: block; font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 4px; }
/* Start Fresh's opening numbers (v2.47.0) */
.start-fresh-opening { border: 1px solid var(--border-color); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; display: flex; flex-direction: column; gap: 4px; background: var(--bg-secondary); }
.start-fresh-opening[hidden] { display: none; }
.start-fresh-opening h3 { font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 4px; }
.start-fresh-opening .opening-group-title { font-size: 0.86rem; margin: 12px 0 2px; }
.start-fresh-opening .finance-health-row small { display: block; }
.start-fresh-opening .opening-deposits { align-items: center; }
.start-fresh-opening .opening-deposits input { flex: 0 1 150px; min-width: 0; padding: 6px 8px; text-align: right; border: 1px solid var(--border-color); border-radius: 6px; background: var(--bg-primary); color: var(--text-primary); }
.start-fresh-opening .btn { align-self: flex-start; margin-top: 6px; }
/* Waiting to clear (v2.44.0), on the Bank tab */
.waiting-to-clear { margin-top: 22px; border-top: 1px solid var(--border-color); padding-top: 18px; }
.waiting-to-clear h3 { font-size: 1rem; margin-bottom: 6px; }
.waiting-list { list-style: none; margin: 10px 0 0; padding: 0; }
.waiting-group-title { font-size: 0.9rem; margin: 12px 0 4px; }
.waiting-pending { margin-top: 16px; }
.waiting-pending summary { font-weight: 600; cursor: pointer; font-size: 0.9rem; }
.waiting-pending > .reconciliation-muted { margin: 6px 0 0; }
.waiting-row { padding: 12px 0; border-bottom: 1px solid var(--border-color); display: flex; flex-direction: column; gap: 6px; }
.waiting-row.is-flagged { border-left: 3px solid var(--warning-color); padding-left: 10px; }
.waiting-row-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.waiting-row-head > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.waiting-row-head small { display: block; font-size: 0.8rem; color: var(--text-muted); }
.waiting-row-figures { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: 0 0 auto; }
.waiting-row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 0.86rem; }
.waiting-row-actions input { flex: 0 1 180px; min-width: 0; padding: 6px 8px; border: 1px solid var(--border-color); border-radius: 6px; background: var(--bg-primary); color: var(--text-primary); }
/* The emergency fund (v2.41.0) wears the goal card; only its spacing is its own */
.emergency-fund { margin-bottom: 16px; }
.emergency-fund[hidden] { display: none; }
.emergency-fund-offer { margin: 0; font-size: 0.88rem; color: var(--text-secondary); }
.emergency-fund-actions { display: flex; gap: 14px; }
.insight-evidence { margin: 0 0 0 18px; font-size: 0.85rem; line-height: 1.5; color: var(--text-secondary); }
@media (max-width: 768px) {
  .goals-strip { grid-template-columns: 1fr; gap: 10px; }
}
.subscription-toolbar { margin: 8px 0; }
.subscription-add-form { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.subscription-add-form input[type="text"] { flex: 1 1 160px; }
.subscription-add-form input[type="number"] { width: 100px; }
.subscription-runrate { font-size: 0.9rem; color: var(--text-secondary); }
.subscriptions-body h3 { margin: 12px 0 6px; font-size: 0.95rem; }
.subscription-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border-color); }
.subscription-main { display: flex; flex-direction: column; gap: 2px; }
.subscription-title { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.subscription-group { margin: 10px 0; }
.subscription-group > summary { cursor: pointer; font-weight: 650; padding: 6px 0; }
.subscription-meta { font-size: 0.85rem; color: var(--text-secondary); }
.subscription-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.subscription-goal-toggle { font-size: 0.85rem; color: var(--text-secondary); display: inline-flex; align-items: center; gap: 4px; }
.subscription-dismissed .subscription-main { opacity: 0.7; }
.subscription-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.subscription-chip { padding: 2px 8px; border-radius: 999px; background: var(--bg-secondary); font-size: 0.85rem; }
.subscription-chip-remove { margin-left: 4px; color: var(--text-secondary); background: none; border: none; cursor: pointer; }
#subscriptions-modal [hidden], #goal-setup-modal [hidden], #emergency-fund-modal [hidden] { display: none !important; }

/* ── Start Fresh rows (v2.30.0) ── */
.cat-suggestion-applied {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--brand-primary-dark);
}
.suggestion-leftover-title { margin: 0 0 4px; }
.suggestion-leftover-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.suggestion-leftover-add { margin-left: 8px; font-size: 0.85rem; font-weight: 700; }
.suggestion-leftover-added { margin-left: 8px; font-size: 0.85rem; color: var(--text-secondary); }


/* ==== Start Fresh Release 2 (v2.31.0): dates, errors and the phone flow ==== */

/* The sheet scrolls on its own; a focused field stops clear of the footer */
#reset-modal .modal-content {
  overscroll-behavior: contain;
  scroll-padding-bottom: 170px;
}
/* While the wizard is open the page behind it holds still (the backdrop too) */
html.start-fresh-open,
html.start-fresh-open body {
  overflow: hidden;
  overscroll-behavior: none;
}
#reset-modal { overscroll-behavior: contain; }

/* On a laptop the row's first line is placed explicitly, so the suggestion,
   chip and warning that follow the amount in the page keep their own lines */
.category-input-row > .cat-name { grid-row: 1; grid-column: 1; }
.category-input-row > .cat-amount { grid-row: 1; grid-column: 2; }
.category-input-row > .cat-notes { grid-row: 1; grid-column: 3; }
.category-input-row > .cat-row-controls { grid-row: 1; grid-column: 4; }

/* The footer has an edge, and carries what is still to assign */
#reset-modal .modal-actions {
  flex-wrap: wrap;
  align-items: center;
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -10px 14px -12px rgba(0, 0, 0, 0.3);
}
#reset-modal .modal-actions .btn-link { flex: 0 0 auto; min-height: 44px; }
.reset-footer-balance {
  flex: 1 1 100%;
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-secondary);
}
.reset-footer-balance.balanced { color: #07584f; }
[data-theme="dark"] .reset-footer-balance.balanced { color: var(--success-color); }
.reset-footer-balance.under { color: var(--text-primary); }
.reset-footer-balance.over { color: #8f2626; }
[data-theme="dark"] .reset-footer-balance.over { color: #fca5a5; }

/* Discard is a quiet link, apart from Go live (4.5:1 in both themes) */
.btn-link.btn-link-danger { color: #8f2626; }
[data-theme="dark"] .btn-link.btn-link-danger { color: #fca5a5; }

/* A hint under a field (what is left from the running period) */
.field-hint {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Quick setup folds away once the form has envelopes */
.template-selection > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none;
}
.template-selection > summary::-webkit-details-marker { display: none; }
.template-selection > summary::before {
  content: '▸';
  display: inline-block; /* turns even where <summary> is not a flex box */
  margin-right: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: transform 0.15s ease;
}
.template-selection[open] > summary::before { transform: rotate(90deg); }
.template-selection[open] > summary { margin-bottom: 10px; }

/* Templates as a labelled list of 44px choices */
.template-choices { margin-top: 10px; }
.template-choices[hidden] { display: none; }
.template-choices-label { margin: 0 0 6px; font-weight: 600; color: var(--text-primary); }
.template-choices-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.template-choice {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
}
.template-choice:hover,
.template-choice:focus-visible { border-color: var(--btn-primary-bg); }
.template-choices .btn-link { min-height: 44px; padding: 0 4px; display: inline-flex; align-items: center; }

/* One ⋮ per row, 44px, with a menu of 44px items */
.cat-row-controls { position: relative; }
.cat-row-menu-btn {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
}
.cat-row-menu-btn:hover,
.cat-row-menu-btn[aria-expanded="true"] { border-color: var(--btn-primary-bg); color: var(--text-primary); }
.cat-row-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 5;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  padding: 4px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}
.cat-row-menu[hidden] { display: none; }
.cat-row-menu .cat-row-menu-item {
  width: auto;
  height: auto;
  min-height: 44px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.cat-row-menu-item {
  min-height: 44px;
}
.cat-row-menu .cat-row-menu-item:hover,
.cat-row-menu .cat-row-menu-item:focus-visible { background: var(--bg-secondary); color: var(--text-primary); }
.cat-row-menu .cat-row-menu-item[aria-disabled="true"] { color: var(--text-muted, #888); cursor: default; background: none; }
.cat-row-menu .cat-row-menu-remove { color: #8f2626; }
[data-theme="dark"] .cat-row-menu .cat-row-menu-remove { color: #fca5a5; }

/* Start Fresh on a phone (v2.31.0) */
@media (max-width: 768px) {
  /* A row reads name and amount, then the suggestion for that amount, a chip
     or warning on its own line, then the note and the row's ⋮. That is also
     the order in the page, so Tab and a screen reader follow what is drawn. */
  .category-input-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }
  /* Name and amount fill the first line exactly, so the note always starts a
     line of its own (with basis 0 an empty row squeezed all three together) */
  .category-input-row .cat-name { flex: 1 1 calc(100% - 118px); min-width: 0; }
  .category-input-row .cat-amount { flex: 0 0 110px; }
  .category-input-row .cat-suggestion { flex: 1 1 100%; margin: 0; }
  .category-input-row .cat-notes { flex: 1 1 calc(100% - 52px); min-width: 0; }
  .cat-suggestion-use,
  .cat-suggestion-why { min-height: 44px; min-width: 44px; }
  /* The footer on a phone is three lines tall, plus the home indicator */
  #reset-modal .modal-content { scroll-padding-bottom: calc(220px + env(safe-area-inset-bottom, 0px)); }
  /* The footer's balance stays above Go live, which an earlier phone rule
     draws first (the balance takes no focus, so focus order is unchanged) */
  #reset-modal .modal-actions .reset-footer-balance { order: -2; }
  /* Full-width 44px buttons, drawn in the order focus moves through them */
  .confirmation-actions { flex-direction: column; }
  .confirmation-actions .btn { width: 100%; min-height: 44px; }
}
/* end Start Fresh on a phone */


/* ==== Start Fresh Release 3 (v2.32.0): wording and polish ==== */

/* Icon hovers on the template editor rows: white on a light fill in the
   dark theme was about 2:1, so the dark theme draws them dark */
[data-theme="dark"] .btn-remove-category:hover,
[data-theme="dark"] .btn-reorder-category:hover { color: #0f172a; }

/* Each member's legend is underlined in their colour, as on the tab */
legend.section-label[data-section="household"] { border-bottom-color: var(--section-household); }
legend.section-label[data-section="rose"] { border-bottom-color: var(--section-rose); }
legend.section-label[data-section="jason"] { border-bottom-color: var(--section-jason); }

/* Start Fresh where the period has ended: the line and the button wrap
   together and stay aligned; the button is a 44px target */
.cockpit-attention.has-start-fresh { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cockpit-attention .cockpit-start-fresh { min-height: 44px; }

/* ==== Overage in Start Fresh (v2.33.0) ==== */

/* Its own block above the envelopes, never an envelope row */
.overage-box {
  margin: 0 0 20px;
  padding: 12px 15px;
  min-width: 0;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-left: 4px solid var(--warning-color);
  border-radius: 8px;
}
.overage-box[hidden] { display: none; }
.overage-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding-bottom: 6px;
  margin-bottom: 10px;
  border-bottom: 2px solid var(--warning-color);
}
.overage-title { float: none; padding: 0; margin: 0; font-weight: 700; font-size: 1.05rem; color: var(--text-primary); }
.overage-pill { font-size: 0.8rem; padding: 3px 9px; border-radius: 999px; background: var(--bg-tertiary); color: var(--text-secondary); }
.overage-lead { margin: 0 0 4px; font-weight: 600; color: var(--text-primary); }
.overage-tick {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  color: var(--text-primary);
}
.overage-tick input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; padding: 0; margin: 0; flex-shrink: 0; accent-color: var(--btn-primary-bg); }
.overage-name { flex: 1; min-width: 0; }
.overage-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; vertical-align: middle; }
.overage-over { white-space: nowrap; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.overage-tick.is-off .overage-name,
.overage-tick.is-off .overage-over { color: var(--text-muted); text-decoration: line-through; }
.overage-context { margin: 8px 0 0; font-size: 0.88rem; color: var(--text-secondary); }
.overage-cover { display: grid; grid-template-columns: minmax(0, 1fr) 130px auto; align-items: center; gap: 10px; margin-top: 12px; }
.overage-cover-label { font-weight: 700; color: var(--text-primary); }
.overage-cover-label small { display: block; font-weight: 400; font-size: 0.8rem; color: var(--text-secondary); }
.overage-amount { width: 100%; min-width: 0; font-variant-numeric: tabular-nums; }
.overage-cover .btn-link { min-height: 44px; }
.overage-note { margin: 8px 0 0; padding: 8px 10px; border-radius: 6px; background: var(--bg-tertiary); color: var(--text-primary); font-size: 0.88rem; }
.overage-collapsed { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; color: var(--text-secondary); }
.overage-collapsed .btn-link { min-height: 44px; }

/* The summary's line for it, and the Budget tab's afterwards */
.allocation-row.allocation-overage span:last-child { color: #854d0e; font-weight: 600; }
[data-theme="dark"] .allocation-row.allocation-overage span:last-child { color: #f6b44b; }
.overage-owner { margin-left: 6px; font-size: 0.85rem; color: var(--text-secondary); }
.overage-context[hidden] { display: none; }
/* The hint's Add it / Remove it and the note's Take out are 44px targets */
#starting-funds-hint .btn-link,
.overage-note .btn-link { min-height: 44px; display: inline-flex; align-items: center; padding: 0 4px; }
/* Budget history: what a period covered, and what became of its own overage */
.period-overage { margin: 0 16px 12px; padding: 8px 10px; border-radius: 8px; background: var(--bg-secondary); border-left: 3px solid var(--warning-color); color: var(--text-secondary); font-size: 0.88rem; }
.period-overage p { margin: 0; }
.period-overage p + p { margin-top: 4px; }
.cockpit-overage-note { margin: 10px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--bg-secondary); border-left: 3px solid var(--warning-color); color: var(--text-secondary); font-size: 0.88rem; }

@media (max-width: 768px) {
  .overage-cover { grid-template-columns: minmax(0, 1fr) 110px; }
  .overage-cover .btn-link { grid-column: 1 / -1; justify-self: start; }
}

/* ========================================
   Morning bank review (v2.35.0): the Bank tab badge, the Budget card (A),
   the Bank tab queue (B) and the one-at-a-time review (C)
   ======================================== */
.tab-btn { position: relative; }
.tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; box-sizing: border-box;
  border-radius: 999px; background: var(--brand-primary); color: #ffffff;
  font-size: 0.7rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums;
}
.tab-badge[hidden] { display: none; }
.tab-badge.is-warn { background: var(--warning-color); }
.tab-btn.active .tab-badge { background: var(--bg-primary); color: var(--btn-primary-bg); }
[data-theme="dark"] .tab-badge { color: #0b2f2a; }
[data-theme="dark"] .tab-btn.active .tab-badge { color: var(--btn-primary-bg); background: var(--btn-primary-text); }
@media (max-width: 768px) {
  .tab-btn .tab-badge { position: absolute; top: 2px; right: calc(50% - 22px); display: inline-flex; min-width: 16px; height: 16px; font-size: 0.62rem; }
  .tab-btn .tab-badge[hidden] { display: none; }
}

/* A: Bank activity, first on the Budget tab */
.bank-inbox {
  background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 12px;
  box-shadow: var(--shadow-md); padding: 14px 16px; margin-bottom: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.bank-inbox[hidden] { display: none; }
.bank-inbox.is-warn { border-color: var(--warning-color); }
.bank-inbox.is-sorted { box-shadow: none; padding: 10px 14px; }
.bank-inbox-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bank-inbox-icon { width: 20px; height: 20px; fill: none; stroke: var(--brand-primary); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.bank-inbox.is-warn .bank-inbox-icon { stroke: var(--warning-color); }
.bank-inbox-title { margin: 0; font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.bank-inbox-pill { font-size: 0.78rem; font-weight: 700; color: #ffffff; background: var(--btn-primary-bg); border-radius: 999px; padding: 3px 10px; }
[data-theme="dark"] .bank-inbox-pill { color: #0b2f2a; }
.bank-inbox-fresh, .bank-inbox-split { margin: 0; font-size: 0.84rem; color: var(--text-muted); }
.bank-inbox-split { color: var(--text-secondary); }
.bank-inbox-fresh.is-warn { color: var(--warning-color); font-weight: 600; }
.bank-inbox-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bank-inbox-actions .btn { min-height: 44px; }
.bank-inbox-sort { flex-grow: 1; }
.bank-inbox-strip { display: flex; align-items: center; gap: 10px; }
.bank-inbox-strip-text { flex-grow: 1; min-width: 0; }
.bank-inbox-strip .bank-inbox-title { font-size: 0.95rem; }
.bank-inbox-check { color: var(--success-color); font-weight: 800; font-size: 1.1rem; }
.bank-inbox-link { min-height: 44px; font-weight: 600; }
.bank-next { border-top: 1px solid var(--border-color); padding-top: 10px; display: flex; flex-direction: column; gap: 5px; }
.bank-next-eyebrow { margin: 0; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-muted); }
.bank-next-facts { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.bank-next-merchant { font-weight: 600; font-size: 0.97rem; min-width: 0; overflow-wrap: anywhere; }
.bank-next-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.bank-next-meta, .bank-next-suggestion { margin: 0; font-size: 0.82rem; color: var(--text-muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.bank-next-suggestion { color: var(--text-secondary); }
/* The floating Add expense stays on a phone while the card pushes the hero down */
@media (max-width: 768px) {
  body[data-tab="budget"].bank-inbox-open .fab-add-expense { display: flex; }
}

/* The one-tap choice, in the card, the Budget card and the review */
.bank-quick { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.bank-quick-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bank-quick-primary { flex-grow: 1; min-height: 48px; font-size: 0.98rem; }
.bank-quick-ignore { min-height: 44px; padding: 0 10px; color: var(--text-secondary); font-weight: 600; }
.bank-quick-alternatives { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.bank-quick-alternatives .btn { min-height: 40px; }
.bank-quick-label { font-size: 0.82rem; color: var(--text-muted); }
.bank-quick-match { margin: 0; font-size: 0.86rem; color: var(--text-secondary); }
.reconciliation-more { border-top: 1px solid var(--border-color); padding-top: 8px; }
.reconciliation-more > summary { cursor: pointer; font-weight: 600; color: var(--brand-primary-dark); min-height: 36px; display: flex; align-items: center; }
.reconciliation-more[open] > summary { margin-bottom: 8px; }

/* B: the Bank tab */
.bank-page { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.bank-page-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.bank-page-heading h2 { margin: 0; font-size: 1.25rem; }
.bank-page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bank-page-actions .btn { min-height: 44px; }
.bank-delivery { display: flex; flex-direction: column; gap: 4px; }
.bank-delivery p { margin: 0; }
.bank-delivery-detail { font-size: 0.88rem; color: var(--text-muted); }
.bank-delivery-title { font-weight: 700; }
.bank-delivery.is-warn { background: #fbf3e4; border-radius: 10px; padding: 10px 12px; }
.bank-delivery.is-warn .bank-delivery-title { color: #71480f; }
[data-theme="dark"] .bank-delivery.is-warn { background: rgba(246, 180, 75, 0.12); }
[data-theme="dark"] .bank-delivery.is-warn .bank-delivery-title { color: var(--warning-color); }
.bank-delivery.is-quiet { background: var(--bg-secondary); border-radius: 10px; padding: 10px 12px; }
.bank-mac-help { font-size: 0.86rem; color: var(--text-secondary); }
.bank-mac-help summary { cursor: pointer; font-weight: 600; min-height: 36px; display: flex; align-items: center; }
.bank-mac-help ol { margin: 4px 0 0 18px; padding: 0; display: grid; gap: 4px; }
.bank-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.bank-filters[hidden] { display: none; }
.bank-filter {
  min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border-color);
  background: var(--bg-secondary); color: var(--text-primary); font-size: 0.84rem; font-weight: 600; cursor: pointer;
}
.bank-filter.is-active { background: var(--btn-primary-bg); border-color: var(--btn-primary-bg); color: var(--btn-primary-text); }
.bank-how { font-size: 0.88rem; color: var(--text-secondary); }
.bank-how summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }
.bank-group-title { margin: 6px 0 0; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-muted); }
.bank-done { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 24px 12px; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 12px; }
.bank-done h3 { margin: 0; font-size: 1.2rem; }
.bank-done p { margin: 0; }
.bank-done-check { width: 52px; height: 52px; border-radius: 50%; background: var(--brand-light); color: var(--brand-primary); display: flex; align-items: center; justify-content: center; font-size: 1.6rem; font-weight: 800; }
.bank-done-summary { font-weight: 600; }
.bank-sorted { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.bank-sorted[hidden] { display: none; }
.bank-sorted-list { list-style: none; margin: 0; padding: 0; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 12px; }
.bank-sorted-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; flex-wrap: wrap; }
.bank-sorted-row + .bank-sorted-row { border-top: 1px solid var(--border-color); }
.bank-sorted-label { flex-grow: 1; font-weight: 600; min-width: 0; }
.bank-sorted-state { font-size: 0.82rem; color: var(--text-muted); }
.bank-sorted-state.is-failed { color: var(--danger-color); }

/* C: one at a time, a dialog you open yourself */
.bank-review { position: fixed; inset: 0; z-index: 1200; background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; }
.bank-review[hidden] { display: none; }
body.bank-review-open { overflow: hidden; }
.bank-review-stage {
  background: var(--bg-primary); color: var(--text-primary); width: min(600px, calc(100vw - 32px));
  max-height: min(860px, calc(100vh - 48px)); overflow-y: auto; border-radius: 16px; box-shadow: var(--shadow-md);
  display: flex; flex-direction: column;
}
.bank-review-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border-color); position: sticky; top: 0; background: var(--bg-primary); z-index: 1; }
.bank-review-top .btn-link { min-height: 44px; padding: 0 8px; font-weight: 600; }
.bank-review-progress { font-weight: 700; font-variant-numeric: tabular-nums; }
.bank-review-segments { display: flex; gap: 3px; padding: 8px 14px 0; }
.bank-review-segments span { flex: 1; height: 4px; border-radius: 2px; background: var(--bg-tertiary); }
.bank-review-segments span.is-done { background: var(--brand-primary); }
.bank-review-segments span.is-current { background: var(--brand-primary); opacity: 0.45; }
.bank-review-segments span.is-skipped { background: transparent; box-shadow: inset 0 0 0 1px var(--warning-color); }
.bank-review-body { padding: 14px 18px 8px; display: flex; flex-direction: column; gap: 12px; }
.bank-review-eyebrow { margin: 0; font-size: 0.76rem; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-muted); }
.reconciliation-card.is-review { border: 0; padding: 0; box-shadow: none; }
.reconciliation-card.is-review h3 { font-size: 1.4rem; }
.reconciliation-card.is-review .reconciliation-facts { font-size: 1.15rem; }
.reconciliation-card.is-review .bank-quick-primary { min-height: 56px; font-size: 1.05rem; }
.bank-review-skip { align-self: flex-start; min-height: 44px; font-weight: 600; color: var(--text-secondary); }
.bank-review-notice { margin: 0 18px 10px; padding: 10px 14px; border-radius: 10px; background: var(--danger-bg, rgba(220, 53, 69, 0.12)); color: var(--danger-color); line-height: 1.45; }
.bank-review-notice[hidden] { display: none; }
/* Each envelope's key, shown only in the one-at-a-time review */
.bank-digit { display: none; }
.bank-review .bank-digit { display: inline-flex; align-items: center; justify-content: center; min-width: 1.35em; height: 1.35em; margin-right: 6px; border-radius: 4px; font: inherit; font-size: 0.72em; font-weight: 700; background: rgba(0, 0, 0, 0.12); }
.bank-review-undo { margin: 0 18px 10px; background: var(--text-primary); color: var(--bg-primary); border-radius: 10px; padding: 8px 8px 8px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bank-review-undo[hidden] { display: none; }
.bank-review-undo-button { min-height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid currentColor; background: transparent; color: inherit; font-weight: 700; cursor: pointer; }
.bank-review-keys { margin: 0; padding: 8px 18px 14px; font-size: 0.78rem; color: var(--text-muted); }
.bank-review-summary { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 18px 0 6px; }
.bank-review-summary h2 { margin: 0; }
.bank-review-summary-line { margin: 0; font-weight: 600; }
.bank-review-envelopes { list-style: none; margin: 0; padding: 0; align-self: stretch; border: 1px solid var(--border-color); border-radius: 12px; text-align: left; }
.bank-review-envelopes li { padding: 8px 14px; font-variant-numeric: tabular-nums; }
.bank-review-envelopes li + li { border-top: 1px solid var(--border-color); }
.bank-review-envelopes-total { font-weight: 700; }
.bank-review-summary-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.bank-review-summary-actions .btn { min-height: 48px; }
@media (max-width: 768px) {
  .bank-review { align-items: stretch; }
  .bank-review-stage { width: 100%; max-height: none; height: 100%; border-radius: 0; }
  .bank-review-keys { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .bank-review, .bank-review-stage { transition: none; }
}

/* ── Change dates (v2.38.0) ─────────────────────────────────────────────── */
/* .form-group and .btn set a display, which would otherwise beat [hidden] */
#edit-period-modal [hidden],
.period-overlap-offer[hidden] { display: none !important; }
.period-dates-dialog {
  max-height: 85vh;
  overflow-y: auto;
  max-width: 520px;
}
.period-dates-section { margin: 0 0 14px; }
.period-dates-section h4 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--text-primary);
}
.period-dates-section ul {
  margin: 0;
  padding-left: 18px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.period-dates-changes li { color: var(--text-primary); font-weight: 600; }
.period-dates-problems h4,
.period-dates-stranded h4 { color: var(--danger-color); }
.period-dates-dialog p.period-dates-calm { color: var(--success-color); margin-bottom: 14px; }
.period-dates-dialog p.period-dates-help { color: var(--text-secondary); margin-bottom: 14px; }
.period-dates-quiet ul { color: var(--text-muted); }
.period-dates-dialog p.period-dates-status { min-height: 1.2em; margin-bottom: 12px; color: var(--text-secondary); }

.period-overlap-offer {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--warning-color);
  border-radius: 8px;
  background: var(--bg-secondary);
}
.period-overlap-offer p { margin: 0 0 8px; color: var(--text-primary); }
.period-overlap-offer .field-hint { margin: 6px 0 0; }
.period-overlap-offer .btn { min-height: 44px; }

.edit-period-end-row { display: flex; gap: 8px; align-items: center; }
.edit-period-end-row input { flex: 1; min-width: 0; }
.edit-period-end-row .btn { white-space: nowrap; min-height: 44px; }

.confirmation-choice {
  border: 0;
  margin: 0 0 18px;
  padding: 0;
}
.confirmation-choice legend { font-weight: 600; color: var(--text-primary); margin-bottom: 8px; }
.confirmation-choice label {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  color: var(--text-primary);
  cursor: pointer;
}

.btn-icon-dates {
  background: var(--btn-secondary-bg);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn-icon-dates:hover { background: var(--btn-secondary-hover); }
@media (max-width: 768px) {
  .btn-icon-dates { width: 100%; justify-content: center; }
}
