/*
 * NES Premium Layout — Definitivo
 * Ativado por: body.nes-premium-active
 * Não altera nada sem essa classe. Zero impacto na UI original.
 * ---------------------------------------------------------------- */

/* ── Variáveis de layout ───────────────────────────────────────── */
body.nes-premium-active {
  --np-topbar-h:   52px;
  --np-sidebar-w:  250px;
  --np-offset:     52px;   /* atualizado por JS: topbar + patient bar */
  --np-navy:       #0c2340;
  --np-navy-md:    #1a3a6b;
  --np-teal:       #00897b;
  --np-teal-dk:    #00695c;
  --np-teal-lt:    #e0f2f1;
  --np-gray-bg:    #f2f5f8;
  --np-border:     #e2e8f0;
  --np-white:      #ffffff;
  --np-shadow-sm:  0 1px 3px rgba(0,0,0,.08);
  --np-shadow-md:  0 4px 16px rgba(0,0,0,.12);
}

/* ── Topbar ────────────────────────────────────────────────────── */
body.nes-premium-active #app-screen .farm-hero.painel-header.topbar,
body.nes-premium-active #app-screen .nes-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 900;
  height: var(--np-topbar-h);
  min-height: var(--np-topbar-h);
  padding: 0;
  background: var(--np-navy);
  box-shadow: 0 1px 0 rgba(255,255,255,.06);
}

body.nes-premium-active #app-screen .farm-hero-inner {
  height: var(--np-topbar-h);
  max-width: none;
  padding: 0 12px;
  gap: 8px;
}

/* Ocultar hamburger antigo — o premium usa o próprio */
body.nes-premium-active #app-screen .sidebar-hamburger {
  display: none !important;
}

/* ── Barra do paciente ativo ───────────────────────────────────── */
body.nes-premium-active #paciente-ativo-bar {
  position: fixed;
  top: var(--np-topbar-h);
  left: 0;
  right: 0;
  z-index: 850;
  background: #0f2d56;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: none;           /* visível só após JS detectar paciente ou estado vazio */
  flex-direction: column;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  /* Cap de segurança: impede que tags clínicas com wrap exploda o layout */
  max-height: 120px;
  overflow: hidden;
}

body.nes-premium-active #paciente-ativo-bar.visible {
  display: flex !important;
}

/* Linha 1 — identificação */
body.nes-premium-active .np-pbar-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 14px 3px;
  min-height: 38px;
  max-height: 46px;
  overflow: hidden;
}

/* Avatar */
body.nes-premium-active #nes-pb-avatar,
body.nes-premium-active .np-pbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--np-navy-md), var(--np-teal));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: .02em;
}

/* Nome do paciente — protagonista */
body.nes-premium-active #nes-pb-nome {
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -.01em;
  white-space: nowrap;
}

/* Chips de dados demográficos */
body.nes-premium-active .np-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: rgba(255,255,255,.72);
  white-space: nowrap;
}

body.nes-premium-active .np-chip-sep {
  color: rgba(255,255,255,.25);
  font-size: 11px;
}

/* Tags clínicas — nowrap para manter a barra em altura fixa */
body.nes-premium-active #nes-pb-tags {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

body.nes-premium-active #nes-pb-tags .patient-bar-tag,
body.nes-premium-active #nes-pb-tags > span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  border: 0.5px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.09);
  color: rgba(255,255,255,.85);
  white-space: nowrap;
}

/* Tags com classe de severidade */
body.nes-premium-active #nes-pb-tags .tag-danger,
body.nes-premium-active #nes-pb-tags [class*="alergia"],
body.nes-premium-active #nes-pb-tags [class*="alerg"] {
  background: rgba(239,68,68,.2);
  border-color: rgba(239,68,68,.35);
  color: #fca5a5;
}

body.nes-premium-active #nes-pb-tags .tag-warning {
  background: rgba(245,158,11,.2);
  border-color: rgba(245,158,11,.3);
  color: #fcd34d;
}

body.nes-premium-active #nes-pb-tags .tag-ok,
body.nes-premium-active #nes-pb-tags .tag-success {
  background: rgba(0,137,123,.22);
  border-color: rgba(0,137,123,.35);
  color: #5eead4;
}

/* Linha 2 — ações rápidas */
body.nes-premium-active .np-pbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 14px 5px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  max-height: 36px;
}

body.nes-premium-active .np-pbar-actions::-webkit-scrollbar { display: none; }

body.nes-premium-active .np-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: 6px;
  border: 0.5px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s;
  flex-shrink: 0;
}

body.nes-premium-active .np-action-btn:hover {
  background: rgba(255,255,255,.18);
}

body.nes-premium-active .np-action-btn.pri {
  background: var(--np-teal);
  border-color: var(--np-teal);
}

body.nes-premium-active .np-action-btn.pri:hover {
  background: var(--np-teal-dk);
}

body.nes-premium-active .np-action-btn.ghost {
  background: transparent;
  border-color: rgba(255,255,255,.12);
  color: rgba(255,255,255,.55);
}

body.nes-premium-active .np-action-btn.ghost:hover {
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.8);
}

body.nes-premium-active .np-action-divider {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,.15);
  flex-shrink: 0;
  margin: 0 4px;
}

/* Estado sem paciente */
body.nes-premium-active #paciente-ativo-bar.np-sem-paciente .np-pbar-identity {
  opacity: .5;
  pointer-events: none;
}

body.nes-premium-active #paciente-ativo-bar.np-sem-paciente .np-pbar-actions {
  opacity: .45;
  pointer-events: none;
}

body.nes-premium-active .np-pbar-vazio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 11px;
  color: rgba(255,255,255,.45);
}

body.nes-premium-active #nes-pb-empty-state {
  padding: 0 !important;
}

/* ── Adaptações HTML real (.patient-bar-inner = identidade no farmaceutico.html) ── */

/* Ocultar botões legados — premium usa .np-pbar-actions */
body.nes-premium-active #paciente-ativo-bar .patient-bar-actions,
body.nes-premium-active #paciente-ativo-bar .patient-actions {
  display: none !important;
}

/* Paciente ativo: mostrar identidade e ocultar empty state */
body.nes-premium-active #paciente-ativo-bar.patient-active .patient-bar-inner,
body.nes-premium-active #paciente-ativo-bar.patient-active .patient-main {
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 7px 14px 5px;
  min-height: 44px;
}

body.nes-premium-active #paciente-ativo-bar.patient-active #nes-pb-empty-state,
body.nes-premium-active #paciente-ativo-bar.patient-active .nes-pb-empty-state {
  display: none !important;
}

/* Sem paciente: manter identidade oculta */
body.nes-premium-active #paciente-ativo-bar:not(.patient-active) .patient-bar-inner,
body.nes-premium-active #paciente-ativo-bar:not(.patient-active) .patient-main {
  display: none !important;
}

/* Info do paciente (nome + meta + tags) em coluna */
body.nes-premium-active #paciente-ativo-bar .patient-bar-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

/* ── Layout principal ──────────────────────────────────────────── */
body.nes-premium-active #app-screen .farm-layout.layout.app {
  display: grid;
  grid-template-columns: var(--np-sidebar-w) 1fr;
  /* !important necessário: nes-painel-farmaceutico.css e nes-painel-layout.css
     definem margin-top: 64px com seletores menos específicos que conflitam */
  margin-top: var(--np-offset) !important;
  min-height: calc(100vh - var(--np-offset));
  background: var(--np-gray-bg);
}

body.nes-premium-active #app-screen .farm-main.main-content,
body.nes-premium-active #app-screen .nes-main {
  background: var(--np-gray-bg);
  padding: 18px 20px 80px;
  overflow-y: auto;
  height: calc(100vh - var(--np-offset));
  max-height: none;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
body.nes-premium-active #app-screen .farm-sidebar.sidebar {
  width: var(--np-sidebar-w);
  min-width: var(--np-sidebar-w);
  background: var(--np-navy);
  padding: 0;
  height: calc(100vh - var(--np-offset));
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.06);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}

body.nes-premium-active #app-screen .farm-sidebar.sidebar::-webkit-scrollbar { width: 3px; }
body.nes-premium-active #app-screen .farm-sidebar.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.1);
  border-radius: 2px;
}

/* Ocultar nav antiga na sidebar */
body.nes-premium-active #btn-nav-dashboard,
body.nes-premium-active #btn-nav-metodo-nes,
body.nes-premium-active #btn-nav-servicos,
body.nes-premium-active #sidebar-paciente-ativo {
  display: none !important;
}

/* Empurrar busca e lista para o final da sidebar */
body.nes-premium-active #app-screen .sidebar-search {
  padding: 8px 10px;
  border-top: 1px solid rgba(255,255,255,.07);
  border-bottom: 1px solid rgba(255,255,255,.07);
  background: rgba(0,0,0,.12);
  flex-shrink: 0;
}

body.nes-premium-active #app-screen .sidebar-search input,
body.nes-premium-active #app-screen #busca-paciente {
  width: 100%;
  background: rgba(255,255,255,.07);
  border: 0.5px solid rgba(255,255,255,.14);
  border-radius: 6px;
  padding: 6px 9px;
  color: #fff;
  font-size: 11px;
}

body.nes-premium-active #app-screen .sidebar-search input::placeholder,
body.nes-premium-active #app-screen #busca-paciente::placeholder {
  color: rgba(255,255,255,.38);
}

body.nes-premium-active #app-screen .paciente-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* ── Mobile drawer ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  body.nes-premium-active #app-screen .farm-layout.layout.app {
    grid-template-columns: 1fr;
  }

  body.nes-premium-active #app-screen .farm-sidebar.sidebar {
    position: fixed;
    top: var(--np-offset);
    left: 0;
    bottom: 0;
    height: auto;
    z-index: 800;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: none;
    width: min(var(--np-sidebar-w), 80vw);
  }

  body.nes-premium-active #app-screen .farm-sidebar.sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: var(--np-shadow-md);
  }

  body.nes-premium-active #app-screen .farm-main.main-content {
    height: calc(100vh - var(--np-offset));
    padding: 14px 14px 60px;
  }

  /* Botão mobile no topbar */
  body.nes-premium-active .np-mobile-btn {
    display: inline-flex !important;
  }

  /* Linha de ações da barra de paciente vira scroll horizontal */
  body.nes-premium-active .np-pbar-actions {
    padding: 4px 10px 6px;
    gap: 5px;
  }

  body.nes-premium-active .np-action-btn {
    padding: 4px 9px;
    font-size: 10px;
  }
}

@media (min-width: 901px) {
  body.nes-premium-active .np-mobile-btn {
    display: none !important;
  }
}
