/* Interface de toque: navegação inferior, formulários legíveis e cartões fluidos em celulares. */
@media screen and (max-width: 640px) {
  html { scroll-padding-top: 78px; }
  body { font-size: 15px; overflow-x: hidden; }
  .app-shell { display: block; min-height: 100dvh; padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .sidebar { position: fixed; inset: auto 0 0; z-index: 60; width: 100%; height: auto; min-height: 0; flex: none; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); color: var(--ink); background: rgba(255,255,255,.96); border-top: 1px solid #e3e9ee; box-shadow: 0 -5px 20px rgba(23,49,69,.08); backdrop-filter: blur(14px); }
  .sidebar .brand, .sidebar .workspace-label, .sidebar-bottom { display: none; }
  .nav-list { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 2px; }
  .nav-item, .nav-item.active { min-width: 0; min-height: 49px; padding: 4px 1px; flex-direction: column; justify-content: center; gap: 1px; border-radius: 10px; background: transparent; box-shadow: none; color: #677b8f; font-size: 9px; line-height: 1.15; text-align: center; white-space: nowrap; }
  .nav-item .nav-icon, .nav-item.active .nav-icon { display: block; width: auto; color: #71859a; font-size: 18px; line-height: 1.15; }
  .nav-item.active { color: var(--navy); background: #eaf1f7; }
  .nav-item.active .nav-icon { color: #c57d18; }
  .main-area { width: 100%; max-width: none; margin: 0; padding: 0 14px 25px; }
  .topbar { position: sticky; top: 0; z-index: 20; height: auto; min-height: 70px; gap: 8px; align-items: center; padding: 10px 0; margin-bottom: 17px; background: rgba(244,247,250,.96); backdrop-filter: blur(12px); }
  .topbar h1 { max-width: 44vw; font-size: 19px; line-height: 1.15; }
  .top-actions { gap: 6px; }
  .local-pill { font-size: 0; gap: 0; }
  .local-pill i { width: 9px; height: 9px; }
  #topNewBtn { padding: 9px 10px; font-size: 11px; white-space: nowrap; }
  .tools-menu { position: relative; }
  .tools-menu summary { min-height: 38px; display: grid; place-items: center; padding: 0 10px; border: 1px solid #d8e1e8; border-radius: 8px; background: #fff; color: var(--navy2); font-size: 11px; font-weight: 700; list-style: none; cursor: pointer; }
  .tools-menu summary::-webkit-details-marker { display: none; }
  .tools-popover { position: absolute; top: calc(100% + 8px); right: 0; z-index: 40; width: 190px; padding: 7px; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: 0 10px 28px #142d4522; }
  .tools-popover button { width: 100%; min-height: 42px; padding: 9px; border: 0; border-radius: 7px; background: transparent; color: var(--ink); font-size: 12px; text-align: left; }
  .tools-popover button:hover { background: #f2f6f8; }
  .welcome-banner { min-height: 0; padding: 22px 19px; border-radius: 13px; }
  .welcome-banner h2 { max-width: 300px; font-size: 22px; }
  .welcome-banner p { max-width: 300px; font-size: 12px; }
  .banner-art { right: -70px; top: 15px; opacity: .23; }
  .section-heading { margin: 22px 0 12px; }
  .metric-grid { grid-template-columns: 1fr; gap: 9px; }
  .metric-card { min-height: 0; padding: 14px 16px; }
  .metric-card > strong { margin-top: 5px; font-size: 22px; }
  .content-card { padding: 15px; }
  .card-heading { align-items: flex-start; gap: 8px; }
  .text-button { padding: 6px 2px; font-size: 11px; }
  .page-intro { align-items: stretch; flex-direction: column; gap: 12px; margin: 4px 0 17px; }
  .page-intro h2 { font-size: 19px; }
  .page-intro p { font-size: 12px; line-height: 1.45; }
  .page-intro > .btn, .page-intro > .badge { align-self: flex-start; }
  .invoice-import-card { display: flex; align-items: flex-start; flex-direction: column; gap: 12px; padding: 15px; margin-bottom: 14px; }
  .invoice-import-card .btn { width: 100%; min-height: 44px; }
  .form-card { padding: 15px 14px; margin-bottom: 11px; }
  .form-section-title { align-items: flex-start; gap: 9px; margin-bottom: 14px; flex-wrap: wrap; }
  .form-section-title > div { flex: 1; min-width: 160px; }
  .form-section-title h3 { font-size: 14px; }
  .form-section-title p { font-size: 11px; line-height: 1.4; }
  .form-section-title .btn.small { margin-left: 37px; }
  .field-grid.four { grid-template-columns: minmax(0,1fr); gap: 12px; }
  .field-grid .span2 { grid-column: auto; }
  .field > span { font-size: 12px; }
  .field input, .field select { min-height: 44px; padding: 10px 11px; font-size: 16px; }
  .form-actions { align-items: stretch; flex-direction: column; gap: 11px; }
  .form-actions .muted { font-size: 11px; line-height: 1.45; }
  #calculateBtn { width: 100%; min-height: 48px; }
  .filter-row { flex-wrap: wrap; }
  .search-box { flex-basis: 100%; max-width: none; height: 44px; }
  .search-box input, .filter-row select { min-height: 42px; font-size: 14px; }
  .filter-row select { flex: 1; width: auto; }
  .table-wrap { max-height: 62vh; overflow: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 680px; }
  th { padding: 10px 11px; }
  td { padding: 10px 11px; }
  .recent-row { grid-template-columns: 1fr auto; gap: 6px 10px; padding: 12px 1px; }
  .recent-row > div:nth-child(n+2):nth-child(-n+4) { font-size: 10px; }
  .recent-row > div:first-child { grid-column: 1 / 2; }
  .recent-row > button { grid-column: 2; grid-row: 1 / span 2; }
  .report-sheet { padding: 0; overflow: visible; }
  .mg-page { width: 100% !important; max-width: 100%; height: auto !important; min-height: 0 !important; aspect-ratio: auto !important; margin: 0 0 14px !important; padding: 14px !important; overflow: visible !important; border-radius: 12px; box-shadow: 0 4px 16px rgba(20,45,69,.08); }
  .mg-cover { min-height: 570px !important; padding: 22px 18px !important; }
  .cover-main, .cover-client-card { align-items: stretch; flex-direction: column; gap: 15px; }
  .cover-main { margin-top: 44px; }
  .cover-impact { min-width: 0; border-left: 0; border-top: 1px solid #ffffff4a; padding: 12px 0 0; }
  .cover-client-data { grid-template-columns: 1fr 1fr; gap: 10px; }
  .cover-client-data b { overflow-wrap: anywhere; }
  .mg-client-strip { grid-template-columns: 1fr 1fr; gap: 8px; padding: 9px; }
  .mg-client-strip > span { min-width: 0; }
  .mg-client-strip b { overflow-wrap: anywhere; }
  .mg-section-title { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; align-items: center; margin: 14px 0 10px; }
  .mg-section-title > span { grid-row: span 2; font-size: 19px; }
  .mg-section-title h2 { font-size: 17px; }
  .mg-section-title p { grid-column: 1 / -1; margin: 2px 0 0; font-size: 10px; line-height: 1.4; }
  .mg-kpi-row { grid-template-columns: 1fr 1fr; gap: 7px; }
  .mg-kpi-row article { min-width: 0; padding: 10px; }
  .mg-kpi-row article > b { font-size: 15px; overflow-wrap: anywhere; }
  .mg-two-charts, .mg-economic-bottom, .mg-cost-columns, .mg-tech-columns { grid-template-columns: 1fr !important; gap: 9px; }
  .mg-panel { min-width: 0; padding: 10px; }
  .mg-panel h3 { gap: 5px; flex-wrap: wrap; font-size: 11px; }
  .mg-svg { width: 100%; height: auto; }
  .mg-economic-bottom { margin-top: 8px; }
  .mg-highlights { padding: 11px 12px !important; margin-top: 9px !important; }
  .mg-highlights ul { padding-left: 15px; }
  .mg-highlights li { font-size: 10px; line-height: 1.4; }
  .mg-cost-columns .mg-table, .mg-tech-columns .mg-table { min-width: 0; }
  .mg-cost-columns .mg-table th, .mg-cost-columns .mg-table td, .mg-tech-columns .mg-table th, .mg-tech-columns .mg-table td { padding: 6px 5px !important; font-size: 8.5px !important; white-space: normal; overflow-wrap: anywhere; }
  .mg-donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .mg-donut { width: min(180px, 55vw); }
  .mg-donut-legend { width: 100%; }
  .mg-glossary-grid { grid-template-columns: 1fr !important; gap: 8px; }
  .mg-howto, .mg-disclaimer { padding: 12px !important; }
  .mg-footer { gap: 8px; align-items: flex-end; font-size: 8px; }
  .invoice-modal { padding: 8px; align-items: end; }
  .invoice-review-dialog { width: 100%; max-height: 94dvh; padding: 15px 13px calc(12px + env(safe-area-inset-bottom)); border-radius: 16px 16px 10px 10px; }
  .invoice-review-header { gap: 8px; }
  .invoice-review-header h2 { font-size: 18px; }
  .invoice-review-legend { flex-direction: column; gap: 5px; }
  .invoice-review-grid { grid-template-columns: 1fr !important; gap: 10px; }
  .invoice-review-field input, .invoice-review-field select { min-height: 44px; font-size: 16px; }
  .invoice-review-footer { position: sticky; bottom: -13px; flex-direction: column; gap: 10px; margin: 12px -13px -13px; padding: 12px 13px calc(10px + env(safe-area-inset-bottom)); background: #f7f9fb; border-top: 1px solid var(--line); }
  .invoice-review-footer > div { width: 100%; display: grid; grid-template-columns: 1fr 1.5fr; gap: 8px; }
  .invoice-review-footer .btn { min-height: 44px; padding: 8px; font-size: 11px; }
  .toast { left: 12px; right: 12px; bottom: calc(78px + env(safe-area-inset-bottom)); text-align: center; }
}

@media screen and (max-width: 380px) {
  .main-area { padding-right: 11px; padding-left: 11px; }
  .topbar h1 { font-size: 17px; }
  #topNewBtn { padding: 8px; font-size: 10px; }
  .tools-menu summary { padding: 0 8px; }
  .nav-item, .nav-item.active { font-size: 8px; }
}

@media screen and (max-width: 640px) { .nav-item:not(.active) .nav-icon { display: block; } }
#installAppBtn[hidden] { display: none; }

@media screen and (max-width: 640px) {
  .mg-tech-charts-three { grid-template-columns: 1fr !important; }
  .tariff-toolbar { display: flex; width: 100%; flex-wrap: wrap; gap: 7px; }
  .tariff-toolbar .btn { min-height: 42px; }
  .tariff-editor-grid { grid-template-columns: 1fr; }
  .tariff-editor-field input, .tariff-editor-field select { min-height: 44px; font-size: 16px; }
  .tariff-editor-dialog .invoice-review-footer { position: sticky; bottom: -13px; }
}

@media screen and (max-width: 640px) {
  .invoice-import-actions { width: 100%; min-width: 0; flex-direction: column; gap: 8px; }
  .invoice-import-actions .btn { width: 100%; min-height: 46px; }
  .invoice-field-source, .invoice-current-value { font-size: 11px; }
  .invoice-demand-allocation select { min-height: 44px; font-size: 16px; }
}

@media screen and (max-width: 640px) {
  .invoice-tax-treatment { padding: 11px; font-size: 12px; }
  .invoice-tax-treatment input { width: 21px; height: 21px; }
  .invoice-tax-treatment small { margin-left: 30px; font-size: 11px; }
}
