/* ──────────────────────────────────────────────────────────────────
   RESPONSIVE OVERRIDES — Mobile-first adjustments for The Ledger
   Applied as media queries on top of the desktop base layout.
   ────────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  /* App shell — sidebar collapses; bottom tab nav appears.
     Leave ~84px at the bottom for the floating tab bar. */
  .app-shell {
    flex-direction: column !important;
    min-height: 100dvh;
  }
  .app-main {
    padding-bottom: 84px !important;
  }

  /* Section padding shrinks. Each screen uses the .ledger-screen
     wrapper class so we can shrink uniformly. */
  .ledger-screen {
    padding: 24px 16px 32px !important;
    gap: 20px !important;
  }

  /* Hero title scales down */
  .hero {
    font-size: 28px !important;
    line-height: 34px !important;
    letter-spacing: -0.6px !important;
  }
  .eyebrow {
    font-size: 10px !important;
  }

  /* Form / modal padding */
  .ledger-card-pad {
    padding: 20px !important;
  }
  .ledger-modal {
    width: calc(100vw - 24px) !important;
    max-width: 460px !important;
    padding: 22px !important;
  }

  /* Spending chart shrinks min-height */
  .ledger-chart {
    min-height: 280px !important;
    padding: 20px !important;
  }
  .ledger-alloc {
    width: 100% !important;
    flex: 1 1 auto !important;
    min-height: 280px !important;
    padding: 20px !important;
  }
  .ledger-alloc > div:first-of-type + h3 {
    margin-bottom: 16px !important;
  }

  /* Sortable column header style for stacked card lists */
  .ledger-stacked-row {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
    align-items: stretch !important;
    padding: 14px 16px !important;
    gap: 10px !important;
  }
  .ledger-stacked-row > * {
    text-align: left !important;
    width: 100% !important;
  }

  /* Hide column-header rows on mobile (cards have inline labels) */
  .ledger-table-head {
    display: none !important;
  }

  /* Inputs touch-friendly */
  input, select, textarea {
    font-size: 16px !important; /* prevents iOS zoom on focus */
  }

  /* Forecasts top filter bar wraps */
  .ledger-page-header h1.hero { word-break: break-word; }

  /* Modal becomes nearly full-screen */
  .ledger-fullscreen-modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }
}

@media (max-width: 480px) {
  .hero { font-size: 24px !important; line-height: 30px !important; }
  .ledger-screen { padding: 20px 14px 32px !important; }
}

/* ──────────────────────────────────────────────────────────────────
   MOBILE HARDENING — corrige scroll lateral, sobreposição de texto,
   barras que estouram a largura e cabeçalhos/ações que não cabem.
   ────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* 1. Nunca permitir scroll horizontal na página inteira */
  html, body, #app, .app-shell, .app-main {
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  .app-main { width: 100% !important; box-sizing: border-box !important; }

  /* 2. Qualquer linha de ações no topo das telas (botões Editar em lote /
        Nova Entrada, filtros) deve quebrar em vez de estourar a largura */
  .ledger-page-header,
  .ledger-page-header > div,
  .ledger-screen > div:first-child {
    flex-wrap: wrap !important;
  }
  .ledger-page-header { gap: 12px !important; }

  /* Botões em telas pequenas ocupam linha cheia e não transbordam */
  .ledger-screen button {
    max-width: 100% !important;
  }

  /* Linha de ações do cabeçalho (Editar em lote / Nova Entrada) ocupa
     a largura toda e os botões dividem o espaço, sem estourar a tela */
  .ledger-header-actions {
    width: 100% !important;
  }
  .ledger-header-actions > button {
    flex: 1 1 auto !important;
  }

  /* 3. Linhas de lançamento: garantir layout em coluna, sem sobreposição.
        O valor e a categoria não podem ficar um por cima do outro. */
  .ledger-stacked-row,
  .ledger-tx-row {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    grid-template-columns: none !important;
    gap: 8px !important;
    padding: 14px 16px !important;
  }
  .ledger-tx-row > * { width: auto !important; }

  /* 4. Tabelas em grid (editar em lote, previsões em lote) viram blocos
        roláveis horizontalmente DENTRO do card, sem empurrar a página */
  .ledger-bulk-scroll {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* 5. Gráficos nunca estouram a largura da tela */
  .ledger-chart, .ledger-alloc, svg, canvas, .recharts-wrapper, .recharts-surface {
    max-width: 100% !important;
  }
  .ledger-chart > div, .ledger-alloc > div { min-width: 0 !important; }

  /* 6. Cards de KPI: UM por linha no celular, com números completos visíveis */
  .ledger-kpi-grid {
    grid-template-columns: 1fr !important;
  }
  /* Fonte dos valores um pouco menor no mobile para caber o número inteiro */
  .ledger-kpi-grid .num {
    font-size: 22px !important;
    line-height: 28px !important;
    white-space: normal !important;
  }

  /* 7. Reserva espaço extra no fim da página para a barra inferior +
        o botão central "+" que sobe acima dela */
  .app-main { padding-bottom: 96px !important; }

  /* Selects e inputs nunca passam da largura disponível */
  select, input, textarea { max-width: 100% !important; box-sizing: border-box !important; }
}

@media (max-width: 380px) {
  /* Telas muito estreitas: reduz ainda mais o valor dos KPIs */
  .ledger-kpi-grid .num { font-size: 20px !important; }
}
