/* ============================================================
   Design Tokens
   ============================================================ */
:root {
  --color-bg:      #f5f3f7;
  --color-surface: #ffffff;
  --color-primary: #7c3aed;
  --color-primary-light: #a78bfa;
  --color-income:  #059669;
  --color-expense: #dc2626;
  --color-border:  #e9e5f0;
  --color-text:    #1e1b2e;
  --color-muted:   #6b6180;
  --shadow-card:   0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.06);
}

/* ============================================================
   Global Reset
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* Kill 300ms tap delay on mobile */
a, button, select, input, [role="tab"], .mobile-chat-bar-input, .mobile-chat-bar-btn, .mobile-chat-overlay-close {
  touch-action: manipulation;
}

html, body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
}

@media (min-width: 1025px) {
  html {
    height: 100%;
    overflow: hidden;
  }
  body {
    height: 100%;
    overflow: hidden;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  background: var(--color-bg);
  color: var(--color-text);
}

/* ============================================================
   Responsive Helpers
   ============================================================ */
.desktop-only { display: none; }
.mobile-only  { display: block; }

@media (min-width: 1025px) {
  .desktop-only { display: block; }
  .mobile-only  { display: none !important; }
}

/* ============================================================
   Layout
   ============================================================ */
.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

@media (min-width: 1025px) {
  .layout {
    height: 100vh;
    overflow: hidden;
  }
}

/* ============================================================
   App Header
   ============================================================ */
.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  max-height: 48px;
  padding: 8px 12px;
  background: linear-gradient(135deg, #7c3aed 0%, #9333ea 50%, #6d28d9 100%);
  border-bottom: none;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.3;
}
.app-header h1 span {
  color: rgba(255,255,255,0.7);
}
.app-header h1 span#app-title {
  color: #ffffff;
}
.app-header p {
  font-size: 12px;
  color: rgba(255,255,255,0.8);
  margin-right: auto;
}

/* Header hamburger menu */
.header-menu-wrapper {
  position: relative;
}

.header-menu-btn {
  font-size: 18px;
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  line-height: 1;
}
.header-menu-btn:hover { background: rgba(255,255,255,0.25); }

.header-menu-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  z-index: 200;
  min-width: 120px;
  padding: 4px 0;
}
.header-menu-dropdown.open {
  display: block;
}

.header-menu-item {
  display: block;
  width: 100%;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--color-text);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
}
.header-menu-item:hover {
  background: var(--color-bg);
}



/* ============================================================
   Filter Bar
   ============================================================ */
.filter-bar {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.filter-bar select,
#report-filters select {
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: white;
  color: var(--color-text);
  cursor: pointer;
}

.filter-bar select:focus,
#report-filters select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(124,58,237,0.12);
}

/* ============================================================
   Session Banner (removed — session expiry redirects to login.html)
   ============================================================ */

/* ============================================================
   Content Fade-in (smooth load appearance)
   ============================================================ */
.stats, .content-left, .content-right-wrapper, .filter-bar, .mobile-filters {
  opacity: 0;
}
.stats.visible, .content-left.visible, .content-right-wrapper.visible, .filter-bar.visible, .mobile-filters.visible {
  opacity: 1;
}

/* ============================================================
   Report Filters
   ============================================================ */
@media (max-width: 1024px) {
  #report-filters { display: none; }
}

/* ============================================================
   Panels
   ============================================================ */
.panel { display: none; }
.panel.active { display: block; }

@media (min-width: 1025px) {
  #panel-report { display: block; }
}

/* ============================================================
   Stats Grid
   ============================================================ */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 8px;
  padding: 0 12px;
  flex-shrink: 0;
}

.stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 10px 12px;
  box-shadow: var(--shadow-card);
  min-width: 0;
  overflow: hidden;
  max-height: 64px;
}

.stat-label {
  font-size: 11px;
  color: var(--color-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat-value {
  font-size: clamp(12px, 2.5vw, 22px);
  font-weight: 700;
  white-space: nowrap;
}

@media (max-width: 390px) {
  .stat {
    padding: 8px 6px;
  }
  .stat-label {
    font-size: 9px;
  }
  .stat-value {
    font-size: 11px;
  }
  .stats {
    gap: 4px;
    padding: 0 6px;
  }
}
.stat-value.income  { color: var(--color-income); }
.stat-value.expense { color: var(--color-expense); }
.stat-value.net     { color: var(--color-text); }

/* ============================================================
   Content Grid (two-column desktop layout)
   ============================================================ */
.content-grid {
  display: grid;
  grid-template-columns: 1fr minmax(280px, 320px);
  gap: 8px;
  padding: 0 12px;
  flex: 1;
  overflow: hidden;
}

.content-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  height: 100%;
  padding: 4px 0;
}

/* ============================================================
   Right Column Wrapper (transactions + chat as siblings)
   ============================================================ */
.content-right-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  overflow: hidden;
}

.content-right {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 10px;
  box-shadow: var(--shadow-card);
}

.content-right .txn-section-header {
  position: static;
  flex-shrink: 0;
}

.content-right .txn-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.content-right .pagination {
  position: static;
  flex-shrink: 0;
  border-top: 1px solid var(--color-border);
  padding-top: 8px;
  margin-top: 4px;
  background: transparent;
}

/* ============================================================
   Chat Panel — separate card below transactions
   ============================================================ */
.chat-panel {
  background: #fffde7;
  border: 2px solid #f59e0b;
  border-radius: 4px;
  padding: 0;
  box-shadow: 0 2px 8px rgba(245,158,11,.12);
  display: flex;
  flex-direction: column;
  height: 220px;
  overflow: hidden;
  flex-shrink: 0;
  margin-bottom: 4px;
  transition: height 0.2s ease;
}

.chat-panel.expanded {
  height: 320px;
}

.chat-panel--accent {
  /* No accent needed */
}

.chat-panel .chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  min-height: 0;
  max-height: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
}

.chat-panel .msg {
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 4px;
}

.chat-panel .msg.bot {
  background: #ffffff;
  border: 1px solid #f0e68c;
  color: var(--color-text);
}

.chat-panel .msg.user {
  background: var(--color-primary);
  color: white;
}

.chat-panel .msg.error {
  background: #fff0f0;
  border: 1px solid #ffcccc;
  color: #cc0000;
}

.chat-panel .msg.loading {
  background: #ffffff;
  border: 1px solid #f0e68c;
  color: var(--color-muted);
  font-style: italic;
}

.chat-panel .input-row {
  padding: 8px 10px 6px;
  border-top: 1px solid #f0e68c;
  background: #fff9c4;
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.chat-panel .input-row input,
.chat-panel .input-row textarea {
  min-width: 0;
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border-radius: 4px;
  background: #ffffff;
  border: 1px solid #f0e68c;
  color: var(--color-text);
  font-family: inherit;
  resize: none;
  overflow: hidden;
  line-height: 1.4;
  max-height: 200px;
}
.chat-panel .input-row input::placeholder,
.chat-panel .input-row textarea::placeholder {
  color: var(--color-muted);
}
.chat-panel .input-row input:focus,
.chat-panel .input-row textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(124,58,237,0.12);
  outline: none;
}

.chat-panel #send-btn {
  background: var(--color-primary);
  color: white;
}

.chat-panel .hint {
  padding: 2px 10px 4px;
  flex-shrink: 0;
  font-size: 10px;
  color: var(--color-muted);
  margin-top: 0;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-bottom: 1px solid #f0e68c;
  flex-shrink: 0;
}

.chat-panel-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-collapse-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid #d8d3e3;
  background: white;
  color: var(--color-muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.chat-collapse-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* Collapsed state — input only */
.chat-panel.collapsed {
  height: auto;
}
.chat-panel.collapsed .chat-panel-header,
.chat-panel.collapsed .chat-log,
.chat-panel.collapsed .chat-help-content,
.chat-panel.collapsed .hint {
  display: none;
}

.chat-panel-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
}

.chat-help-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid #d8d3e3;
  background: white;
  color: var(--color-muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.chat-help-btn:hover {
  border-color: #f59e0b;
  color: #f59e0b;
}

.chat-help-content {
  display: none;
  padding: 8px 12px;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  font-size: 11px;
  color: #92400e;
  line-height: 1.5;
  flex-shrink: 0;
}
.chat-help-content.open {
  display: block;
}
.chat-help-content p {
  margin: 1px 0;
}
.chat-help-content strong {
  color: #78350f;
}

/* ============================================================
   Charts — pie charts with fixed aspect ratio
   ============================================================ */
.charts-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.charts-pair .chart-container {
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.chart-wrapper {
  position: relative;
  max-width: 100%;
  min-height: 200px;
}

.charts-pair .chart-wrapper {
  position: relative;
  max-width: 100%;
  min-height: 200px;
}

.charts-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.chart-container {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 12px;
  box-shadow: var(--shadow-card);
  max-width: 100%;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-muted);
  margin-bottom: 8px;
}

.trend-chart-container {
  min-height: unset;
  margin-bottom: 0;
}

.trend-chart-wrapper {
  position: relative;
  height: 180px;
  max-width: 100%;
}

/* Legend scrolling for charts with many categories */
.chart-legend-scroll {
  overflow: visible;
}
.chart-legend-scroll canvas {
  max-height: calc(100% - 100px);
}

/* Text summary fallback when canvas container is too small */
.chart-text-summary {
  font-size: 12px;
  color: var(--color-muted);
  padding: 8px 0;
  line-height: 1.6;
}

/* ============================================================
   Chat Log (generic — used by mobile messages too)
   ============================================================ */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  min-height: 160px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 12px;
  box-shadow: var(--shadow-card);
}

.msg {
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.4;
  max-width: 90%;
}

.msg.bot     { background: var(--color-bg); border: 1px solid var(--color-border); align-self: flex-start; color: var(--color-text); }
.msg.user    { background: var(--color-primary); color: white; align-self: flex-end; }
.msg.error   { background: #fff0f0; border: 1px solid #ffcccc; color: #cc0000; align-self: flex-start; }
.msg.loading { background: var(--color-bg); border: 1px solid var(--color-border); align-self: flex-start; color: var(--color-muted); font-style: italic; }

.input-row { display: flex; gap: 6px; align-items: flex-end; }

/* Currency filter custom dropdown */
.currency-filter-wrapper {
  position: relative;
  display: inline-block;
}
.currency-filter-btn {
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: white;
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
  height: 100%;
  box-sizing: border-box;
}
.currency-filter-btn:hover {
  border-color: var(--color-primary);
}
.currency-filter-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  z-index: 9999;
  min-width: 120px;
  padding: 4px 0;
}
.currency-filter-dropdown.open {
  display: block;
}
.currency-filter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
}
.currency-filter-item:hover {
  background: var(--color-bg);
}
.currency-filter-item.selected {
  font-weight: 600;
  background: #f3f0ff;
}
.currency-filter-label {
  flex: 1;
}
.currency-filter-star {
  font-size: 16px;
  color: #ddd;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  transition: color 0.1s;
}
.currency-filter-star:hover {
  color: #f5a623;
}
.currency-filter-star.active {
  color: #f5a623;
}

/* Mobile: currency dropdown as bottom sheet */
@media (max-width: 1024px) {
  .currency-filter-btn {
    padding: 8px 10px;
    font-size: 13px;
  }

  .currency-filter-dropdown.open {
    z-index: 10000;
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 20px rgba(0,0,0,.2);
    border: none;
    border-top: 1px solid var(--color-border);
  }

  .currency-filter-item {
    padding: 12px 16px;
    font-size: 15px;
  }
}

.input-row input,
.input-row textarea {
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  outline: none;
  background: white;
  color: var(--color-text);
  font-family: inherit;
  resize: none;
  overflow: hidden;
  line-height: 1.4;
  max-height: 200px;
}
.input-row input:focus,
.input-row textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(124,58,237,0.12);
}

#send-btn, #send-btn-mobile {
  padding: 8px 12px;
  font-size: 16px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-panel #send-btn {
  height: 38px;
  min-width: 42px;
}
#send-btn:hover, #send-btn-mobile:hover { opacity: 0.88; }
#send-btn:disabled, #send-btn-mobile:disabled { opacity: 0.45; cursor: not-allowed; }

.hint { font-size: 11px; color: var(--color-muted); margin-top: 6px; }

/* ============================================================
   Transaction List
   ============================================================ */
.txn-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface);
}

.txn-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}

.txn-tabs { display: flex; gap: 4px; }

.txn-tab {
  padding: 4px 10px;
  font-size: 11px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: white;
  cursor: pointer;
  color: var(--color-muted);
}
.txn-tab:hover { border-color: var(--color-primary); color: var(--color-primary); }
.txn-tab.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

/* Sort tabs */
.txn-controls {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.sort-tabs { display: flex; gap: 4px; }

.sort-tab {
  padding: 3px 8px;
  font-size: 10px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: white;
  cursor: pointer;
  color: var(--color-muted);
}
.sort-tab:hover { border-color: var(--color-primary); color: var(--color-primary); }
.sort-tab.active {
  background: var(--color-text);
  color: white;
  border-color: var(--color-text);
}

/* Category multi-select dropdown */
.category-filter-wrapper {
  position: relative;
  display: inline-block;
}

.category-filter-btn {
  padding: 4px 10px;
  font-size: 11px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: white;
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.category-filter-btn:hover {
  border-color: var(--color-primary);
}

.category-filter-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
  min-width: 160px;
  padding: 4px 0;
}

.category-filter-dropdown.open {
  display: block;
}

.category-filter-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
}
.category-filter-item:hover {
  background: var(--color-bg);
}

.category-filter-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.txn-list {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 4px;
}

.txn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--color-border);
  margin: 0;
}
.txn:last-child { border-bottom: none; }

.txn-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
  padding-left: 0;
}

.txn-category {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.txn-vendor {
  font-size: 11px;
  color: var(--color-muted);
  white-space: normal;
  overflow: visible;
  word-break: break-word;
  line-height: 1.4;
}

.txn-meta {
  font-size: 11px;
  color: var(--color-muted);
}

.txn-amount {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 80px;
  text-align: right;
  order: -1;
}
.txn-amount.income  { color: var(--color-income); }
.txn-amount.expense { color: var(--color-expense); }

.txn-date {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text);
  opacity: 0.7;
  letter-spacing: 0.02em;
}

.txn-rate {
  cursor: help;
  text-decoration: underline dotted var(--color-muted);
  text-underline-offset: 2px;
  position: relative;
  display: inline-block;
}

.txn-rate:hover::after {
  content: "Rate: " attr(data-rate);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: white;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 1000;
  pointer-events: none;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
}

.empty { text-align: center; color: var(--color-muted); font-size: 13px; padding: 30px 0; }

/* ============================================================
   Pagination
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 0;
  margin-top: 8px;
  flex-wrap: wrap;
}

.pagination button {
  padding: 5px 12px;
  font-size: 12px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: white;
  color: var(--color-text);
  cursor: pointer;
}
.pagination button:hover:not(:disabled) {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

#page-indicator {
  font-size: 12px;
  color: var(--color-muted);
  min-width: 70px;
  text-align: center;
}

#page-size-select {
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: white;
  color: var(--color-muted);
  cursor: pointer;
}

/* ============================================================
   Sticky Header (filters + stats)
   ============================================================ */
.sticky-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--color-bg);
  padding-bottom: 12px;
  margin-bottom: 8px;
}

.period-heading {
  display: none;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 8px;
  padding: 0 12px;
}

/* ============================================================
   Mobile Chat Bottom Bar (tap to open overlay)
   ============================================================ */
.mobile-chat-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: none;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: #fff9c4;
  border-top: 1px solid #f0e68c;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
  z-index: 200;
  align-items: flex-end;
}

.mobile-chat-bar-input {
  flex: 1;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: white;
  color: var(--color-muted);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  height: 46px;
  display: flex;
  align-items: center;
}

.mobile-chat-bar-btn {
  padding: 12px 20px;
  font-size: 16px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  height: 46px;
  min-width: 56px;
  flex-shrink: 0;
}

/* ============================================================
   Mobile Full-Screen Chat Overlay
   ============================================================ */
.mobile-chat-overlay {
  position: fixed;
  inset: 0;
  background: #fffde7;
  z-index: 1000;
  display: none !important;
  flex-direction: column;
  overscroll-behavior: none;
}

.mobile-chat-overlay.open {
  display: flex !important;
}

.mobile-chat-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: #fff9c4;
  border-bottom: 1px solid #f0e68c;
  flex-shrink: 0;
  position: relative;
}

.swipe-handle {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  background: rgba(0,0,0,0.2);
  border-radius: 2px;
}

.mobile-chat-overlay-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  margin-right: auto;
}

.mobile-chat-help-content {
  display: none;
  padding: 8px 16px;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  font-size: 12px;
  color: #92400e;
  line-height: 1.5;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
.mobile-chat-help-content.open {
  display: block;
}
.mobile-chat-help-content.open + .mobile-chat-overlay-log {
  display: none;
}
.mobile-chat-help-content p {
  margin: 1px 0;
}
.mobile-chat-help-content strong {
  color: #78350f;
}

.mobile-chat-overlay-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #e0d8a8;
  background: white;
  font-size: 16px;
  color: var(--color-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-chat-overlay-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.mobile-chat-overlay-log .msg {
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.4;
  max-width: 85%;
}

.mobile-chat-overlay-log .msg.bot {
  background: #ffffff;
  border: 1px solid #f0e68c;
  color: var(--color-text);
  align-self: flex-start;
}

.mobile-chat-overlay-log .msg.user {
  background: var(--color-primary);
  color: white;
  align-self: flex-end;
}

.mobile-chat-overlay-log .msg.error {
  background: #fff0f0;
  border: 1px solid #ffcccc;
  color: #cc0000;
  align-self: flex-start;
}

.mobile-chat-overlay-log .msg.loading {
  background: #ffffff;
  border: 1px solid #f0e68c;
  color: var(--color-muted);
  font-style: italic;
  align-self: flex-start;
}

.mobile-chat-overlay-input {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: #fff9c4;
  border-top: 1px solid #f0e68c;
  flex-shrink: 0;
  align-items: flex-end;
}

.mobile-chat-overlay-input input,
.mobile-chat-overlay-input textarea {
  flex: 1;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  outline: none;
  background: white;
  color: var(--color-text);
  font-family: inherit;
  resize: none;
  overflow: hidden;
  line-height: 1.4;
  max-height: 120px;
}

.mobile-chat-overlay-input input:focus,
.mobile-chat-overlay-input textarea:focus {
  border-color: var(--color-primary);
  box-shadow: inset 0 0 0 1px rgba(124,58,237,0.12);
}

.mobile-chat-overlay-input button {
  padding: 12px 20px;
  font-size: 16px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  height: 46px;
  min-width: 56px;
}

/* ============================================================
   Mobile Toast
   ============================================================ */
.mobile-toast {
  position: fixed;
  bottom: 90px;
  left: 16px;
  right: 16px;
  background: var(--color-text);
  color: white;
  padding: 12px 16px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.4;
  z-index: 300;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
.mobile-toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ============================================================
   Mobile Filters Row
   ============================================================ */
.mobile-filters {
  display: flex;
  gap: 6px;
  padding-bottom: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.mobile-filters select {
  flex-shrink: 0;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: white;
  color: var(--color-text);
}

/* Mobile filter pill buttons */
.filter-pill {
  flex-shrink: 0;
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: white;
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  line-height: 1.3;
}
.filter-pill:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.filter-pill:active {
  background: var(--color-bg);
}

/* ============================================================
   Mobile Bottom Sheet
   ============================================================ */
.mobile-sheet {
  display: none;
  position: fixed;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.1);
  z-index: 9999;
  max-height: 50vh;
  min-width: 140px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0;
}
.mobile-sheet.open {
  display: block;
}

.mobile-sheet-header {
  display: none;
}

.mobile-sheet-options {
  padding: 0;
}

.mobile-sheet-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 15px;
  color: var(--color-text);
  cursor: pointer;
  gap: 8px;
  overflow: hidden;
}
.mobile-sheet-option > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.mobile-sheet-option:active {
  background: var(--color-bg);
}
.mobile-sheet-option.selected {
  font-weight: 600;
  background: #f3f0ff;
  color: var(--color-primary);
}

.mobile-sheet-option .currency-star {
  font-size: 18px;
  color: #ddd;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.mobile-sheet-option .currency-star.active {
  color: #f5a623;
}
.mobile-sheet-option .currency-star:active {
  transform: scale(1.2);
}

.mobile-sheet-handle {
  display: none;
}

/* ============================================================
   Mobile Responsive Overrides
   ============================================================ */
@media (max-width: 1024px) {
  html, body {
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    position: relative;
    width: 100%;
  }

  .layout {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    height: auto;
    overflow: visible;
    padding-bottom: 70px;
    max-width: 100vw;
    width: 100%;
  }

  .content-grid {
    grid-template-columns: 1fr;
    overflow: visible;
    flex: none; /* remove flex: 1 on mobile */
    padding: 0 8px;
    max-width: 100%;
    width: 100%;
  }

  .content-left, .content-right, .content-right-wrapper {
    max-width: 100%;
  }

  .charts-pair {
    grid-template-columns: 1fr;
    max-width: 100%;
    overflow: hidden;
  }

  .chart-container {
    margin-bottom: 8px;
    overflow: hidden;
    max-width: 100%;
    width: 100%;
  }

  .chart-wrapper, .charts-pair .chart-wrapper {
    overflow: hidden;
    max-width: 100%;
    width: 100%;
    height: 300px;
    position: relative;
  }

  .chart-wrapper canvas, .charts-pair .chart-wrapper canvas {
    display: block;
    max-width: 100% !important;
    width: 100% !important;
    max-height: 300px !important;
  }

  .trend-chart-wrapper canvas {
    display: block;
    max-width: 100% !important;
    width: 100% !important;
  }

  .trend-chart-wrapper {
    overflow: hidden;
    max-width: 100%;
    width: 100%;
  }

  .content-left {
    height: auto;
    max-height: none;
    overflow-y: visible;
    padding: 0;
  }

  .content-right {
    height: auto;
    max-height: none;
    overflow-y: visible;
    overflow: visible;
  }

  .content-right-wrapper {
    height: auto;
    overflow: visible;
  }

  .content-right .txn-list {
    overflow-y: visible;
    flex: none;
    min-height: 200px;
  }

  .txn-list {
    max-width: 100%;
    overflow-x: hidden;
  }

  .txn {
    max-width: 100%;
  }

  .txn-amount {
    width: 75px;
    min-width: 75px;
    max-width: 75px;
    font-size: 12px;
  }

  .stats {
    padding: 0 8px;
    margin-top: 0;
  }

  .filter-bar {
    max-height: none;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 6px 8px;
    max-width: 100%;
  }

  .chat-panel {
    display: none;
  }

  .app-header {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    padding: 10px 12px;
    gap: 4px 8px;
    max-height: none;
  }

  .app-header h1 {
    grid-column: 1;
    grid-row: 1;
  }

  .app-header p {
    grid-column: 1;
    grid-row: 2;
    margin-right: 0;
  }

  .app-header .header-menu-wrapper {
    grid-column: 2;
    grid-row: 1 / -1;
    align-self: center;
  }

  .txn-vendor {
    white-space: normal;
    overflow: visible;
  }
  .txn-category {
    white-space: normal;
    overflow: visible;
  }

  .trend-chart-wrapper {
    height: 160px;
  }

  .sticky-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--color-bg);
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .period-heading {
    display: none;
  }

  .mobile-filters {
    padding: 8px 8px 8px;
  }

  .mobile-filters .filter-pill {
    padding: 8px 12px;
  }

  .mobile-chat-bar {
    display: flex !important;
  }
}

/* Force hide mobile chat bar on desktop */
@media (min-width: 1025px) {
  .mobile-chat-bar {
    display: none !important;
  }
}

/* ============================================================
   Short Viewport — collapse chat panel to input-only
   (wide screens with limited height, e.g. split-screen browser)
   ============================================================ */
@media (max-height: 650px) and (min-width: 1025px) {
  .chat-panel {
    height: auto;
    position: relative;
  }

  .chat-panel .chat-panel-header,
  .chat-panel .chat-log,
  .chat-panel .chat-help-content,
  .chat-panel .hint {
    display: none;
  }

  .chat-panel.expanded {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100%;
    z-index: 100;
  }

  .chat-panel.expanded .chat-panel-header,
  .chat-panel.expanded .chat-log {
    display: flex;
  }

  .chat-panel.expanded .chat-help-content.open {
    display: block;
  }

  .content-right-wrapper {
    position: relative;
  }
}

/* ============================================================
   Clickable Transaction Rows
   ============================================================ */
.txn-clickable {
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 4px;
}
.txn-clickable:hover {
  background: var(--color-bg);
}
.txn-clickable:active {
  background: #ede9f5;
}

/* ============================================================
   Transaction Detail Overlay
   ============================================================ */
.txn-detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: txnOverlayFadeIn 0.15s ease;
}

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

.txn-detail-panel {
  background: var(--color-surface);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  width: 100%;
  max-width: 380px;
  max-height: 90vh;
  overflow-y: auto;
  animation: txnPanelSlideUp 0.2s ease;
}

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

.txn-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  position: relative;
}

.txn-detail-swipe-handle {
  display: none;
}

.txn-detail-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

.txn-detail-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: white;
  font-size: 18px;
  color: var(--color-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.txn-detail-close:hover {
  border-color: var(--color-expense);
  color: var(--color-expense);
}

.txn-detail-body {
  padding: 16px 12px;
}

.txn-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 8px 4px;
  border-bottom: 1px solid var(--color-border);
  gap: 12px;
  border-radius: 4px;
}
.txn-detail-row:last-child {
  border-bottom: none;
}

.txn-detail-label {
  font-size: 12px;
  color: var(--color-muted);
  flex-shrink: 0;
  min-width: 90px;
}

.txn-detail-value {
  font-size: 13px;
  color: var(--color-text);
  font-weight: 500;
  text-align: right;
  word-break: break-word;
}

.txn-detail-footer {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--color-border);
}

.txn-detail-delete-btn {
  width: 100%;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: white;
  background: var(--color-expense);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.txn-detail-delete-btn:hover {
  opacity: 0.88;
}
.txn-detail-delete-btn:active {
  opacity: 0.75;
}

/* Mobile adjustments for detail panel */
@media (max-width: 1024px) {
  .txn-detail-overlay {
    align-items: stretch;
    padding: 0;
    background: var(--color-surface);
    position: fixed;
    inset: 0;
    overscroll-behavior: none;
  }

  .txn-detail-panel {
    max-width: 100%;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    animation: none;
    display: flex;
    flex-direction: column;
    box-shadow: none;
  }

  .txn-detail-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
  }

  .txn-detail-header {
    flex-shrink: 0;
    position: relative;
    touch-action: pan-y;
  }

  .txn-detail-swipe-handle {
    display: block;
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
  }

  .txn-detail-footer {
    flex-shrink: 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}

/* ============================================================
   Inline Editable Fields in Transaction Detail
   ============================================================ */
.txn-editable .txn-detail-value {
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 6px;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.txn-editable .txn-detail-value:hover {
  background: var(--color-bg);
}
.txn-editable .txn-detail-value:active {
  background: #ede9f5;
}
.txn-editable .txn-detail-value::after {
  content: "✎";
  font-size: 11px;
  color: var(--color-primary-light);
  opacity: 0.6;
}

.txn-detail-amount-row {
  text-align: center;
  margin-bottom: 12px;
  padding: 4px 0;
}

.txn-detail-amount-value {
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 4px;
  padding: 4px 12px;
  transition: background 0.15s;
  display: inline-block;
}
.txn-detail-amount-value:hover {
  background: var(--color-bg);
}
.txn-detail-amount-value.income  { color: var(--color-income); }
.txn-detail-amount-value.expense { color: var(--color-expense); }

.txn-detail-amount-value .txn-inline-input {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  max-width: 160px;
}

.txn-inline-input,
.txn-inline-select {
  width: 100%;
  padding: 4px 8px;
  font-size: 16px;
  border: 1px solid var(--color-primary-light);
  border-radius: 4px;
  outline: none;
  background: white;
  color: var(--color-text);
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.12);
}
.txn-inline-input:focus,
.txn-inline-select:focus {
  border-color: var(--color-primary);
}

/* ============================================================
   Detail Panel Divider & Meta Rows
   ============================================================ */
.txn-detail-divider {
  height: 1px;
  background: var(--color-border);
  margin: 12px 0 8px;
}

.txn-detail-meta .txn-detail-label,
.txn-detail-meta .txn-detail-value {
  font-size: 11px;
  color: var(--color-muted);
}
.txn-detail-meta .txn-detail-value {
  font-weight: 400;
}
