/* ============================================
   MONEY VIEW - RESPONSIVE LAYOUT
   ============================================ */

/* Mobile Layout (default) - Vertical Stack */
#money-view .section-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--brokerly-text-primary);
  margin-bottom: 16px;
}

#money-view .section-header {
  margin-bottom: 8px;
  padding-left: 4px; /* Align slightly with cards */
}

#money-view .section-subtitle {
  font-size: 14px;
  color: var(--brokerly-text-secondary);
  margin-top: -8px;
  margin-bottom: 16px;
  opacity: 0.8;
}

#money-view .collapsible-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--brokerly-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#money-view .money-main-content {
  display: flex;
  flex-direction: column;
  gap: 32px;
  width: 100%;
}

#money-view .money-left-column {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  order: 1;
}

/* Mobile ordering */
#money-view #spend-pulse-section {
  order: 2;
  width: 100%;
}

#money-view #accounts-section {
  order: 3;
  width: 100%;
}

#money-view #spend-trend-section {
  order: 4;
  width: 100%;
}

#money-view #cash-flow-section {
  order: 5;
  width: 100%;
}

#money-view #balance-flow-section {
  order: 6;
  width: 100%;
}

#money-view #expense-breakdowns {
  order: 7;
  width: 100%;
}

/* Financial summary - use default Quick Stats styling, no overrides */
#money-view #financial-summary {
  width: 100%;
}

#money-view .quick-stats-section {
  width: 100%;
}

/* Scroll containment for expanded collapsible sections */
#money-view .collapsible-content.expanded {
  max-height: 420px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#money-view .collapsible-content.expanded::-webkit-scrollbar {
  width: 6px;
}

#money-view .collapsible-content.expanded::-webkit-scrollbar-track {
  background: transparent;
}

#money-view .collapsible-content.expanded::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

#money-view .collapsible-content.expanded::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}


/* ============================================
   Desktop Layout (768px+)
   Grid:
     Col 1 (1fr)  | Col 2 (auto ~260px)
     Row 1: Financial Summary | Spending Pulse
     Row 2: Accounts (full width)
     Row 3: Spend Trend (full width)
     Row 4: Cash Flow (full width)
     Row 5: Expense Breakdowns (full width)
   ============================================ */
@media (min-width: 768px) {
  #money-view .view-content {
    max-width: 1100px !important;
    margin: 0 auto;
  }

  #money-view .money-main-content {
    display: grid;
    grid-template-columns: 1fr 260px;
    grid-template-rows: auto auto auto auto auto;
    gap: 24px;
    align-items: start;
    max-width: 100%;
    margin: 0 auto;
  }

  /* Row 1, col 1: financial summary */
  #money-view .money-left-column {
    max-width: 100%;
    width: 100%;
    grid-column: 1;
    grid-row: 1;
  }

  /* Ensure financial summary section fills the container */
  #money-view .quick-stats-section {
    width: 100%;
  }

  /* Row 1, col 2: Spending Pulse */
  #money-view #spend-pulse-section {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
    width: 100%;
    order: unset;
  }

  /* Row 2: Accounts - full width */
  #money-view #accounts-section {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    order: unset;
  }

  /* Remove old fixed-height card constraint — accounts is now full width */
  #money-view #accounts-section .money-section {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
  }

  /* Accounts content no longer needs fixed-height scroll box */
  #money-view #accounts-section .collapsible-content.expanded {
    overflow-y: visible;
    overflow-x: visible;
    flex: unset;
    max-height: none;
    padding-right: 0;
    margin-top: 12px;
  }

  /* Row 3: Spend Trend */
  #money-view #spend-trend-section {
    grid-column: 1 / -1;
    grid-row: 3;
    max-width: 100%;
    order: unset;
  }

  /* Row 4: Cash Flow */
  #money-view #cash-flow-section {
    grid-column: 1 / -1;
    grid-row: 4;
    max-width: 100%;
    order: unset;
  }

  /* Row 5: Balance Flow (Financial Pulse) */
  #money-view #balance-flow-section {
    grid-column: 1 / -1;
    grid-row: 5;
    max-width: 100%;
    order: unset;
  }

  /* Row 6: Expense Breakdowns */
  #money-view #expense-breakdowns {
    grid-column: 1 / -1;
    grid-row: 6;
    max-width: 100%;
    order: unset;
  }
}

/* Larger screen sizes */
@media (min-width: 1024px) and (max-width: 1439px) {
  #money-view .view-content {
    max-width: var(--view-max-width) !important;
  }

  #money-view .money-main-content {
    grid-template-columns: 1fr 280px;
  }
}

@media (min-width: 1440px) and (max-width: 1919px) {
  #money-view .view-content {
    max-width: 1100px;
  }

  #money-view .money-main-content {
    grid-template-columns: 1fr 300px;
  }
}

@media (min-width: 1920px) {
  #money-view .view-content {
    max-width: 1200px;
  }

  #money-view .money-main-content {
    grid-template-columns: 1fr 320px;
  }
}

/* ============================================
   RESPONSIVE SPREADSHEET MODAL FOR MOBILE
   ============================================ */
@media (max-width: 767px) {
  /* Reduce modal border boundaries to fit small screens */
  .spend-analysis-wrapper-card.widget-expanded-overlay {
    padding: 8px !important;
  }

  /* Maximize usable height and horizontal space inside the card content */
  .spend-analysis-wrapper-card.widget-expanded-overlay .spend-analysis-modal-content {
    padding: 16px 12px 16px !important;
    max-height: 98vh !important;
    border-radius: 16px !important;
    gap: 8px !important;
  }

  /* Make the ledger-toolbar stack items vertically and stretch */
  .spend-analysis-wrapper-card .ledger-toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    padding: 8px !important;
    height: auto !important;
    min-height: 0 !important;
  }

  /* Let search bar and category filter span full width and stack vertically */
  .spend-analysis-wrapper-card .search-filter-area {
    max-width: 100% !important;
    width: 100% !important;
    flex-direction: column !important;
    gap: 8px !important;
  }

  /* Spread the Save Changes & Discard buttons evenly */
  .spend-analysis-wrapper-card .save-actions-area {
    width: 100% !important;
    display: flex !important;
    gap: 8px !important;
  }

  .spend-analysis-wrapper-card .save-actions-area button {
    flex: 1 !important;
    text-align: center !important;
    padding: 8px !important;
    font-size: 0.8rem !important;
  }

  /* Stack bulk actions area controls wrap cleanly */
  .spend-analysis-wrapper-card .bulk-actions-area {
    width: 100% !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    padding: 6px !important;
  }

  /* Set min-width on table to prevent squeezing, enabling natural horizontal scroll */
  .spend-analysis-wrapper-card .ledger-spreadsheet-table {
    min-width: 850px !important;
  }

  /* Make the inputs and select boxes slightly more compact */
  .spend-analysis-wrapper-card .spreadsheet-input,
  .spend-analysis-wrapper-card .spreadsheet-select {
    padding: 4px 6px !important;
    font-size: 0.8rem !important;
  }
}