/* Método NES Care — Layout responsivo (mobile, tablet, notebook, desktop) */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

#app-screen .app-shell {
  display: flex;
  min-height: calc(100vh - 64px);
  width: 100%;
}

#app-screen .sidebar,
#app-screen .farm-sidebar.sidebar,
#app-screen .nes-sidebar {
  width: 260px;
  min-width: 260px;
  max-width: 260px;
  flex-shrink: 0;
}

#app-screen .main-content,
#app-screen .farm-main {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 20px;
  overflow-x: hidden;
}

.page-content {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

/* Botão hambúrguer — oculto em desktop */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #16846f;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 44px;
  flex-shrink: 0;
}

.sidebar-mobile-backdrop,
.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 999;
  pointer-events: none;
}

.sidebar-mobile-backdrop.visible,
.sidebar-mobile-backdrop.open,
.mobile-overlay.visible,
.mobile-overlay.is-open,
.mobile-overlay.open {
  display: block;
  pointer-events: auto;
}

body.menu-open,
body.nes-sidebar-open {
  overflow: hidden;
}

/* Grids de formulário — desktop 2 colunas */
.form-grid,
.services-grid,
.agenda-grid,
.nes-voucher-grid,
.nes-form-grid,
.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .form-group,
.nes-voucher-grid .form-group,
.nes-form-grid .form-group {
  min-width: 0;
}

.form-grid .nes-field-full,
.nes-voucher-grid .nes-field-full,
.form-grid-2 .span-2 {
  grid-column: 1 / -1;
}

.form-group label,
.form-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.85rem;
}

/* Barra inferior de ações (telas críticas) */
.mobile-action-bar {
  display: none;
}

/* Navegação inferior — celular */
.nes-mobile-bottom-nav {
  display: none;
}

/* ─── Tablet / mobile (até 1024px) — drawer lateral ─── */
@media (max-width: 1024px) {
  #app-screen .farm-layout.layout.app,
  #app-screen .nes-layout,
  #app-screen .app-shell {
    display: block !important;
    grid-template-columns: 1fr !important;
  }

  #app-screen .sidebar.sidebar-mobile,
  #app-screen .farm-sidebar.sidebar.sidebar-mobile,
  #app-screen .nes-sidebar.sidebar-mobile {
    position: fixed !important;
    top: 0;
    left: -100% !important;
    width: 85vw !important;
    max-width: 340px !important;
    min-width: 0 !important;
    height: 100vh !important;
    z-index: 1000;
    transition: left 0.25s ease;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.2);
    transform: none !important;
    margin: 0 !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #app-screen .sidebar.sidebar-mobile.open,
  #app-screen .sidebar.sidebar-open,
  #app-screen .farm-sidebar.sidebar.sidebar-mobile.open,
  #app-screen .farm-sidebar.sidebar.sidebar-open,
  #app-screen .nes-sidebar.sidebar-mobile.open,
  #app-screen .nes-sidebar.open {
    left: 0 !important;
  }

  #app-screen .main-content,
  #app-screen .farm-main,
  #app-screen .nes-main {
    padding: 16px;
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
  }

  #hamburger.sidebar-hamburger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
  }

  .mobile-menu-btn {
    display: none !important;
  }

  .form-grid,
  .services-grid,
  .agenda-grid,
  .nes-voucher-grid,
  .nes-srv-layout,
  .nes-voucher-layout,
  .nes-form-grid,
  .form-grid-2 {
    grid-template-columns: 1fr !important;
  }

  .nes-agenda-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .nes-agenda-tab {
    flex-shrink: 0;
  }
}

/* ─── Celular (até 640px) ─── */
@media (max-width: 640px) {
  #app-screen .farm-hero.painel-header.topbar,
  #app-screen .nes-topbar {
    height: auto;
    min-height: 56px;
    padding: 10px 12px;
    flex-wrap: wrap;
  }

  #app-screen .farm-hero-inner {
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }

  #app-screen .nes-topbar h1,
  #app-screen .topbar h1,
  .page-title {
    font-size: 18px;
  }

  #app-screen .nes-topbar-sub {
    font-size: 0.75rem;
  }

  #app-screen .main-content,
  #app-screen .farm-main,
  .page-content {
    padding: 12px;
  }

  .card,
  .panel,
  .form-card,
  .nes-srv-form-card,
  .nes-srv-list-card,
  .nes-voucher-form-card,
  .nes-voucher-agenda-card,
  .nes-clinico-panel {
    border-radius: 14px;
    padding: 14px;
  }

  .nes-page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    top: 0;
  }

  .nes-page-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    justify-content: stretch;
    width: 100%;
  }

  .nes-page-actions button,
  #app-screen .nes-page-actions .btn,
  #app-screen button.btn:not(.topbar-icon-btn):not(.nes-agenda-tab):not(.nes-voucher-cal-day),
  #app-screen .btn:not(.topbar-icon-btn):not(.nes-agenda-tab) {
    width: 100%;
    min-height: 44px;
    font-size: 15px;
  }

  #app-screen input:not([type="checkbox"]):not([type="radio"]),
  #app-screen select,
  #app-screen textarea,
  #app-screen .form-input {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .patient-summary,
  .patient-header,
  .patient-bar-inner,
  .voucher-summary,
  .nes-voucher-paciente-banner,
  #paciente-ativo-bar .patient-bar-inner {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .patient-bar-actions,
  .patient-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  .patient-bar-actions .btn,
  .patient-actions .btn {
    width: 100%;
    min-height: 44px;
  }

  .nes-voucher-footer,
  .nes-agenda-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .nes-voucher-footer .btn,
  .nes-agenda-footer .btn {
    width: 100%;
    min-height: 44px;
  }

  .mobile-action-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    position: sticky;
    bottom: 0;
    background: #f4f8f7;
    padding: 10px;
    margin: 16px -12px -12px;
    border-top: 1px solid #d7e5e1;
    z-index: 80;
  }

  .mobile-action-bar button {
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid #b9d1cb;
    background: #fff;
    color: #0f3f4f;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
  }

  .mobile-action-bar button.primary {
    background: #16846f;
    color: #fff;
    border-color: #16846f;
  }

  .page-content.has-mobile-actions {
    padding-bottom: 8px;
  }

  /* Menu inferior */
  .nes-mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    background: #fff;
    border-top: 1px solid #d7e5e1;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 20px rgba(15, 63, 79, 0.08);
  }

  .nes-mobile-bottom-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: transparent;
    color: #52706a;
    font-size: 0.65rem;
    font-weight: 700;
    min-height: 48px;
    padding: 4px;
    border-radius: 10px;
    cursor: pointer;
  }

  .nes-mobile-bottom-nav button .nes-mob-icon {
    font-size: 1.15rem;
    line-height: 1;
  }

  .nes-mobile-bottom-nav button.active,
  .nes-mobile-bottom-nav button:hover {
    background: #f0fdfa;
    color: #16846f;
  }

  #app-screen .farm-main,
  #app-screen .main-content {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  #app-screen .farm-main:has(.mobile-action-bar),
  #app-screen .page-content.has-mobile-actions {
    padding-bottom: calc(130px + env(safe-area-inset-bottom, 0px));
  }

  /* Modais */
  .modal-backdrop,
  .modal-overlay {
    padding: 8px !important;
    align-items: flex-end !important;
  }

  .modal-backdrop .modal,
  .modal-overlay .modal,
  .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 94vh !important;
    border-radius: 16px !important;
    margin: 0 !important;
  }

  .modal-header,
  .nes-clinico-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 2;
    background: inherit;
  }

  .modal-body,
  .nes-clinico-body {
    overflow-y: auto;
    max-height: calc(94vh - 140px);
    -webkit-overflow-scrolling: touch;
  }

  .modal-actions,
  .nes-modal-actions-bar,
  .modal-footer {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    position: sticky;
    bottom: 0;
    background: #f8fafc;
    padding: 10px;
    z-index: 2;
  }

  .modal-actions .btn,
  .modal-footer .btn {
    width: 100%;
    min-height: 44px;
  }

  /* Tabelas → cards */
  table.responsive-table,
  table.nes-table,
  table.nes-mic-diag-table,
  .farm-main table {
    display: block;
    width: 100%;
    border-collapse: collapse;
  }

  table.responsive-table thead,
  table.nes-table thead,
  table.nes-mic-diag-table thead,
  .farm-main table thead {
    display: none;
  }

  table.responsive-table tbody,
  table.nes-table tbody,
  table.nes-mic-diag-table tbody,
  .farm-main table tbody {
    display: block;
    width: 100%;
  }

  table.responsive-table tr,
  table.nes-table tr,
  table.nes-mic-diag-table tr,
  .farm-main table tr {
    display: block;
    width: 100%;
    background: #fff;
    border: 1px solid #dbe7e4;
    border-radius: 14px;
    padding: 12px;
    margin-bottom: 12px;
  }

  table.responsive-table td,
  table.nes-table td,
  table.nes-mic-diag-table td,
  .farm-main table td {
    display: block;
    width: 100%;
    border: none;
    padding: 6px 0;
    text-align: left;
  }

  table.responsive-table td::before,
  table.nes-table td::before,
  table.nes-mic-diag-table td::before,
  .farm-main table td::before {
    content: attr(data-label);
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: #52706a;
    margin-bottom: 2px;
  }

  table.responsive-table td:empty,
  table.nes-table td:empty {
    display: none;
  }

  .nes-srv-item,
  .nes-ag-item {
    flex-direction: column;
    align-items: stretch;
  }

  .nes-srv-item-actions,
  .nes-ag-item-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    width: 100%;
    margin-top: 8px;
  }

  .nes-voucher-cal-grid {
    gap: 3px;
  }

  .nes-voucher-cal-day {
    min-height: 36px;
    font-size: 0.75rem;
  }
}

/* Modais — desktop */
@media (min-width: 641px) {
  .modal-backdrop .modal:not(.hidden),
  .modal-overlay .modal:not(.hidden),
  .modal-content {
    max-width: 1100px;
    width: calc(100% - 32px);
  }

  .modal-body,
  .nes-clinico-body {
    overflow-y: auto;
    max-height: calc(90vh - 160px);
  }
}

/* ─── Notebook 1366px ─── */
@media (min-width: 1025px) and (max-width: 1440px) {
  .page-content {
    padding: 20px 24px;
  }
}

/* ─── Celular crítico (até 768px) — drawer + overlay ─── */
@media (max-width: 768px) {
  #app-screen .sidebar,
  #app-screen .farm-sidebar.sidebar,
  #app-screen .nes-sidebar,
  #app-screen .sidebar.sidebar-mobile,
  #app-screen .farm-sidebar.sidebar.sidebar-mobile {
    position: fixed !important;
    top: 0;
    left: -100% !important;
    width: 86vw !important;
    max-width: 360px !important;
    min-width: 0 !important;
    height: 100vh !important;
    z-index: 1001;
    transition: left 0.25s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #app-screen .sidebar.open,
  #app-screen .sidebar.sidebar-open,
  #app-screen .farm-sidebar.sidebar.open,
  #app-screen .nes-sidebar.open {
    left: 0 !important;
  }

  body.menu-open {
    overflow: hidden;
  }

  .mobile-overlay,
  .sidebar-mobile-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    display: none;
  }

  .mobile-overlay.open,
  .sidebar-mobile-backdrop.open,
  .sidebar-mobile-backdrop.visible {
    display: block;
  }

  .modal-actions button,
  .modal-footer button,
  .nes-modal-header-actions .nes-modal-nav-btn {
    opacity: 1 !important;
    visibility: visible !important;
    color: #07304f !important;
    background: #ffffff !important;
    border: 1px solid #cfe0ec !important;
  }

  .modal-actions .btn-primary,
  .modal-footer .btn-primary {
    color: #ffffff !important;
    background: #0f8f76 !important;
    border-color: #0f8f76 !important;
  }

  #paciente-ativo-bar:not(.nes-sem-paciente) [data-action]:not([data-nes-sem-paciente="1"]) {
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  #paciente-ativo-bar.nes-sem-paciente .patient-bar-inner {
    display: none !important;
  }

  #paciente-ativo-bar.nes-sem-paciente .nes-pb-empty-state {
    display: block !important;
    pointer-events: auto !important;
  }

  #paciente-ativo-bar.nes-sem-paciente #nes-pb-buscar-paciente {
    min-height: 44px;
    width: 100%;
    max-width: 280px;
    touch-action: manipulation;
  }

  .nes-pb-empty-state {
    padding: 1rem 1.25rem;
    text-align: center;
  }

  .nes-pb-empty-title {
    margin: 0 0 0.35rem;
    font-weight: 700;
    font-size: 1rem;
    color: var(--navy-800, #0f2f4a);
  }

  .nes-pb-empty-hint {
    margin: 0 0 0.85rem;
    font-size: 0.88rem;
    color: var(--navy-500, #5b6b7a);
  }

  .patient-search-dropdown {
    z-index: 10002 !important;
    max-height: 55vh !important;
    pointer-events: auto !important;
    touch-action: manipulation;
  }

  #app-screen .sidebar.open,
  #app-screen .sidebar.sidebar-open,
  #app-screen .farm-sidebar.sidebar.open {
    pointer-events: auto !important;
  }

  .patient-search-box,
  .patient-search-input-wrap,
  #buscaPaciente {
    pointer-events: auto !important;
    touch-action: manipulation;
  }

  .nes-module-card .nes-mod-btn-abrir,
  .nes-module-card .btn-primary,
  .metodo-nes-grid .btn {
    min-height: 44px;
    width: 100%;
    touch-action: manipulation;
    pointer-events: auto !important;
  }

  #modal-nes-sem-paciente-backdrop {
    z-index: 10050 !important;
  }

  #modal-nes-sem-paciente-backdrop .modal-footer {
    display: grid !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
}

/* ─── Mobile estrutural — header fixo + conteúdo abaixo ─── */
@media (max-width: 768px) {
  #app-screen .topbar,
  #app-screen .header,
  #app-screen .app-header,
  #app-screen .farm-hero.painel-header.topbar,
  #app-screen .nes-topbar {
    position: sticky;
    top: 0;
    z-index: 900;
    min-height: 72px;
    height: auto;
  }

  #app-screen .main-content,
  #app-screen .farm-main,
  #app-screen .dashboard-content,
  #app-screen .nes-main {
    padding-top: 84px !important;
    padding-bottom: 96px !important;
  }

  #app-screen .nes-mobile-bottom-nav {
    z-index: 900;
  }
}

/* ─── Desktop 1440px+ ─── */
@media (min-width: 1441px) {
  .page-content {
    max-width: 1280px;
    padding: 24px 32px;
  }

  #app-screen .main-content,
  #app-screen .farm-main {
    padding: 24px 28px;
  }
}
