/* ==========================================================================
   SpendTrack — The Financial Luminary ("Sovereign Vault") Design System
   Zero-Build Vanilla CSS
   ========================================================================== */

:root {
  /* Surface Hierarchy & Tonal Layering */
  --surface-lowest: #0c0e15;
  --surface: #11131a;
  --surface-low: #191b22;
  --surface-container: #1d1f26;
  --surface-high: #282a31;
  --surface-highest: #33343c;
  --surface-bright: #373941;

  /* Text & Foreground */
  --on-surface: #e2e2ec;
  --on-surface-variant: #c1c6d7;
  --outline: #8b90a0;
  --outline-variant: #414755;

  /* Signature Accents */
  --primary: #00e475;
  --primary-container: #00a754;
  --primary-fixed: #62ff96;
  --on-primary: #003114;

  --secondary: #b0c6ff;
  --secondary-container: #0068ed;

  --tertiary: #ffb4ac;
  --tertiary-container: #de7067;

  --amber: #f59e0b;
  --purple: #a855f7;
  --cyan: #06b6d4;
  --pink: #ec4899;

  /* Borders & Glows */
  --ghost-border: rgba(65, 71, 85, 0.18);
  --ghost-border-strong: rgba(65, 71, 85, 0.35);
  --primary-glow: 0 24px 36px -4px rgba(0, 228, 117, 0.08);
  --ambient-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);

  /* Typography */
  --font-headline: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Radiuses */
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;
}

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

st-app,
st-summary-cards,
st-filter-bar,
st-spending-chart,
st-month-comparison-chart,
st-transaction-list,
st-add-modal,
st-settings-modal {
  display: block;
  max-width: 100%;
  min-width: 0;
}

html {
  overflow-y: scroll; /* Prevents scrollbar jump when filtering reduces list length */
  overflow-x: hidden;
  max-width: 100vw;
  background-color: var(--surface);
  color: var(--on-surface);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
  background-color: var(--surface);
  background-image:
    radial-gradient(circle at 12% 0%, rgba(0, 228, 117, 0.045) 0%, transparent 40%),
    radial-gradient(circle at 88% 12%, rgba(0, 104, 237, 0.05) 0%, transparent 40%);
  color: var(--on-surface);
  line-height: 1.5;
}

html.modal-open,
body.modal-open {
  overflow: hidden !important;
  overscroll-behavior: contain;
}

::selection {
  background: var(--primary);
  color: var(--on-primary);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--surface-highest);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--outline-variant);
}

/* ==========================================================================
   Top Glass Header
   ========================================================================== */
.top-glass-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(17, 19, 26, 0.72);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--ghost-border);
  box-shadow: var(--primary-glow);
}

.header-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0.85rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: nowrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.brand-mark {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 0.7rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-container) 100%);
  color: var(--on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(0, 228, 117, 0.22);
  flex-shrink: 0;
}

.brand-title {
  font-family: var(--font-headline);
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  color: var(--on-surface);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
}

.brand-accent {
  color: var(--primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

/* Sync status in header (Desktop vs Mobile) */
.desktop-only-sync {
  display: flex;
}

.mobile-only-sync {
  display: none !important;
  position: relative;
}

.mobile-sync-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
}

.btn-label-desktop,
.trend-label-desktop {
  display: inline;
}

.btn-label-mobile,
.trend-label-mobile {
  display: none;
}

.spin-icon {
  animation: spin 1s linear infinite;
}

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

/* Sync Status Pill */
.sync-pill-group {
  display: flex;
  align-items: center;
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-full);
  padding: 0.25rem 0.35rem 0.25rem 0.85rem;
  gap: 0.6rem;
}

.sync-indicator {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  color: var(--on-surface-variant);
  white-space: nowrap;
}

.sync-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
}

.sync-dot.syncing {
  background: var(--secondary);
  box-shadow: 0 0 8px var(--secondary);
  animation: pulseGlow 1.2s infinite ease-in-out;
}

.sync-dot.warning {
  background: var(--tertiary-container);
  box-shadow: 0 0 8px var(--tertiary-container);
}

.sync-dot.disconnected {
  background: var(--outline);
  box-shadow: none;
}

@keyframes pulseGlow {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(1.25); }
}

.btn-sync-now {
  background: var(--surface-container);
  color: var(--on-surface);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-full);
  padding: 0.3rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.btn-sync-now:hover:not(:disabled) {
  background: var(--surface-highest);
  color: var(--primary);
  border-color: rgba(0, 228, 117, 0.3);
}

.btn-sync-now:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* Reauth Alert Banner */
.reauth-banner {
  max-width: 1360px;
  margin: 1rem auto 0;
  padding: 0 1.75rem;
}

.reauth-banner-inner {
  background: rgba(222, 112, 103, 0.1);
  border: 1px solid rgba(222, 112, 103, 0.35);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-container) 100%);
  color: var(--on-primary);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  box-shadow: 0 12px 24px -6px rgba(0, 228, 117, 0.25);
  transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary:hover {
  filter: brightness(1.06);
  box-shadow: 0 16px 28px -6px rgba(0, 228, 117, 0.35);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: var(--surface-low);
  color: var(--on-surface);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.85rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--ghost-border-strong);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.btn-secondary:hover {
  background: var(--surface-container);
  border-color: rgba(176, 198, 255, 0.35);
  color: #fff;
}

.btn-ghost-icon {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: var(--radius-md);
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  color: var(--on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
}

.btn-ghost-icon:hover {
  background: var(--surface-container);
  color: var(--primary);
  border-color: rgba(0, 228, 117, 0.28);
}

.btn-danger-ghost {
  background: rgba(222, 112, 103, 0.1);
  color: var(--tertiary);
  border: 1px solid rgba(222, 112, 103, 0.25);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease;
}

.btn-danger-ghost:hover {
  background: rgba(222, 112, 103, 0.2);
  border-color: rgba(222, 112, 103, 0.45);
}

/* ==========================================================================
   Main Bento Workspace
   ========================================================================== */
.vault-main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 1.75rem 1.75rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Subheader & Filter Bar */
.page-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem;
}

.page-title-block h1 {
  font-family: var(--font-headline);
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--on-surface);
  margin-bottom: 0.2rem;
}

.page-title-block p {
  font-size: 0.875rem;
  color: var(--on-surface-variant);
}

/* Filter Controls Bar */
.filter-shell {
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-xl);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  transition: all 0.2s ease;
  width: 100%;
}

.filter-primary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  flex-wrap: wrap;
}

.month-stepper {
  display: inline-flex;
  align-items: center;
  background: var(--surface-lowest);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-md);
  padding: 0.2rem;
  gap: 0.2rem;
  flex-shrink: 0;
}

.month-step-btn {
  background: transparent;
  border: none;
  color: var(--on-surface-variant);
  width: 1.9rem;
  height: 1.9rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.month-step-btn:hover:not(:disabled) {
  background: var(--surface-container);
  color: var(--primary);
}

.month-step-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.filter-select,
.filter-input {
  background: var(--surface-lowest);
  color: var(--on-surface);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.85rem;
  font-family: var(--font-body);
  font-size: 0.825rem;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.month-stepper .filter-select {
  border: none;
  background: transparent;
  font-weight: 600;
  padding: 0.35rem 0.5rem;
  font-size: 0.825rem;
  cursor: pointer;
}

.filter-select:focus,
.filter-input:focus {
  outline: none;
  border-color: rgba(0, 228, 117, 0.45);
  box-shadow: 0 0 0 2px rgba(0, 228, 117, 0.12);
}

.filter-primary-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-filter-toggle {
  background: var(--surface-lowest);
  color: var(--on-surface-variant);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-full);
  padding: 0.38rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.18s ease;
}

.btn-filter-toggle:hover {
  border-color: var(--ghost-border-strong);
  color: var(--on-surface);
  background: var(--surface-container);
}

.btn-filter-toggle.open {
  background: var(--surface-container);
  color: var(--on-surface);
  border-color: var(--ghost-border-strong);
}

.btn-filter-toggle.has-active {
  background: rgba(0, 228, 117, 0.1);
  color: var(--primary);
  border-color: rgba(0, 228, 117, 0.35);
}

.filter-count-badge {
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-full);
  line-height: 1;
}

.chevron-icon {
  transition: transform 0.2s ease;
}

.chevron-icon.open {
  transform: rotate(180deg);
}

.chip-toggle {
  background: var(--surface-lowest);
  color: var(--on-surface-variant);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-full);
  padding: 0.38rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.chip-toggle:hover {
  border-color: var(--ghost-border-strong);
  color: var(--on-surface);
}

.chip-toggle.active {
  background: rgba(245, 158, 11, 0.14);
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.4);
}

.review-label-desktop {
  display: inline;
}

.review-label-mobile {
  display: none;
}

.filter-btn-text {
  display: inline;
}

.clear-btn-text {
  display: inline;
}

.chip-clear {
  background: transparent;
  color: var(--primary);
  border: none;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: var(--radius-full);
  transition: background 0.15s ease;
}

.chip-clear:hover {
  background: rgba(0, 228, 117, 0.08);
}

/* Collapsible Secondary Filter Drawer */
.filter-drawer {
  width: 100%;
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.24s cubic-bezier(0.4, 0, 0.2, 1), margin-top 0.24s ease, opacity 0.2s ease;
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
}

.filter-drawer.expanded {
  grid-template-rows: 1fr;
  opacity: 1;
  visibility: visible;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--ghost-border);
}

.filter-drawer-inner {
  min-height: 0;
  overflow: hidden;
}

.filter-grid-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 1.6fr;
  gap: 0.85rem;
  align-items: flex-end;
}

@media (max-width: 840px) {
  .filter-grid-fields {
    grid-template-columns: 1fr 1fr;
  }
  .filter-field-box.filter-search-box {
    grid-column: span 2;
  }
}

@media (max-width: 540px) {
  .filter-shell {
    padding: 0.6rem 0.75rem;
  }
  .filter-grid-fields {
    grid-template-columns: 1fr;
  }
  .filter-field-box.filter-search-box {
    grid-column: span 1;
  }
  .filter-primary-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    width: 100%;
    flex-wrap: nowrap;
  }
  .month-stepper {
    width: auto;
    flex-shrink: 1;
    min-width: 0;
    padding: 0.15rem;
    gap: 0.1rem;
    justify-content: flex-start;
  }
  .month-stepper .filter-select {
    padding: 0.25rem 0.35rem;
    font-size: 0.8rem;
    max-width: 130px;
    min-width: 0;
    text-overflow: ellipsis;
    text-align: left;
  }
  .month-step-btn {
    width: 1.75rem;
    height: 1.75rem;
    flex-shrink: 0;
  }
  .filter-primary-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    flex-wrap: nowrap;
    justify-content: flex-end;
    width: auto;
  }
  .chip-toggle {
    padding: 0.35rem 0.55rem;
    font-size: 0.78rem;
    gap: 0.35rem;
  }
  .review-label-desktop {
    display: none;
  }
  .review-label-mobile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.72rem;
  }
  .btn-filter-toggle {
    padding: 0.35rem 0.55rem;
    font-size: 0.78rem;
    gap: 0.35rem;
  }
  .filter-btn-text {
    display: none;
  }
  .clear-btn-text {
    display: none;
  }
  .chip-clear {
    padding: 0.35rem 0.45rem;
    font-size: 0.75rem;
  }
}

.filter-field-box {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.filter-field-box label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.search-pill-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.search-pill-wrap svg {
  position: absolute;
  left: 0.85rem;
  width: 0.95rem;
  height: 0.95rem;
  color: var(--outline);
  pointer-events: none;
}

.search-pill-input {
  background: var(--surface-lowest);
  color: var(--on-surface);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-full);
  padding: 0.5rem 1.25rem 0.5rem 2.35rem;
  font-size: 0.825rem;
  width: 100%;
  transition: all 0.2s ease;
}

.search-pill-input:focus {
  outline: none;
  border-color: rgba(0, 228, 117, 0.45);
  box-shadow: 0 0 0 2px rgba(0, 228, 117, 0.12);
}

/* ==========================================================================
   KPI Summary Trio (Sovereign Vault Editorial Cards)
   ========================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.25rem;
}

@media (max-width: 900px) {
  .kpi-grid {
    gap: 0.75rem;
  }

  .kpi-card {
    padding: 1.1rem 1rem;
    min-height: auto;
  }

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

.kpi-card {
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-xl);
  padding: 1.4rem 1.6rem;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 138px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.kpi-card:hover {
  border-color: var(--ghost-border-strong);
}

.kpi-glow {
  position: absolute;
  top: -2rem;
  right: -2rem;
  width: 7rem;
  height: 7rem;
  border-radius: 50%;
  filter: blur(36px);
  pointer-events: none;
  opacity: 0.55;
}

.kpi-glow.emerald { background: rgba(0, 228, 117, 0.18); }
.kpi-glow.coral   { background: rgba(222, 112, 103, 0.18); }
.kpi-glow.sapphire{ background: rgba(0, 104, 237, 0.2); }

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--on-surface-variant);
}

.kpi-icon-box {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-icon-box.emerald {
  background: rgba(0, 228, 117, 0.12);
  color: var(--primary);
}

.kpi-icon-box.coral {
  background: rgba(222, 112, 103, 0.12);
  color: var(--tertiary-container);
}

.kpi-icon-box.sapphire {
  background: rgba(176, 198, 255, 0.12);
  color: var(--secondary);
}

.kpi-value {
  font-family: var(--font-headline);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.kpi-value.positive { color: var(--primary); }
.kpi-value.negative { color: var(--tertiary-container); }
.kpi-value.neutral  { color: var(--on-surface); }

.kpi-footer {
  margin-top: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.76rem;
  color: var(--on-surface-variant);
}

.mom-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.18rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap !important;
  flex-shrink: 0 !important;
}

#txTotalCountBadge {
  white-space: nowrap !important;
  flex-shrink: 0 !important;
}


.mom-pill.good {
  background: rgba(0, 228, 117, 0.12);
  color: var(--primary);
}

.mom-pill.warn {
  background: rgba(222, 112, 103, 0.14);
  color: var(--tertiary);
}

.mom-pill.muted {
  background: rgba(193, 198, 215, 0.1);
  color: var(--on-surface-variant);
}

/* Responsive Summary Card Typography & Label Modifiers */
.kpi-label-full,
.mom-context,
.pill-desktop {
  display: inline;
}

.kpi-label-compact,
.pill-mobile {
  display: none;
}

.kpi-subtext {
  font-size: 0.76rem;
  color: var(--on-surface-variant);
  white-space: nowrap;
}

/* Condensed 3-in-a-row Summary Cards for Mobile Viewports */
@media (max-width: 640px) {
  .kpi-grid {
    gap: 0.5rem;
  }

  .kpi-card {
    padding: 0.8rem 0.65rem;
    min-height: auto;
    border-radius: var(--radius-lg);
    justify-content: center;
  }

  .kpi-glow {
    width: 3.5rem;
    height: 3.5rem;
    top: -1rem;
    right: -1rem;
    filter: blur(16px);
    opacity: 0.35;
  }

  .kpi-header {
    margin-bottom: 0.4rem;
    gap: 0.25rem;
  }

  .kpi-label {
    font-size: 0.72rem;
    letter-spacing: 0.05em;
  }

  .kpi-label-full {
    display: none !important;
  }

  .kpi-label-compact {
    display: inline !important;
  }

  /* Drop corner symbols (icon boxes) in mobile */
  .kpi-icon-box {
    display: none !important;
  }

  .kpi-value {
    font-size: clamp(1.15rem, 3.8vw, 1.45rem);
    line-height: 1.15;
    letter-spacing: -0.03em;
    margin-bottom: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Drop the footer in mobile view */
  .kpi-footer {
    display: none !important;
  }
}

@media (max-width: 370px) {
  .kpi-grid {
    gap: 0.35rem;
  }

  .kpi-card {
    padding: 0.7rem 0.5rem;
  }

  .kpi-label {
    font-size: 0.66rem;
  }

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

/* ==========================================================================
   Asymmetric Bento Grid (Left Analytics Column + Right Transaction Ledger)
   ========================================================================== */
.bento-workspace {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1.5rem;
  align-items: start;
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

.bento-analytics {
  grid-column: span 5;
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  min-height: 540px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}

.bento-transactions {
  grid-column: span 7;
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  min-height: 540px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 1080px) {
  .bento-analytics,
  .bento-transactions {
    grid-column: span 12;
  }
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.panel-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.panel-title {
  font-family: var(--font-headline);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--on-surface);
  line-height: 1.3;
}

.panel-subtitle {
  font-size: 0.78rem;
  color: var(--on-surface-variant);
  line-height: 1.35;
}

/* Segmented Pill Toggle (Distribution vs Monthly Trend) */
.segmented-control {
  display: inline-flex;
  background: var(--surface-lowest);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-md);
  padding: 0.2rem;
  gap: 0.2rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.seg-btn {
  background: transparent;
  border: none;
  color: var(--on-surface-variant);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.38rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.18s ease;
}

.seg-btn:hover {
  color: var(--on-surface);
}

.seg-btn.active {
  background: var(--surface-container);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* Analytics Chart Container & Smooth Transition Switcher */
.analytics-chart-container {
  position: relative;
  width: 100%;
  min-height: 380px;
}

.chart-pane {
  transition: opacity 0.22s cubic-bezier(0.4, 0, 0.2, 1), transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  width: 100%;
}

.chart-pane.chart-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  position: relative;
  transform: translateY(0);
}

.chart-pane.chart-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
  transform: translateY(6px);
}

/* ==========================================================================
   Donut Chart & Interactive Legend
   ========================================================================== */
.donut-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0.5rem 0 1.25rem;
  position: relative;
}

.donut-svg-wrap {
  position: relative;
  width: 220px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.donut-segment {
  pointer-events: stroke;
}

.donut-segment:hover {
  filter: brightness(1.15);
}

.donut-center-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
}

.donut-center-caption {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--on-surface-variant);
}

.donut-center-amount {
  font-family: var(--font-headline);
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--on-surface);
  margin-top: 0.15rem;
}

.donut-legend {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.5rem;
}

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  background: var(--surface-lowest);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.16s ease;
}

.legend-row:hover {
  background: var(--surface-container);
  border-color: var(--ghost-border-strong);
}

.legend-row.selected {
  background: rgba(0, 228, 117, 0.08);
  border-color: rgba(0, 228, 117, 0.35);
}

.legend-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--on-surface);
  min-width: 0;
  overflow: hidden;
}

.legend-left span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-swatch {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

st-month-comparison-chart svg {
  max-width: 100%;
  height: auto;
  display: block;
}

.legend-pct {
  color: var(--on-surface-variant);
  font-size: 0.74rem;
  min-width: 2.8rem;
  text-align: right;
}

.legend-amt {
  font-weight: 600;
  color: var(--on-surface);
}

/* ==========================================================================
   Transaction List (No-Line Editorial Cards + Stable Columns)
   ========================================================================== */
.tx-table-wrap {
  width: 100%;
  overflow-x: auto;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}

.tx-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 0.55rem;
  text-align: left;
  table-layout: fixed;
}

.tx-table thead th {
  padding: 0.35rem 0.85rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--outline);
  cursor: pointer;
  user-select: none;
  border: none;
  transition: color 0.15s ease;
}

.tx-table thead th:hover {
  color: var(--on-surface);
}

/* Explicit percentage column widths to prevent layout jumping */
.th-merchant, .td-main { width: 44%; }
.th-category, .col-category { width: 22%; }
.th-account, .col-account  { width: 16%; }
.th-amount, .td-amount   { width: 18%; text-align: right; }

.tx-row {
  background: var(--surface-lowest);
  transition: background-color 0.18s ease, transform 0.18s ease;
  cursor: pointer;
}

.tx-row:hover {
  background: var(--surface-container);
}

.tx-row.editing {
  background: rgba(255, 255, 255, 0.038) !important;
  outline: none !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 4px 18px rgba(0, 0, 0, 0.35);
}

.tx-row.editing td:first-child {
  border-bottom-left-radius: 0 !important;
}

.tx-row.editing td:last-child {
  border-bottom-right-radius: 0 !important;
}

.tx-row td {
  padding: 0.85rem 0.85rem;
  vertical-align: middle;
  border: none;
}

.tx-row td:first-child {
  border-top-left-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-lg);
}

.tx-row td:last-child {
  border-top-right-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

.tx-merchant-cell {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.tx-cat-icon {
  width: 2.65rem;
  height: 2.65rem;
  border-radius: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tx-cat-icon svg {
  width: 1.2rem;
  height: 1.2rem;
}

.tx-merchant-info {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.tx-merchant-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-submeta {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.74rem;
  color: var(--on-surface-variant);
  margin-top: 0.15rem;
  flex-wrap: wrap;
}

/* Category Chip */
.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-high);
  color: var(--on-surface);
  border: 1px solid var(--ghost-border);
}

.cat-chip.uncategorized {
  background: rgba(245, 158, 11, 0.14);
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.35);
}

.cat-chip.transfer {
  background: rgba(139, 144, 160, 0.14);
  color: var(--on-surface-variant);
}

/* Account & Provenance Badges */
.account-badge {
  font-size: 0.78rem;
  color: var(--on-surface-variant);
  display: flex;
  flex-direction: column;
}

.account-last4 {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--outline);
}

.tx-amount-cell {
  text-align: right;
  flex-shrink: 0;
}

.tx-amount-val {
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--on-surface);
  white-space: nowrap;
}

.tx-amount-val.income {
  color: var(--primary);
}

.tx-amount-val.transfer {
  color: var(--on-surface-variant);
}

.provenance-pill {
  display: inline-block;
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
  margin-top: 0.2rem;
  white-space: nowrap;
}

.provenance-pill.email {
  background: rgba(0, 228, 117, 0.1);
  color: var(--primary);
}

.provenance-pill.manual {
  background: rgba(176, 198, 255, 0.12);
  color: var(--secondary);
}

.provenance-pill.import {
  background: rgba(168, 85, 247, 0.12);
  color: var(--purple);
}

/* Inline Editor Drawer inside Row */
.tx-edit-row td {
  padding: 0 0 0.55rem 0 !important;
  border: none;
}

.inline-edit-panel {
  background: rgba(255, 255, 255, 0.038);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  border-top-left-radius: 0 !important;
  border-top-right-radius: 0 !important;
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
  margin-top: -0.55rem;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25);
  animation: expandDrawer 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  overflow: hidden;
}

@keyframes expandDrawer {
  0% {
    opacity: 0;
    max-height: 0;
    transform: translateY(-4px) scaleY(0.98);
    transform-origin: top center;
  }
  70% {
    opacity: 0.85;
  }
  100% {
    opacity: 1;
    max-height: 260px;
    transform: translateY(0) scaleY(1);
    transform-origin: top center;
  }
}

@keyframes retractDrawer {
  0% {
    opacity: 1;
    max-height: 260px;
    transform: translateY(0) scaleY(1);
    transform-origin: top center;
  }
  30% {
    opacity: 0.8;
  }
  100% {
    opacity: 0;
    max-height: 0;
    transform: translateY(-4px) scaleY(0.98);
    transform-origin: top center;
  }
}

.inline-edit-panel.retracting {
  animation: retractDrawer 0.18s cubic-bezier(0.4, 0, 0.2, 1) forwards !important;
  pointer-events: none;
}

.tx-row.editing.retracting {
  background: var(--surface-lowest) !important;
  box-shadow: none !important;
  transition: background-color 0.18s ease, box-shadow 0.18s ease;
}

.tx-row.editing.retracting td:first-child {
  border-bottom-left-radius: var(--radius-lg) !important;
  transition: border-radius 0.18s ease;
}

.tx-row.editing.retracting td:last-child {
  border-bottom-right-radius: var(--radius-lg) !important;
  transition: border-radius 0.18s ease;
}

.inline-edit-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.inline-cat-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex: 1 1 auto;
}

.inline-cat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--on-surface-variant);
  white-space: nowrap;
  flex-shrink: 0;
}

.edit-cat-select {
  min-width: 140px;
  max-width: 220px;
  padding: 0.42rem 0.65rem;
  font-size: 0.8rem;
}

.inline-edit-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.inline-edit-actions .btn-primary {
  padding: 0.42rem 0.9rem;
  font-size: 0.78rem;
}

.inline-edit-actions .btn-secondary {
  padding: 0.42rem 0.75rem;
  font-size: 0.78rem;
}

.inline-edit-actions .btn-danger-ghost {
  padding: 0.42rem 0.75rem;
  font-size: 0.78rem;
}

.rule-prompt-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--ghost-border);
  font-size: 0.8rem;
  color: var(--on-surface-variant);
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  user-select: none;
  color: var(--on-surface);
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: 0.95rem;
  height: 0.95rem;
  cursor: pointer;
}

/* Mobile Responsive Table Collapse */
.mobile-only-meta {
  display: none;
}

@media (max-width: 720px) {
  .tx-table-wrap {
    overflow-x: hidden !important;
    width: 100%;
  }

  .tx-table {
    display: block;
    width: 100%;
    border-spacing: 0;
  }

  .tx-table thead {
    display: none;
  }

  .tx-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
  }

  .tx-row {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem 0.85rem;
    border-radius: var(--radius-lg) !important;
    box-sizing: border-box;
    gap: 0.65rem;
  }

  .tx-row.editing {
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    margin-bottom: 0 !important;
    box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.08), inset 1px 0 0 0 rgba(255, 255, 255, 0.08), inset -1px 0 0 0 rgba(255, 255, 255, 0.08) !important;
  }

  .tx-row.editing.retracting {
    border-bottom-left-radius: var(--radius-lg) !important;
    border-bottom-right-radius: var(--radius-lg) !important;
    margin-bottom: 0.5rem !important;
    box-shadow: none !important;
  }

  .tx-row td {
    padding: 0 !important;
  }

  .tx-row td.td-main {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
  }

  .tx-row td.col-category,
  .tx-row td.col-account {
    display: none !important;
  }

  .tx-row td.td-amount {
    flex: 0 0 auto;
    text-align: right;
    width: auto;
  }

  .tx-merchant-cell {
    gap: 0.65rem;
    min-width: 0;
  }

  .tx-cat-icon {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.65rem;
  }

  .tx-cat-icon svg {
    width: 1.05rem;
    height: 1.05rem;
  }

  .tx-merchant-info {
    min-width: 0;
  }

  .tx-merchant-name {
    font-size: 0.86rem;
    max-width: 100%;
  }

  .tx-submeta {
    font-size: 0.7rem;
    gap: 0.3rem;
  }

  .mobile-only-meta {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--outline);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tx-amount-val {
    font-size: 0.9rem;
  }

  .provenance-pill {
    font-size: 0.6rem;
    padding: 0.08rem 0.35rem;
  }

  .tx-edit-row {
    display: block !important;
    width: 100%;
    margin-top: -0.5rem !important;
  }

  .tx-edit-row .td-edit-drawer {
    display: block !important;
    padding: 0 !important;
    width: 100%;
  }

  .inline-edit-panel {
    margin-top: 0 !important;
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
    border-bottom-left-radius: var(--radius-lg) !important;
    border-bottom-right-radius: var(--radius-lg) !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.04) !important;
  }

  .inline-edit-top {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .inline-cat-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    flex-wrap: nowrap;
  }

  .inline-cat-label {
    flex-shrink: 0;
    white-space: nowrap;
  }

  .inline-cat-row .edit-cat-select {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .inline-edit-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.45rem;
    width: 100%;
  }

  .inline-edit-actions button {
    flex: 1 1 0;
    text-align: center;
    justify-content: center;
  }

  .rule-prompt-box {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .desktop-only-sync {
    display: none !important;
  }

  .mobile-only-sync {
    display: inline-flex !important;
  }

  .btn-label-desktop,
  .trend-label-desktop {
    display: none !important;
  }

  .btn-label-mobile,
  .trend-label-mobile {
    display: inline !important;
  }

  .analytics-panel-header {
    gap: 0.5rem;
    align-items: flex-start;
  }

  .analytics-panel-header .panel-title {
    font-size: 1.05rem;
  }

  .analytics-panel-header .seg-btn {
    padding: 0.28rem 0.6rem;
    font-size: 0.74rem;
  }

  .header-inner {
    padding: 0.65rem 0.85rem;
  }

  .vault-main {
    padding: 1rem 0.75rem 3.5rem;
    gap: 1.15rem;
  }

  .bento-analytics,
  .bento-transactions {
    padding: 1rem 0.85rem;
    border-radius: var(--radius-lg);
  }
}

/* ==========================================================================
   Modals (Add Transaction & Settings/Rules Drawer)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(12, 14, 21, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  animation: fadeIn 0.16s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  background: var(--surface-container);
  border: 1px solid var(--ghost-border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--ambient-shadow), var(--primary-glow);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.75rem;
}

.modal-card.wide {
  max-width: 680px;
}

.modal-card.extra-wide {
  max-width: 820px;
}

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

.modal-title {
  font-family: var(--font-headline);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--on-surface);
}

.modal-subtitle {
  font-size: 0.8rem;
  color: var(--on-surface-variant);
  margin-top: 0.2rem;
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

@media (max-width: 520px) {
  .form-row-2 {
    grid-template-columns: 1fr;
  }
}

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

.form-field label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-field input,
.form-field select {
  background: var(--surface-lowest);
  color: var(--on-surface);
  border: 1px solid var(--ghost-border-strong);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.85rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.form-field input:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 228, 117, 0.15);
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* ==========================================================================
   Settings & Merchant Rules List
   ========================================================================== */
.settings-section {
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.settings-section h3 {
  font-family: var(--font-headline);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.rule-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.85rem;
  max-height: 240px;
  overflow-y: auto;
}

.rule-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-lowest);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  font-size: 0.84rem;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.rule-pattern {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--on-surface);
  font-weight: 600;
  word-break: break-all;
}

/* ==========================================================================
   Sign-In / Magic Link View
   ========================================================================== */
.auth-viewport {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  background: var(--surface-low);
  border: 1px solid var(--ghost-border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--ambient-shadow), var(--primary-glow);
  width: 100%;
  max-width: 440px;
  padding: 2.25rem;
  text-align: center;
}

.auth-card h1 {
  font-family: var(--font-headline);
  font-size: 1.65rem;
  font-weight: 800;
  margin: 0.85rem 0 0.4rem;
}

.w-full {
  width: 100%;
}

/* Toast Notifications — Dark Glassmorphic Pill Cards */
.toast-stack {
  position: fixed;
  bottom: 1.75rem;
  right: 1.75rem;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 400px;
  width: calc(100vw - 2.5rem);
  pointer-events: none;
}

.toast-item {
  position: relative;
  pointer-events: auto;
  border-radius: var(--radius-lg);
  padding: 0.95rem 1.15rem;
  background: rgba(22, 25, 34, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 16px 36px -6px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  overflow: hidden;
  animation: toastSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Subtle micro-grid texture on the right side */
.toast-item::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 52%;
  height: 100%;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 14px 14px;
  background-position: right top;
  -webkit-mask-image: linear-gradient(to left, rgba(0, 0, 0, 0.85) 0%, transparent 90%);
  mask-image: linear-gradient(to left, rgba(0, 0, 0, 0.85) 0%, transparent 90%);
  pointer-events: none;
  z-index: 0;
}

/* Success Toast */
.toast-item.success {
  background: linear-gradient(135deg, rgba(0, 228, 117, 0.12) 0%, rgba(20, 24, 32, 0.95) 55%);
  border-color: rgba(0, 228, 117, 0.22);
}
.toast-item.success .toast-icon-wrap {
  color: #00e475;
}

/* Info Toast */
.toast-item.info {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.12) 0%, rgba(20, 24, 32, 0.95) 55%);
  border-color: rgba(56, 189, 248, 0.22);
}
.toast-item.info .toast-icon-wrap {
  color: #38bdf8;
}

/* Error Toast */
.toast-item.error {
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.14) 0%, rgba(26, 22, 26, 0.95) 55%);
  border-color: rgba(248, 113, 113, 0.25);
}
.toast-item.error .toast-icon-wrap {
  color: #f87171;
}

.toast-icon-wrap {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-body {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.toast-title {
  font-family: var(--font-headline);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--on-surface);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.toast-message {
  font-size: 0.82rem;
  color: var(--on-surface-variant);
  line-height: 1.4;
  word-break: break-word;
}

.toast-close {
  position: relative;
  z-index: 1;
  background: transparent;
  border: none;
  color: var(--outline);
  padding: 0.2rem;
  margin: -0.2rem -0.2rem 0 0;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background-color 0.15s ease;
  flex-shrink: 0;
}
.toast-close:hover {
  color: var(--on-surface);
  background: rgba(255, 255, 255, 0.08);
}

@keyframes toastSlideUp {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--on-surface-variant);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

/* Small screen (< 480px) refinements & iOS input zoom fix */
@media (max-width: 480px) {
  .brand-title {
    font-size: 1.1rem;
  }

  .brand-mark {
    width: 2.1rem;
    height: 2.1rem;
  }

  .header-inner {
    padding: 0.6rem 0.75rem;
    gap: 0.4rem;
  }

  .header-actions {
    gap: 0.4rem;
  }

  #openAddModalBtn,
  .add-menu-toggle {
    padding: 0.45rem 0.65rem;
    font-size: 0.8rem;
  }


  .modal-backdrop {
    padding: 0.65rem;
  }

  .modal-card {
    padding: 1.25rem 1rem;
    max-height: 94vh;
    border-radius: var(--radius-lg);
  }

  .form-field input,
  .form-field select,
  .filter-select,
  .search-pill-input {
    font-size: 16px; /* Prevents auto-zoom on iOS */
  }

  .auth-card {
    padding: 1.5rem 1.15rem;
  }
}

@media (max-width: 360px) {
  .brand-title {
    font-size: 1rem;
  }

  .btn-filter-toggle span:not(.filter-count-badge) {
    display: none;
  }
}

/* ==========================================================================
   Add Transaction / Import CSV Dropdown Menu
   ========================================================================== */
.add-menu-container {
  position: relative;
  display: inline-block;
}

.add-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.add-menu-caret {
  transition: transform 0.18s ease;
  margin-left: -0.1rem;
}

.add-menu-container.open .add-menu-caret {
  transform: rotate(180deg);
}

.add-dropdown-menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 50;
  min-width: 250px;
  max-width: calc(100vw - 1.5rem);
  background: var(--surface-container);
  border: 1px solid var(--ghost-border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--ambient-shadow), 0 8px 24px rgba(0, 0, 0, 0.45);
  padding: 0.45rem;
  display: none;
  flex-direction: column;
  gap: 0.2rem;
  animation: fadeIn 0.14s ease-out;
}

.add-menu-container.open .add-dropdown-menu {
  display: flex;
}

.add-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  color: var(--on-surface);
  text-align: left;
  cursor: pointer;
  width: 100%;
  font-family: var(--font-body);
  transition: background-color 0.16s ease, color 0.16s ease;
}

.add-dropdown-item:hover {
  background: var(--surface-highest);
}

.dropdown-item-icon {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  flex-shrink: 0;
}

.dropdown-item-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.dropdown-item-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--on-surface);
}

.dropdown-item-desc {
  font-size: 0.72rem;
  color: var(--on-surface-variant);
}

.add-dropdown-divider {
  height: 1px;
  background: var(--ghost-border);
  margin: 0.25rem 0.35rem;
}

/* ==========================================================================
   CSV Import Modal & Reconciliation Preview
   ========================================================================== */
.csv-dropzone {
  border: 2px dashed var(--ghost-border-strong);
  border-radius: var(--radius-lg);
  padding: 2.75rem 1.5rem;
  text-align: center;
  background: var(--surface-lowest);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.csv-dropzone:hover,
.csv-dropzone.drag-active {
  border-color: var(--primary);
  background: rgba(0, 228, 117, 0.04);
}

.dropzone-icon {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: var(--radius-full);
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  margin-bottom: 0.4rem;
}

.dropzone-title {
  font-family: var(--font-headline);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--on-surface);
}

.dropzone-desc {
  font-size: 0.82rem;
  color: var(--on-surface-variant);
  margin-bottom: 0.5rem;
}

.supported-formats {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.supported-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--outline);
}

.format-chips {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: center;
}

.format-chip {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-full);
  background: var(--surface-high);
  border: 1px solid var(--ghost-border);
  color: var(--on-surface-variant);
}

/* Loading & Centered States */
.import-state-centered {
  padding: 3.5rem 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.import-state-centered h3 {
  font-family: var(--font-headline);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--on-surface);
}

.import-state-centered p {
  font-size: 0.84rem;
  color: var(--on-surface-variant);
  max-width: 420px;
}

.spin-icon-lg {
  animation: spin 1s linear infinite;
  display: inline-flex;
}

/* Error Box */
.import-error-box {
  background: rgba(222, 112, 103, 0.1);
  border: 1px solid rgba(222, 112, 103, 0.35);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.import-error-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--tertiary-container);
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.import-error-message {
  font-size: 0.85rem;
  color: var(--on-surface);
  line-height: 1.5;
}

/* Metadata Banner */
.import-meta-banner {
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.import-meta-left {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.import-format-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--on-surface);
}

.bank-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--primary);
}

.bank-dot.chase {
  background: #117aca;
  box-shadow: 0 0 8px rgba(17, 122, 202, 0.6);
}

.bank-dot.discover {
  background: #ff6000;
  box-shadow: 0 0 8px rgba(255, 96, 0, 0.6);
}

.import-meta-details {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-size: 0.78rem;
  color: var(--on-surface-variant);
  flex-wrap: wrap;
}

.meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.meta-item.filename {
  font-family: var(--font-mono);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.import-meta-right {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.import-meta-right label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--outline);
}

.last4-input-group input {
  background: var(--surface-lowest);
  border: 1px solid var(--ghost-border-strong);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.65rem;
  color: var(--on-surface);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  width: 110px;
}

.last4-input-group input:focus {
  outline: none;
  border-color: var(--primary);
}

/* KPI Impact Grid */
.import-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 640px) {
  .import-kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.import-kpi-card {
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.import-kpi-card.green {
  border-color: rgba(0, 228, 117, 0.25);
  background: rgba(0, 228, 117, 0.04);
}

.import-kpi-card.blue {
  border-color: rgba(176, 198, 255, 0.25);
  background: rgba(176, 198, 255, 0.04);
}

.import-kpi-card.amber {
  border-color: rgba(245, 158, 11, 0.25);
  background: rgba(245, 158, 11, 0.04);
}

.import-kpi-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--outline);
}

.import-kpi-val {
  font-family: var(--font-headline);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--on-surface);
  line-height: 1.2;
}

.text-green { color: var(--primary) !important; }
.text-blue  { color: var(--secondary) !important; }
.text-amber { color: var(--amber) !important; }
.text-muted { color: var(--outline) !important; }

.import-kpi-sub {
  font-size: 0.72rem;
  color: var(--on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.import-skipped-notice {
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  font-size: 0.78rem;
  color: var(--on-surface-variant);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* Breakdown Table */
.import-table-section {
  background: var(--surface-low);
  border: 1px solid var(--ghost-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.import-table-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--ghost-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--surface-container);
  overflow-x: auto;
}

.import-filter-tabs {
  background: var(--surface-lowest);
}

.import-table-scroll {
  max-height: 280px;
  overflow-y: auto;
  overflow-x: auto;
}

.import-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.import-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-container);
  padding: 0.5rem 0.75rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--outline);
  border-bottom: 1px solid var(--ghost-border);
  white-space: nowrap;
}

.import-table tbody tr {
  border-bottom: 1px solid var(--ghost-border);
  transition: background-color 0.14s ease;
}

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

.import-table tbody tr:hover {
  background: var(--surface-container);
}

.import-table td {
  padding: 0.6rem 0.75rem;
  vertical-align: middle;
}

.cell-date {
  font-size: 0.78rem;
  color: var(--on-surface-variant);
  white-space: nowrap;
}

.cell-merchant {
  min-width: 0;
}

.row-merchant-title {
  font-weight: 600;
  color: var(--on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.row-merchant-sub {
  font-size: 0.7rem;
  color: var(--outline);
  margin-top: 0.1rem;
}

.cat-chip-sm {
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.18rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--surface-high);
  color: var(--on-surface);
  white-space: nowrap;
}

.cell-amount {
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
}

.cell-action {
  text-align: center;
  white-space: nowrap;
}

.status-pill {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  display: inline-block;
  white-space: nowrap;
}

.status-pill.insert {
  background: rgba(0, 228, 117, 0.15);
  color: var(--primary);
  border: 1px solid rgba(0, 228, 117, 0.35);
}

.status-pill.merge {
  background: rgba(176, 198, 255, 0.15);
  color: var(--secondary);
  border: 1px solid rgba(176, 198, 255, 0.35);
}

.status-pill.purge {
  background: rgba(245, 158, 11, 0.15);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.status-pill.skip {
  background: rgba(139, 144, 160, 0.15);
  color: var(--outline);
  border: 1px solid var(--ghost-border);
}

.row-purged {
  opacity: 0.7;
}

.row-purged .row-merchant-title,
.row-purged .cell-amount {
  text-decoration: line-through;
  color: var(--outline);
}

.row-muted {
  opacity: 0.55;
}

.import-empty-row {
  text-align: center;
  padding: 2rem 1rem !important;
  color: var(--outline);
  font-size: 0.85rem;
}

