:root {
  --bg-color: #ffffff;
  --text-color: #333333;
  --card-bg: #f8f9fa;
  --link-color: #007bff;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --brand-logo-bg: #ffffff;
  --sidebar-bg: #f8f9fa;

  --topbar-height: 56px;
  --sidebar-width: 250px;
}

/* =========================================================
   DARK THEME
========================================================= */

[data-theme="dark"] {
  --bg-color: #121212;
  --text-color: #e0e0e0;
  --card-bg: #1e1e1e;
  --link-color: #82b1ff;
  --shadow-color: rgba(0, 0, 0, 0.7);
  --brand-logo-bg: #2a2a2a;
  --sidebar-bg: #1e1e1e;
}

/* =========================================================
   BASE
========================================================= */

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  padding: 0 !important;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  opacity: 0.85;
}

[data-theme="dark"] a {
  color: var(--link-color);
}

main {
  margin-left: 0;
}

.content-area {
  min-width: 0;
  width: 100%;
}

/* =========================================================
   TOPBAR ERP
========================================================= */

.topbar {
  background: linear-gradient(90deg, #101318, #1a1f27) !important;
  color: #fff !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}

[data-theme="dark"] .topbar {
  background: linear-gradient(90deg, #101318, #1a1f27) !important;
}

.brand-logo {
  background-color: var(--brand-logo-bg);
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
}

.logo-img {
  display: block;
  height: 32px;
  width: auto;
  object-fit: contain;
}

.page-logo {
  background-color: var(--brand-logo-bg);
  padding: 1rem;
  border-radius: 0.5rem;
  display: inline-block;
}

.page-logo img {
  max-height: 100px;
  width: auto;
  object-fit: contain;
}

/* =========================================================
   SIDEBAR ERP
========================================================= */

.sidebar {
  width: var(--sidebar-width) !important;
  flex-shrink: 0;
  background-color: var(--sidebar-bg);
}

[data-theme="dark"] .sidebar {
  background-color: var(--sidebar-bg) !important;
}

.sidebar a {
  color: var(--text-color);
}

.sidebar a:hover {
  color: var(--link-color);
}

.sidebar .nav-link {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

nav.sidebar ul.nav.flex-column {
  display: block !important;
  gap: 0 !important;
}

nav.sidebar ul.nav.flex-column > li.nav-item {
  margin-bottom: 1rem !important;
}

nav.sidebar ul.nav.flex-column > li.nav-item:last-child {
  margin-bottom: 0 !important;
}

nav.sidebar ul.nav.flex-column li.nav-item a.nav-link {
  display: block !important;
  padding-top: 0.5rem !important;
  padding-bottom: 0.5rem !important;
  line-height: 1.2 !important;
  margin: 0 !important;
}

/* =========================================================
   CARDS / CONTAINERS
========================================================= */

.card-custom {
  background-color: var(--card-bg);
  border-radius: 1.5rem;
  box-shadow: 0 2px 8px var(--shadow-color);
}

.mx-auto {
  width: 100%;
}

@media (min-width: 992px) {
  .mx-auto[style] {
    max-width: 900px !important;
  }
}

.mx-auto .table {
  margin-bottom: 0;
}

/* =========================================================
   EMBEDS / TERMS
========================================================= */

.embed-container {
  position: relative;
  width: 100%;
  height: calc(100vh - 140px);
  overflow: hidden;
  margin-bottom: 0;
}

.embed-container iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.terms-card {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 140px);
}

.terms-content {
  flex: 1;
  overflow: auto;
  margin-bottom: 1rem;
}

/* =========================================================
   CHAT WIDGET ERP
   Estructura esperada:
   #portalChatWrap
     #portalChatLauncher
     #portalChatPanel
========================================================= */

#portalChatWrap {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  pointer-events: auto;

  width: 56px;
  height: 56px;

  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
}

#portalChatLauncher {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  padding: 0 !important;
  background: #0d6efd;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  cursor: grab;
  overflow: hidden;
  touch-action: none;
  will-change: transform, box-shadow;
}

#portalChatLauncher:active {
  cursor: grabbing;
}

#portalChatLauncher img,
#portalChatLauncher .sidebar-chat-icon {
  width: 100% !important;
  height: 100% !important;
  display: block !important;
  object-fit: cover !important;
  border-radius: 50% !important;
}

/* Panel relativo al wrapper: clave para que el drag funcione */
#portalChatPanel {
  position: absolute;
  right: 0;
  bottom: 68px;

  width: 360px;
  height: 460px;

  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);

  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);

  display: none;
  flex-direction: column;
  overflow: hidden;

  transition: width 0.2s ease, height 0.2s ease;
}

#portalChatPanel.open {
  display: flex !important;
  flex-direction: column;
}

#portalChatPanel.open.expanded,
#portalChatPanel.expanded {
  width: min(520px, calc(100vw - 32px));
  height: min(650px, calc(100vh - 80px));
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 60px);
}

/* Posicionamiento dinámico usado por el JS del Portal */
#portalChatPanel.panel-left {
  left: 0;
  right: auto;
}

#portalChatPanel.panel-right {
  right: 0;
  left: auto;
}

#portalChatPanel.panel-up {
  bottom: 68px;
  top: auto;
}

#portalChatPanel.panel-down {
  top: 68px;
  bottom: auto;
}

/* Header del chat */
#portalChatPanel .sidebar-chat-header {
  padding: 10px 12px;
  background: #0d6efd;
  color: #fff;

  display: flex;
  align-items: center;
  justify-content: space-between;

  font-weight: 600;
  cursor: grab;
  touch-action: none;
}

#portalChatPanel .sidebar-chat-header:active {
  cursor: grabbing;
}

.sidebar-chat-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 28px;
  background: rgba(255, 255, 255, 0.15);
}

.sidebar-chat-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: 50%;
}

.sidebar-chat-title {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.sidebar-chat-subtitle {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
}

#portalChatClose,
#portalChatExpand {
  background: transparent !important;
  border: none !important;
  color: #fff !important;
  font-size: 18px;
  cursor: pointer;
  box-shadow: none !important;
  text-decoration: none !important;
  line-height: 1;
}

/* Body */
#portalChatBody {
  flex: 1 1 auto;
  padding: 10px;
  overflow-y: auto;
  background: #f7f8fa;
}

/* Mensajes */
.sidebar-chat-msg {
  margin-bottom: 8px;
  display: flex;
}

.sidebar-chat-msg.bot {
  justify-content: flex-start;
}

.sidebar-chat-msg.user {
  justify-content: flex-end;
}

.sidebar-chat-bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.35;
  word-break: break-word;
  white-space: pre-wrap;
}

.sidebar-chat-msg.bot .sidebar-chat-bubble {
  background: #e9ecef;
  color: #111;
}

.sidebar-chat-msg.user .sidebar-chat-bubble {
  background: #0d6efd;
  color: #fff;
}

/* Form */
#portalChatForm {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid #ddd;
  background: #fff;
}

#portalChatInput {
  flex: 1 1 auto;
  min-width: 0;
  border-radius: 20px;
  padding: 6px 12px;
  border: 1px solid #ccc;
  font-size: 14px;
}

#portalChatMic,
#portalChatSpeakToggle,
#portalChatStopSpeak,
#portalChatForm button[type="submit"] {
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 14px;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  flex: 0 0 34px;
  padding: 0;
}

#portalChatMic,
#portalChatSpeakToggle,
#portalChatStopSpeak {
  border: 1px solid #ccc;
  background: #fff;
}

#portalChatMic.is-listening {
  border-color: #dc3545;
  color: #dc3545;
  animation: portalChatPulse 1s infinite;
}

#portalChatSpeakToggle.is-on {
  border-color: #0d6efd;
  color: #0d6efd;
}

#portalChatMic.is-conversation {
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.20);
}

#portalChatWrap.is-dragging #portalChatLauncher,
#portalChatWrap.is-dragging .sidebar-chat-header {
  cursor: grabbing !important;
}

/* Micro animación del launcher */
#portalChatLauncher.is-alive {
  animation: chatAliveFloat 5.2s ease-in-out infinite;
}

@keyframes chatAliveFloat {
  0%, 70%, 100% {
    transform: translateY(0);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.22);
  }

  78% {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24);
  }

  86% {
    transform: translateY(0);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.22);
  }

  92% {
    transform: translateY(-1px);
    box-shadow: 0 11px 22px rgba(0, 0, 0, 0.23);
  }
}

@keyframes portalChatPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  #portalChatLauncher.is-alive,
  #portalChatMic.is-listening {
    animation: none !important;
  }
}

/* Mobile: no arrastrar, queda fijo abajo */
@media (max-width: 768px) {
  #portalChatWrap {
    right: 16px !important;
    bottom: 16px !important;
    left: auto !important;
    top: auto !important;
  }

  #portalChatPanel {
    right: 0;
    left: auto;
    bottom: 68px;
    top: auto;

    width: calc(100vw - 32px);
    height: 60vh;
  }

  #portalChatPanel.open.expanded,
  #portalChatPanel.expanded {
    width: calc(100vw - 32px);
    height: calc(100vh - 140px);
  }
}

@media (min-width: 992px) {
  #portalChatWrap {
    right: 20px;
    bottom: 20px;
  }

  #portalChatPanel {
    max-height: 60vh;
  }
}

/* =========================================================
   DARK MODE PARA CHAT
========================================================= */

body[data-theme="dark"] #portalChatPanel {
  background: #1e1e1e;
  color: var(--text-color);
  border: 1px solid rgba(255, 255, 255, 0.10);
}

body[data-theme="dark"] #portalChatBody {
  background: #151515;
}

body[data-theme="dark"] #portalChatForm {
  background: #1e1e1e;
  border-top-color: rgba(255, 255, 255, 0.10);
}

body[data-theme="dark"] #portalChatInput {
  background: #252525;
  color: var(--text-color);
  border-color: rgba(255, 255, 255, 0.14);
}

body[data-theme="dark"] #portalChatInput::placeholder {
  color: rgba(224, 224, 224, 0.62);
}

body[data-theme="dark"] .sidebar-chat-msg.bot .sidebar-chat-bubble {
  background: #2a2a2a;
  color: var(--text-color);
}

body[data-theme="dark"] #portalChatMic,
body[data-theme="dark"] #portalChatSpeakToggle,
body[data-theme="dark"] #portalChatStopSpeak {
  background: #252525;
  color: var(--text-color);
  border-color: rgba(255, 255, 255, 0.14);
}

/* =========================================================
   OKR / FULLSCREEN — queda por compatibilidad si alguna pantalla ERP lo usa
========================================================= */

#okr-summary:fullscreen,
#okr-summary:-webkit-full-screen {
  width: 100% !important;
  height: 100% !important;
  margin: 0;
  padding: 1rem;
  background: var(--bg-color);
  overflow: auto;
}

#okr-fullscreen-container:-webkit-full-screen,
#okr-fullscreen-container:-moz-full-screen,
#okr-fullscreen-container:fullscreen {
  height: 100vh;
  overflow-y: auto;
}

#okr-summary {
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

