/* ═══════════════════════════════════════════════════════════════════
   OpenBudget — Base styles
   Imports design tokens, then defines: reset, typography base,
   utility classes, mobile-first layout grid, and global shared
   components referenced in base.html.

   Page-specific components live in static/css/components/*.css.
   NO hardcoded colours or spacing values — tokens only.
   ═══════════════════════════════════════════════════════════════════ */

@import url("tokens.css");


/* ── 1. Reset ────────────────────────────────────────────────────── */

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

[x-cloak] { display: none !important; }


/* ── 2. Document base ────────────────────────────────────────────── */

html {
  font-size: var(--type-body-size);      /* 14px — establishes rem root */
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--type-body-size);
  font-weight: var(--type-body-weight);
  line-height: var(--type-body-lh);
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ── 3. Layout grid ──────────────────────────────────────────────── */

/* Desktop: sidebar | main */
body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Mobile: single-column, scrollable, with space for fixed bars */
@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: auto;
    padding-bottom: var(--tab-bar-h);
    padding-top: var(--topnav-h);
  }
}


/* ── 4. Typography utility classes ───────────────────────────────── */

.type-display {
  font-size:   var(--type-display-size);
  font-weight: var(--type-display-weight);
  line-height: var(--type-display-lh);
}
.type-heading-1 {
  font-size:   var(--type-heading-1-size);
  font-weight: var(--type-heading-1-weight);
  line-height: var(--type-heading-1-lh);
}
.type-heading-2 {
  font-size:   var(--type-heading-2-size);
  font-weight: var(--type-heading-2-weight);
  line-height: var(--type-heading-2-lh);
}
.type-heading-3 {
  font-size:   var(--type-heading-3-size);
  font-weight: var(--type-heading-3-weight);
  line-height: var(--type-heading-3-lh);
}
.type-body {
  font-size:   var(--type-body-size);
  font-weight: var(--type-body-weight);
  line-height: var(--type-body-lh);
}
.type-body-medium {
  font-size:   var(--type-body-medium-size);
  font-weight: var(--type-body-medium-weight);
  line-height: var(--type-body-medium-lh);
}
.type-amount-large {
  font-size:              var(--type-amount-large-size);
  font-weight:            var(--type-amount-large-weight);
  line-height:            var(--type-amount-large-lh);
  font-family:            var(--font-mono);
  font-variant-numeric:   tabular-nums;
}
.type-amount {
  font-size:              var(--type-amount-size);
  font-weight:            var(--type-amount-weight);
  line-height:            var(--type-amount-lh);
  font-family:            var(--font-mono);
  font-variant-numeric:   tabular-nums;
}
.type-amount-secondary {
  font-size:              var(--type-amount-secondary-size);
  font-weight:            var(--type-amount-secondary-weight);
  line-height:            var(--type-amount-secondary-lh);
  font-family:            var(--font-mono);
  font-variant-numeric:   tabular-nums;
}
.type-caption {
  font-size:   var(--type-caption-size);
  font-weight: var(--type-caption-weight);
  line-height: var(--type-caption-lh);
}
.type-caption-medium {
  font-size:   var(--type-caption-medium-size);
  font-weight: var(--type-caption-medium-weight);
  line-height: var(--type-caption-medium-lh);
}
.type-overline {
  font-size:      var(--type-overline-size);
  font-weight:    var(--type-overline-weight);
  line-height:    var(--type-overline-lh);
  letter-spacing: var(--type-overline-ls);
  text-transform: uppercase;
}


/* ── 5. Colour utility classes ───────────────────────────────────── */

.text-budget-positive  { color: var(--color-budget-positive); }
.text-budget-warning   { color: var(--color-budget-warning); }
.text-budget-overspent { color: var(--color-budget-overspent); }
.text-budget-zero      { color: var(--color-budget-zero); }
.text-secondary        { color: var(--color-text-secondary); }
.text-tertiary         { color: var(--color-text-tertiary); }
.text-interactive      { color: var(--color-interactive-primary); }
.text-danger           { color: var(--color-interactive-danger); }
.text-cleared          { color: var(--color-cleared); }

/* Legacy colour utility names used in existing templates */
.text-green  { color: var(--color-budget-positive); }
.text-amber  { color: var(--color-budget-warning); }
.text-red    { color: var(--color-budget-overspent); }
.text-grey   { color: var(--color-budget-zero); }
.text-muted  { color: var(--color-text-secondary); }


/* ── 6. Amount display ───────────────────────────────────────────── */

.amount {
  font-family:          var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size:            var(--type-amount-size);
  font-weight:          var(--type-amount-weight);
}
.amount.income   { color: var(--color-budget-positive); }
.amount.expense  { color: var(--color-budget-overspent); }
.amount.muted    { color: var(--color-text-tertiary); }

/* Legacy size variants used by existing templates */
.amount-lg {
  font-family:          var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size:            var(--type-display-size);
  font-weight:          var(--type-display-weight);
}
.amount-xl {
  font-family:          var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size:            48px;
  font-weight:          700;
}


/* ── 7. Status badges ────────────────────────────────────────────── */

.badge {
  display:              inline-flex;
  align-items:          center;
  padding:              2px var(--space-2);
  border-radius:        var(--radius-badge);
  font-size:            var(--type-caption-size);
  font-weight:          var(--type-caption-medium-weight);
  font-family:          var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space:          nowrap;
  line-height:          var(--type-caption-lh);
  min-height:           24px;  /* spec §3.6: badge height = 24px */
}
.badge-green  { background: var(--color-budget-positive-bg);  color: var(--color-budget-positive); }
.badge-amber  { background: var(--color-budget-warning-bg);   color: var(--color-budget-warning); }
.badge-red    { background: var(--color-budget-overspent-bg); color: var(--color-budget-overspent); }
.badge-grey   { background: var(--color-budget-zero-bg);      color: var(--color-budget-zero); }
.badge-accent { background: var(--color-surface-selected);    color: var(--color-interactive-primary); }


/* ── 8. Buttons ──────────────────────────────────────────────────── */

.btn {
  display:         inline-flex;
  align-items:     center;
  gap:             var(--space-2);
  padding:         var(--space-2) var(--space-3);
  border-radius:   var(--radius-md);
  border:          1px solid transparent;
  font-family:     var(--font-sans);
  font-size:       var(--type-body-size);
  font-weight:     var(--type-body-medium-weight);
  line-height:     var(--type-body-lh);
  cursor:          pointer;
  transition:      background var(--transition), color var(--transition),
                   border-color var(--transition), opacity var(--transition);
  text-decoration: none;
  white-space:     nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background:   var(--color-interactive-primary);
  color:        var(--color-text-inverse);
  border-color: var(--color-interactive-primary);
}
.btn-primary:hover:not(:disabled) {
  background:   var(--color-interactive-primary-hover);
  border-color: var(--color-interactive-primary-hover);
}
.btn-primary:active:not(:disabled) {
  background:   var(--color-interactive-primary-active);
  transform:    scale(0.97);
}

.btn-ghost {
  background:   transparent;
  color:        var(--color-text-secondary);
  border-color: var(--color-border-subtle);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--color-interactive-secondary-hover);
  color:      var(--color-text-primary);
}

.btn-danger {
  background:   var(--color-interactive-danger);
  color:        var(--color-text-inverse);
  border-color: var(--color-interactive-danger);
}
.btn-danger:hover:not(:disabled) { opacity: 0.85; }

/* Sizes */
.btn-sm {
  padding:   4px var(--space-2);
  font-size: var(--type-caption-medium-size);
  min-height: 28px;
}
.btn-lg {
  padding:    var(--space-3) var(--space-4);
  font-size:  var(--type-body-size);
  min-height: 44px;
}


/* ── 9. Card ─────────────────────────────────────────────────────── */

.card {
  background:    var(--color-surface-primary);
  border:        1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  box-shadow:    var(--shadow-sm);
}


/* ── 10. Form inputs ─────────────────────────────────────────────── */

.input {
  width:         100%;
  padding:       var(--space-2) var(--space-3);
  background:    var(--color-bg-secondary);
  border:        1px solid var(--color-border-subtle);
  border-radius: var(--radius-input);
  font-family:   var(--font-sans);
  font-size:     var(--type-body-size);
  color:         var(--color-text-primary);
  transition:    border-color var(--transition), box-shadow var(--transition);
  outline:       none;
  line-height:   var(--type-body-lh);
  min-height:    40px;
}
.input::placeholder { color: var(--color-text-tertiary); }
.input:focus {
  border-color: var(--color-border-focus);
  box-shadow:   0 0 0 3px color-mix(in srgb, var(--color-border-focus) 15%, transparent);
}


/* ── 11. Progress bar ────────────────────────────────────────────── */

.progress-bar {
  height:        4px;       /* spec §3.5: standard = 4px */
  border-radius: var(--radius-progress);
  background:    var(--color-progress-track);
  overflow:      hidden;
}
.progress-bar.compact { height: 2px; }

.progress-bar-fill {
  height:     100%;
  border-radius: var(--radius-progress);
  transition: width 400ms ease-out;
}
.progress-bar-fill.green { background: var(--color-budget-positive); }
.progress-bar-fill.amber { background: var(--color-budget-warning); }
.progress-bar-fill.red   { background: var(--color-budget-overspent); }
.progress-bar-fill.grey  { background: var(--color-budget-zero); }


/* ── 12. Sidebar (desktop) ───────────────────────────────────────── */

.sidebar {
  background:  var(--color-sidebar-bg);
  height:      100vh;
  overflow-y:  auto;
  overflow-x:  hidden;
  display:     flex;
  flex-direction: column;
  flex-shrink: 0;
  width:       var(--sidebar-w);
}

@media (max-width: 768px) {
  .sidebar {
    position:   fixed;
    top:        0;
    left:       calc(-1 * var(--sidebar-w));
    width:      var(--sidebar-w);
    height:     100vh;
    z-index:    200;
    transition: left var(--transition-slow);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.mobile-open { left: 0; }
}

.sidebar-top {
  flex: 1;
  padding-bottom: var(--space-4);
}

.sidebar-brand {
  display:       flex;
  align-items:   center;
  gap:           var(--space-2);
  padding:       var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: var(--space-2);
}
.sidebar-brand-icon {
  width:         8px;
  height:        8px;
  background:    var(--color-interactive-primary);
  border-radius: 2px;
  flex-shrink:   0;
}
.sidebar-brand-logo {
  width:         26px;
  height:        26px;
  object-fit:    contain;
  border-radius: var(--radius-sm);
  flex-shrink:   0;
}
.sidebar-brand-name {
  font-size:   15px;
  font-weight: 700;
  color:       var(--color-sidebar-text-active);
  letter-spacing: -0.01em;
}

.sidebar-nav         { padding: 0 var(--space-2); margin-bottom: var(--space-3); }
.sidebar-nav-link {
  display:       flex;
  align-items:   center;
  gap:           var(--space-2);
  height:        36px;
  padding:       0 var(--space-3);
  border-radius: var(--radius-md);
  color:         var(--color-sidebar-text);
  text-decoration: none;
  font-size:     var(--type-body-size);
  font-weight:   var(--type-body-medium-weight);
  transition:    background var(--transition), color var(--transition);
  margin-bottom: 2px;
}
.sidebar-nav-link:hover {
  background: var(--color-sidebar-item-hover);
  color:      var(--color-sidebar-text-active);
}
.sidebar-nav-link.active {
  background: var(--color-sidebar-item-active);
  color:      var(--color-sidebar-text-active);
}
.sidebar-nav-link i { flex-shrink: 0; width: 16px; height: 16px; }

.sidebar-section-label {
  font-size:      var(--type-overline-size);
  font-weight:    var(--type-overline-weight);
  letter-spacing: var(--type-overline-ls);
  text-transform: uppercase;
  color:          var(--color-sidebar-text);
  padding:        0 var(--space-4);
  margin-top:     var(--space-4);
  margin-bottom:  var(--space-1);
}

.sidebar-accounts { padding: 0 var(--space-2); }
.sidebar-account-link {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  gap:             var(--space-2);
  height:          32px;
  padding:         0 var(--space-3);
  border-radius:   var(--radius-md);
  text-decoration: none;
  border-left:     2px solid transparent;
  transition:      background var(--transition), border-color var(--transition);
}
.sidebar-account-link:hover  { background: var(--color-sidebar-item-hover); }
.sidebar-account-link.active {
  border-left-color: var(--color-interactive-primary);
  background:        rgba(37, 99, 235, 0.15);
}
.sidebar-acct-name {
  flex: 1;
  min-width: 0;
  overflow:      hidden;
  text-overflow: ellipsis;
  white-space:   nowrap;
  color:         var(--color-sidebar-text-active);
  font-size:     var(--type-body-size);
}
.sidebar-acct-balance {
  font-size:            var(--type-caption-size);
  font-family:          var(--font-mono);
  font-variant-numeric: tabular-nums;
  color:                var(--color-sidebar-text);
  flex-shrink:          0;
}
.sidebar-acct-balance.positive { color: var(--color-budget-positive); }
.sidebar-acct-balance.negative { color: var(--color-budget-overspent); }

.sidebar-bottom {
  padding:       var(--space-3) var(--space-4);
  border-top:    1px solid rgba(255, 255, 255, 0.08);
  display:       flex;
  align-items:   center;
  gap:           var(--space-2);
}
.sidebar-icon-btn {
  background:    none;
  border:        none;
  color:         var(--color-sidebar-text);
  cursor:        pointer;
  padding:       var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition:    background var(--transition), color var(--transition);
  display:       flex;
  align-items:   center;
}
.sidebar-icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color:      var(--color-sidebar-text-active);
}


/* ── 13. Sidebar overlay (mobile backdrop) ───────────────────────── */

.sidebar-overlay {
  display:    none;
  position:   fixed;
  inset:      0;
  background: var(--color-overlay);
  z-index:    199;
}
.sidebar-overlay.visible { display: block; }


/* ── 14. Mobile header (Top App Bar — Standard variant) ─────────── */

.mobile-header {
  display:        none;
  position:       fixed;
  top:  0; left: 0; right: 0;
  height:         var(--topnav-h);
  background:     var(--color-surface-primary);
  border-bottom:  1px solid var(--color-border-subtle);
  z-index:        100;
  align-items:    center;
  justify-content:space-between;
  padding:        0 var(--space-4);
}
@media (max-width: 768px) { .mobile-header { display: flex; } }

.mobile-menu-btn,
.mobile-theme-btn {
  background:    none;
  border:        none;
  color:         var(--color-text-secondary);
  cursor:        pointer;
  padding:       var(--space-1);
  border-radius: var(--radius-sm);
  display:       flex;
  align-items:   center;
  transition:    color var(--transition);
}
.mobile-menu-btn:hover,
.mobile-theme-btn:hover { color: var(--color-text-primary); }

.mobile-brand {
  font-size:   15px;
  font-weight: 700;
  color:       var(--color-text-primary);
}


/* ── 15. Main content area ───────────────────────────────────────── */

.main-content {
  overflow-y: auto;
  height:     100vh;
  min-height: 0;
}
@media (max-width: 768px) { .main-content { height: auto; } }


/* ── 16. Mobile bottom tab bar ───────────────────────────────────── */

.bottom-nav {
  display:    none;
  position:   fixed;
  bottom: 0; left: 0; right: 0;
  height:     var(--tab-bar-h);
  background: var(--color-surface-primary);
  border-top: 1px solid var(--color-border-subtle);
  z-index:    100;
}
@media (max-width: 768px) { .bottom-nav { display: flex; } }

.bottom-nav-tab {
  flex:            1;
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  gap:             2px;
  text-decoration: none;
  color:           var(--color-text-secondary);
  font-size:       var(--type-caption-size);
  font-weight:     var(--type-caption-medium-weight);
  transition:      color var(--transition);
}
.bottom-nav-tab.active,
.bottom-nav-tab:hover { color: var(--color-interactive-primary); }


/* ── 17. Theme icon visibility ───────────────────────────────────── */

[data-theme="light"] .theme-icon-dark  { display: none; }
[data-theme="dark"]  .theme-icon-light { display: none; }
/* System-preference fallback (no data-theme set yet) */
@media (prefers-color-scheme: dark)  { :root:not([data-theme]) .theme-icon-light { display: none; } }
@media (prefers-color-scheme: light) { :root:not([data-theme]) .theme-icon-dark  { display: none; } }


/* ── 18. htmx: top loading bar ───────────────────────────────────── */

#top-loader {
  position:         fixed;
  top: 0; left: 0; right: 0;
  height:           2px;
  background:       var(--color-interactive-primary);
  transform:        scaleX(0);
  transform-origin: left;
  z-index:          10000;
  display:          none;
}
.htmx-request #top-loader {
  display:   block;
  animation: topLoading 1s ease infinite alternate;
}
@keyframes topLoading {
  from { transform: scaleX(0.1); }
  to   { transform: scaleX(0.9); }
}

.htmx-request .htmx-indicator { display: inline; }
.htmx-indicator                { display: none; }


/* ── 19. Toast / Snackbar ────────────────────────────────────────── */

.toast {
  position:      fixed;
  bottom:        var(--space-6);
  right:         var(--space-6);
  padding:       var(--space-3) var(--space-4);
  background:    var(--color-sidebar-bg);
  color:         var(--color-sidebar-text-active);
  border-radius: var(--radius-md);
  box-shadow:    var(--shadow-lg);
  font-size:     var(--type-body-size);
  z-index:       9999;
  max-width:     320px;
  display:       flex;
  align-items:   center;
  gap:           var(--space-3);
  animation:     toastIn 200ms ease;
}
.toast-success { border-left: 3px solid var(--color-budget-positive); }
.toast-error   { border-left: 3px solid var(--color-budget-overspent); }
.toast-info    { border-left: 3px solid var(--color-interactive-primary); }

@media (max-width: 768px) {
  .toast {
    bottom: calc(var(--tab-bar-h) + var(--space-4));
    left:   var(--space-4);
    right:  var(--space-4);
  }
}

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


/* ── 20. Keyboard shortcuts modal ────────────────────────────────── */

.shortcuts-modal {
  position:        fixed;
  inset:           0;
  background:      var(--color-overlay);
  z-index:         10001;
  display:         flex;
  align-items:     center;
  justify-content: center;
}
.shortcuts-modal.hidden { display: none; }
.shortcuts-card {
  width:     100%;
  max-width: 400px;
  padding:   0;
}
.shortcuts-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         var(--space-4) var(--space-6);
  border-bottom:   1px solid var(--color-border-subtle);
}
.shortcuts-header h3 {
  font-size:   15px;
  font-weight: 600;
}
.shortcuts-close {
  background:  none;
  border:      none;
  font-size:   20px;
  line-height: 1;
  cursor:      pointer;
  color:       var(--color-text-secondary);
  padding:     0 4px;
}
.shortcuts-close:hover { color: var(--color-text-primary); }
.shortcuts-body { padding: var(--space-3) var(--space-6) var(--space-6); }
.shortcut-row {
  display:       flex;
  align-items:   center;
  gap:           var(--space-3);
  padding:       var(--space-2) 0;
  border-bottom: 1px solid var(--color-border-subtle);
  font-size:     var(--type-body-size);
}
.shortcut-row:last-child { border-bottom: none; }
.shortcut-row kbd {
  font-family:   var(--font-mono);
  font-size:     11px;
  background:    var(--color-bg-secondary);
  border:        1px solid var(--color-border-primary);
  border-radius: var(--radius-sm);
  padding:       1px 6px;
  white-space:   nowrap;
  color:         var(--color-text-primary);
}
.shortcut-row span {
  color: var(--color-text-secondary);
  flex:  1;
}


/* ── 21. Row entrance animation ──────────────────────────────────── */

@keyframes slideIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: slideIn 200ms ease; }


/* ── 22. Loading skeleton shimmer ────────────────────────────────── */

@keyframes shimmer {
  from { background-position: -200% 0; }
  to   { background-position:  200% 0; }
}
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-skeleton) 25%,
    color-mix(in srgb, var(--color-skeleton) 60%, var(--color-surface-primary)) 50%,
    var(--color-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}


/* ── 23. Scrollbar ───────────────────────────────────────────────── */

::-webkit-scrollbar         { width: 6px; height: 6px; }
::-webkit-scrollbar-track   { background: transparent; }
::-webkit-scrollbar-thumb   { background: var(--color-border-primary); border-radius: var(--radius-full); }


/* ── 24. FAB (Floating Action Button) ───────────────────────────── */

.fab {
  position:        fixed;
  bottom:          calc(var(--tab-bar-h) + var(--space-4));
  right:           var(--space-4);
  width:           var(--fab-size);       /* 56px */
  height:          var(--fab-size);
  border-radius:   var(--radius-full);
  background:      var(--color-interactive-primary);
  color:           var(--color-text-inverse);
  border:          none;
  cursor:          pointer;
  display:         flex;
  align-items:     center;
  justify-content: center;
  box-shadow:      0 4px 12px rgba(0, 0, 0, 0.15);
  z-index:         90;
  transition:      background var(--transition-fast), box-shadow var(--transition-fast),
                   transform var(--transition-fast);
}
.fab:hover  { background: var(--color-interactive-primary-hover); box-shadow: 0 6px 16px rgba(0,0,0,0.2); }
.fab:active { transform: scale(0.95); }

@media (min-width: 1024px) {
  .fab { display: none; }    /* FAB is mobile-only; desktop uses toolbar buttons */
}


/* ── 25. Bottom sheet ────────────────────────────────────────────── */

.sheet-backdrop {
  position:   fixed;
  inset:      0;
  background: rgba(0, 0, 0, 0.45);
  z-index:    200;
  display:    flex;
  align-items: flex-end;
}

.sheet-panel {
  position:      fixed;
  bottom:        0;
  left:          0;
  right:         0;
  z-index:       201;
  background:    var(--color-surface-primary);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width:         100%;
  max-height:    85vh;
  overflow-y:    auto;
  padding:       0 0 calc(var(--tab-bar-h) + var(--space-4));
  transform:     translateY(0);
  transition:    transform var(--transition-fast);
}

.sheet-handle {
  width:         40px;
  height:        4px;
  background:    var(--color-border-primary);
  border-radius: var(--radius-full);
  margin:        var(--space-3) auto;
}

.sheet-header {
  display:     flex;
  align-items: center;
  padding:     var(--space-2) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--color-border-subtle);
}

.sheet-title {
  flex:        1;
  font-size:   17px;
  font-weight: 600;
  color:       var(--color-text-primary);
}

.sheet-close {
  background: none;
  border:     none;
  cursor:     pointer;
  color:      var(--color-text-secondary);
  padding:    var(--space-1);
  border-radius: var(--radius-sm);
  display:    flex;
  align-items: center;
  justify-content: center;
}
.sheet-close:hover { background: var(--color-bg-secondary); }

@media (min-width: 1024px) {
  .sheet-backdrop { display: none !important; }
}


/* ── 26. Transaction form (bottom sheet contents) ────────────────── */

.txn-form-wrap { padding: var(--space-4); }

.txn-type-toggle {
  display:       flex;
  gap:           var(--space-1);
  background:    var(--color-bg-secondary);
  border-radius: var(--radius-md);
  padding:       3px;
  margin-bottom: var(--space-4);
}

.txn-type-btn {
  flex:          1;
  padding:       var(--space-2) var(--space-3);
  font-size:     13px;
  font-weight:   500;
  border:        none;
  background:    none;
  color:         var(--color-text-secondary);
  border-radius: var(--radius-sm);
  cursor:        pointer;
  transition:    background var(--transition-fast), color var(--transition-fast);
}
.txn-type-btn--active {
  background: var(--color-surface-primary);
  color:      var(--color-text-primary);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.txn-form { display: flex; flex-direction: column; gap: var(--space-3); }

.txn-form-field { display: flex; flex-direction: column; gap: var(--space-1); }

.txn-form-label {
  font-size:      11px;
  font-weight:    700;
  text-transform: uppercase;
  letter-spacing: 0.55px;
  color:          var(--color-text-secondary);
}

.txn-form-field--check { flex-direction: row; align-items: center; }
.txn-form-label--check {
  display:     flex;
  align-items: center;
  gap:         var(--space-2);
  font-size:   14px;
  font-weight: 500;
  color:       var(--color-text-primary);
  cursor:      pointer;
}

.txn-amount-input {
  font-size:   20px;
  font-weight: 600;
  font-family: var(--font-mono);
  text-align:  right;
}

.txn-form-actions { margin-top: var(--space-2); }
.txn-form-submit  { width: 100%; padding: var(--space-3); font-size: 16px; }


/* ── 27. Month nav (budget.html) ─────────────────────────────────── */

.month-nav {
  display:     flex;
  align-items: center;
  gap:         var(--space-2);
  height:      48px;
  padding:     0 var(--space-4);
  background:  var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border-subtle);
  position:    sticky;
  top:         var(--topnav-h);   /* sticks just below mobile header */
  z-index:     50;
}

.month-nav-arrow {
  display:         flex;
  align-items:     center;
  justify-content: center;
  width:           max-content;
  height:          28px;
  border-radius:   var(--radius-sm);
  color:           var(--color-text-secondary);
  text-decoration: none;
  transition:      background var(--transition-fast);
}
.month-nav-arrow:hover { background: var(--color-border-subtle); }

.month-nav-label {
  font-size:   14px;
  font-weight: 600;
  color:       var(--color-text-primary);
  white-space: nowrap;
}

.month-nav-spacer { flex: 1; }

.month-nav-tbb-label {
  font-size:      11px;
  font-weight:    500;
  text-transform: uppercase;
  letter-spacing: 0.55px;
  color:          var(--color-text-secondary);
}

.month-nav-tbb {
  font-size:          14px;
  font-weight:        600;
  font-variant-numeric: tabular-nums;
  white-space:        nowrap;
}
.month-nav-tbb.tbb-positive { color: var(--color-budget-positive); }
.month-nav-tbb.tbb-zero     { color: var(--color-text-secondary); }
.month-nav-tbb.tbb-negative { color: var(--color-budget-overspent); }

.month-nav-warn {
  display:       flex;
  align-items:   center;
  gap:           3px;
  padding:       2px var(--space-2);
  background:    var(--color-budget-warning-bg);
  color:         var(--color-budget-warning);
  border-radius: var(--radius-full);
  font-size:     11px;
  font-weight:   600;
  white-space:   nowrap;
}

@media (min-width: 1024px) {
  .month-nav {
    padding: var(--space-2) var(--space-5) var(--space-18);
    top: 0;
  }   /* no mobile header on desktop */

  .month-nav-sub {
    display: flex;
    width: 80%;
  }
}

@media (max-width: 768px) {
  .month-nav { top: 0; }   /* no mobile header on desktop */

  .month-nav-tbb-group {
    justify-content: center;
  }
}


/* ── 28. Account register — new Figma-aligned header ────────────── */

.account-header {
  display:    flex;
  align-items: center;
  gap:        var(--space-4);
  padding:    var(--space-4) var(--space-4);
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border-subtle);
}

.account-header-info { flex: 1; min-width: 0; }

.account-header-name {
  font-size:   20px;
  font-weight: 600;
  color:       var(--color-text-primary);
  white-space: nowrap;
  overflow:    hidden;
  text-overflow: ellipsis;
}

.account-header-type {
  font-size: 13px;
  color:     var(--color-text-secondary);
  margin-top: 2px;
}

.account-header-balance { text-align: right; flex-shrink: 0; }

.account-toolbar {
  display:     flex;
  align-items: center;
  gap:         var(--space-3);
  padding:     var(--space-2) var(--space-4);
  background:  var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border-subtle);
  flex-wrap:   wrap;
}

.account-stat-inline { display: flex; align-items: center; gap: var(--space-2); flex: 1; }

.account-stat-label {
  font-size:      10px;
  font-weight:    700;
  text-transform: uppercase;
  letter-spacing: 0.55px;
  color:          var(--color-text-secondary);
}

.account-stat-value {
  font-family:    var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size:      20px;
  font-weight:    600;
  color:          var(--color-budget-positive);
}
.account-stat-value.negative { color: var(--color-budget-overspent); }
.account-stat-value.zero     { color: var(--color-text-secondary); }


/* ── 29. Register search bar ─────────────────────────────────────── */

.register-search-bar {
  display:     flex;
  align-items: center;
  gap:         var(--space-2);
  padding:     var(--space-2) var(--space-4);
  background:  var(--color-surface-primary);
  border-bottom: 1px solid var(--color-border-subtle);
}

.register-search-input-wrap {
  flex:          1;
  display:       flex;
  align-items:   center;
  gap:           var(--space-2);
  background:    var(--color-bg-secondary);
  border-radius: var(--radius-full);
  padding:       0 var(--space-3);
  height:        32px;
}

.register-search-input {
  flex:       1;
  border:     none;
  background: transparent;
  font-size:  13px;
  color:      var(--color-text-primary);
  outline:    none;
}
.register-search-input::placeholder { color: var(--color-text-tertiary); }

.register-filter-btn {
  display:         flex;
  align-items:     center;
  justify-content: center;
  width:           32px;
  height:          32px;
  border-radius:   var(--radius-full);
  background:      var(--color-bg-secondary);
  border:          none;
  cursor:          pointer;
  color:           var(--color-text-secondary);
  flex-shrink:     0;
  transition:      background var(--transition-fast);
}
.register-filter-btn:hover { background: var(--color-border-subtle); }


/* ── Fix 1: Date Picker ──────────────────────────────────────────── */

.date-picker { position: relative; display: block; }

.dp-trigger {
  display:      flex;
  align-items:  center;
  gap:          var(--space-2);
  width:        100%;
  padding:      var(--space-2) var(--space-3);
  border:       1px solid var(--color-border-subtle);
  border-radius: var(--radius-input);
  background:   var(--color-bg-secondary);
  color:        var(--color-text-primary);
  font-family:  var(--font-sans);
  font-size:    var(--type-body-size);
  min-height:   40px;
  cursor:       pointer;
  transition:   border-color var(--transition);
  text-align:   left;
}
.dp-trigger:hover,
.dp-trigger--open { border-color: var(--color-border-focus); }

.dp-icon   { width: 14px; height: 14px; color: var(--color-text-secondary); flex-shrink: 0; }
.dp-trigger-label { flex: 1; }
.dp-chevron {
  width: 12px; height: 12px;
  color: var(--color-text-tertiary);
  flex-shrink: 0;
  transition: transform var(--transition);
}
.dp-chevron--open { transform: rotate(180deg); }

/* Desktop: inline dropdown */
.dp-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 1000;
  width: 280px;
  background: var(--color-surface-elevated);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 6px rgba(0,0,0,0.10);
  padding: var(--space-3) var(--space-4) var(--space-4);
}

.dp-chips {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.dp-chip {
  height: 32px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-chip);
  border: 1px solid var(--color-border-primary);
  background: var(--color-interactive-secondary);
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: var(--type-body-medium-weight);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
  white-space: nowrap;
}
.dp-chip:hover {
  border-color: var(--color-interactive-primary);
  color: var(--color-interactive-primary);
}

.dp-cal-header {
  display: flex;
  align-items: center;
  margin-bottom: var(--space-2);
}
.dp-nav-btn {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: color var(--transition), background var(--transition);
}
.dp-nav-btn:hover { color: var(--color-text-primary); background: var(--color-interactive-secondary); }
.dp-cal-month {
  flex: 1;
  text-align: center;
  font-size: var(--type-body-medium-size);
  font-weight: 600;
  color: var(--color-text-primary);
}

.dp-day-headers,
.dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 30px);
  justify-content: space-between;
  gap: 2px;
}
.dp-day-headers { margin-bottom: 4px; }
.dp-day-headers span {
  width: 30px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: var(--type-body-medium-weight);
  color: var(--color-text-tertiary);
}
.dp-day {
  width: 30px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius-chip);
  font-size: 13px;
  color: var(--color-text-primary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.dp-day:hover:not(.dp-day--other):not(.dp-day--selected) {
  background: var(--color-interactive-secondary);
}
.dp-day--other    { color: var(--color-text-tertiary); pointer-events: none; }
.dp-day--today    { background: var(--color-surface-selected); color: var(--color-interactive-primary); }
.dp-day--selected { background: var(--color-interactive-primary); color: var(--color-text-inverse); font-weight: 600; }

/* Mobile: bottom sheet */
.dp-backdrop { display: none; }

@media (max-width: 768px) {
  .dp-panel {
    position: fixed;
    bottom: 0; left: 0; right: 0; top: auto;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
    z-index: 1100;
    padding: var(--space-4);
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  }
  .dp-day-headers,
  .dp-grid { grid-template-columns: repeat(7, 1fr); gap: 4px; }
  .dp-day-headers span { width: 100%; }
  .dp-day { width: 100%; height: 36px; }
  .dp-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1099;
    background: var(--color-overlay);
  }
}


/* ── Flatpickr dark-mode theme override ─────────────────────────── */

.flatpickr-calendar {
  background: var(--color-surface-primary) !important;
  border: 1px solid var(--color-border-subtle) !important;
  box-shadow: var(--shadow-lg) !important;
  border-radius: var(--radius-md) !important;
  color: var(--color-text-primary) !important;
}

.flatpickr-day {
  color: var(--color-text-primary) !important;
}

.flatpickr-day.selected,
.flatpickr-day.selected:hover {
  background: var(--color-interactive-primary) !important;
  border-color: var(--color-interactive-primary) !important;
  color: #fff !important;
}

.flatpickr-day:hover {
  background: var(--color-bg-secondary) !important;
}

.flatpickr-day.today {
  border-color: var(--color-interactive-primary) !important;
}

.flatpickr-day.flatpickr-disabled,
.flatpickr-day.flatpickr-disabled:hover {
  color: var(--color-text-disabled) !important;
  background: transparent !important;
}

.flatpickr-months .flatpickr-month,
.flatpickr-current-month,
.flatpickr-weekday {
  background: var(--color-surface-primary) !important;
  color: var(--color-text-secondary) !important;
  fill: var(--color-text-secondary) !important;
}

.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year {
  background: transparent !important;
  color: var(--color-text-primary) !important;
}

.flatpickr-prev-month svg,
.flatpickr-next-month svg {
  fill: var(--color-text-secondary) !important;
}

.flatpickr-prev-month:hover svg,
.flatpickr-next-month:hover svg {
  fill: var(--color-interactive-primary) !important;
}

/* monthSelect plugin */
.flatpickr-monthSelect-month {
  color: var(--color-text-primary) !important;
  border-radius: var(--radius-sm) !important;
}

.flatpickr-monthSelect-month:hover {
  background: var(--color-bg-secondary) !important;
}

.flatpickr-monthSelect-month.selected {
  background: var(--color-interactive-primary) !important;
  color: #fff !important;
}


/* ── Payee autocomplete dropdown ────────────────────────────────── */

.ac-wrap {
  position: relative;
}

.ac-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-surface-primary);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  list-style: none;
  margin: 0;
  padding: var(--space-1) 0;
  z-index: 200;
  max-height: 200px;
  overflow-y: auto;
}

.ac-dropdown__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font-size: var(--type-body-size);
  color: var(--color-text-primary);
  gap: var(--space-2);
  transition: background var(--transition);
}

.ac-dropdown__item:hover,
.ac-dropdown__item.highlighted {
  background: var(--color-bg-secondary);
}

.ac-dropdown__name {
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ac-dropdown__cat {
  font-size: var(--type-caption-size);
  color: var(--color-text-secondary);
  flex-shrink: 0;
}
