/* KNSF Sistema — Sprint 004 / Etapa 4.2.1
   Ajustes conservadores de navegação e ergonomia mobile.
   Nenhuma regra de negócio é alterada. */

@media (max-width: 720px) {
  :root {
    --knsf-mobile-nav-h: 64px;
    --knsf-safe-bottom: env(safe-area-inset-bottom, 0px);
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-padding-top: 112px;
  }

  body {
    padding-bottom: calc(var(--knsf-mobile-nav-h) + var(--knsf-safe-bottom) + 12px);
    overflow-x: hidden;
  }

  /* Cabeçalho compacto: identidade e sincronização ficam visíveis. */
  header {
    min-height: 58px;
    padding: 8px 10px;
    gap: 8px;
    flex-wrap: nowrap;
  }

  header img {
    width: 38px;
    height: 38px;
    border-radius: 9px;
  }

  .hd-title {
    font-size: 13px;
    line-height: 1.15;
  }

  .hd-sub {
    font-size: 10px;
    margin-top: 2px;
  }

  #sync-status {
    display: block !important;
    margin: 0 0 0 auto !important;
    max-width: 92px;
    font-size: 9px !important;
    line-height: 1.15;
    text-align: right;
    white-space: normal;
  }

  /* Navegação principal vira uma barra inferior de aplicativo. */
  .hd-right {
    position: fixed;
    z-index: 9950;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--knsf-mobile-nav-h) + var(--knsf-safe-bottom));
    padding: 6px 6px calc(6px + var(--knsf-safe-bottom));
    margin: 0;
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    background: rgba(255,255,255,.98);
    border-top: 1px solid var(--g100);
    box-shadow: 0 -5px 20px rgba(0,0,0,.11);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .hd-right::-webkit-scrollbar { display: none; }

  .hd-btn {
    flex: 1 0 72px;
    min-width: 72px;
    height: 50px;
    padding: 5px 4px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--g600);
    font-size: 10px;
    line-height: 1.15;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    white-space: nowrap;
  }

  .hd-btn:hover { background: var(--g50); }
  .hd-btn.active {
    color: var(--red);
    background: var(--red-light);
    border: 0;
  }

  /* Abas internas ficam acessíveis ao rolar. */
  .tabs {
    position: sticky;
    top: 58px;
    z-index: 90;
    padding: 0 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
  }

  .tab {
    min-height: 44px;
    padding: 11px 12px;
    font-size: 12px;
  }

  /* Melhor aproveitamento da largura útil. */
  .container {
    width: 100%;
    max-width: none;
    padding: 12px 8px 24px;
  }

  .card {
    padding: 16px 14px;
    margin-bottom: 10px;
    border-radius: 9px;
  }

  .card-title {
    margin-bottom: 13px;
    padding-bottom: 8px;
  }

  /* Áreas de toque e teclado mais confortáveis. */
  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px; /* evita zoom automático do Chrome Android */
    padding: 10px 11px;
  }

  textarea { min-height: 72px; }

  button,
  .chip,
  .add-btn,
  .orc-btn,
  .btn-filtro,
  .sub-tab,
  .imp-sub-tab {
    min-height: 42px;
    touch-action: manipulation;
  }

  .actions {
    gap: 8px;
  }

  .actions .btn-r,
  .btn-r {
    min-height: 46px;
  }

  /* Totais mais legíveis e sem desperdício de largura. */
  .totais { width: 100%; }
  .trow { width: 100%; justify-content: flex-end; }
  .trow label { min-width: 110px; }
  .trow input { width: 112px; }

  /* Filtros passam a usar toda a largura disponível. */
  .filtros,
  .ev-toolbar,
  .rel-filters {
    gap: 8px;
  }

  .filtros .field,
  .ev-toolbar input,
  .ev-toolbar select,
  .rel-filters .field {
    min-width: calc(50% - 4px) !important;
    max-width: none;
  }

  /* Badge não disputa espaço com a barra inferior. */
  .knsf-env-badge {
    right: 8px !important;
    bottom: calc(var(--knsf-mobile-nav-h) + var(--knsf-safe-bottom) + 8px) !important;
    padding: 5px 8px !important;
    font-size: 9px !important;
  }

  .knsf-pwa-toast,
  .knsf-install-card {
    bottom: calc(var(--knsf-mobile-nav-h) + var(--knsf-safe-bottom) + 10px) !important;
  }

  /* Modais usam melhor o viewport e respeitam a barra inferior. */
  .modal-overlay {
    align-items: flex-end;
  }

  .modal-box {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 58px);
    border-radius: 14px 14px 0 0;
    padding: 16px 14px calc(16px + var(--knsf-safe-bottom));
  }
}

@media (max-width: 390px) {
  #sync-status { display: none !important; }
  .hd-title { font-size: 12px; }
  .hd-btn { flex-basis: 68px; min-width: 68px; }
  .container { padding-left: 6px; padding-right: 6px; }
  .card { padding-left: 12px; padding-right: 12px; }
  .filtros .field,
  .ev-toolbar input,
  .ev-toolbar select,
  .rel-filters .field {
    min-width: 100% !important;
  }
}
