/* ============================================================
   NexusMed v16 — Single CSS file, mobile-first, no overrides
   ============================================================ */

:root {
  --nm-primary: #10b981;
  --nm-primary-dark: #047857;
  --nm-primary-soft: #ecfdf5;
  --nm-primary-100: #d1fae5;
  --nm-accent: #34d399;

  --nm-navy: #0a0e1a;
  --nm-navy-2: #111a2e;

  --nm-text: #0f172a;
  --nm-text-soft: #475569;
  --nm-text-mute: #94a3b8;
  --nm-text-faint: #cbd5e1;

  --nm-border: #e5e9f0;
  --nm-border-soft: #f1f4f9;
  --nm-bg: #f7f9fc;
  --nm-surface: #ffffff;

  --nm-success: #10b981;
  --nm-success-dark: #047857;
  --nm-success-soft: #ecfdf5;
  --nm-warn: #f59e0b;
  --nm-warn-soft: #fffbeb;
  --nm-danger: #ef4444;
  --nm-danger-soft: #fef2f2;
  --nm-info: #3b82f6;
  --nm-info-soft: #eff6ff;

  --nm-r-sm: 8px;
  --nm-r-md: 10px;
  --nm-r-lg: 14px;
  --nm-r-xl: 18px;

  /* v17.9.40 — Sombras MUITO mais sutis (estilo iClinic/Feegow).
     Antes era visual carregado. Agora cards "respiram" — leveza. */
  --nm-shadow-1: 0 1px 2px rgba(15,23,42,.04);
  --nm-shadow-2: 0 1px 3px rgba(15,23,42,.04), 0 2px 8px rgba(15,23,42,.03);
  --nm-shadow-3: 0 2px 4px rgba(15,23,42,.04), 0 8px 20px rgba(15,23,42,.05);
  --nm-shadow-lg: 0 8px 24px rgba(15,23,42,.06), 0 16px 48px rgba(15,23,42,.06);

  --nm-ease: cubic-bezier(.16,1,.3,1);
  --nm-sb-w: 240px;
}

/* ============================================================ */
/* Reset + perf mobile (zero tap delay, sem highlight, sem blur cara) */
/* ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
  /* v17.9.39 — Anti-overflow horizontal global. Mobile NUNCA tem scroll lateral. */
  overflow-x: hidden;
  max-width: 100vw;
}
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--nm-text);
  background: var(--nm-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  /* v17.9.39 — Reforço anti-overflow */
  overflow-x: hidden;
  max-width: 100vw;
}
/* v17.9.39 — iOS Safari: auto-zoom em inputs <16px bagunça layout inteiro.
   Forçar font-size 16px nos inputs em mobile evita o auto-zoom. */
@media (max-width: 768px) {
  input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
  select, textarea {
    font-size: 16px !important;
  }
}
button, a, [role="button"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; cursor: pointer; }
a { color: inherit; }
img { max-width: 100%; display: block; }
input, select, textarea { font: inherit; color: inherit; touch-action: manipulation; }

/* ============================================================ */
/* App shell — base mobile, sidebar como drawer                  */
/* ============================================================ */
.nm-app {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}
.nm-sb {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 240px;
  max-width: 85vw;
  /* v17.9.40 — Sidebar LIGHT estilo iClinic/Feegow.
     Era navy escuro pesado. Agora branco-off com border sutil = mais médico, leve. */
  background: #ffffff;
  color: var(--nm-text);
  display: flex;
  flex-direction: column;
  transform: translate3d(-100%, 0, 0);
  transition: transform .18s ease-out;
  z-index: 90;
  border-right: 1px solid var(--nm-border);
  box-shadow: 0 0 30px rgba(15,23,42,.08);
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 0);
  padding-top: env(safe-area-inset-top, 0);
  will-change: transform;
}
body.nm-drawer-open .nm-sb { transform: translate3d(0, 0, 0); }
.nm-sb-overlay {
  position: fixed; inset: 0;
  background: rgba(10,14,26,.55);
  /* sem blur no mobile - mata performance do Safari iOS */
  z-index: 85;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s linear;
  will-change: opacity;
}
body.nm-drawer-open .nm-sb-overlay { opacity: 1; pointer-events: auto; }

.nm-sb-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px;
  border-bottom: 1px solid var(--nm-border-soft);
  flex-shrink: 0;
}
.nm-sb-mark {
  /* v17.9.40 — Logo MENOR + glow ainda mais sutil. Sidebar light pede sutileza. */
  width: 36px; height: 36px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: transparent;
  box-shadow: 0 4px 12px rgba(16,185,129,.18);
  overflow: hidden;
}
.nm-sb-mark img { width: 100%; height: 100%; object-fit: contain; }
.nm-sb-name { font-weight: 700; font-size: 15px; letter-spacing: -.3px; line-height: 1; color: var(--nm-text); }
.nm-sb-name em { font-style: normal; color: var(--nm-primary); }
.nm-sb-tag { font-size: 11px; color: var(--nm-text-mute); margin-top: 3px; }

.nm-sb-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}
.nm-sb-section {
  /* v17.9.40 — sidebar light: section title em cinza-médio */
  font-size: 10.5px;
  font-weight: 700;
  color: var(--nm-text-mute);
  letter-spacing: .8px;
  text-transform: uppercase;
  padding: 16px 14px 6px;
}
.nm-nav {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  background: transparent;
  border: none;
  /* v17.9.40 — sidebar light: texto cinza-escuro, hover bg cinza-claro */
  color: var(--nm-text-soft);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  margin-bottom: 1px;
  transition: background .15s var(--nm-ease), color .15s var(--nm-ease);
  min-height: 40px;
}
.nm-nav:hover {
  background: var(--nm-primary-soft);
  color: var(--nm-primary-dark);
}
.nm-nav.on {
  /* v17.9.40 — Item ativo: bg verde sutil + texto verde-escuro + barra lateral.
     Mais elegante que o gradiente cheio anterior. */
  background: var(--nm-primary-soft);
  color: var(--nm-primary-dark);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--nm-primary);
}
.nm-nav-ico { width: 18px; font-size: 16px; flex-shrink: 0; }
.nm-nav-txt { flex: 1; min-width: 0; }

.nm-sb-bot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--nm-border-soft);
  flex-shrink: 0;
}
.nm-sb-av {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  overflow: hidden;
}
.nm-sb-av img { width: 100%; height: 100%; object-fit: cover; }
.nm-sb-info { flex: 1; min-width: 0; }
.nm-sb-info b { display: block; font-size: 13px; font-weight: 600; color: var(--nm-text); line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nm-sb-info span { display: block; font-size: 11px; color: var(--nm-text-mute); margin-top: 2px; }
.nm-sb-logout {
  background: transparent;
  border: 1px solid var(--nm-border);
  color: var(--nm-text-mute);
  width: 34px; height: 34px;
  border-radius: 8px;
  font-size: 15px;
  flex-shrink: 0;
}
.nm-sb-logout:hover { background: var(--nm-danger-soft); color: var(--nm-danger); border-color: var(--nm-danger); }

/* ============================================================ */
/* Topbar                                                       */
/* ============================================================ */
.nm-topbar {
  /* v17.6.2 — adiciona safe-area-inset-top pra status bar do iOS */
  height: calc(60px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--nm-surface);
  border-bottom: 1px solid var(--nm-border);
  display: flex;
  align-items: center;
  padding-left: 110px;
  padding-right: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-shrink: 0;
}
.nm-topbar-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.3px;
  color: var(--nm-text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nm-topbar-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.nm-hamburger {
  position: fixed;
  /* v17.6.2 — respeita Dynamic Island / notch do iOS, fica acima de qualquer overlay */
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--nm-navy);
  color: #fff;
  border: none;
  font-size: 22px;
  /* z-index acima de banner Instalar (9700) e bottom nav (9600) */
  z-index: 9800;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.30);
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
  touch-action: manipulation;
}
.nm-hamburger:active { transform: scale(.96); }

/* v17.6.2 — Botão Voltar (visível só fora do dashboard) */
.nm-back {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: calc(64px + env(safe-area-inset-left, 0px));
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--nm-surface);
  color: var(--nm-text);
  border: 1px solid var(--nm-border);
  font-size: 20px;
  font-weight: 700;
  z-index: 9800;
  display: none;
  align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.10);
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
  touch-action: manipulation;
}
.nm-back:active { transform: scale(.96); }
@media (min-width: 900px) { .nm-back { left: calc(var(--nm-sb-w) + 16px); } }

/* ============================================================ */
/* Main content                                                 */
/* ============================================================ */
.nm-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  /* v17.4.8 — Defesa final contra overflow horizontal: nada vaza pra fora do main */
  overflow-x: hidden;
  max-width: 100%;
}
.nm-content {
  padding: 16px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0));
  flex: 1;
  /* v17.4.8 — também aqui: o conteúdo respeita o viewport */
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.nm-content > * { max-width: 100%; box-sizing: border-box; }

/* ============================================================ */
/* Buttons                                                      */
/* ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13.5px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: background-color .12s linear, border-color .12s linear, transform .08s ease;
  font-family: inherit;
  white-space: nowrap;
  text-decoration: none;
  letter-spacing: -.05px;
  min-height: 42px;
  background: var(--nm-surface);
  color: var(--nm-text);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(16,185,129,.25);
}
.btn-ghost {
  background: var(--nm-surface);
  border-color: var(--nm-border);
  color: var(--nm-text);
  box-shadow: var(--nm-shadow-1);
}
.btn-danger {
  background: var(--nm-danger-soft);
  color: var(--nm-danger);
  border-color: rgba(239,68,68,.20);
}
/* v17.4.6 — botão de arquivar (descreto, ação destrutiva mas reversível) */
.btn-danger-ghost {
  background: transparent;
  color: var(--nm-danger);
  border-color: rgba(239,68,68,.25);
}
/* hover só em desktop (mobile não tem hover real e dispara como tap) */
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { box-shadow: 0 6px 20px rgba(16,185,129,.35); transform: translateY(-1px); }
  .btn-ghost:hover { border-color: var(--nm-primary); color: var(--nm-primary-dark); background: var(--nm-primary-soft); }
  .btn-danger:hover { background: var(--nm-danger); color: #fff; }
  .btn-danger-ghost:hover { background: var(--nm-danger-soft); border-color: var(--nm-danger); }
}
.btn-sm { padding: 7px 12px; font-size: 12.5px; min-height: 34px; }
.btn-lg { padding: 14px 22px; font-size: 14.5px; min-height: 50px; }
.btn-block { width: 100%; }
.btn-icon { padding: 9px 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ============================================================ */
/* Cards                                                        */
/* ============================================================ */
.card {
  background: var(--nm-surface);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-r-lg);
  padding: 18px;
  box-shadow: var(--nm-shadow-2);
  margin-bottom: 14px;
}
.card-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 10px;
}
.card-t {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -.2px;
  color: var(--nm-text);
}
.card-link {
  font-size: 12.5px;
  color: var(--nm-primary-dark);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.card-link:hover { text-decoration: underline; }

/* ============================================================ */
/* Forms                                                        */
/* ============================================================ */
.field { margin-bottom: 14px; }
.field label,
.field > .lbl {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--nm-text-soft);
  margin-bottom: 6px;
  letter-spacing: .05px;
}
.input, .select, .textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--nm-border);
  border-radius: 10px;
  background: var(--nm-surface);
  color: var(--nm-text);
  font-size: 16px; /* iOS no zoom */
  font-family: inherit;
  transition: all .15s var(--nm-ease);
  min-height: 46px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--nm-primary);
  box-shadow: 0 0 0 4px rgba(16,185,129,.12);
}
.textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
.field-row { display: grid; grid-template-columns: 1fr; gap: 12px; }

/* ============================================================ */
/* Badges & pills                                               */
/* ============================================================ */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .15px;
}
.badge-green { background: var(--nm-success-soft); color: var(--nm-success-dark); border: 1px solid rgba(16,185,129,.18); }
.badge-blue { background: var(--nm-info-soft); color: #1d4ed8; border: 1px solid rgba(59,130,246,.18); }
.badge-yellow { background: var(--nm-warn-soft); color: #92400e; border: 1px solid rgba(245,158,11,.18); }
.badge-red { background: var(--nm-danger-soft); color: #991b1b; border: 1px solid rgba(239,68,68,.18); }
.badge-violet { background: #f5f3ff; color: #6d28d9; border: 1px solid rgba(139,92,246,.18); }

/* ============================================================ */
/* Modal — base mobile = bottom sheet                           */
/* ============================================================ */
.nm-md-host { /* unused holder for keyframes */ }
.nm-mdbk {
  position: fixed; inset: 0;
  background: rgba(10,14,26,.55);
  /* Sem backdrop-filter no mobile — caro demais. Reabilita só desktop abaixo. */
  z-index: 9990;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: nm-fade-in .12s linear;
  will-change: opacity;
}
@keyframes nm-fade-in { from { opacity: 0; } to { opacity: 1; } }
.nm-md {
  background: var(--nm-surface);
  width: 100%;
  max-width: 100%;
  /* v17.10.5 — dvh respeita address bar do Safari iOS (vh estourava no mobile,
     fazendo o footer com "Fechar" sair do viewport). 92dvh = sempre cabe. */
  max-height: 92dvh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--nm-shadow-lg);
  animation: nm-slide-up .14s ease-out;
  overflow: hidden;
  transform: translateZ(0); /* GPU layer */
}
/* v17.9.8 — Modal Memed mobile: 100% tela (não tem espaço sobrando).
   Desktop ajusta abaixo na media query (95vw × 95vh = janela GRANDE proporcional).
   Sem flex/overflow complicado — tudo simples pra iframe pegar clique. */
.nm-md.nm-md-xl {
  height: 100dvh;
  max-height: 100dvh;
  width: 100vw;
  max-width: 100vw;
  border-radius: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}
.nm-md.nm-md-xl .nm-md-b {
  padding: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.nm-md.nm-md-xl #memed-prescricao {
  position: absolute;
  inset: 0;
  pointer-events: auto;
}
.nm-md.nm-md-xl #memed-prescricao iframe {
  display: block;
  width: 100% !important;
  height: 100% !important;
  border: 0;
  pointer-events: auto;
  position: absolute;
  inset: 0;
}
/* v17.9.10 — Quando iframe entra no DOM, escondemos o spinner. */
.nm-md.nm-md-xl #memed-prescricao:has(iframe) #nm-memed-loader { display: none; }
@keyframes nm-slide-up { from { transform: translateY(20px); } to { transform: translateY(0); } }
.nm-md-h {
  padding: 16px 18px;
  border-bottom: 1px solid var(--nm-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--nm-surface);
  /* v17.8.5 — header sempre ACIMA de iframes (Memed, Jitsi).
     Bug crítico antigo: iframe cobria o X e modal não fechava. */
  position: relative;
  z-index: 10;
}
.nm-md-x {
  position: relative;
  z-index: 11;
}
.nm-md-t {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.2px;
  color: var(--nm-text);
}
.nm-md-x {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--nm-bg);
  border: none;
  color: var(--nm-text-soft);
  font-size: 22px;
  line-height: 1;
}
.nm-md-x:hover { background: var(--nm-border); color: var(--nm-text); }
.nm-md-b {
  padding: 18px;
  overflow-y: auto;
  /* v17.4.8 — mata overflow horizontal: nada vaza pra fora do modal no mobile */
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  background: var(--nm-bg);
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.nm-md-b > * { max-width: 100%; min-width: 0; }
.nm-md-b .field, .nm-md-b .field-row, .nm-md-b .input, .nm-md-b .select, .nm-md-b textarea { max-width: 100%; box-sizing: border-box; }
/* v17.10.23 — Footer com CSS GRID (não flex). Grid 1-coluna nunca tem
   o bug clássico de flex-wrap + column-reverse fazendo botão escapar.
   Cada botão ocupa 100% da célula automaticamente, sem precisar de width. */
.nm-md-f {
  padding: 12px 14px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--nm-border);
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: auto;
  gap: 8px;
  background: var(--nm-surface);
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  /* Ordem natural: primary primeiro no DOM = aparece em cima.
     Cancelar/ghost no fim do DOM = embaixo. JS já segue essa ordem. */
}
.nm-md-f .btn {
  width: auto !important; /* grid resolve width — sem fight com regras antigas */
  min-width: 0;
  box-sizing: border-box;
  margin: 0;
  white-space: normal;
  text-align: center;
  min-height: 46px;
  line-height: 1.3;
}

/* v17.10.5 — Anti-sobreposição global: qualquer grupo de botões adjacentes ganha gap
   mínimo, e botões dentro de card-h, page-h, vfs-header se distribuem com flex-wrap. */
.btn + .btn { margin-left: 0; }
.card-h, .video-fs-h, .page-h, .pv-shell .pv-card h3 + div {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card-h > *, .video-fs-h > * { min-width: 0; }
/* Botões em sequência horizontal — força gap mesmo sem container flex */
.btn-row, .btns-row, .actions-row {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}
/* No mobile, botões adjacentes nunca grudam */
@media (max-width: 768px) {
  .btn + .btn { margin-top: 0; }
  .card-h, .video-fs-h { gap: 8px; }
}

/* ============================================================ */
/* Toast                                                        */
/* ============================================================ */
#nm-toast {
  position: fixed;
  left: 14px; right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0));
  background: var(--nm-navy);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 99999;
  box-shadow: var(--nm-shadow-lg);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
#nm-toast.on { opacity: 1; transform: translateY(0); }
#nm-toast.ok { background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark)); }
#nm-toast.err { background: linear-gradient(135deg, var(--nm-danger), #b91c1c); }

/* ============================================================ */
/* Loaders & empty states                                       */
/* ============================================================ */
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--nm-primary-100);
  border-top-color: var(--nm-primary);
  border-radius: 50%;
  animation: nm-spin .9s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes nm-spin { to { transform: rotate(360deg); } }
@keyframes nm-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.6; transform: scale(1.4); } }

/* ============================================================ */
/* Voice editor (contenteditable com cores duais)                */
/* ============================================================ */
.nm-ed {
  width: 100%;
  min-height: 320px;
  padding: 14px 16px;
  border: 1.5px solid var(--nm-border);
  border-radius: 10px;
  font-size: 15px;
  line-height: 1.65;
  font-family: inherit;
  background: var(--nm-surface);
  color: var(--nm-text);
  outline: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
  max-height: 60vh;
}
.nm-ed:empty::before {
  content: attr(data-placeholder);
  color: var(--nm-text-mute);
  pointer-events: none;
}
.nm-ed:focus { border-color: var(--nm-primary); box-shadow: 0 0 0 4px rgba(16,185,129,.10); }
.nm-ed .spk-voice,
.spk-voice {
  color: #2563eb;
  background: rgba(37,99,235,.06);
  border-radius: 3px;
  padding: 0 2px;
}
.nm-ed .spk-ai,
.spk-ai {
  color: #6d28d9;
  background: rgba(139,92,246,.06);
}
.nm-ed h1, .nm-ed h2, .nm-ed h3 { font-size: 15px; font-weight: 700; margin: 14px 0 6px; color: var(--nm-text); }
.nm-ed-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 11.5px;
  color: var(--nm-text-mute);
  margin: 6px 0 8px;
}
.nm-ed-legend .lg-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.nm-ed-legend .lg-typed .lg-dot { background: var(--nm-text); }
.nm-ed-legend .lg-voice .lg-dot { background: #2563eb; }
.nm-ed-legend .lg-ai .lg-dot { background: #6d28d9; }
.loading { padding: 60px 20px; text-align: center; color: var(--nm-text-mute); }
.empty {
  padding: 40px 24px;
  text-align: center;
  background: var(--nm-bg);
  border: 1px dashed var(--nm-border);
  border-radius: var(--nm-r-lg);
  color: var(--nm-text-soft);
}
.empty-ic { font-size: 40px; opacity: .55; margin-bottom: 10px; }
.empty p { font-size: 14.5px; font-weight: 600; color: var(--nm-text-soft); margin: 0 0 4px; }
.empty small { font-size: 12.5px; color: var(--nm-text-mute); }

/* ============================================================ */
/* Stats grid                                                   */
/* ============================================================ */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--nm-surface);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-r-lg);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--nm-shadow-1);
}
.stat-ic {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--nm-primary-soft);
  color: var(--nm-primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.stat-info { min-width: 0; flex: 1; }
.stat-l { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--nm-text-mute); margin-bottom: 2px; }
.stat-v { font-size: 22px; font-weight: 800; color: var(--nm-text); letter-spacing: -.5px; line-height: 1.1; }

/* v17.4.4 — cards clicáveis com afeição visual de botão */
.stat-clickable {
  cursor: pointer;
  transition: transform .12s var(--nm-ease), box-shadow .12s var(--nm-ease), border-color .12s var(--nm-ease);
  position: relative;
}
.stat-clickable:hover {
  transform: translateY(-1px);
  box-shadow: var(--nm-shadow-2);
  border-color: var(--nm-primary);
}
.stat-clickable:active { transform: translateY(0); }
.stat-clickable::after {
  content: '→';
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--nm-text-mute);
  opacity: 0;
  transition: opacity .12s var(--nm-ease), transform .12s var(--nm-ease);
}
.stat-clickable:hover::after { opacity: 1; transform: translateY(-50%) translateX(2px); color: var(--nm-primary); }
.stat-clickable:focus-visible { outline: 2px solid var(--nm-primary); outline-offset: 2px; }

/* Relógio no hero */
.hero-clock { font-variant-numeric: tabular-nums; font-weight: 600; opacity: .9; }

/* ============================================================ */
/* Hero (dashboard greeting)                                    */
/* ============================================================ */
.hero {
  background: linear-gradient(135deg, var(--nm-navy) 0%, var(--nm-navy-2) 100%);
  color: #fff;
  border-radius: var(--nm-r-lg);
  padding: 20px;
  /* v17.8.0 — respeita notch no iOS standalone */
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(at 100% 0%, rgba(16,185,129,.20) 0px, transparent 60%);
  pointer-events: none;
}
.hero-eyebrow { font-size: 12.5px; opacity: .75; text-transform: capitalize; font-weight: 500; margin-bottom: 6px; position: relative; }
.hero-title { font-size: 22px; font-weight: 800; letter-spacing: -.6px; margin: 0 0 6px; line-height: 1.15; position: relative; }
.hero-title em { font-style: normal; background: linear-gradient(135deg, #5eead4, #34d399); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.hero-sub { font-size: 13px; opacity: .80; margin: 0; position: relative; }

/* ============================================================ */
/* Patient header                                               */
/* ============================================================ */
.pt-head {
  background: linear-gradient(135deg, var(--nm-navy) 0%, var(--nm-navy-2) 100%);
  color: #fff;
  border-radius: var(--nm-r-lg);
  /* v17.9.24 — Padding-left maior pra reservar espaço pra seta de voltar
     (evita sobreposição com avatar). Padding-top também aumentado. */
  padding: 22px 18px 18px 64px;
  margin-bottom: 16px;
  border: 1px solid rgba(255,255,255,.06);
  position: relative;
  overflow: visible;
}
@media (min-width: 900px) {
  /* Desktop: a seta fica fora do conteúdo (sidebar a engloba), volta padding normal */
  .pt-head { padding: 22px 24px; }
}
.pt-head::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--nm-primary), var(--nm-accent));
  border-radius: var(--nm-r-lg) 0 0 var(--nm-r-lg);
}
.pt-head-row {
  display: flex;
  align-items: center;
  /* v17.9.24 — Gap maior entre avatar e info, margin-bottom maior antes dos botões */
  gap: 16px;
  margin-bottom: 16px;
  position: relative;
  flex-wrap: nowrap;
  min-width: 0;
}
.pt-av {
  width: 50px; height: 50px;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark));
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(16,185,129,.30);
}
.pt-info { min-width: 0; flex: 1; }
.pt-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.4px;
  color: #fff;
  word-break: break-word;
  line-height: 1.2;
}
.pt-meta {
  font-size: 13px;
  color: rgba(255,255,255,.88);
  margin-top: 6px;
  word-break: break-word;
  /* v17.9.24 — line-height maior pra dois separadores (· · ·) não grudarem visualmente */
  line-height: 1.55;
}
.pt-meta b { color: #fff; font-weight: 600; }
.pt-actions {
  display: flex;
  /* v17.9.24 — Gap maior pra botões respirarem; nunca um colado no outro */
  gap: 8px;
  flex-wrap: wrap;
  position: relative;
}
.pt-actions .btn {
  /* v17.9.24 — flex-basis ajusta-se ao conteúdo; gap garante separação */
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
  padding: 11px 10px;
  font-size: 12.5px;
  background: rgba(255,255,255,.10);
  color: #fff;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: none;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.pt-actions .btn:hover {
  background: rgba(255,255,255,.18);
  border-color: rgba(255,255,255,.24);
  color: #fff;
}
.pt-actions .btn-prescribe {
  flex: 1 1 100%;
  background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark));
  border-color: transparent;
  font-weight: 700;
  font-size: 13.5px;
  padding: 13px;
}

/* ============================================================ */
/* Quick action buttons (dashboard)                             */
/* ============================================================ */
.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.quick-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: var(--nm-bg);
  border: 1.5px solid var(--nm-border);
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--nm-text);
  text-align: left;
  font-family: inherit;
  transition: all .15s var(--nm-ease);
  min-height: 56px;
}
.quick-btn:hover {
  border-color: var(--nm-primary);
  background: var(--nm-primary-soft);
  color: var(--nm-primary-dark);
}
.quick-btn .ic {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--nm-surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: var(--nm-shadow-1);
}
.quick-btn-atman {
  background: linear-gradient(135deg, #6d28d9, #4c1d95);
  color: #fff;
  border-color: transparent;
}
.quick-btn-atman:hover { background: linear-gradient(135deg, #7c3aed, #5b21b6); color: #fff; border-color: transparent; }
.quick-btn-atman .ic { background: rgba(255,255,255,.20); color: #fff; box-shadow: none; }

/* ============================================================ */
/* Appointment row                                              */
/* ============================================================ */
.appt-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--nm-bg);
  border: 1px solid var(--nm-border-soft);
  border-radius: 12px;
  margin-bottom: 8px;
  transition: all .12s ease;
}
.appt-row:hover { background: var(--nm-primary-soft); border-color: var(--nm-primary); }
.appt-time {
  font-size: 14px;
  font-weight: 700;
  color: var(--nm-primary-dark);
  font-variant-numeric: tabular-nums;
  width: 50px;
  flex-shrink: 0;
}
.appt-info { flex: 1; min-width: 0; }
.appt-name { font-size: 13.5px; font-weight: 600; color: var(--nm-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appt-meta { font-size: 11.5px; color: var(--nm-text-mute); margin-top: 2px; }

/* v17.5.2 — Banner de status do cadastro de prescritor (Meu Perfil)
   + asterisco de campo obrigatório + visual de input com erro. */
.prof-status {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--nm-border);
  max-width: 100%;
  box-sizing: border-box;
}
.prof-status .ic {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 16px;
}
.prof-status b { display: block; font-size: 14px; font-weight: 700; margin-bottom: 2px; }
.prof-status small { display: block; font-size: 12.5px; line-height: 1.5; }
.prof-status-warn {
  background: var(--nm-warn-soft);
  border-color: rgba(245,158,11,.30);
}
.prof-status-warn .ic { background: #f59e0b; color: #fff; }
.prof-status-warn b { color: #92400e; }
.prof-status-warn small { color: #78350f; }
.prof-status-ok {
  background: var(--nm-primary-soft);
  border-color: rgba(16,185,129,.30);
}
.prof-status-ok .ic { background: var(--nm-primary); color: #fff; }
.prof-status-ok b { color: var(--nm-primary-dark); }
.prof-status-ok small { color: #065f46; }

.req {
  color: var(--nm-danger);
  font-weight: 700;
  margin-left: 2px;
}
.input.input-err {
  border-color: var(--nm-danger) !important;
  box-shadow: 0 0 0 3px rgba(239,68,68,.12) !important;
  background: #fff7f7 !important;
}

/* v17.8.0 — Bottom nav REMOVIDO. Forçamos display:none caso versão antiga
   tenha cacheado HTML. Hambúrguer na topbar abre a sidebar inteira. */
.nm-bottom-nav { display: none !important; }

/* v17.8.1 — Badge de lembretes WhatsApp na topbar */
.nm-wpp-bell {
  display: inline-flex; align-items: center; gap: 4px;
  background: linear-gradient(135deg, #25D366, #128C7E);
  color: #fff; border: none; padding: 6px 12px;
  border-radius: 999px; cursor: pointer;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 2px 6px rgba(37,211,102,.25);
  transition: transform .12s ease;
}
.nm-wpp-bell:hover { transform: scale(1.04); }
.nm-wpp-bell .nm-wpp-count {
  background: #fff; color: #128C7E;
  border-radius: 999px; padding: 1px 7px;
  font-size: 11.5px; font-weight: 800;
  min-width: 18px; text-align: center;
}

/* Conteúdo respira pra rodapé sem barra fixa */
@media (max-width: 899px) {
  .nm-content { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
}

/* Modo PWA standalone respeita safe-area do topo (notch) */
body.nm-standalone .nm-sb,
body.nm-standalone .nm-tb { padding-top: env(safe-area-inset-top, 0px); }
.nm-tb { padding-top: env(safe-area-inset-top, 0px); }

/* v17.6.0 — Banner "Instalar app" (PWA) — fica fixado na parte de baixo da tela */
.nm-install-banner {
  position: fixed;
  left: 12px; right: 12px;
  /* v17.8.0 — sem bottom nav, fica acima do safe-area do iPhone */
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 9700;
  background: var(--nm-surface);
  border: 1px solid var(--nm-primary);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,.18);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
  max-width: 560px; margin: 0 auto;
  animation: nm-fade-in .25s var(--nm-ease);
}
.nib-ic {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--nm-primary-soft);
  color: var(--nm-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.nib-body { flex: 1; min-width: 0; }
.nib-title { font-size: 14px; font-weight: 700; color: var(--nm-text); line-height: 1.2; }
.nib-desc  { font-size: 12.5px; color: var(--nm-text-soft); line-height: 1.5; margin-top: 4px; word-break: break-word; }
.nib-acts  { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
@media (max-width: 480px) {
  .nm-install-banner { flex-direction: column; align-items: flex-start; }
  .nib-acts { width: 100%; justify-content: flex-end; }
}

/* Botão flutuante "Ativar alertas" — acima do bottom nav */
.nm-notif-toggle {
  position: fixed;
  right: 16px;
  bottom: calc(140px + env(safe-area-inset-bottom, 0px));
  z-index: 9650;
  background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark));
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(16,185,129,.40);
  display: flex; align-items: center; gap: 6px;
}
.nm-notif-toggle:hover { transform: translateY(-1px); box-shadow: 0 12px 30px rgba(16,185,129,.50); }
@media (min-width: 900px) {
  .nm-notif-toggle { bottom: 24px; }
}

/* v17.5.4 — Painel "Status Memed" (Ferramentas → Status Memed) */
.ms-section { margin-bottom: 20px; }
.ms-section h3 { font-size: 15px; font-weight: 700; margin: 0 0 6px; color: var(--nm-text); }
.ms-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ms-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid var(--nm-border);
  background: var(--nm-surface);
}
.ms-chip .ms-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 11px;
  flex-shrink: 0;
}
.ms-chip.ms-ok { background: var(--nm-primary-soft); border-color: rgba(16,185,129,.30); color: var(--nm-primary-dark); }
.ms-chip.ms-ok .ms-dot { background: var(--nm-primary); color: #fff; }
.ms-chip.ms-bad { background: var(--nm-danger-soft); border-color: rgba(239,68,68,.30); color: var(--nm-danger); }
.ms-chip.ms-bad .ms-dot { background: var(--nm-danger); color: #fff; }
.ms-chip.ms-info { background: var(--nm-bg); }
.ms-chip.ms-info .ms-dot { background: var(--nm-text-mute); color: #fff; }

.ms-banner { margin-top: 10px; padding: 10px 14px; border-radius: 10px; font-size: 13px; font-weight: 600; }
.ms-banner.ms-ok { background: var(--nm-primary-soft); color: var(--nm-primary-dark); border: 1px solid rgba(16,185,129,.30); }
.ms-banner.ms-bad { background: var(--nm-danger-soft); color: var(--nm-danger); border: 1px solid rgba(239,68,68,.30); }
.ms-banner a { color: inherit; text-decoration: underline; font-weight: 700; }

.ms-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.ms-stat {
  flex: 1;
  min-width: 90px;
  padding: 12px 14px;
  background: var(--nm-bg);
  border: 1px solid var(--nm-border);
  border-radius: 10px;
  text-align: center;
}
.ms-stat b { display: block; font-size: 22px; font-weight: 800; color: var(--nm-text); letter-spacing: -.5px; }
.ms-stat span { display: block; font-size: 11.5px; color: var(--nm-text-mute); margin-top: 2px; text-transform: uppercase; letter-spacing: .3px; }
.ms-stat.ms-stat-ok b { color: var(--nm-primary-dark); }
.ms-stat.ms-stat-mute b { color: var(--nm-text-mute); }

.rx-row.rx-deleted { opacity: .65; background: var(--nm-bg); }
.rx-row.rx-deleted .rx-pt { text-decoration: line-through; }

/* v17.4.9 — Arquivo de Prescrições Memed (modal com lista) */
.rx-list { display: flex; flex-direction: column; gap: 10px; }
.rx-row {
  background: var(--nm-surface);
  border: 1px solid var(--nm-border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 100%;
  min-width: 0;
}
.rx-row-head { display: flex; align-items: center; gap: 12px; cursor: pointer; min-width: 0; }
.rx-row-head:hover .rx-pt { color: var(--nm-primary-dark); }
.rx-icon {
  width: 38px; height: 38px;
  background: var(--nm-primary-soft);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.rx-info { flex: 1; min-width: 0; }
.rx-pt { font-size: 14px; font-weight: 700; color: var(--nm-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rx-when { font-size: 12px; color: var(--nm-text-mute); margin-top: 2px; }
.rx-summary {
  font-size: 12.5px;
  color: var(--nm-text-soft);
  background: var(--nm-bg);
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.5;
  border: 1px dashed var(--nm-border-soft);
  max-width: 100%;
  word-break: break-word;
}
.rx-row .btn { align-self: flex-start; }

/* v17.4.8 — Toolbar do editor de prontuário (mobile: empilha; desktop: lado a lado).
   Sem overflow horizontal: cada botão wrap em nova linha quando não cabe. */
.rd-tools-label {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  max-width: 100%;
}
.rd-tools-title { font-size: 13px; font-weight: 600; color: var(--nm-text-soft); }
.rd-tools-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
  align-items: center;
}
.rd-tools-actions .btn {
  flex: 1 1 calc(50% - 3px);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (min-width: 600px) {
  .rd-tools-label { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
  .rd-tools-actions { width: auto; flex: 0 1 auto; }
  .rd-tools-actions .btn { flex: 0 0 auto; }
}

/* v17.4.7 — Linha de consulta agora usa coluna: cabeçalho + ações inline.
   Sem botão "⋯" escondido. Médico vê e clica direto. */
.appt-row { flex-direction: column; align-items: stretch; gap: 10px; }
.appt-row-head { display: flex; align-items: center; gap: 12px; cursor: pointer; min-width: 0; }
.appt-row-head:hover .appt-name { color: var(--nm-primary-dark); }
.appt-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px dashed var(--nm-border-soft);
}
.appt-act {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--nm-surface);
  border: 1px solid var(--nm-border);
  border-radius: 8px;
  color: var(--nm-text-soft);
  cursor: pointer;
  font-family: inherit;
  transition: all .12s var(--nm-ease);
  min-height: 34px;
}
.appt-act .ic { font-size: 14px; line-height: 1; }
.appt-act .lb { line-height: 1; }
.appt-act:hover { transform: translateY(-1px); box-shadow: var(--nm-shadow-1); }
.appt-act.open { color: var(--nm-primary-dark); border-color: var(--nm-primary); background: var(--nm-primary-soft); }
.appt-act.open:hover { background: var(--nm-primary); color: #fff; }
.appt-act.resched { color: #6d28d9; border-color: #c4b5fd; background: #f5f3ff; }
.appt-act.resched:hover { background: #6d28d9; color: #fff; border-color: #6d28d9; }
.appt-act.free { color: #92400e; border-color: #fcd34d; background: var(--nm-warn-soft); }
.appt-act.free:hover { background: #f59e0b; color: #fff; border-color: #f59e0b; }
.appt-act.cancel { color: var(--nm-danger); border-color: rgba(239,68,68,.30); background: var(--nm-danger-soft); }
.appt-act.cancel:hover { background: var(--nm-danger); color: #fff; border-color: var(--nm-danger); }
.appt-act:focus-visible { outline: 2px solid var(--nm-primary); outline-offset: 2px; }

/* No mobile: ações em linha cheia, mais compactas */
@media (max-width: 480px) {
  .appt-act { flex: 1 1 calc(50% - 3px); justify-content: center; padding: 9px 6px; font-size: 12px; }
  .appt-act .ic { font-size: 13px; }
}

/* Badge "Arquivado" em Pacientes Cadastrados */
.dir-row-archived { opacity: .65; }
.dir-row-archived .dir-name::after {
  content: 'Arquivado';
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  font-size: 10.5px;
  font-weight: 700;
  border-radius: 6px;
  background: #e2e8f0;
  color: #475569;
  letter-spacing: .3px;
  text-transform: uppercase;
  vertical-align: middle;
}

/* ============================================================ */
/* Patient list cards                                           */
/* ============================================================ */
.search-bar {
  position: relative;
  margin-bottom: 12px;
}
.search-bar input {
  width: 100%;
  height: 46px;
  padding: 0 16px 0 44px;
  border-radius: 12px;
  border: 1.5px solid var(--nm-border);
  background: var(--nm-surface);
  font-size: 16px;
  box-shadow: var(--nm-shadow-1);
}
.search-bar input:focus { outline: none; border-color: var(--nm-primary); box-shadow: 0 0 0 4px rgba(16,185,129,.12); }
.search-bar::before {
  content: '🔍';
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  opacity: .6;
}
.patient-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.patient-card {
  background: var(--nm-surface);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-r-lg);
  padding: 14px;
  cursor: pointer;
  transition: all .15s var(--nm-ease);
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--nm-shadow-1);
}
.patient-card:hover {
  border-color: var(--nm-primary);
  transform: translateY(-1px);
  box-shadow: var(--nm-shadow-2);
}
.patient-card-av {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14.5px;
  flex-shrink: 0;
}
.patient-card-info { min-width: 0; flex: 1; }
.patient-card-name { font-size: 14.5px; font-weight: 700; color: var(--nm-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.patient-card-meta { font-size: 12px; color: var(--nm-text-mute); margin-top: 2px; }

/* ============================================================ */
/* Tables                                                       */
/* ============================================================ */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; border: 1px solid var(--nm-border); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--nm-surface); }
.tbl th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--nm-text-mute);
  background: var(--nm-bg);
  border-bottom: 1px solid var(--nm-border);
  white-space: nowrap;
}
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--nm-border-soft); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--nm-bg); }

/* ============================================================ */
/* Doc list                                                     */
/* ============================================================ */
.doc {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: var(--nm-surface);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-r-md);
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.doc-thumb, .doc-ic {
  width: 46px; height: 46px;
  border-radius: 10px;
  flex-shrink: 0;
}
.doc-thumb { object-fit: cover; }
.doc-ic {
  background: var(--nm-primary-soft);
  color: var(--nm-primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 11.5px;
}
.doc-info { flex: 1 1 calc(100% - 60px); min-width: 0; }
.doc-n { font-size: 13.5px; font-weight: 600; color: var(--nm-text); word-break: break-word; }
.doc-m { font-size: 11.5px; color: var(--nm-text-mute); margin-top: 3px; }
.doc-acts { width: 100%; display: flex; gap: 6px; flex-wrap: wrap; }
.doc-acts > * { flex: 1 1 calc(33% - 6px); padding: 8px; font-size: 11.5px; min-height: 36px; text-align: center; justify-content: center; }

/* ============================================================ */
/* Tabs (patient detail, settings)                              */
/* v17.9.20 — Tabs MUITO mais visíveis. Médico passa rápido pelo */
/* paciente, precisa identificar Resumo/Prontuários/Histórico   */
/* num piscar de olhos. Inativo: cinza-escuro com peso.         */
/* Ativo: pílula verde sólida (mesma identidade NexusMed).      */
/* ============================================================ */
.tabs {
  display: flex;
  gap: 6px;
  background: #eef2f7;
  border: 1px solid #d8e0ea;
  border-radius: 14px;
  padding: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6);
}
.tab {
  flex-shrink: 0;
  padding: 11px 20px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 700;
  color: #1f2937;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s var(--nm-ease), color .15s var(--nm-ease), box-shadow .15s var(--nm-ease), transform .12s var(--nm-ease);
  white-space: nowrap;
  min-height: 40px;
  letter-spacing: .15px;
}
.tab:hover {
  background: rgba(255,255,255,.7);
  color: #0f172a;
}
.tab.on {
  background: linear-gradient(180deg, #10b981, #047857);
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(4,120,87,.32), inset 0 1px 0 rgba(255,255,255,.22);
  text-shadow: 0 1px 0 rgba(0,0,0,.12);
}
.tab.on:hover { color: #ffffff; }

/* ============================================================ */
/* Histórico cronológico do paciente (v17.9.20)                 */
/* ============================================================ */
.hist-filters {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 8px;
  background: #f8fafc;
  border: 1px solid var(--nm-border);
  border-radius: 12px;
}
.hist-flt {
  padding: 8px 14px;
  border: 1px solid #d8e0ea;
  background: #fff;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: all .12s var(--nm-ease);
  white-space: nowrap;
  min-height: 34px;
}
.hist-flt:hover { background: #f1f5f9; }
.hist-flt.on {
  background: linear-gradient(180deg, #10b981, #047857);
  color: #fff;
  border-color: #047857;
  box-shadow: 0 4px 10px rgba(4,120,87,.25);
}
.hist-row {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--nm-border);
  border-radius: 12px;
  margin-bottom: 8px;
  background: #fff;
  transition: border-color .12s var(--nm-ease), box-shadow .12s var(--nm-ease), transform .12s var(--nm-ease);
}
.hist-row[data-hist-rec],
.hist-row[data-hist-doc] {
  cursor: pointer;
}
.hist-row[data-hist-rec]:hover,
.hist-row[data-hist-doc]:hover {
  border-color: #10b981;
  box-shadow: 0 4px 14px rgba(16,185,129,.12);
  transform: translateY(-1px);
}
.hist-ic {
  width: 38px; height: 38px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: #f1f5f9;
  font-size: 18px;
}
.hist-appt .hist-ic { background: #ecfdf5; }
.hist-rec  .hist-ic { background: #eff6ff; }
.hist-ate  .hist-ic { background: #fff7ed; }
.hist-pay  .hist-ic { background: #f0fdf4; }
.hist-doc  .hist-ic { background: #f5f3ff; }
.hist-body { flex: 1; min-width: 0; }
.hist-row-h {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px; flex-wrap: wrap;
  margin-bottom: 4px;
}
.hist-row-h b { font-size: 14px; color: #0f172a; font-weight: 700; }
.hist-date { font-size: 12px; color: var(--nm-text-mute); white-space: nowrap; font-variant-numeric: tabular-nums; }
.hist-meta { font-size: 12.5px; color: var(--nm-text-soft); margin-bottom: 4px; }
.hist-text { font-size: 13px; color: var(--nm-text); line-height: 1.5; }

/* v17.9.7 — Tabs do calendário (Dia/Semana/Mês) em roxo quando ativas.
   Visualmente diferente do resto pra deixar claro que é seleção de visão. */
button[data-cv] {
  border: 1.5px solid transparent;
}
button[data-cv].on {
  background: linear-gradient(180deg, #8b5cf6, #7c3aed) !important;
  color: #fff !important;
  border-color: #6d28d9 !important;
  box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 4px 12px rgba(124,58,237,.22) !important;
}
button[data-cv]:not(.on):hover {
  background: rgba(124,58,237,.06);
  color: #6d28d9;
}

/* ============================================================ */
/* Login — mobile-first, layout balanceado                      */
/* v17.4.5 — Mobile order: marca → form → vantagens.             */
/* Sem scroll horizontal. Sem element vazando.                   */
/* ============================================================ */
html, body { overflow-x: hidden; }
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  box-sizing: border-box;
  /* v17.9.41 — LIGHT (estilo iClinic/Doctoralia). Era navy pesado.
     Branco-off com radial verde discreto = leve, médico, premium. */
  background:
    radial-gradient(at 15% 0%, rgba(16,185,129,.06) 0, transparent 50%),
    radial-gradient(at 100% 100%, rgba(16,185,129,.04) 0, transparent 60%),
    #f7f9fc;
  color: var(--nm-text);
  padding: 24px 16px;
  padding-top: calc(24px + env(safe-area-inset-top, 0));
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0));
}
.login-shell {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-sizing: border-box;
  /* v17.9.39 — Anti-overflow: garantia que nada saia da tela em mobile */
  overflow-x: hidden;
}
.login-shell > * { min-width: 0; max-width: 100%; box-sizing: border-box; overflow-wrap: anywhere; }
.login-shell input, .login-shell select, .login-shell textarea, .login-shell button {
  max-width: 100%;
  box-sizing: border-box;
}
/* v17.9.39 — iOS Safari faz auto-zoom em inputs com font-size <16px,
   o que bagunça o layout do mobile inteiro. Forçar 16px nos inputs evita. */
@media (max-width: 768px) {
  .login-shell .input, .login-shell input, .login-shell select, .login-shell textarea {
    font-size: 16px !important;
  }
}
.login-brand-bar {
  display: flex;
  align-items: center;
  margin-bottom: 2px;
}
.login-form-col {
  display: flex;
  flex-direction: column;
}
.login-hero {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 4px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.login-brand-mark {
  /* v17.9.41 — light theme: glow ainda mais sutil */
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(16,185,129,.22);
  overflow: hidden;
  flex-shrink: 0;
}
.login-brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.login-brand-text .n { font-size: 17px; font-weight: 800; letter-spacing: -.4px; line-height: 1.1; color: var(--nm-text); }
.login-brand-text .n em { font-style: normal; color: var(--nm-primary); }
.login-brand-text .t { font-size: 12px; color: var(--nm-text-mute); margin-top: 3px; }

.login-h1 {
  /* v17.9.41 — light theme: headline em texto escuro */
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.5px;
  line-height: 1.2;
  margin: 0;
  color: var(--nm-text);
  word-break: break-word;
  overflow-wrap: anywhere;
}
@media (min-width: 900px) {
  .login-h1 { font-size: 32px; line-height: 1.18; letter-spacing: -.7px; }
}
.login-h1 em {
  font-style: normal;
  color: var(--nm-primary-dark);
}
.login-sub {
  font-size: 14px;
  line-height: 1.6;
  color: var(--nm-text-soft);
  margin: 0;
}
.login-card {
  /* v17.9.41 — Card de form em branco com sombra elevada (estilo iClinic) */
  background: #ffffff;
  border: 1px solid var(--nm-border);
  border-radius: 16px;
  padding: 26px 24px;
  box-shadow: var(--nm-shadow-3);
}
.login-card h2 {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--nm-text);
  letter-spacing: -.3px;
}
.login-card .desc {
  font-size: 13.5px;
  color: var(--nm-text-soft);
  margin: 0 0 22px;
}
.login-card .field { margin-bottom: 16px; }
.login-card .field label,
.login-card .field > .lbl {
  color: var(--nm-text-soft);
  font-size: 12.5px;
  font-weight: 600;
}
.login-card .input {
  background: #fff;
  border: 1.5px solid var(--nm-border);
  color: var(--nm-text);
  height: 48px;
  font-size: 15px;
}
.login-card .input::placeholder { color: var(--nm-text-mute); }
.login-card .input:focus { border-color: var(--nm-primary); background: var(--nm-primary-soft); box-shadow: 0 0 0 4px rgba(16,185,129,.12); }
.login-card .btn-primary { width: 100%; height: 50px; font-size: 15px; margin-top: 4px; }
.login-card .btn-link {
  display: block;
  background: none;
  border: none;
  color: var(--nm-text-mute);
  font-size: 13px;
  margin-top: 16px;
  width: 100%;
  text-align: center;
  cursor: pointer;
  font-family: inherit;
  padding: 6px;
}
.login-card .btn-link:hover { color: var(--nm-primary-dark); }
.login-err {
  background: var(--nm-danger-soft);
  border: 1px solid #fca5a5;
  color: #991b1b;
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 14px;
}
/* v17.9.29 — Login institucional. Paleta única (verde-NexusMed sutil),
   tipografia clara, sem cores berrantes nem animação chamativa. */
.login-feats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
@media (min-width: 600px) {
  .login-feats { grid-template-columns: 1fr 1fr; }
}
.login-feat {
  /* v17.9.41 — light theme */
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--nm-border);
  border-radius: 12px;
  transition: border-color .2s, transform .2s, box-shadow .2s;
}
.login-feat:hover {
  border-color: var(--nm-primary);
  transform: translateY(-1px);
  box-shadow: var(--nm-shadow-2);
}
.login-feat .ic {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--nm-primary-soft);
  border: 1px solid rgba(16,185,129,.20);
  color: var(--nm-primary-dark);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.login-feat .body { min-width: 0; flex: 1; }
.login-feat .body .t {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--nm-text);
  line-height: 1.3;
  letter-spacing: -.1px;
}
.login-feat .body .d {
  font-size: 12px;
  color: rgba(255,255,255,.52);
  margin-top: 3px;
  line-height: 1.5;
}

/* v17.9.41 — Bloco institucional unificado (light theme) */
.login-compliance {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 18px;
  background: #fff;
  border: 1px solid var(--nm-border);
  border-radius: 12px;
}
.login-compliance-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.login-compliance-ic {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--nm-primary-dark);
  background: var(--nm-primary-soft);
}
.login-compliance-t {
  font-size: 13px;
  font-weight: 600;
  color: var(--nm-text);
  letter-spacing: -.1px;
  line-height: 1.3;
}
.login-compliance-d {
  font-size: 12px;
  color: var(--nm-text-soft);
  line-height: 1.55;
  margin-top: 4px;
}

.login-trust {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.login-trust span {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--nm-text-mute);
  padding: 5px 10px;
  background: #fff;
  border: 1px solid var(--nm-border);
  border-radius: 4px;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.login-foot {
  text-align: center;
  font-size: 11.5px;
  color: var(--nm-text-mute);
  margin-top: 8px;
}

/* v17.6.5 — Selo institucional Memed na tela de login.
   Aparece logo abaixo dos features e antes da fita de trust badges.
   Visual deliberadamente discreto: não compete com o CTA de login,
   mas comunica autoridade técnica antes da decisão de entrar. */
.login-memed-seal {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  margin: 14px 0 10px;
  background: linear-gradient(135deg, rgba(16,185,129,.12), rgba(16,185,129,.04));
  border: 1px solid rgba(16,185,129,.30);
  border-radius: 14px;
}
.login-memed-seal-mark {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16,185,129,.20);
  color: #10b981;
}
.login-memed-seal-body { min-width: 0; flex: 1; }
.login-memed-seal-body .t {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--nm-primary-dark);
  letter-spacing: .2px;
  line-height: 1.25;
}
.login-memed-seal-body .d {
  font-size: 11.5px;
  color: var(--nm-text-soft);
  line-height: 1.45;
  margin-top: 3px;
}

/* v17.6.5 — Pill "Memed Conectado" no topbar do app.
   Aparece somente quando o médico tem doctor_token salvo.
   Verde-NexusMed, com bolinha pulsante pra leitura imediata. */
.nm-memed-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(16,185,129,.18), rgba(16,185,129,.08));
  border: 1px solid rgba(16,185,129,.40);
  color: var(--nm-primary-dark, #047857);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .2px;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s ease, transform .15s ease;
}
.nm-memed-pill:hover {
  background: linear-gradient(135deg, rgba(16,185,129,.28), rgba(16,185,129,.14));
  transform: translateY(-1px);
}
.nm-memed-pill b { font-weight: 700; }
.nm-memed-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 0 rgba(16,185,129,.55);
  animation: nm-memed-pulse 2.2s ease-out infinite;
}
@keyframes nm-memed-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(16,185,129,.55); }
  70%  { box-shadow: 0 0 0 8px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}
@media (max-width: 480px) {
  /* No mobile o título do topbar já ocupa espaço — encurta o pill. */
  .nm-memed-pill b { display: none; }
  .nm-memed-pill::after { content: 'Memed'; font-weight: 700; font-size: 12px; }
  .nm-memed-pill { padding: 6px 10px; }
}

/* ============================================================ */
/* Atman drawer — usa dvh para respeitar teclado virtual         */
/* ============================================================ */
.atman {
  position: fixed;
  top: 0; right: 0;
  width: 100%;
  max-width: 100%;
  height: 100vh;
  height: 100dvh; /* dynamic viewport — encolhe quando teclado abre */
  background: var(--nm-surface);
  z-index: 9000;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgba(15,23,42,.14);
  animation: nm-slide-in .15s ease-out;
  will-change: transform;
  transform: translateZ(0);
  /* v17.8.5 — respeita notch do iPhone no topo (cabeçalho não cola na barra de status) */
  padding-top: env(safe-area-inset-top, 0px);
}
.atman-h {
  padding-top: 16px !important;
}
@keyframes nm-slide-in { from { transform: translate3d(100%, 0, 0); } to { transform: translate3d(0, 0, 0); } }
.atman-h {
  padding: 16px 18px;
  background: linear-gradient(135deg, #6d28d9, #4c1d95);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.atman-h .l { display: flex; gap: 12px; align-items: center; }
.atman-ic { width: 40px; height: 40px; border-radius: 12px; background: rgba(255,255,255,.18); display: flex; align-items: center; justify-content: center; font-size: 20px; }
.atman-name { font-weight: 700; font-size: 15.5px; line-height: 1; }
.atman-tag { font-size: 11px; opacity: .85; margin-top: 3px; }
.atman-x { width: 36px; height: 36px; background: rgba(255,255,255,.16); border: none; color: #fff; border-radius: 10px; font-size: 22px; line-height: 1; }
.atman-disclaimer {
  background: var(--nm-warn-soft);
  border-bottom: 1px solid rgba(245,158,11,.20);
  padding: 8px 14px;
  font-size: 11.5px;
  color: #92400e;
  line-height: 1.45;
  text-align: center;
  flex-shrink: 0;
}
.atman-msgs { flex: 1; padding: 16px; background: var(--nm-bg); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.atman-msg { margin-bottom: 12px; }
.atman-msg.user { display: flex; justify-content: flex-end; }
.atman-msg.user .b { background: linear-gradient(135deg, #6d28d9, #4c1d95); color: #fff; max-width: 88%; border-radius: 14px 14px 4px 14px; }
.atman-msg.assistant .b { background: var(--nm-surface); border: 1px solid var(--nm-border); border-radius: 14px 14px 14px 4px; max-width: 95%; }
.atman-msg .b { padding: 11px 14px; font-size: 14px; line-height: 1.55; display: inline-block; }

/* v17.10.5 — Loading bubble do Atman com 3 pontinhos pulsantes + texto rotativo */
.atman-msg.atman-loading .b { color: var(--nm-text-soft); font-style: italic; }
.atman-loading-dots { display: inline-flex; gap: 4px; align-items: center; }
.atman-loading-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: #6d28d9;
  display: inline-block;
  animation: atman-dot 1.2s infinite ease-in-out;
}
.atman-loading-dots span:nth-child(2) { animation-delay: 0.18s; }
.atman-loading-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes atman-dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}
.atman-loading-label { transition: opacity .25s ease; }
.atman-input { padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--nm-border); background: var(--nm-surface); display: flex; gap: 8px; flex-shrink: 0; }
.atman-input textarea { flex: 1; resize: none; border: 1.5px solid var(--nm-border); border-radius: 12px; padding: 11px 14px; font-size: 16px; min-height: 44px; max-height: 120px; }
.atman-input textarea:focus { outline: none; border-color: #6d28d9; }
.atman-send { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, #6d28d9, #4c1d95); color: #fff; border: none; font-size: 20px; flex-shrink: 0; cursor: pointer; }
/* v17.10.6 — Botão "Buscar atual" (web_search opt-in) */
.atman-web {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--nm-bg); color: var(--nm-text-soft);
  border: 1.5px solid var(--nm-border); font-size: 18px; flex-shrink: 0; cursor: pointer;
  transition: all .15s ease;
}
.atman-web:hover { background: var(--nm-surface); border-color: #6d28d9; color: #6d28d9; }
.atman-web.on { background: linear-gradient(135deg,#6d28d9,#4c1d95); color: #fff; border-color: transparent; box-shadow: 0 2px 8px rgba(109,40,217,.30); }
.atman-chip-row { padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 6px; background: var(--nm-surface); border-top: 1px solid var(--nm-border); }
.atman-chip {
  padding: 6px 11px;
  background: var(--nm-info-soft);
  color: #1d4ed8;
  border: 1px solid rgba(59,130,246,.15);
  border-radius: 999px;
  font-size: 11.5px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
}

/* ============================================================ */
/* Calendar                                                     */
/* ============================================================ */
.cal-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.cal-nav { display: flex; align-items: center; gap: 6px; justify-content: center; }
.cal-label { margin: 0 6px; font-size: 15px; font-weight: 700; text-transform: capitalize; }
.cal-views { display: flex; gap: 4px; background: var(--nm-surface); border-radius: 12px; padding: 4px; border: 1px solid var(--nm-border); }
.cal-views .tab { flex: 1; padding: 8px 14px; border-radius: 8px; border: none; background: transparent; cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--nm-text-soft); transition: all .15s ease; white-space: nowrap; }
.cal-views .tab:hover { background: var(--nm-bg); color: var(--nm-text); }
.cal-views .tab.on { background: linear-gradient(135deg,#6d28d9,#4c1d95); color: #fff; box-shadow: 0 2px 8px rgba(109,40,217,.25); }
/* v17.10.5 — Container externo do conjunto: tabs + botão Consulta separados */
.cal-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
@media (max-width: 768px) {
  .cal-actions { width: 100%; justify-content: space-between; }
  .cal-views { flex: 1; }
}
.cal-grid {
  background: var(--nm-surface);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-r-md);
  overflow: hidden;
  box-shadow: var(--nm-shadow-1);
}
.cal-month { display: grid; grid-template-columns: repeat(7, 1fr); }

/* v17.4.2 — Mobile: deixa o calendário do mês scrollável horizontal
   pra que todos os 7 dias apareçam (swipe lateral). */
@media (max-width: 768px) {
  .cal-grid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }
  .cal-grid .cal-month {
    min-width: 700px;
  }
  .cal-grid .cal-month .dow,
  .cal-grid .cal-day {
    min-width: 100px;
    scroll-snap-align: start;
  }
}
.cal-month .dow { padding: 8px 4px; text-align: center; font-size: 10.5px; font-weight: 700; color: var(--nm-text-mute); background: var(--nm-bg); border-bottom: 1px solid var(--nm-border); text-transform: uppercase; letter-spacing: .5px; }
.cal-day { min-height: 72px; padding: 6px; border-right: 1px solid var(--nm-border-soft); border-bottom: 1px solid var(--nm-border-soft); cursor: pointer; }
.cal-day.other { color: var(--nm-text-mute); background: #fbfcfe; }
.cal-day .num { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.cal-day.today .num { background: var(--nm-primary); color: #fff; border-radius: 50%; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; font-size: 11px; }
.cal-evt { font-size: 9.5px; padding: 2px 5px; border-radius: 4px; background: var(--nm-primary-100); color: var(--nm-primary-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; cursor: pointer; font-weight: 600; }
.cal-evt-return {
  background: var(--nm-danger-soft);
  color: #991b1b;
  border-left: 3px solid var(--nm-danger);
  padding-left: 6px;
}
.cal-evt-video {
  background: #f5f3ff;
  color: #6d28d9;
  border-left: 3px solid #8b5cf6;
  padding-left: 6px;
}
.appt-row-return {
  background: var(--nm-danger-soft) !important;
  border-left: 3px solid var(--nm-danger) !important;
}
.appt-row-return .appt-time { color: var(--nm-danger); }

/* v17.9.22 — Botões de tipo: 3 colunas desktop, mobile empilha 1+1+1 sem cortar texto */
.ap-type-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
@media (max-width: 540px) {
  .ap-type-row { grid-template-columns: 1fr; }
}
.ap-type-btn {
  padding: 13px 10px;
  font-size: 13px;
  font-weight: 700;
  background: var(--nm-bg);
  border: 1.5px solid var(--nm-border);
  border-radius: 10px;
  color: #1f2937;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  transition: all .15s var(--nm-ease);
  /* Garantia anti-corte: nunca trunca o texto, ajusta ao container */
  min-height: 48px;
  white-space: normal;
  word-break: keep-all;
  overflow-wrap: anywhere;
  line-height: 1.25;
}
.ap-type-btn:hover { border-color: var(--nm-primary); color: var(--nm-primary-dark); }
.ap-type-btn.on {
  background: var(--nm-primary-soft);
  border-color: var(--nm-primary);
  color: var(--nm-primary-dark);
  box-shadow: 0 0 0 3px rgba(16,185,129,.10);
}
.ap-type-btn[data-type="return"].on {
  background: var(--nm-danger-soft);
  border-color: var(--nm-danger);
  color: #991b1b;
  box-shadow: 0 0 0 3px rgba(239,68,68,.10);
}
.ap-type-btn[data-type="video"].on {
  background: #f5f3ff;
  border-color: #8b5cf6;
  color: #6d28d9;
  box-shadow: 0 0 0 3px rgba(139,92,246,.10);
}
/* v17.9.21 — Acompanhamento: âmbar/laranja, paga (como first) mas distinto na agenda */
.ap-type-btn[data-type="followup"].on {
  background: #fffbeb;
  border-color: #d97706;
  color: #92400e;
  box-shadow: 0 0 0 3px rgba(217,119,6,.12);
}
.appt-row-followup {
  background: #fffbeb !important;
  border-left: 3px solid #d97706 !important;
}
.appt-row-followup .appt-time { color: #92400e; }
.appt-row[data-type="followup"], .appt-card[data-type="followup"] {
  border-left: 4px solid #d97706 !important;
}
.badge-amber {
  background: #fef3c7;
  color: #92400e;
}

/* v17.9.18 — Botões de modalidade: SEMPRE legíveis, com cor sólida quando
   selecionado (verde Presencial / violeta Teleconsulta) e cinza claro quando
   não selecionado. Padding generoso pra leitura confortável em qualquer tela. */
.ap-mod-btn {
  padding: 14px 12px;
  font-size: 14px;
  font-weight: 600;
  background: #f8fafc;
  border: 1.5px solid var(--nm-border);
  border-radius: 10px;
  color: #475569;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  transition: all .15s var(--nm-ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
}
.ap-mod-btn:hover {
  border-color: var(--cor, var(--nm-primary));
  color: var(--cor, var(--nm-primary-dark));
  background: #fff;
}
.ap-mod-btn.on {
  border-color: var(--cor) !important;
  color: #fff !important;
  background: var(--cor) !important;
  box-shadow: 0 1px 0 rgba(255,255,255,.20) inset, 0 4px 12px rgba(0,0,0,.10);
  font-weight: 700;
}
/* Cores específicas com fallback caso var(--cor) falte */
.ap-mod-btn[data-mod="presencial"].on { background: #059669 !important; border-color: #059669 !important; box-shadow: 0 1px 0 rgba(255,255,255,.20) inset, 0 4px 12px rgba(5,150,105,.25); }
.ap-mod-btn[data-mod="online"].on     { background: #7c3aed !important; border-color: #7c3aed !important; box-shadow: 0 1px 0 rgba(255,255,255,.20) inset, 0 4px 12px rgba(124,58,237,.25); }

/* v17.9.4 — Cor de borda lateral nos cards da agenda por modalidade */
/* v17.9.23 — Botões de ação na aba Resumo do paciente: 3 cols desktop, empilha em mobile */
.ov-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
@media (max-width: 720px) {
  .ov-actions { grid-template-columns: 1fr; }
}

/* v17.9.23 — Modal "Registrar pagamento": botões responsivos sem corte */
.rp-type-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}
@media (max-width: 540px) { .rp-type-row { grid-template-columns: 1fr; } }
.rp-type-btn {
  padding: 13px 10px;
  font-size: 13.5px;
  font-weight: 700;
  background: var(--nm-bg);
  border: 1.5px solid var(--nm-border);
  border-radius: 10px;
  color: #1f2937;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  transition: all .15s var(--nm-ease);
  min-height: 48px;
  white-space: normal;
  line-height: 1.25;
}
.rp-type-btn:hover { border-color: var(--nm-primary); }
.rp-type-btn.on {
  background: linear-gradient(180deg, #10b981, #047857);
  border-color: #047857;
  color: #fff;
  box-shadow: 0 4px 12px rgba(4,120,87,.22);
  text-shadow: 0 1px 0 rgba(0,0,0,.10);
}

.rp-method-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}
@media (max-width: 720px) { .rp-method-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 380px) { .rp-method-row { grid-template-columns: 1fr; } }
.rp-method-btn {
  padding: 10px 8px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--nm-bg);
  border: 1.5px solid var(--nm-border);
  border-radius: 8px;
  color: #334155;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  transition: all .12s var(--nm-ease);
  min-height: 40px;
  white-space: normal;
  line-height: 1.25;
}
.rp-method-btn:hover { background: #f1f5f9; }
.rp-method-btn.on {
  background: linear-gradient(180deg, #10b981, #047857);
  border-color: #047857;
  color: #fff;
  box-shadow: 0 3px 10px rgba(4,120,87,.22);
  font-weight: 700;
}

.appt-row[data-modality="online"], .appt-card[data-modality="online"], .agenda-item[data-modality="online"] {
  border-left: 4px solid #7c3aed !important;
}
.appt-row[data-modality="presencial"], .appt-card[data-modality="presencial"], .agenda-item[data-modality="presencial"] {
  border-left: 4px solid #059669 !important;
}

/* ============================================================ */
/* Editor (record) — simplified                                 */
/* ============================================================ */
.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px;
  background: var(--nm-surface);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-r-md);
  margin-bottom: 12px;
  font-size: 12.5px;
}
.record-meta b { display: block; font-size: 10.5px; color: var(--nm-text-mute); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 2px; font-weight: 700; }
.record-meta span { font-weight: 600; color: var(--nm-text); }
.record-editor {
  background: var(--nm-surface);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-r-md);
  padding: 16px;
  margin-bottom: 12px;
}
.record-editor textarea { width: 100%; min-height: 280px; border: none; resize: vertical; font-size: 15px; line-height: 1.55; padding: 4px; outline: none; font-family: inherit; }

/* ============================================================ */
/* Record document — visual de papel timbrado real              */
/* ============================================================ */
.record-doc {
  background: var(--nm-surface);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-r-md);
  padding: 0;
  overflow: hidden;
}
.rd-letterhead-top { width: 100%; }
.rd-letterhead-top img { width: 100%; display: block; }
.rd-letterhead-bot { width: 100%; margin-top: 14px; }
.rd-letterhead-bot img { width: 100%; display: block; }
.rd-header-default {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 2px solid var(--nm-primary);
  background: linear-gradient(135deg, #f7f9fc, #ffffff);
}
.rd-logo {
  width: 40px; height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}
.rd-logo-placeholder {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark));
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(16,185,129,.25);
}
.rd-doctor-name { font-size: 15px !important; }
.rd-doctor-line { font-size: 12px !important; }
.rd-doctor { min-width: 0; flex: 1; }
.rd-doctor-name { font-size: 17px; font-weight: 700; color: var(--nm-text); letter-spacing: -.3px; }
.rd-doctor-line { font-size: 12.5px; color: var(--nm-text-soft); margin-top: 2px; }
.rd-pt-bar {
  background: var(--nm-navy);
  color: #fff;
  padding: 12px 18px;
  margin: 14px 18px 0;
  border-radius: 10px;
  border-left: 4px solid var(--nm-primary);
}
.rd-pt-name { font-size: 15.5px; font-weight: 700; }
.rd-pt-meta { font-size: 12px; color: rgba(255,255,255,.75); margin-top: 3px; line-height: 1.5; word-break: break-word; }
.rd-fields {
  display: flex;
  gap: 14px;
  padding: 16px 18px 0;
  flex-wrap: wrap;
}
.record-doc .field { padding: 0 18px; }
.record-doc .field:last-of-type { padding-bottom: 16px; }
.rd-footer-default {
  padding: 14px 18px;
  border-top: 1px solid var(--nm-border);
  font-size: 11.5px;
  color: var(--nm-text-mute);
  text-align: center;
  line-height: 1.6;
  background: var(--nm-bg);
}
@media (min-width: 900px) {
  .rd-pt-meta { font-size: 12.5px; }
  .rd-doctor-name { font-size: 18px; }
}

/* ============================================================ */
/* DESKTOP — ≥ 900px                                             */
/* ============================================================ */
@media (min-width: 900px) {
  .nm-sb {
    position: static;
    transform: none;
    width: var(--nm-sb-w);
    max-width: var(--nm-sb-w);
    box-shadow: none;
    flex-shrink: 0;
  }
  .nm-sb-overlay { display: none !important; }
  /* v17.9.3 — hambúrguer só aparece em mobile/tablet (< 900px). Desktop tem
     a sidebar fixa visível, então não precisa do botão. */
  .nm-hamburger { display: none !important; }
  /* v17.10.5 — Desktop NÃO precisa de botão Voltar — tem sidebar pra navegar.
     Esconder elimina a sobreposição com o título da topbar. */
  .nm-back { display: none !important; }
  .nm-app { flex-direction: row; }
  .nm-main { width: calc(100% - var(--nm-sb-w)); }
  .nm-topbar { padding: 0 28px; }
  .nm-content { padding: 24px 28px; padding-bottom: 80px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
  .stat { padding: 18px; }
  .stat-v { font-size: 26px; }
  .field-row { grid-template-columns: 1fr 1fr; gap: 14px; }
  .quick-grid { grid-template-columns: 1fr 1fr 1fr 1fr; }
  .nm-mdbk { align-items: center; padding: 24px; }
  .nm-md { width: 100%; max-width: 600px; max-height: 90vh; border-radius: var(--nm-r-xl); }
  .nm-md.nm-md-lg { max-width: 980px; }
  /* v17.9.8 — Modal Memed desktop: 95vw × 95vh (janela grande proporcional) */
  .nm-md.nm-md-xl { max-width: 95vw; max-height: 95vh; width: 95vw; height: 95vh; border-radius: 14px; }
  .nm-md.nm-md-xl .nm-md-b { padding: 0; flex: 1 1 auto; min-height: 0; overflow: hidden; position: relative; }
  .nm-md.nm-md-xl #memed-prescricao { position: absolute; inset: 0; }
  .nm-md.nm-md-xl #memed-prescricao iframe { width: 100%; height: 100%; border: 0; display: block; }
  /* v17.10.23 — Desktop: footer em row com flex (lado a lado, alinhado à direita).
     Grid 1-col só vale no mobile. */
  .nm-md-f { display: flex; flex-direction: row; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
  .nm-md-f .btn { width: auto !important; min-width: 100px; }
  .pt-head { padding: 22px 26px; }
  /* v17.9.24 — Desktop: avatar+info em uma linha, botões em LINHA SEPARADA embaixo.
     Evita overlapping em qualquer largura, fica organizado e respirável. */
  .pt-head-row { gap: 16px; margin-bottom: 16px; }
  .pt-av { width: 60px; height: 60px; font-size: 22px; border-radius: 14px; }
  .pt-name { font-size: 22px; }
  .pt-meta { font-size: 13.5px; line-height: 1.55; }
  .pt-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
  }
  .pt-actions .btn { flex: 0 0 auto; padding: 10px 14px; font-size: 13px; }
  .pt-actions .btn-prescribe { flex: 0 0 auto; padding: 11px 20px; font-size: 13.5px; }
  .hero { padding: 30px 32px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
  .hero-title { font-size: 30px; }
  .hero-sub { font-size: 14.5px; }
  .login-wrap { padding: 32px; }
  /* v17.4.5 — desktop usa grid-template-areas para reposicionar:
     hero (vantagens) à esquerda, formulário à direita, marca no topo da hero. */
  .login-shell {
    max-width: 1180px;
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
    grid-template-rows: auto auto;
    grid-template-areas:
      'brand form'
      'hero  form';
    gap: 28px 64px;
    align-items: start;
  }
  .login-brand-bar { grid-area: brand; }
  .login-form-col { grid-area: form; align-self: center; }
  .login-hero { grid-area: hero; gap: 24px; align-self: start; margin-top: 0; }
  .login-h1 { font-size: 52px; letter-spacing: -1.5px; line-height: 1.05; }
  .login-sub { font-size: 16px; max-width: 540px; }
  .login-feats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .login-feat { padding: 14px 16px; }
  .login-feat .ic { width: 38px; height: 38px; font-size: 17px; }
  .login-feat .body .t { font-size: 13.5px; }
  .login-feat .body .d { font-size: 12px; }
  .login-trust { justify-content: flex-start; }
  .login-card {
    padding: 36px 32px;
    border-radius: 22px;
    width: 100%;
    max-width: 460px;
    margin: 0 auto;
  }
  .login-card h2 { font-size: 24px; }
  .login-card .desc { font-size: 14px; }
  .login-foot { text-align: left; }
  .atman { width: 440px; max-width: 92vw; }
  .quick-btn { padding: 14px 16px; min-height: 60px; }
  .patient-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
  .doc { flex-wrap: nowrap; }
  .doc-info { flex: 1; }
  .doc-acts { width: auto; flex: 0 0 auto; }
  .doc-acts > * { flex: 0 0 auto; padding: 8px 12px; }
  .cal-head { flex-direction: row; justify-content: space-between; align-items: center; }
  .cal-day { min-height: 100px; padding: 10px; }
  .cal-day .num { font-size: 13px; }
  .cal-evt { font-size: 11px; padding: 3px 6px; }
}

/* ============================================================ */
/* Full-screen video session (lado do médico)                   */
/* ============================================================ */
.video-fs {
  position: fixed;
  inset: 0;
  z-index: 9800;
  background: #0a0e1a;
  color: #fff;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.video-fs-err {
  margin: auto;
  padding: 32px;
  text-align: center;
  max-width: 360px;
}
.video-fs-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  /* v17.9.2 — safe-area-inset-top pra notch + flex-wrap pro mobile não cortar */
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.30);
  flex-shrink: 0;
  gap: 8px;
  flex-wrap: wrap;
}
.video-fs-h-l { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
/* v17.9.2 — Botões da direita podem quebrar linha no mobile, sem cortar */
.video-fs-h-r { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.video-fs-back {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: rgba(255,255,255,.08);
  border: none;
  color: #fff;
  font-size: 20px;
  flex-shrink: 0;
  cursor: pointer;
}
.video-fs-back:hover { background: rgba(255,255,255,.16); }
.video-fs-title { font-size: 14px; font-weight: 700; letter-spacing: -.2px; }
.video-fs-pt { font-size: 12.5px; color: rgba(255,255,255,.65); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }

.video-fs-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 10px;
  padding: 10px;
}
.video-fs-jitsi {
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  flex: 1;
  min-height: 40vh;
  position: relative;
}
.video-fs-jitsi iframe { width: 100%; height: 100%; border: 0; display: block; }
.video-fs-side {
  background: #fff;
  color: var(--nm-text);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  max-height: 50vh;
  overflow: hidden;
}
.video-fs-tabs {
  display: flex;
  background: var(--nm-bg);
  border-bottom: 1px solid var(--nm-border);
  flex-shrink: 0;
}
.video-fs-tab {
  flex: 1;
  padding: 11px 12px;
  border: none;
  background: transparent;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--nm-text-soft);
  cursor: pointer;
  font-family: inherit;
  border-bottom: 2px solid transparent;
}
.video-fs-tab.on {
  color: var(--nm-primary-dark);
  background: var(--nm-surface);
  border-bottom-color: var(--nm-primary);
}
.video-fs-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.video-fs-side-h {
  padding: 12px 14px;
  border-bottom: 1px solid var(--nm-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.video-fs-side-h b { font-size: 14px; font-weight: 700; color: var(--nm-text); display: block; }
.video-fs-msgs {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  background: var(--nm-bg);
  min-height: 120px;
}
.video-fs-empty { text-align: center; padding: 30px 16px; color: var(--nm-text-mute); }
.video-fs-empty p { font-size: 13.5px; margin: 0 0 4px; color: var(--nm-text-soft); font-weight: 600; }
.video-fs-empty small { font-size: 12px; }
.vfs-msg { margin-bottom: 8px; display: flex; flex-direction: column; }
.vfs-msg.me { align-items: flex-end; }
.vfs-msg.them { align-items: flex-start; }
.vfs-bub {
  max-width: 88%;
  padding: 9px 13px;
  font-size: 13.5px;
  line-height: 1.45;
  word-wrap: break-word;
  border-radius: 14px 14px 14px 4px;
  background: #fff;
  border: 1px solid var(--nm-border);
}
.vfs-msg.me .vfs-bub {
  background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark));
  color: #fff;
  border-color: transparent;
  border-radius: 14px 14px 4px 14px;
}
.vfs-bub-file img { max-width: 220px; max-height: 160px; border-radius: 8px; display: block; }
.vfs-bub-file a { text-decoration: none; color: inherit; display: block; }
.vfs-msg.me .vfs-bub-file a { color: #fff; }
.vfs-t { font-size: 10.5px; color: var(--nm-text-mute); margin-top: 3px; }
.video-fs-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--nm-border);
  background: #fff;
  flex-shrink: 0;
}
.video-fs-form input[type="text"] {
  flex: 1;
  height: 42px;
  padding: 0 14px;
  border: 1.5px solid var(--nm-border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: #fff;
  color: var(--nm-text);
}
.video-fs-form input[type="text"]:focus { outline: none; border-color: var(--nm-primary); box-shadow: 0 0 0 3px rgba(16,185,129,.12); }
.video-fs-form .btn { width: 44px; padding: 0; min-height: 42px; font-size: 18px; }

@media (min-width: 900px) {
  .video-fs-body { flex-direction: row; padding: 16px; gap: 14px; }
  .video-fs-jitsi { flex: 1; min-height: 0; }
  .video-fs-side { width: 380px; flex: 0 0 380px; max-height: none; }
}

/* v17.4.2 — Mobile: prontuário precisa de espaço pra digitar.
   Vídeo fica menor (35vh) e painel lateral cresce até final da tela.
   Editor interno ganha altura plena com scroll próprio. */
@media (max-width: 899px) {
  .video-fs-jitsi {
    flex: 0 0 auto;
    min-height: 28vh;
    max-height: 36vh;
  }
  .video-fs-side {
    max-height: none;
    flex: 1 1 auto;
    min-height: 0;
  }
  .video-fs-pane { min-height: 0; }
  #vfs-rec-host {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  #vfs-rec-host .nm-ed {
    max-height: none !important;
    min-height: 240px;
    flex: 1;
  }
  /* Quando aba prontuário está ativa, dá ainda mais espaço pro painel */
  .video-fs-side.on-record .video-fs-jitsi-shrink ~ * {}
}
.video-fs-side.on-record { /* hook usado pelo JS pra detectar aba ativa */ }

/* ============================================================ */
/* Patient video page                                           */
/* ============================================================ */
.pv-shell {
  min-height: 100vh;
  min-height: 100dvh;
  background: #0a0e1a;
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top, 0));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  gap: 12px;
}
.pv-jitsi-wrap {
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  min-height: 50vh;
  flex: 0 0 auto;
}
.pv-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
}
.pv-card {
  background: #fff;
  color: var(--nm-text);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
}
.pv-card h3 { font-size: 15px; font-weight: 700; margin: 0 0 6px; letter-spacing: -.2px; }
.pv-card p { font-size: 12.5px; color: var(--nm-text-soft); margin: 0 0 12px; }
.pv-status { font-size: 12.5px; color: var(--nm-text-mute); margin-top: 10px; }
.pv-chat-card {
  flex: 1;
  min-height: 240px;
  max-height: 50vh;
}
.pv-chat-msgs {
  flex: 1;
  overflow-y: auto;
  background: var(--nm-bg);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
  -webkit-overflow-scrolling: touch;
  min-height: 120px;
}
.pv-chat-empty { text-align: center; color: var(--nm-text-mute); font-size: 12.5px; padding: 24px 12px; }
.pv-msg { margin-bottom: 8px; display: flex; flex-direction: column; }
.pv-msg.me { align-items: flex-end; }
.pv-msg.them { align-items: flex-start; }
.pv-bub {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.45;
  word-wrap: break-word;
}
.pv-msg.me .pv-bub { background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark)); color: #fff; border-radius: 12px 12px 4px 12px; }
.pv-msg.them .pv-bub { background: #fff; border: 1px solid var(--nm-border); border-radius: 12px 12px 12px 4px; }
.pv-bub-file img { max-width: 220px; max-height: 160px; border-radius: 8px; display: block; }
.pv-bub-file a { text-decoration: none; color: inherit; }
.pv-msg.me .pv-bub-file a { color: #fff; }
.pv-t { font-size: 10.5px; color: var(--nm-text-mute); margin-top: 3px; }
.pv-chat-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.pv-chat-form input[type="text"] {
  flex: 1;
  height: 42px;
  padding: 0 14px;
  border: 1.5px solid var(--nm-border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
}
.pv-chat-form input[type="text"]:focus { outline: none; border-color: var(--nm-primary); }
.pv-chat-form .btn { width: 44px; padding: 0; min-height: 42px; font-size: 18px; }

@media (min-width: 900px) {
  .pv-shell { flex-direction: row; padding: 16px; }
  .pv-jitsi-wrap { flex: 1; min-height: 0; }
  .pv-side { width: 360px; flex: 0 0 360px; max-height: none; }
  .pv-chat-card { max-height: none; }
}

/* ============================================================ */
/* v17.4 — Diretório de pacientes cadastrados                    */
/* ============================================================ */
.dir-group {
  background: var(--nm-surface);
  border: 1px solid var(--nm-border);
  border-radius: var(--nm-r-md);
  margin-bottom: 10px;
  overflow: hidden;
  box-shadow: var(--nm-shadow-1);
}
.dir-group-h {
  padding: 8px 16px;
  background: var(--nm-bg);
  font-size: 12px;
  font-weight: 800;
  color: var(--nm-text-soft);
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--nm-border);
}
.dir-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--nm-border-soft);
  cursor: pointer;
  transition: background-color .08s linear;
}
.dir-row:last-child { border-bottom: none; }
.dir-row:hover { background: var(--nm-primary-soft); }
.dir-av {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.dir-info { min-width: 0; flex: 1; }
.dir-name { font-size: 14px; font-weight: 600; color: var(--nm-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dir-meta { font-size: 12px; color: var(--nm-text-mute); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ps-head {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--nm-border);
}
.ps-av {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--nm-primary), var(--nm-primary-dark));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px;
  flex-shrink: 0;
}
.ps-name-block { min-width: 0; flex: 1; }
.ps-name { font-size: 18px; font-weight: 800; color: var(--nm-text); letter-spacing: -.3px; }
.ps-meta { font-size: 12.5px; color: var(--nm-text-mute); margin-top: 3px; word-break: break-word; }
.ps-contacts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.ps-contact {
  padding: 10px 12px;
  background: var(--nm-bg);
  border-radius: 10px;
  font-size: 13px;
}
.ps-contact b { display: block; font-size: 11px; color: var(--nm-text-mute); text-transform: uppercase; letter-spacing: .4px; font-weight: 700; margin-bottom: 3px; }
.ps-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 14px;
}
.ps-grid h4 { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--nm-text); }
.ps-rec {
  padding: 8px 10px;
  background: var(--nm-bg);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}
.ps-rec-d { font-size: 11px; color: var(--nm-text-mute); font-weight: 600; }
.ps-rec-s { color: var(--nm-text); margin-top: 2px; line-height: 1.45; }
.ps-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

@media (min-width: 700px) {
  .ps-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .ps-contacts { grid-template-columns: 1fr; }
}

/* ============================================================ */
/* Helpers                                                      */
/* ============================================================ */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.flex-1 { flex: 1; }
.text-mute { color: var(--nm-text-mute); }
.text-soft { color: var(--nm-text-soft); }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11.5px; }
.fw-700 { font-weight: 700; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; }
.hide { display: none !important; }
.divider { height: 1px; background: var(--nm-border); margin: 12px 0; }

/* ============================================================ */
/* v17.10.0 — Auditoria mobile robusta                          */
/* Resolve sobreposições, modais que não fecham, overflow e     */
/* travas no Financeiro e na vídeo-consulta em telas pequenas.  */
/* ============================================================ */

/* Modais: garante que o backdrop sempre fecha e o X é clicável */
.nm-modal, .modal, [class*="-modal"] { z-index: 9000; }
.nm-modal-overlay, .modal-overlay { z-index: 8999; }
.nm-modal-close, .modal-close, [data-close] {
  position: relative;
  z-index: 10001;
  pointer-events: auto !important;
  cursor: pointer;
}

/* Anti overflow horizontal em todas as telas */
html, body { overflow-x: hidden; }
.nm-view, .nm-content, #nm-view { max-width: 100vw; overflow-x: hidden; }

@media (max-width: 768px) {
  /* === FINANCEIRO mobile — cards verticais, sem sobreposição === */
  #nm-view .card { margin-bottom: 14px; padding: 14px; border-radius: 14px; }
  #nm-view .card-h {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
    margin-bottom: 12px !important;
  }
  #nm-view .card-h .card-t { font-size: 15px !important; }
  /* Botões do header de card vão pra baixo do título */
  #nm-view .card-h .btn,
  #nm-view .card-h > div { width: 100%; }
  /* Resumo: 2 colunas (em vez de 4) pra caber */
  #nm-view .stats {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }
  /* Card "Consultas vs Outros" também 2 cols no mobile */
  #nm-view [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  /* Tabela vira lista vertical (sem squish) */
  #nm-view .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #nm-view .tbl { font-size: 12.5px; }
  #nm-view .tbl th, #nm-view .tbl td { padding: 8px 6px; white-space: nowrap; }
  /* Presets de período: scroll horizontal sem quebrar layout */
  #fin-presets {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  #fin-presets .btn { flex-shrink: 0; }

  /* === Forms mobile (modais de pagamento, paciente, etc) === */
  .nm-modal .modal-body, .nm-modal-content {
    max-height: calc(100vh - 80px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  /* iOS: input fonte 16px pra não dar zoom auto */
  input, select, textarea { font-size: 16px !important; }
  /* Botão de fechar grande no mobile (44x44 — tamanho de toque) */
  .nm-modal-close, .modal-close, [data-close] {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    font-size: 22px !important;
  }
}

/* === VÍDEO-CONSULTA mobile com painel minimizável === */
@media (max-width: 900px) {
  /* Overlay full-screen ocupa altura dinâmica (iOS 100dvh) */
  .video-fs {
    height: 100vh !important;
    height: 100dvh !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }
  /* Header compacto */
  .video-fs-h {
    flex-shrink: 0;
    padding: 8px 10px !important;
    flex-wrap: wrap;
    gap: 6px !important;
  }
  .video-fs-h-r { gap: 4px !important; flex-wrap: wrap; }
  .video-fs-h-r .btn { padding: 6px 10px; font-size: 12px; }

  /* Corpo: empilhado (vídeo em cima, painel embaixo) */
  .video-fs-body {
    flex: 1 1 auto;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden;
    position: relative;
  }
  /* Jitsi ocupa o que o painel deixar (transição suave) */
  .video-fs-jitsi {
    width: 100% !important;
    flex: 1 1 auto !important;
    min-height: 200px;
    transition: flex-basis .25s ease;
  }
  /* Painel lateral vira fixo embaixo e ESCAMOTÁVEL */
  .video-fs-side {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 50vh !important;
    border-left: none !important;
    border-top: 1px solid var(--nm-border) !important;
    background: #fff;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden;
    transition: flex-basis .25s ease;
  }
  /* MINIMIZADO: só as abas ficam (56px) — vídeo expande */
  .video-fs-side.minimized {
    flex: 0 0 56px !important;
  }
  .video-fs-side.minimized .video-fs-pane,
  .video-fs-side.minimized .video-fs-side-h {
    display: none !important;
  }
  /* Tabs como botões grandes pra toque */
  .video-fs-tabs {
    flex-shrink: 0;
    padding: 8px;
    gap: 6px;
    background: #fff;
    border-bottom: 1px solid var(--nm-border);
  }
  .video-fs-tab {
    flex: 1;
    height: 40px;
    font-size: 13px;
    font-weight: 600;
  }
  /* Botão flutuante de toggle do painel — minimizar/expandir */
  .video-fs-toggle {
    position: absolute;
    top: 10px; right: 10px;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: rgba(15,23,42,.78);
    color: #fff;
    border: none;
    font-size: 18px;
    z-index: 50;
    box-shadow: 0 4px 14px rgba(0,0,0,.30);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .video-fs-pane {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ============================================================ */
/* v17.10.14 — REVISÃO MOBILE PROFISSIONAL                       */
/* Refinamento amplo de touch, padding, tipografia e bug visuais */
/* ============================================================ */

/* Mobile: padding do conteúdo principal mais apertado e consistente */
@media (max-width: 768px) {
  .nm-content { padding: 14px 12px 88px; }
  .nm-topbar { height: calc(54px + env(safe-area-inset-top, 0px)); padding-left: 64px; padding-right: 12px; }
  .nm-topbar-title { font-size: 14px; }

  /* Cards mobile: padding menor pra caber mais conteúdo */
  .card { padding: 14px; border-radius: 12px; }
  .card-h { gap: 8px; margin-bottom: 10px; }
  .card-t { font-size: 14px; font-weight: 700; }

  /* Stats grid: SEMPRE 2 colunas em mobile (não auto-fit que pode virar 1) */
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 12px; }
  .stat-ic { font-size: 18px; }
  .stat-v { font-size: 19px; line-height: 1.1; }
  .stat-l { font-size: 11px; }

  /* Quick actions: 2 cols mobile (não 4 que aperta demais) */
  .quick-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
  .quick-btn { padding: 14px 10px; min-height: 78px; }
  .quick-btn .ic { font-size: 22px; }

  /* Hero do dashboard menor no mobile */
  .hero { padding: 16px; margin-bottom: 14px; }
  .hero-title { font-size: 20px; line-height: 1.2; }
  .hero-sub { font-size: 13px; }
  .hero-eyebrow { font-size: 11px; }

  /* TOUCH TARGETS: nenhum botão clicável abaixo de 44px no mobile */
  .btn { min-height: 44px; padding: 11px 16px; font-size: 14px; }
  .btn-sm { min-height: 38px; padding: 9px 13px; font-size: 13px; }
  .btn-lg { min-height: 52px; padding: 15px 22px; font-size: 15px; }

  /* INPUTS mobile: font 16px obrigatório pra iOS Safari não dar zoom no foco */
  .input, .select, .textarea,
  input[type="text"], input[type="email"], input[type="password"],
  input[type="tel"], input[type="number"], input[type="search"],
  input[type="date"], input[type="datetime-local"], input[type="time"],
  input[type="url"], textarea, select {
    font-size: 16px !important;
    min-height: 44px;
    padding: 11px 13px;
  }

  /* Labels mais respiradas */
  .field { margin-bottom: 12px; }
  .field label { font-size: 12px; margin-bottom: 5px; display: block; }

  /* Tabelas: scroll horizontal limpo em vez de quebrar layout */
  .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -12px; padding: 0 12px; }
  .tbl { font-size: 13px; min-width: 480px; }
  .tbl th, .tbl td { padding: 8px 10px; }

  /* Modal mobile: ordem correta dos botões + gap + sem perder o footer */
  .nm-md-h { padding: 12px 14px; }
  .nm-md-t { font-size: 15px; }
  .nm-md-x { width: 38px; height: 38px; }
  .nm-md-b { padding: 14px; }
  .nm-md-f { padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0)); gap: 8px; }
  .nm-md-f .btn { min-height: 46px; }

  /* Sidebar mais elegante mobile */
  .nm-sb-h { padding: 18px 18px 12px; }
  .nm-sb-it { padding: 11px 16px; font-size: 14px; }

  /* Atman drawer: 100% mobile, com cabeçalho não sticky-bug */
  .atman { width: 100vw !important; max-width: 100vw !important; }
  .atman-h { padding: 12px 14px; }
  .atman-msg .b { max-width: 92% !important; }

  /* Empty states menores */
  .empty { padding: 28px 16px; }
  .empty-ic { font-size: 36px; margin-bottom: 8px; }
}

/* Mobile MUITO pequeno (≤ 380px): aperta um pouco mais sem quebrar */
@media (max-width: 380px) {
  .nm-content { padding-left: 10px; padding-right: 10px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .quick-grid { gap: 6px; }
  .hero-title { font-size: 18px; }
  .nm-topbar { padding-left: 58px; padding-right: 10px; }
}

/* Anti-overflow horizontal — defesa final contra qualquer conteúdo vazar */
@media (max-width: 768px) {
  html, body { overflow-x: hidden; }
  .nm-main, .nm-content, .card, .nm-md-b { max-width: 100%; }
  pre, code { white-space: pre-wrap; word-break: break-word; }
}

/* iOS específico: smooth scroll + tap delay zero */
@media (max-width: 768px) {
  * { -webkit-tap-highlight-color: rgba(0,0,0,0); }
  button, [role="button"], a { touch-action: manipulation; }
}

/* ============================================================ */
/* v17.10.19 — REFINAMENTO MOBILE: zero trava, zero overlap     */
/* ============================================================ */

/* Mobile: substitui transition:all por transition específica (color, bg, border).
   'all' anima TUDO inclusive layout — gera reflow em cada hover/tap = trava. */
@media (max-width: 768px) {
  .btn, .ap-type-btn, .ap-mod-btn, .cal-views .tab,
  .stat, .quick-btn, .nm-sb-it, .video-fs-tab, .atman-chip {
    transition: background-color .12s ease, border-color .12s ease, color .12s ease, transform .12s ease !important;
  }

  /* Botões: padding consistente, nunca grudam, nunca quebram em zigzag */
  .btn { letter-spacing: 0; }
  /* Garante que ícone + texto dentro do botão respiram */
  .btn > * + * { margin-left: 6px; }

  /* Card-h: título + botões. Botões NUNCA encavalam o título */
  .card-h {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px !important; flex-wrap: wrap;
  }
  .card-h .card-t { flex: 1 1 auto; min-width: 0; }
  .card-h > div:last-child { flex-shrink: 0; }
  /* Quando estourar a linha, todos os botões empilham e ocupam 100% */
  .card-h > div:has(.btn) { display: flex; gap: 8px; flex-wrap: wrap; }

  /* Modal footer: ordem certa (primary embaixo, ghost em cima na column-reverse) */
  .nm-md-f .btn { width: 100%; box-sizing: border-box; }
  .nm-md-f .btn + .btn { margin: 0; }

  /* Inputs com font-size 16px (anti-zoom iOS), padding mais respirado */
  input, select, textarea { font-size: 16px !important; }

  /* Anti-overflow horizontal estrito */
  html, body, .nm-app, .nm-main, .nm-content { overflow-x: hidden; max-width: 100vw; }

  /* Anima header sem reflow: usa transform em vez de top */
  .nm-topbar { transform: translateZ(0); }

  /* Sidebar mobile: nunca corta texto, scroll suave */
  .nm-sb { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  .nm-sb-it { white-space: nowrap; }

  /* Quick-btn: alinhamento perfeito (icon + label centrados) */
  .quick-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; }
  .quick-btn span { display: block; line-height: 1.2; }

  /* Stats: sem hover-shadow no mobile (não tem hover, é só peso visual) */
  .stat-clickable:active { transform: scale(.98); }
  .stat-clickable:hover { box-shadow: none !important; }

  /* Tabs (Resumo/Prontuários/Histórico) com scroll horizontal */
  .pt-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .pt-tabs::-webkit-scrollbar { display: none; }
  .pt-tab { flex-shrink: 0; }
}

/* Mobile pequeno (≤380): aperta gaps e fontes sem quebrar */
@media (max-width: 380px) {
  .nm-md-h { padding: 10px 12px; }
  .nm-md-t { font-size: 14px; }
  .nm-md-x { width: 34px; height: 34px; font-size: 20px; }
  .nm-md-b, .nm-md-f { padding-left: 12px; padding-right: 12px; }
  .card { padding: 12px; }
  .stat { padding: 10px; }
  .stat-v { font-size: 17px; }
}

/* Lazy: pinta animações em compositor (GPU), não na main thread */
.nm-mdbk, .nm-md, .atman, .nm-sb { will-change: transform, opacity; }

/* Desativa animações pra quem prefere reduced motion (acessibilidade + perf) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ============================================================ */
/* v17.10.20 — DEFESA FINAL ANTI-OVERFLOW (universal)            */
/* ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

/* Modal mobile: containers FORÇADOS a respeitar viewport */
@media (max-width: 768px) {
  .nm-mdbk { padding: 0; }
  .nm-md {
    width: 100vw !important;
    max-width: 100vw !important;
    border-radius: 16px 16px 0 0;
    overflow: hidden;
  }
  .nm-md-b, .nm-md-f, .nm-md-h { width: 100%; box-sizing: border-box; }
  .nm-md-f .btn { padding-left: 12px; padding-right: 12px; }

  /* Quando footer tem 4+ botões empilhados (prontuário: Cancelar/Excluir/Modelo
     /Retorno/Imprimir/Salvar = 6 botões), garante scroll vertical dentro
     do footer se passar de 60vh. */
  .nm-md-f {
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Body sempre tem espaço suficiente, mesmo com footer alto */
  .nm-md-b { flex: 1 1 auto; min-height: 0; max-height: calc(92dvh - 60vh - 60px); }

  /* Cards de conteúdo dentro do modal nunca vazam */
  .nm-md-b > * { max-width: 100%; min-width: 0; }
  .nm-md-b img, .nm-md-b iframe, .nm-md-b video { max-width: 100%; height: auto; }

  /* Tabela dentro de modal scrolla horizontal sem quebrar */
  .nm-md-b table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Anti-overflow estrutural: cobre TODA a hierarquia, não só modal */
html, body { max-width: 100%; overflow-x: hidden; }
.nm-app, .nm-main, .nm-content, .card { max-width: 100%; }
img, video, iframe, canvas, svg { max-width: 100%; }
pre, code { white-space: pre-wrap; word-break: break-word; }

/* Tap fluído em qualquer botão/link */
button, a, [role="button"], input[type="submit"], input[type="button"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Inputs nunca quebram layout */
input, textarea, select { max-width: 100%; box-sizing: border-box; }

/* ============================================================ */
/* v17.10.20 — Rodapé institucional (todas as páginas)           */
/* ============================================================ */
.nm-inst-foot {
  width: 100%;
  padding: 16px 24px calc(16px + env(safe-area-inset-bottom, 0));
  background: var(--nm-surface, #fff);
  border-top: 1px solid var(--nm-border, #e5e9f0);
  font-size: 11.5px;
  color: var(--nm-text-mute, #94a3b8);
  text-align: center;
  letter-spacing: .2px;
  line-height: 1.6;
  position: relative;
  z-index: 5;
}
/* v17.10.22 — Rodapé com peso/cor uniforme, sem destaques (clean) */
.nm-inst-foot strong { color: inherit; font-weight: inherit; }
.nm-inst-foot sup { font-size: inherit; vertical-align: baseline; }
.nm-inst-foot-row { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; justify-content: center; max-width: 100%; }
.nm-inst-foot-row + .nm-inst-foot-row { margin-top: 4px; }
.nm-inst-foot-sub { font-size: 10.5px; color: var(--nm-text-mute, #94a3b8); opacity: .9; }
.nm-inst-foot-sep { color: var(--nm-border, #d1d5db); }
@media (max-width: 600px) {
  .nm-inst-foot { padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0)); font-size: 11px; }
  .nm-inst-foot-sep { display: none; }
  .nm-inst-foot-row { gap: 2px 8px; }
  .nm-inst-foot-row > span { display: inline-block; }
}

/* ============================================================ */
/* v17.10.23 — KILL SWITCH FINAL: garante footer sempre dentro    */
/* (usa especificidade alta + !important pra ANULAR overrides     */
/* legados que ainda usavam flex/column-reverse e deixavam botão  */
/* "Cancelar" vazar pra fora do modal no celular)                 */
/* ============================================================ */

/* Modal: contenção absoluta. Nada vaza. */
.nm-mdbk .nm-md {
  contain: layout style;
  overflow: clip; /* mais forte que overflow:hidden, browsers novos */
  position: relative;
}

/* Modal-foot: grid 1-col rígido no mobile, row no desktop. SEMPRE. */
@media (max-width: 768px) {
  .nm-mdbk .nm-md .nm-md-f {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-auto-flow: row !important;
    flex-direction: unset !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0)) !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow: visible !important;
    max-height: none !important;
  }
  .nm-mdbk .nm-md .nm-md-f > * {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    /* Botão "puro" garantido — sem herdar font de h2/h3 do body */
    font-family: inherit !important;
    font-weight: 600 !important;
    font-size: 14px !important;
    line-height: 1.3 !important;
    text-align: center !important;
    white-space: normal !important;
    min-height: 46px !important;
    padding: 11px 14px !important;
    border-radius: 10px !important;
    cursor: pointer !important;
    position: static !important;
    transform: none !important;
    float: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  /* Garante visual mínimo se a classe .btn falhar por qualquer motivo */
  .nm-mdbk .nm-md .nm-md-f > button:not(.btn-primary):not(.btn-danger) {
    background: var(--nm-surface, #fff) !important;
    color: var(--nm-text, #0f172a) !important;
    border: 1.5px solid var(--nm-border, #e5e9f0) !important;
  }
}
