/* Small-screen layout refinements */
@media (max-width: 820px) {
  .content-grid { display: grid; grid-template-columns: minmax(0, 1fr); }
  .left-column, .right-column { display: contents; }
  .budget-panel { order: 1; }
  .form-panel { order: 2; grid-row: auto; }
  .chart-panel { order: 3; }
  .category-panel { order: 4; grid-column: auto; }
  .history-panel { order: 5; }
  .savings-panel { order: 6; }
  .assistant-panel { order: 7; }
}

@media (max-width: 560px) {
  .shell { width: min(100% - 24px, 440px); padding-top: 12px; }
  .topbar { height: auto; min-height: 42px; margin-bottom: 24px; gap: 8px; }
  .brand { gap: 8px; min-width: 0; }
  .brand-mark { width: 35px; height: 35px; flex: none; }
  .brand strong { font-size: 15px; }
  .brand small { font-size: 9px; }
  .top-actions { gap: 5px; flex: none; }
  .local-badge { display: none; }
  .currency-button { height: 33px; gap: 4px; padding: 0 7px; }
  .currency-button-symbol { width: 17px; height: 17px; }
  .icon-button { width: 32px; height: 32px; }

  .welcome { align-items: flex-start; gap: 8px; margin-bottom: 19px; }
  .welcome h1 { font-size: clamp(28px, 8vw, 34px); line-height: 1.12; letter-spacing: -1.5px; }
  .welcome-copy { max-width: 250px; font-size: 11px; }
  .date-chip { margin-top: 3px; padding: 8px; flex: none; }

  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
  .metric-card { min-width: 0; min-height: 104px; padding: 12px; border-radius: 13px; }
  .balance-card { grid-column: 1 / -1; min-height: 112px; }
  .metric-label { font-size: 10px; }
  .metric-icon { width: 26px; height: 26px; }
  .metric-value { max-width: 100%; margin: 9px 0 5px; font-size: clamp(16px, 5vw, 22px); letter-spacing: -.7px; overflow-wrap: anywhere; }
  .metric-foot { font-size: 9px; }

  .content-grid, .left-column, .right-column { gap: 11px; }
  .panel { min-width: 0; padding: 15px; border-radius: 14px; }
  .history-panel { padding: 0; }
  .section-heading h2, .history-heading h2, .form-heading h2 { font-size: 12px; }
  .section-heading p, .form-heading p, .history-heading p { font-size: 9px; }
  .budget-main { margin-top: 16px; }
  .budget-main strong { font-size: clamp(18px, 6vw, 22px); }
  .budget-main>div:first-child span, .budget-target { font-size: 9px; }
  .budget-foot { font-size: 9px; }

  .chart-container { height: 205px; }
  .chart-heading { align-items: flex-start; }
  .chart-heading .small-select { max-width: 112px; padding: 7px 19px 7px 7px; font-size: 9px; }

  .history-heading { padding: 15px 13px 11px; }
  .filter-bar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 7px; padding: 0 12px 12px; }
  .search-box { grid-column: 1 / -1; width: 100%; height: 38px; }
  .search-box input { font-size: 12px; }
  .filter-bar .small-select, .month-select { width: 100%; min-width: 0; max-width: none; height: 38px; padding: 0 22px 0 9px; font-size: 10px; }
  .transaction { grid-template-columns: minmax(0, 1fr) auto 28px; gap: 6px; padding: 10px 12px; }
  .tx-main { gap: 8px; }
  .tx-icon { width: 30px; height: 30px; }
  .tx-title { font-size: 10px; }
  .tx-meta { gap: 4px; font-size: 8px; }
  .tx-amount { max-width: 108px; font-size: 10px; overflow-wrap: anywhere; white-space: normal; text-align: right; }

  .field-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  .field label, .field>span:first-child { font-size: 10px; }
  .field input, .field select, .amount-input { height: 40px; font-size: 12px; }
  .submit-button { min-height: 43px; }

  footer { align-items: center; gap: 6px; padding-top: 16px; text-align: center; font-size: 9px; }
  .budget-dialog { max-height: calc(100dvh - 24px); overflow-y: auto; padding: 18px; }
  .dialog-top h2 { max-width: 260px; font-size: 18px; }
  .dialog-copy { font-size: 11px; line-height: 1.55; }
}

@media (max-width: 360px) {
  .shell { width: calc(100% - 20px); }
  .brand-mark { width: 32px; height: 32px; }
  .brand { gap: 6px; }
  .brand strong { font-size: 14px; }
  .brand small { font-size: 8px; }
  .top-actions { gap: 4px; }
  .currency-button { padding: 0 5px; font-size: 8px; }
  .currency-button-symbol { width: 15px; height: 15px; }
  .icon-button { width: 29px; height: 29px; }
  .metric-card { padding: 10px; }
  .metric-value { font-size: 16px; }
  .tx-icon { width: 27px; height: 27px; }
  .tx-amount { max-width: 88px; font-size: 9px; }
}

/* Prevent iOS Safari from zooming the page when entering transaction amounts. */
@media (max-width: 560px) {
  input[type="number"] { font-size: 16px !important; }
}
