/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* === Dark Theme (Default) === */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-card: #1a1a2e;
  --text-primary: #e0e0e0;
  --text-secondary: #888;
  --accent: #39ff14;
  --accent-secondary: #7c3aed;
  --accent-tertiary: #06b6d4;
  --border: #2a2a3e;
  --nav-bg: #0f0f1a;
  --nav-border: #1a1a2e;
  --toggle-bg: #2a2a3e;
  --hover-bg: rgba(57, 255, 20, 0.08);
}

/* === Light Theme === */
[data-theme="light"] {
  --bg-primary: #f5f5f7;
  --bg-secondary: #eaeaef;
  --bg-card: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #666;
  --accent: #16a34a;
  --accent-secondary: #7c3aed;
  --accent-tertiary: #0891b2;
  --border: #d4d4d8;
  --nav-bg: #ffffff;
  --nav-border: #e4e4e7;
  --toggle-bg: #d4d4d8;
  --hover-bg: rgba(22, 163, 74, 0.08);
}

/* === Typography === */
body {
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", "Cascadia Code", monospace;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

h1, h2, h3 {
  font-weight: 600;
  letter-spacing: -0.02em;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* === Navigation === */
.nav {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Desktop: nav-menu is transparent inline wrapper */
.nav-menu {
  display: contents;
}

.nav-links {
  display: flex;
  gap: 0.15rem;
  list-style: none;
  flex: 1;
  justify-content: center;
}

/* Nav group — desktop: label-only, dropdown on hover */
.nav-group {
  position: relative;
  padding: 0 0.25rem;
}

.nav-group + .nav-group {
  margin-left: 0.25rem;
}

.nav-group-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
  display: inline-block;
}

.nav-group:hover .nav-group-label {
  color: var(--accent);
  background: var(--hover-bg);
}

/* Highlight the group label when any child link is active */
.nav-group:has(.active) .nav-group-label {
  color: var(--accent);
}

.nav-group-items {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  flex-direction: column;
  background: var(--nav-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0;
  min-width: 160px;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  list-style: none;
}

.nav-group:hover .nav-group-items {
  display: flex;
}

.nav-group-items a {
  color: var(--text-secondary);
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}

.nav-group-items a:hover,
.nav-group-items a.active {
  color: var(--accent);
  background: var(--hover-bg);
  text-decoration: none;
}

/* Desktop: hide mobile nav-actions (theme toggle is in nav-desktop-actions) */
.nav-menu .nav-actions {
  display: none;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* === Theme Toggle === */
.theme-toggle {
  background: var(--toggle-bg);
  border: none;
  border-radius: 20px;
  width: 44px;
  height: 24px;
  cursor: pointer;
  position: relative;
  transition: background 0.3s;
}

.theme-toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform 0.3s;
}

[data-theme="light"] .theme-toggle::after {
  transform: translateX(20px);
}

/* === Layout === */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* === Card === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}

/* === Filter Bar === */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  margin: 1.25rem 0;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.filter-group label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-group select {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  min-width: 180px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23888' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.filter-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(57, 255, 20, 0.15);
}

.filter-group select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* === Range Buttons === */
.range-buttons {
  display: flex;
  gap: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.range-btn {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.range-btn:last-child {
  border-right: none;
}

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

.range-btn.active {
  background: var(--accent);
  color: #0a0a0f;
  font-weight: 600;
}

[data-theme="light"] .range-btn.active {
  color: #ffffff;
}

.filter-count {
  font-size: 0.85rem;
  color: var(--text-secondary);
  align-self: flex-end;
  padding-bottom: 0.5rem;
  margin-left: auto;
}

.filter-count strong {
  color: var(--accent);
}

/* === Transaction Table === */
.table-wrap {
  margin-top: 0.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.tx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.tx-table thead {
  background: var(--bg-card);
}

.tx-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.tx-table td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.tx-table tbody tr:nth-child(even) {
  background: var(--bg-secondary);
}

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

.tx-date {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.tx-desc {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-negative {
  color: #f87171;
  font-weight: 500;
}

.tx-positive {
  color: var(--accent);
  font-weight: 500;
}

.tx-account {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.tx-category {
  font-size: 0.8rem;
  color: var(--accent-tertiary);
}

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

.text-center {
  text-align: center;
}

/* === Utilities === */
.text-secondary {
  color: var(--text-secondary);
}

.text-accent {
  color: var(--accent);
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* === Button === */
.btn {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: opacity 0.2s;
}

.btn:hover {
  opacity: 0.85;
}

.btn-accent {
  background: var(--accent);
  color: #0a0a0f;
}

[data-theme="light"] .btn-accent {
  color: #ffffff;
}

/* === Coverage Bar === */
.coverage-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin: 1.25rem 0;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.coverage-stats {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 180px;
}

.coverage-pct {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.coverage-detail {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.coverage-track {
  flex: 1;
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
  min-width: 120px;
}

.coverage-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s ease;
}

.coverage-actions {
  margin-left: auto;
}

/* === Category Grid === */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.cat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  transition: border-color 0.2s;
}

.cat-card:hover {
  border-color: var(--accent);
}

.cat-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.cat-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

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

.cat-stats {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.cat-stat strong {
  color: var(--text-primary);
}

.cat-keywords {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.keyword-pill {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--accent-tertiary);
}

/* === Uncategorized Section === */
.uncat-section {
  margin-top: 2rem;
  padding: 1.25rem 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  border-left: 3px solid #f87171;
}

.uncat-section h2 {
  font-size: 1rem;
  color: #f87171;
  margin-bottom: 0.25rem;
}

/* === Searchable Select === */
.search-select {
  position: relative;
}

.search-select-input {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: text;
  width: 100%;
  min-width: 180px;
}

.search-select-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(57, 255, 20, 0.15);
}

.search-select-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 4px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.search-select-dropdown.open {
  display: block;
}

.search-select-option {
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-select-option:hover {
  background: var(--hover-bg);
  color: var(--accent);
}

.search-select-option.hidden {
  display: none;
}

.search-select-create {
  border-top: 1px solid var(--border);
  color: var(--accent);
  font-style: italic;
}

/* Inline variant (inside table rows) */
.search-select-inline {
  min-width: 150px;
}

.search-select-inline .search-select-input {
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  background: transparent;
  border-color: transparent;
  min-width: auto;
}

.search-select-inline .search-select-input:hover {
  border-color: var(--border);
}

.search-select-inline .search-select-dropdown {
  min-width: 200px;
}

/* === Inline Category Select === */
.tx-category-cell {
  padding-top: 0.3rem !important;
  padding-bottom: 0.3rem !important;
}

.tx-category-select {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  background: transparent;
  color: var(--accent-tertiary);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  min-width: 150px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='%23888' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
  padding-right: 1.5rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.tx-category-select:hover {
  border-color: var(--border);
}

.tx-category-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(57, 255, 20, 0.15);
}

.tx-category-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Uncategorized styling */
.tx-uncat-select {
  color: #f87171;
}

.tx-uncategorized {
  border-left: 3px solid #f87171;
}

/* Save flash animation */
.tx-save-flash {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px rgba(57, 255, 20, 0.3) !important;
  transition: border-color 0.15s, box-shadow 0.15s;
}

/* === KPI Cards === */
.kpi-row {
  display: flex;
  gap: 1rem;
}

.kpi-card {
  flex: 1;
  text-align: center;
  padding: 1rem !important;
}

.kpi-label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.kpi-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
}

/* === Toggle Switch === */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;
}

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

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background: var(--text-primary);
  border-radius: 50%;
  transition: transform 0.2s;
}

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

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

/* Hidden account row */
.row-hidden {
  opacity: 0.4;
}

/* Account alias input */
.acct-alias-input {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
  width: 100%;
}

.acct-alias-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* === Search Box === */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box-input {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 200px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(57, 255, 20, 0.15);
}

.search-box-input::placeholder {
  color: var(--text-secondary);
}

.search-clear {
  position: absolute;
  right: 8px;
  color: var(--text-secondary);
  font-size: 1.1rem;
  line-height: 1;
  text-decoration: none;
  padding: 2px 4px;
}

.search-clear:hover {
  color: #f87171;
  text-decoration: none;
}

/* === Search Highlight === */
.search-highlight {
  background: rgba(57, 255, 20, 0.12);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 1px;
}

[data-theme="light"] .search-highlight {
  background: rgba(22, 163, 74, 0.12);
}

/* === Transaction Detail Button === */
.tx-action-cell {
  padding: 0.4rem 0.25rem !important;
  width: 36px;
}

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

.tx-detail-btn:hover {
  color: var(--accent);
  border-color: var(--border);
  background: var(--hover-bg);
}

/* === Modal === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.15s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
  transition: color 0.2s;
}

.modal-close:hover {
  color: #f87171;
}

.modal-amount {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.modal-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
  word-break: break-word;
}

.modal-fields {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.modal-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.modal-field:last-child {
  border-bottom: none;
}

.modal-label {
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* === Rule Learning Toast === */
.rule-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  width: 380px;
  max-width: calc(100vw - 2rem);
  z-index: 600;
  box-shadow: 0 8px 32px rgba(57, 255, 20, 0.15), 0 4px 12px rgba(0, 0, 0, 0.3);
  transform: translateY(20px);
  opacity: 0;
  transition: transform 0.2s ease-out, opacity 0.2s ease-out;
}

.rule-toast.open {
  transform: translateY(0);
  opacity: 1;
}

.rule-toast-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.rule-toast-icon {
  font-size: 1.1rem;
}

.rule-toast-title {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex: 1;
}

.rule-toast-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}

.rule-toast-close:hover {
  color: #f87171;
}

.rule-toast-body {
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 0.75rem;
}

.rule-toast-info .rule-toast-body {
  margin-bottom: 0;
}

.rule-toast-keyword-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}

.rule-keyword-input {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  background: var(--bg-secondary);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 160px;
  outline: none;
  transition: border-color 0.2s;
}

.rule-keyword-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(57, 255, 20, 0.15);
}

.rule-type-toggle {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.rule-type-btn {
  font-family: inherit;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

.rule-type-btn:first-child {
  border-right: 1px solid var(--border);
}

.rule-type-btn.active {
  background: var(--accent);
  color: #0a0a0f;
}

[data-theme="light"] .rule-type-btn.active {
  color: #fff;
}

.rule-toast-match-info {
  font-size: 0.8rem;
}

.rule-toast-conflicts {
  margin: 0.4rem 0;
  padding: 0.5rem 0.6rem;
  background: rgba(234, 179, 8, 0.08);
  border: 1px solid rgba(234, 179, 8, 0.2);
  border-radius: 6px;
  font-size: 0.8rem;
}

.conflict-label {
  color: #eab308;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: block;
  margin-bottom: 0.3rem;
}

.conflict-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0;
}

.conflict-pattern {
  color: #eab308;
  font-weight: 600;
}

.conflict-priority {
  font-size: 0.7rem;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-weight: 600;
}

.rule-toast-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
}

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

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

.btn-done {
  background: #22c55e !important;
  pointer-events: none;
}

/* === Modal Rule Action === */
.modal-rule-action {
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* === Dashboard === */
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.dash-month-form select {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23888' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.dash-month-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(57, 255, 20, 0.15);
}

.summary-cards {
  display: flex;
  gap: 1rem;
  margin: 1.25rem 0;
}

.summary-card {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.summary-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.summary-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.card-spent .summary-value {
  color: #f87171;
}

.card-income .summary-value {
  color: var(--accent);
}

.summary-sub {
  font-size: 0.7rem;
  color: var(--text-secondary);
  opacity: 0.8;
}

.card-net .summary-value.net-positive {
  color: var(--accent);
}

.card-net .summary-value.net-negative {
  color: #f87171;
}

.chart-row {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
}

.chart-container {
  min-width: 0;
}

.chart-container:first-child {
  flex: 2;
}

.chart-container:last-child {
  flex: 3;
}

.chart-container h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.chart-container canvas {
  max-height: 400px;
}

/* === Budget Page === */
.budget-summary {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.budget-summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.budget-summary-labels {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.budget-summary-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.budget-summary-amounts {
  font-size: 1.25rem;
  font-weight: 700;
}

.budget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.budget-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.budget-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.budget-amounts {
  font-size: 0.95rem;
  font-weight: 600;
}

.budget-spent {
  color: var(--text-primary);
}

.budget-limit {
  color: var(--text-secondary);
  border-bottom: 1px dashed var(--border);
  padding-bottom: 1px;
  transition: color 0.2s, border-color 0.2s;
}

.budget-limit:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.budget-limit-input {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  background: var(--bg-secondary);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  width: 100px;
  outline: none;
  box-shadow: 0 0 0 2px rgba(57, 255, 20, 0.15);
}

.budget-progress-track {
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
}

.budget-progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.budget-green {
  background: #22c55e;
}

.budget-yellow {
  background: #eab308;
}

.budget-red {
  background: #f87171;
}

.budget-values {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin: 0.5rem 0;
}

.budget-value-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.budget-value-label {
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.budget-value-amount {
  font-weight: 600;
}

.budget-value-row-set {
  background: rgba(57, 255, 20, 0.08);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  margin: 0 -0.4rem;
}

.budget-label-set {
  color: var(--accent) !important;
  font-weight: 600;
}

.budget-amount-set {
  color: var(--accent) !important;
}

/* === Spending Breakdown Bar === */
.spending-bar-wrap {
  position: relative;
  margin-bottom: 1.5rem;
}

.spending-bar {
  display: flex;
  height: 20px;
  border-radius: 6px;
  overflow: hidden;
}

.spending-budget-line {
  position: absolute;
  top: -4px;
  bottom: -20px;
  width: 0;
  border-left: 2px dashed var(--accent);
  pointer-events: none;
}

.spending-budget-label {
  position: absolute;
  top: 100%;
  left: 2px;
  white-space: nowrap;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 2px;
}

.spending-bar-seg {
  transition: width 0.3s;
  min-width: 2px;
}

.seg-within { background: #22c55e; }
.seg-over { background: #f87171; }
.seg-savings { background: #3b82f6; }
.seg-other { background: #a855f7; }
.seg-untracked { background: var(--border); }

.spending-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.spending-legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.spending-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.budget-drift-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.drift-over {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
}

.drift-under {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.budget-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
}

.budget-pct {
  font-weight: 700;
  font-size: 1rem;
}

.budget-pct-green {
  color: #22c55e;
}

.budget-pct-yellow {
  color: #eab308;
}

.budget-pct-red {
  color: #f87171;
}

.budget-over {
  color: #f87171;
  font-weight: 500;
}

.budget-remaining {
  color: var(--text-secondary);
}

.budget-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
}

.badge-auto {
  background: rgba(57, 255, 20, 0.1);
  color: var(--accent);
  border: 1px solid rgba(57, 255, 20, 0.2);
}

.badge-manual {
  background: rgba(124, 58, 237, 0.1);
  color: var(--accent-secondary);
  border: 1px solid rgba(124, 58, 237, 0.2);
}

.budget-empty h2 {
  font-size: 1.1rem;
}

/* === Rules Page === */
.rule-tester {
  padding: 1.25rem 1.5rem;
}

.rule-tester h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.rule-tester-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.rule-test-result {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.rule-test-match {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
}

.rule-test-winner {
  background: rgba(57, 255, 20, 0.06);
  border: 1px solid rgba(57, 255, 20, 0.15);
}

.rule-winner-badge {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(57, 255, 20, 0.12);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-left: 0.3rem;
}

.rule-priority-badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  min-width: 28px;
  text-align: center;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  cursor: pointer;
}

.priority-high {
  color: var(--accent);
  background: rgba(57, 255, 20, 0.1);
}

.priority-med {
  color: #eab308;
  background: rgba(234, 179, 8, 0.1);
}

.priority-low {
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

.rule-match-type-pill {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 0.4rem;
}

.pill-keyword {
  color: var(--accent-tertiary);
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid rgba(6, 182, 212, 0.2);
}

.pill-regex {
  color: var(--accent-secondary);
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid rgba(124, 58, 237, 0.2);
}

.rule-pattern {
  font-weight: 600;
  color: var(--accent-tertiary);
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: border-color 0.2s;
}

.rule-pattern:hover {
  border-color: var(--accent-tertiary);
}

.rule-category-select {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  background: transparent;
  color: var(--text-primary);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='%23888' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.3rem center;
  padding-right: 1.2rem;
}

.rule-category-select:hover {
  border-color: var(--border);
}

.rule-category-select:focus {
  outline: none;
  border-color: var(--accent);
}

.rule-category-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Suggestion scan button */
.sug-scan-btn {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.sug-scan-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

/* Suggestion category dropdown */
.sug-cat-select {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='%23888' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.3rem center;
  padding-right: 1.2rem;
}

.sug-cat-select:hover {
  border-color: var(--text-secondary);
}

.sug-cat-select:focus {
  outline: none;
  border-color: var(--accent);
}

.sug-cat-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Suggestion accept button */
.sug-accept {
  background: var(--bg-secondary);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.sug-accept:hover {
  background: var(--accent);
  color: #0a0a0f;
}

.rule-inline-input {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  background: var(--bg-secondary);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  outline: none;
  box-shadow: 0 0 0 2px rgba(57, 255, 20, 0.15);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.btn-icon:hover {
  color: #f87171;
  background: rgba(248, 113, 113, 0.1);
}

/* === Dashboard Savings Card === */
.card-savings .summary-value.savings-positive {
  color: #22c55e;
}

.card-savings .summary-value.savings-negative {
  color: #f87171;
}

/* === Dashboard Budget Health === */
.budget-health {
  padding: 1.25rem 1.5rem;
}

.budget-health h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.budget-health-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.budget-health-link {
  font-size: 0.8rem;
  color: var(--accent);
}

.budget-health-rows {
  display: grid;
  grid-template-columns: auto 160px 1fr 100px 55px;
  column-gap: 0.75rem;
  row-gap: 0.6rem;
  align-items: center;
  position: relative;
}

.budget-health-row {
  display: contents;
}

.budget-health-name {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.budget-mini-track {
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 3px;
  display: flex;
  width: 100%;
  min-width: 0;
  position: relative;
  overflow: visible;
}

.budget-mini-track > .budget-progress-fill:first-child {
  border-top-left-radius: 3px;
  border-bottom-left-radius: 3px;
}

.budget-mini-track[data-mark]::after {
  content: '';
  position: absolute;
  left: var(--mark-x);
  top: -0.95rem;
  bottom: -0.95rem;
  width: 1px;
  background: var(--text-secondary);
  opacity: 0.35;
  pointer-events: none;
}

.budget-health-amounts {
  font-size: 0.75rem;
  text-align: right;
}

.budget-health-row .budget-pct {
  font-size: 0.8rem;
  font-weight: 700;
  text-align: right;
}


/* === Hamburger Menu (hidden on desktop) === */
.nav-hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  flex-direction: column;
  gap: 5px;
}

.nav-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: background 0.2s;
}

.nav-hamburger:hover span {
  background: var(--accent);
}

.nav-menu-header {
  display: none;
}

.nav-backdrop {
  display: none;
}

.nav-desktop-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* === Goals Page === */
.goal-section-title {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.goals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
}

.goal-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.goal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.goal-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.goal-name {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.goal-type-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  flex-shrink: 0;
}

.badge-savings {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.badge-debt {
  background: rgba(248, 113, 113, 0.1);
  color: #f87171;
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.goal-header-actions {
  display: flex;
  gap: 0.25rem;
}

.goal-progress-track {
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
}

.goal-progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.goal-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.goal-stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.goal-stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
}

.goal-stat-value {
  font-size: 0.95rem;
  font-weight: 600;
}

.goal-current-display {
  border-bottom: 1px dashed var(--border);
  padding-bottom: 1px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.goal-current-display:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.goal-pct {
  font-size: 1.1rem;
  font-weight: 700;
}

.goal-amount-input {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  background: var(--bg-secondary);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  width: 100px;
  outline: none;
  box-shadow: 0 0 0 2px rgba(57, 255, 20, 0.15);
}

.goal-target-date {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
}

.goal-on-track {
  color: #22c55e;
  font-weight: 600;
}

.goal-behind {
  color: #f87171;
  font-weight: 600;
}

.goal-pace {
  font-weight: 500;
}

.goal-notes {
  font-size: 0.8rem;
  font-style: italic;
}

/* Debt-specific */
.goal-apr-badge {
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: rgba(234, 179, 8, 0.1);
  color: #eab308;
  border: 1px solid rgba(234, 179, 8, 0.2);
}

.goal-promo-badge {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.promo-expired {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
}

.promo-urgent {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
  animation: promoPulse 2s ease-in-out infinite;
}

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

.promo-warning {
  background: rgba(234, 179, 8, 0.1);
  color: #eab308;
}

.promo-ok {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
}

.goal-monthly-target {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.goal-linked-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-tertiary);
  background: rgba(6, 182, 212, 0.08);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  border: 1px solid rgba(6, 182, 212, 0.15);
}

.goal-projections {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  font-size: 0.85rem;
}

.goal-projection-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.goal-projection-label {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.goal-projection-value {
  font-weight: 600;
  font-size: 0.85rem;
}

.goal-payments {
  font-size: 0.85rem;
}

.goal-payments-header {
  cursor: pointer;
}

.goal-payments-header:hover span {
  color: var(--accent);
}

.goal-payments-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.4rem;
  padding: 0.5rem 0.6rem;
  background: var(--bg-secondary);
  border-radius: 6px;
}

.goal-payment-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
}

/* Multi-debt priority */
.debt-priority-banner {
  border-left: 3px solid var(--accent);
}

.debt-priority-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.debt-priority-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.debt-priority-first {
  background: rgba(57, 255, 20, 0.06);
  border: 1px solid rgba(57, 255, 20, 0.15);
}

.debt-priority-rank {
  font-weight: 700;
  color: var(--accent);
  min-width: 20px;
}

.debt-priority-name {
  flex: 1;
  font-weight: 500;
}

.debt-priority-balance {
  font-weight: 600;
  color: #f87171;
}

.goal-empty {
  text-align: center;
  padding: 3rem 1.5rem;
}

.goal-empty h2 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

/* Goal Form */
.goal-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.goal-form-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.goal-form-field label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.goal-form-field input,
.goal-form-field select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.goal-form-field input[type="date"] {
  color-scheme: dark;
}

[data-theme="light"] .goal-form-field input[type="date"] {
  color-scheme: light;
}

.goal-form-field input:focus,
.goal-form-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(57, 255, 20, 0.15);
}

.goal-form-field select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Goal rule search dropdown */
.goal-rule-search {
  position: relative;
}

.goal-rule-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 4px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 300;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.goal-rule-dropdown.open {
  display: block;
}

.goal-rule-option {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.goal-rule-option:hover {
  background: var(--hover-bg);
}

.goal-rule-option.hidden {
  display: none;
}

.goal-rule-option.selected {
  background: var(--hover-bg);
  color: var(--accent);
}

.goal-form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* === Responsive === */

/* --- Large (≤1024px) --- */
@media (max-width: 1024px) {
  .main {
    padding: 1.5rem 1rem;
  }

  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.15rem; }
  h3 { font-size: 0.95rem; }

  .nav-group-label {
    font-size: 0.7rem;
    padding: 0.35rem 0.45rem;
  }

  .nav-group {
    padding: 0 0.15rem;
  }
}

/* --- Medium (≤768px) — Hamburger activates --- */
@media (max-width: 768px) {
  /* Hamburger nav */
  .nav-hamburger {
    display: flex;
  }

  .nav-desktop-actions {
    display: none;
  }

  .nav-menu {
    display: flex;
    position: fixed;
    top: 0;
    right: -280px;
    width: 280px;
    height: 100vh;
    background: var(--nav-bg);
    border-left: 1px solid var(--nav-border);
    z-index: 1000;
    flex-direction: column;
    padding: 0;
    transition: right 0.25s ease;
    overflow-y: auto;
  }

  .nav-menu .nav-actions {
    display: flex;
  }

  .nav-menu.open {
    right: 0;
  }

  .nav-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
  }

  .nav-menu-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.6rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    transition: color 0.2s;
  }

  .nav-menu-close:hover {
    color: var(--accent);
  }

  .nav-menu .nav-links {
    flex-direction: column;
    gap: 0;
    padding: 0;
  }

  .nav-menu .nav-group {
    display: block;
    padding: 0;
    border-left: none;
  }

  .nav-menu .nav-group + .nav-group {
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .nav-menu .nav-group-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 0.75rem 1.25rem 0.25rem;
  }

  .nav-menu .nav-group-items {
    display: flex;
    flex-direction: column;
    gap: 0;
    position: static;
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    min-width: unset;
    box-shadow: none;
  }

  .nav-menu .nav-group-items li {
    border-bottom: 1px solid var(--border);
  }

  .nav-menu .nav-group-items li:last-child {
    border-bottom: none;
  }

  .nav-menu .nav-group-items a {
    display: block;
    padding: 0.75rem 1.25rem 0.75rem 1.75rem;
    font-size: 0.9rem;
    min-height: 44px;
    border-radius: 0;
    white-space: normal;
  }

  .nav-menu .nav-actions {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    margin-top: auto;
  }

  .nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .nav-backdrop.open {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  /* Layout */
  .main {
    padding: 1.25rem 0.75rem;
  }

  h1 { font-size: 1.25rem; }

  /* Dashboard */
  .summary-cards {
    flex-direction: column;
  }

  .chart-row {
    flex-direction: column;
  }

  .chart-container:first-child,
  .chart-container:last-child {
    flex: 1 1 100%;
  }

  .chart-container canvas {
    max-height: 300px;
  }

  /* Budget */
  .budget-grid {
    grid-template-columns: 1fr;
  }

  .kpi-row {
    flex-direction: column;
  }

  .budget-health-rows {
    grid-template-columns: auto 1fr 45px;
  }

  .budget-health-row .cat-swatch {
    display: none;
  }

  .budget-health-name {
    min-width: 60px;
    font-size: 0.75rem;
  }

  .budget-health-amounts {
    display: none;
  }

  .budget-health-row .budget-pct {
    font-size: 0.7rem;
    min-width: 40px;
  }

  .spending-legend {
    gap: 0.5rem;
  }

  .spending-legend-item {
    font-size: 0.75rem;
  }

  /* Categories */
  .cat-grid {
    grid-template-columns: 1fr;
  }

  /* Goals */
  .goals-grid {
    grid-template-columns: 1fr;
  }

  .coverage-bar {
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
  }

  .coverage-actions {
    margin-left: 0;
    width: 100%;
  }

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

  /* Trends */
  .trends-changes {
    grid-template-columns: 1fr;
  }

  .trends-change-row {
    flex-wrap: wrap;
  }

  .trends-change-amounts {
    display: none;
  }

  /* Tables — horizontal scroll wrapper */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tx-table {
    min-width: 600px;
  }

  /* Filter bar */
  .filter-bar {
    gap: 0.75rem;
  }

  .filter-group select {
    min-width: 140px;
  }

  .search-box-input {
    min-width: 140px;
  }

  .filter-count {
    width: 100%;
    margin-left: 0;
    padding-bottom: 0;
  }

  /* Rule tester */
  .rule-tester {
    padding: 1rem;
  }

  /* Modal */
  .modal {
    width: 95%;
    max-width: none;
    margin: 0.5rem;
  }

  /* Toast */
  .rule-toast {
    right: 0.5rem;
    left: 0.5rem;
    bottom: 0.5rem;
    width: auto;
  }

  /* Touch-friendly targets */
  .btn {
    min-height: 44px;
    padding: 0.6rem 1rem;
  }

  .btn-sm {
    min-height: 36px;
  }

  .btn-icon {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .toggle-switch {
    width: 44px;
    height: 24px;
  }

  .tx-detail-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 8px;
  }

  select {
    min-height: 44px;
  }

  input[type="text"],
  input[type="number"] {
    min-height: 44px;
  }

  /* Settings tables */
  .acct-alias-input {
    min-height: 36px;
  }

  /* Snapshot report content */
  .report-content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Dash header */
  .dash-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
}

/* --- Small (≤480px) --- */
@media (max-width: 480px) {
  .main {
    padding: 1rem 0.5rem;
  }

  h1 { font-size: 1.1rem; }
  h2 { font-size: 1rem; }

  .summary-card {
    padding: 1rem;
  }

  .summary-value {
    font-size: 1.25rem;
  }

  .card {
    padding: 1rem;
    border-radius: 8px;
  }

  .kpi-card {
    padding: 0.75rem !important;
  }

  .kpi-value {
    font-size: 1.1rem;
  }

  .budget-card-header {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .budget-amounts {
    font-size: 0.85rem;
  }

  /* Trends merchant table */
  .tx-table {
    font-size: 0.75rem;
  }

  .tx-table th,
  .tx-table td {
    padding: 0.5rem 0.5rem;
  }

  /* Filter bar stacks fully */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group {
    width: 100%;
  }

  .filter-group select {
    width: 100%;
    min-width: auto;
  }

  .search-box-input {
    width: 100%;
    min-width: auto;
  }

  .range-buttons {
    width: 100%;
  }

  .range-btn {
    flex: 1;
    text-align: center;
    min-height: 44px;
  }

  /* Modal fills screen */
  .modal {
    width: 100%;
    margin: 0;
    border-radius: 12px 12px 0 0;
    max-height: 85vh;
  }

  .modal-amount {
    font-size: 1.5rem;
  }

  /* Toast full width */
  .rule-toast {
    right: 0;
    left: 0;
    bottom: 0;
    border-radius: 12px 12px 0 0;
  }

  .chart-container canvas {
    max-height: 250px;
  }
}

/* === Trends Page === */
.chart-container-wide {
  flex: 1 1 100%;
  min-height: 400px;
}

.trends-changes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.trends-change-card {
  padding: 1.25rem 1.5rem;
}

.trends-change-title {
  margin-bottom: 1rem;
  font-size: 1rem;
}

.trends-change-title.trends-up {
  color: #f87171;
}

.trends-change-title.trends-down {
  color: #22c55e;
}

.trends-change-rows {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.trends-change-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.trends-change-name {
  flex: 1;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trends-change-amounts {
  font-size: 0.75rem;
  white-space: nowrap;
}

.trends-change-delta {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  min-width: 100px;
  text-align: right;
}

.trends-change-delta small {
  font-weight: 400;
  opacity: 0.7;
}

.trends-delta-up {
  color: #f87171;
}

.trends-delta-down {
  color: #22c55e;
}

/* trends 768px consolidated into main responsive section above */

/* === Login Page === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
  padding: 1rem;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.login-brand {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-card label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.login-card input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 1rem;
  transition: border-color 0.2s;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-card button {
  width: 100%;
  padding: 0.7rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--bg-primary);
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: opacity 0.2s;
  margin-top: 0.5rem;
}

.login-card button:hover {
  opacity: 0.85;
}

.login-error {
  background: rgba(248, 113, 113, 0.12);
  color: #f87171;
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  text-align: center;
}
