/**
 * Cardionet — Layout definitivo módulo Gestión
 * Alcance: body.cn-gestion-active y #dashboard-gestion-root únicamente.
 *
 * Un solo scroll: el de .dashboard-gestion-body (datos del paciente).
 * html/body/.wrapper/.content-wrapper quedan estáticos (sin scrollbar externo).
 */

 :root {
  --dgl-border: #e2e8f0;
  --dgl-bg: #f0f4f8;
  --dgl-surface: #ffffff;
  --dgl-header-h: var(--cn-header-height, 50px);
  --dgl-footer-h: 42px;
  --dgl-sidebar-w: var(--cn-sidebar-width, 240px);
  --dgl-sidebar-mini-w: 50px;
}

/* Bloquear scroll de página (scrollbar de la derecha) */
html:has(#dashboard-gestion-root),
body:has(#dashboard-gestion-root),
html.cn-gestion-active,
body.cn-gestion-active {
  height: 100% !important;
  overflow: hidden !important;
}

body:has(#dashboard-gestion-root) .wrapper,
body.cn-gestion-active .wrapper {
  height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

/* ── Shell bajo el header principal ── */
body.fixed .content-wrapper:has(#dashboard-gestion-root),
body.skin-blue.fixed .content-wrapper:has(#dashboard-gestion-root),
body.fixed.cn-gestion-active .content-wrapper,
body.skin-blue.fixed.cn-gestion-active .content-wrapper,
body.cn-gestion-active .content-wrapper,
.content-wrapper:has(#dashboard-gestion-root) {
  margin-top: var(--dgl-header-h) !important;
  padding: 0 !important;
  padding-top: 0 !important;
  height: calc(100vh - var(--dgl-header-h)) !important;
  min-height: 0 !important;
  max-height: calc(100vh - var(--dgl-header-h)) !important;
  background: var(--dgl-bg) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  margin-bottom: 0 !important;
  box-shadow: none !important;
  border: none !important;
}

body.cn-gestion-active .content-wrapper > .content.cn-gestion-shell,
body.cn-gestion-active .content-wrapper > .content,
.content-wrapper:has(#dashboard-gestion-root) > .content {
  flex: 1 1 auto !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  max-height: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
  width: 100% !important;
}

body.cn-gestion-active .content-wrapper > .content > .row.cn-gestion-host-row,
body.cn-gestion-active .content-wrapper > .content > .row,
.content-wrapper:has(#dashboard-gestion-root) > .content > .row {
  flex: 1 1 auto !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  margin: 0 !important;
  width: 100% !important;
}

body.cn-gestion-active .cn-gestion-host-box,
body.cn-gestion-active .content-wrapper > .content > .row > .box,
.content-wrapper:has(#dashboard-gestion-root) > .content > .row > .box {
  flex: 1 1 auto !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  overflow: hidden !important;
}

body.cn-gestion-active #cuerpo,
.content-wrapper:has(#dashboard-gestion-root) #cuerpo {
  flex: 1 1 auto !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

/* Footer fijo: no empuja el alto del documento (evita 2º scrollbar) */
body:has(#dashboard-gestion-root) .main-footer,
body.cn-gestion-active .main-footer {
  position: fixed !important;
  left: var(--dgl-sidebar-w) !important;
  right: 0 !important;
  bottom: 0 !important;
  width: auto !important;
  height: var(--dgl-footer-h) !important;
  margin: 0 !important;
  margin-left: 0 !important;
  padding: 10px 15px !important;
  z-index: 830 !important;
  background: #fff !important;
  border-top: 1px solid #e2e8f0 !important;
  box-shadow: none !important;
  line-height: 20px !important;
  overflow: hidden !important;
}

body.sidebar-mini.sidebar-collapse:has(#dashboard-gestion-root) .main-footer,
body.cn-gestion-active.sidebar-mini.sidebar-collapse .main-footer {
  left: var(--dgl-sidebar-mini-w) !important;
}

@media (max-width: 767px) {
  body:has(#dashboard-gestion-root) .main-footer,
  body.cn-gestion-active .main-footer {
    left: 0 !important;
  }
}

body.cn-gestion-active .cn-gestion-host-box > audio {
  position: absolute !important;
  width: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ── Raíz Gestión (sin clase AdminLTE .content) ── */
#dashboard-gestion-root.dashboard-gestion-root {
  flex: 1 1 auto !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  width: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow: hidden !important;
}

/* Cabecera pegada al tope del área útil */
#dashboard-gestion-root .dashboard-gestion-header {
  flex: 0 0 auto !important;
  margin: 0 !important;
  padding: 6px 12px 8px !important;
  background: var(--dgl-surface) !important;
  border: none !important;
  border-bottom: 1px solid var(--dgl-border) !important;
  border-radius: 0 !important;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06) !important;
  overflow: hidden !important;
}

#dashboard-gestion-root .dashboard-nav-bar {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 8px 10px !important;
  flex-wrap: wrap !important;
  width: 100% !important;
  margin: 0 !important;
  min-height: 38px !important;
}

#dashboard-gestion-root .dashboard-nav-tabs {
  display: flex !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
  flex: 1 1 auto !important;
  min-width: 0 !important;
}

#dashboard-gestion-root .dashboard-nav-meta {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  flex: 0 1 auto !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
  margin: 0 !important;
  padding: 0 !important;
  min-width: 0 !important;
}

#dashboard-gestion-root .dashboard-nav-meta #dashboard-top-actions {
  display: flex !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
  min-height: 34px !important;
}

#dashboard-gestion-root .btn-folder {
  min-width: 96px !important;
  margin: 0 !important;
  padding: 7px 12px !important;
}

#dashboard-gestion-root .btn-estado {
  max-width: min(360px, 42vw) !important;
  font-size: 12px !important;
  padding: 6px 10px !important;
  line-height: 1.3 !important;
  white-space: normal !important;
  text-align: left !important;
}

#dashboard-gestion-root .dashboard-metrics-row {
  display: flex !important;
  gap: 8px !important;
  margin: 8px 0 0 !important;
  flex-wrap: wrap !important;
}

#dashboard-gestion-root .dashboard-metric-card {
  flex: 1 1 0 !important;
  min-width: 110px !important;
  padding: 7px 10px !important;
  border-radius: 8px !important;
  background: #f8fafc !important;
  border: 1px solid var(--dgl-border) !important;
}

#dashboard-gestion-root .dashboard-metric-card .metric-value {
  font-size: 18px !important;
  line-height: 1.15 !important;
}

#dashboard-gestion-root .dashboard-metric-card .metric-label {
  font-size: 10px !important;
  margin-top: 1px !important;
}

/* Cuerpo con scroll interno (ÚNICO scrollbar de gestión) */
#dashboard-gestion-root .dashboard-gestion-body {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  padding: 8px 10px calc(10px + var(--dgl-footer-h)) !important;
  -webkit-overflow-scrolling: touch;
}

#dashboard-gestion-root .dashboard-gestion-panel.box {
  margin: 0 !important;
  border-radius: 12px !important;
  border: 1px solid var(--dgl-border) !important;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05) !important;
  background: var(--dgl-surface) !important;
  overflow: hidden !important;
}

#dashboard-gestion-root .dashboard-gestion-panel > [id$="Section"] > div[style*="border:1px solid #750f1b"] {
  border-color: #e2e8f0 !important;
  padding: 10px !important;
}

@media (max-width: 991px) {
  #dashboard-gestion-root .dashboard-nav-bar {
    align-items: stretch !important;
  }

  #dashboard-gestion-root .dashboard-nav-tabs,
  #dashboard-gestion-root .dashboard-nav-meta {
    width: 100% !important;
    justify-content: flex-start !important;
  }

  #dashboard-gestion-root .btn-folder {
    flex: 1 1 calc(33.333% - 6px) !important;
    min-width: 88px !important;
  }

  #dashboard-gestion-root .btn-estado {
    max-width: 100% !important;
    width: 100% !important;
  }
}

@media (max-width: 767px) {
  #dashboard-gestion-root .dashboard-gestion-header {
    padding: 6px 8px 8px !important;
  }

  #dashboard-gestion-root .dashboard-gestion-body {
    padding: 6px 6px 8px !important;
  }

  /* Tabs Info/Consulta/Chat en una sola fila scrolleable (no apilados) */
  #dashboard-gestion-root .dashboard-nav-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  #dashboard-gestion-root .btn-folder {
    flex: 1 1 0 !important;
    min-width: 96px !important;
    width: auto !important;
  }

  /* Metricas movil: 2 columnas compactas (no apilar 5 filas) */
  #dashboard-gestion-root .dashboard-metrics-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 6px !important;
    overflow: visible !important;
    flex-wrap: unset !important;
    margin: 6px 0 8px !important;
  }

  #dashboard-gestion-root .dashboard-metric-card {
    min-width: 0 !important;
    width: auto !important;
    flex: none !important;
    padding: 6px 8px !important;
  }

  #dashboard-gestion-root .dashboard-metric-card .metric-value {
    font-size: 16px !important;
  }

  #dashboard-gestion-root .dashboard-metric-card .metric-label {
    white-space: normal !important;
    overflow: hidden !important;
    display: -webkit-box !important;
    -webkit-box-orient: vertical !important;
    -webkit-line-clamp: 2 !important;
    line-clamp: 2 !important;
    font-size: 10px !important;
    line-height: 1.2 !important;
  }
}

/* ── Chat pestaña Gestión (NO omnicanalidad) ── */
#dashboard-gestion-root.cn-gestion-chat-tab {
  --cn-gestion-chat-stack: 300px;
  min-height: 0 !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab .dashboard-gestion-body {
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  flex: 1 1 0% !important;
  height: auto !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab .dashboard-gestion-panel {
  flex: 1 1 0% !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 280px !important;
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  overflow: hidden !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chatSection.cn-gestion-chat-section {
  flex: 1 1 0% !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  overflow: hidden !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #cn-gestion-chat-shell {
  flex: 1 1 0% !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  overflow: hidden !important;
  gap: 8px !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente.cn-gestion-chat-header {
  flex: 0 0 auto !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente .client-info {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 12px !important;
  flex-wrap: wrap !important;
  margin: 0 !important;
  padding: 12px 14px !important;
  border-radius: 12px !important;
  border: 1px solid var(--dgl-border) !important;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05) !important;
  background: linear-gradient(135deg, #ffffff 0%, #f0f7fc 100%) !important;
  font-size: 12px !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente .client-avatar {
  width: 48px !important;
  height: 48px !important;
  max-width: 48px !important;
  max-height: 48px !important;
  min-width: 48px !important;
  min-height: 48px !important;
  flex-shrink: 0 !important;
  border-radius: 50% !important;
  object-fit: contain !important;
  box-sizing: border-box !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente .client-avatar--paciente {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: linear-gradient(145deg, #14b8a6 0%, #0f766e 100%) !important;
  color: #fff !important;
  border: 2px solid #ccfbf1 !important;
  box-shadow: 0 2px 8px rgba(15, 118, 110, 0.28) !important;
  padding: 0 !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente .client-avatar--paciente > i {
  font-size: 26px !important;
  line-height: 1 !important;
  color: #fff !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente .client-avatar--paciente > span {
  display: none !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente .client-details {
  flex: 1 1 160px !important;
  min-width: 0 !important;
  margin: 0 !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente .client-name {
  font-size: 16px !important;
  font-weight: 700 !important;
  margin: 0 !important;
  color: #1e293b !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente .client-phone {
  font-size: 12px !important;
  margin: 2px 0 0 !important;
  color: #64748b !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente .cha-hdr-actions {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex-wrap: wrap !important;
  flex-shrink: 0 !important;
  margin-left: auto !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #cn-gestion-chat-section.cn-gestion-chat-main {
  flex: 1 1 0% !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #cn-gestion-chat-section > .row {
  flex: 1 1 0% !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  margin: 0 !important;
  overflow: hidden !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #cn-gestion-chat-section .col-md-12 {
  flex: 1 1 0% !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  padding: 0 !important;
  float: none !important;
  width: 100% !important;
  overflow: hidden !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab .cn-gestion-chat-panel.direct-chat.box {
  flex: 1 1 0% !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  margin: 0 !important;
  overflow: visible !important;
  border-radius: 12px !important;
  border: 1px solid var(--dgl-border) !important;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06) !important;
  background: #fff !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab .cn-gestion-chat-panel .box-body {
  flex: 1 1 0% !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  overflow: hidden !important;
  padding: 0 !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat-messages.direct-chat-messages {
  flex: 1 1 0% !important;
  min-height: 120px !important;
  height: auto !important;
  max-height: calc(100vh - var(--cn-gestion-chat-stack)) !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  padding: 12px 14px !important;
  background: #f8fafc !important;
  box-sizing: border-box !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #uploaded-image-container,
#dashboard-gestion-root.cn-gestion-chat-tab #uploaded-emoji-container {
  flex: 0 0 auto !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente_datos.cn-gestion-chat-composer {
  flex: 0 0 auto !important;
  position: relative !important;
  z-index: 5 !important;
  width: 100% !important;
  min-height: 76px !important;
  margin: 0 !important;
  padding: 10px 14px 14px !important;
  background: #f0f2f5 !important;
  border-top: 1px solid #d8e2ec !important;
  border-radius: 0 0 12px 12px !important;
  display: flex !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
  overflow: visible !important;
  box-sizing: border-box !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab .cn-gestion-chat-composer-loading {
  flex: 1 1 100% !important;
  color: #64748b !important;
  font-size: 13px !important;
  padding: 8px 4px !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente_datos #message.form-control {
  flex: 1 1 180px !important;
  min-width: 120px !important;
  margin: 0 !important;
  border-radius: 22px !important;
  border: 1px solid #d8e2ec !important;
  min-height: 42px !important;
  max-height: 120px !important;
  resize: none !important;
  padding: 9px 16px !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente_datos .btn-send {
  border-radius: 50% !important;
  width: 44px !important;
  height: 44px !important;
  padding: 0 !important;
  flex-shrink: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente_datos .attachment-menu {
  position: relative !important;
  flex-shrink: 0 !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente_datos .attachment-menu-btn,
#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente_datos #emoji-button {
  border: none !important;
  background: transparent !important;
  font-size: 20px !important;
  cursor: pointer !important;
  color: #54656f !important;
  flex-shrink: 0 !important;
}

#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente_datos .box-footer .alert,
#dashboard-gestion-root.cn-gestion-chat-tab #chat_total_cliente_datos .alert {
  flex: 1 1 100% !important;
  margin: 0 !important;
}

@media (max-width: 991px) {
  #dashboard-gestion-root.cn-gestion-chat-tab {
    --cn-gestion-chat-stack: 340px;
  }
}
