/* ---------- large tablets / small laptops ---------- */
@media (max-width: 1200px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat-wide { grid-column: span 2; }
  .bd-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid .today { grid-row: auto; }
  .money-panel { grid-column: auto; }
  .dash-grid-wide { grid-template-columns: minmax(0, 1fr); }
  .tc-form { grid-template-columns: minmax(0, 1fr) 320px; }
}

/* ---------- tablets: sidebar becomes a drawer ---------- */
@media (max-width: 1024px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); transform: translateX(-100%); transition: transform .2s ease; box-shadow: none;
    padding-top: calc(20px + env(safe-area-inset-top)); padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(19, 35, 63, .25); }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(19, 35, 63, .4); z-index: 35; opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-grid; margin-left: -8px; }
  .topbar { padding: 10px 20px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .view { padding: 20px 20px 40px; }
  .tc-form { grid-template-columns: minmax(0, 1fr); }
  .calc { position: static; }
  .form-actions { position: sticky; bottom: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); padding: 12px 0; margin: 0 -2px; }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-brand { padding: 32px 24px; padding-top: calc(32px + env(safe-area-inset-top)); }
  .auth-foot { display: none; }
}
@media (max-width: 1024px) and (prefers-reduced-motion: reduce) { .sidebar, .scrim { transition: none; } }

/* ---------- phones ---------- */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .hide-sm { display: none !important; }
  .view { padding: 16px 14px calc(96px + env(safe-area-inset-bottom)); }
  .topbar { min-height: 60px; padding-left: 14px; padding-right: 14px; }
  #page-title { font-size: 19px; }
  .panel { padding: 16px; border-radius: 14px; margin-bottom: 14px; }
  .stats, .stats-sm { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-wide { grid-column: 1 / -1; }
  .stat b { font-size: 22px; }
  .bd-row, .summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-strip { padding: 12px 16px; }
  .dash-grid, .dash-grid-2 { grid-template-columns: minmax(0, 1fr); gap: 14px; margin-bottom: 14px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
  .filters .field { margin-bottom: 12px; }
  .filters-cta { grid-column: 1 / -1; justify-self: stretch; }
  .filters-cta.btn, .filters-cta .btn { width: 100%; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .form-actions { bottom: calc(64px + env(safe-area-inset-bottom)); }
  .form-actions .btn { flex: 1 1 auto; }
  .form-actions .btn-ghost { flex: 0 0 auto; }
  .today-nums { gap: 18px; }
  .today-nums b { font-size: 22px; }
  .auth-brand { padding-bottom: 24px; gap: 12px; }
  .auth-sample { display: none; }
  .auth-panel { place-items: start center; padding-top: 24px; }

  /* tables become stacked cards */
  .table-wrap { overflow: visible; margin: 0; padding: 0; }
  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tfoot { display: block; }
  .rtable tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
  .rtable tbody tr:last-child { border-bottom: 0; }
  .rtable td { display: block; padding: 0; border: 0; text-align: left !important; min-width: 0; }
  .rtable td::before { content: attr(data-label); display: block; font-size: 11.5px; font-weight: 700; color: var(--muted); }
  .rtable td:first-child, .rtable td.cell-task, .rtable td.cell-actions { grid-column: 1 / -1; }
  .rtable td:first-child::before, .rtable td.cell-actions::before { display: none; }
  .cell-task { max-width: none; }
  .row-actions { justify-content: flex-start; }
  .row-actions .btn { flex: 1 1 auto; min-height: 40px; }
  .rtable tfoot tr { background: var(--grey-50); border-radius: var(--r-md); padding: 12px; }
  .rtable tfoot th, .rtable tfoot td { border: 0; padding: 0; }

  /* bottom navigation */
  .bottomnav { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 20px -10px rgba(19, 35, 63, .2); }
  .bn-link { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; border: 0; background: none;
    color: var(--muted); font-size: 11.5px; font-weight: 700; text-decoration: none; border-radius: var(--r-sm); cursor: pointer; }
  .bn-link.on { color: var(--blue); }
  .bn-link .count { position: absolute; top: 2px; left: 55%; min-width: 18px; height: 18px; font-size: 10.5px; padding: 0 5px; }
  .bn-primary .ic { background: var(--blue); color: #fff; border-radius: 50%; width: 36px; height: 36px; padding: 8px; margin-top: -4px; }
  .bn-primary { color: var(--blue); }

  .dlg, .dlg.dlg-wide { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .dlg-inner { max-height: 92vh; }
  .dlg-foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .dlg-foot .btn { flex: 1 1 auto; }
  .toasts { left: 14px; right: 14px; bottom: calc(76px + env(safe-area-inset-bottom)); max-width: none; }
  .big-h { font-size: 28px; }
}

@media (max-width: 380px) {
  .stats, .stats-sm, .bd-row, .summary-strip, .filters { grid-template-columns: minmax(0, 1fr); }
  .stepper input { max-width: 110px; }
}
