/* ==========================================================================
   IBERLEY IA - ESTILOS DEL PANEL LATERAL PARA MICROSOFT WORD
   Diseño corporativo Legal-Tech: Tipografía moderna, paleta azul institucional,
   microinteracciones fluidas y componentes accesibles.
   ========================================================================== */

:root {
  --ib-primary: #091E34;
  --ib-primary-hover: #061525;
  --ib-accent: #0077FF;
  --ib-accent-hover: #0062D6;
  --ib-accent-subtle: #EFF6FF;
  --ib-accent-glow: rgba(0, 119, 255, 0.16);
  --ib-gold: #D97706;
  --ib-gold-subtle: #FEF3C7;
  --ib-success: #10B981;
  --ib-success-subtle: #ECFDF5;
  --ib-warning: #F59E0B;
  --ib-warning-subtle: #FFFBEB;
  --ib-danger: #EF4444;
  --ib-danger-subtle: #FEF2F2;
  
  --ib-bg: #F8FAFC;
  --ib-card-bg: #FFFFFF;
  --ib-border: #E2E8F0;
  --ib-border-strong: #CBD5E1;
  
  --ib-text-main: #0F172A;
  --ib-text-muted: #64748B;
  --ib-text-subtle: #94A3B8;
  
  --ib-radius-xs: 4px;
  --ib-radius-sm: 8px;
  --ib-radius-md: 12px;
  --ib-radius-lg: 16px;
  --ib-radius-full: 9999px;
  
  --ib-shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --ib-shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.03);
  --ib-shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  --ib-shadow-lg: 0 12px 24px -4px rgba(15, 23, 42, 0.12), 0 4px 8px -2px rgba(15, 23, 42, 0.06);
  --ib-shadow-float: 0 -8px 24px -4px rgba(10, 37, 64, 0.12), 0 -2px 6px -1px rgba(10, 37, 64, 0.04);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--ib-bg);
  color: var(--ib-text-main);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Scrollbar estilizada */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

/* --------------------------------------------------------------------------
   LAYOUT GENERAL Y CONTENEDORES
   -------------------------------------------------------------------------- */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* Cabecera Corporativa (Compacta y con jerarquía de marca equilibrada) */
.app-header {
  background: linear-gradient(135deg, #091E34 0%, #0F3057 100%);
  color: #FFFFFF;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 42px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo-img {
  height: 32px;
  width: auto;
  max-width: 150px;
  object-fit: contain;
  transition: transform 0.2s ease;
}

.brand-logo-img:hover {
  transform: scale(1.02);
}

.brand-titles {
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid rgba(255, 255, 255, 0.25);
  padding-left: 10px;
  height: 22px;
}

.brand-subtitle {
  font-size: 9px;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
  line-height: 1;
  margin-top: 1px;
}

.landing-logo-wrapper {
  margin-bottom: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.landing-logo-img {
  height: 52px;
  width: auto;
  max-width: 200px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.06));
}

/* Perfil de Usuario en Cabecera */
.header-profile-container {
  position: relative;
  display: flex;
  align-items: center;
}

.header-profile-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--ib-radius-full);
  padding: 2px 7px 2px 3px;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  color: #FFFFFF;
  transition: all 0.2s ease;
}

.header-profile-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.35);
  transform: translateY(-1px);
}

.header-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00D2FF, #0077FF);
  color: #FFFFFF;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  letter-spacing: -0.5px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.header-chevron {
  stroke: rgba(255, 255, 255, 0.85);
  transition: transform 0.2s ease;
}

.header-profile-btn.active .header-chevron {
  transform: rotate(180deg);
}

/* Popover Flotante de Perfil */
.profile-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #FFFFFF;
  border-radius: var(--ib-radius-md);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--ib-border);
  min-width: 220px;
  padding: 12px;
  z-index: 1000;
  color: var(--ib-text-main);
  animation: popoverFadeIn 0.15s ease-out;
}

@keyframes popoverFadeIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.popover-user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.popover-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ib-primary), #0077FF);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  flex-shrink: 0;
}

.popover-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.popover-name {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ib-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.popover-email {
  font-size: 11px;
  color: var(--ib-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.popover-divider {
  height: 1px;
  background: var(--ib-border);
  margin: 8px -12px;
}

.popover-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  padding: 3px 0;
}

.popover-meta-label {
  color: var(--ib-text-muted);
}

.popover-meta-val {
  color: var(--ib-text-main);
  font-weight: 600;
}

.popover-logout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  margin-top: 4px;
  background: #FEF2F2;
  border: 1px solid #FEE2E2;
  border-radius: var(--ib-radius-sm);
  color: #DC2626;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.popover-logout-btn:hover {
  background: #FEE2E2;
  border-color: #FECACA;
  color: #B91C1C;
}

/* Área de Contenido Principal */
.main-content {
  flex: 1;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 0;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   VISTAS Y PANELES
   -------------------------------------------------------------------------- */
.view-panel {
  display: none;
  animation: fadeIn 0.2s ease-in-out forwards;
}

.view-panel.active {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

#viewWorkspace.active {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  height: 100%;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Tarjeta Landing / Login */
.card-landing {
  background: var(--ib-card-bg);
  border: 1px solid var(--ib-border);
  border-radius: var(--ib-radius-lg);
  padding: 24px 18px;
  text-align: center;
  box-shadow: var(--ib-shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.landing-icon-container {
  width: 56px;
  height: 56px;
  background: var(--ib-accent-subtle);
  border-radius: var(--ib-radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.landing-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--ib-primary);
  margin-bottom: 8px;
}

.landing-description {
  font-size: 12px;
  color: var(--ib-text-muted);
  line-height: 1.5;
  margin-bottom: 20px;
}

.features-list {
  text-align: left;
  width: 100%;
  margin-bottom: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-chip-btn {
  background: #F8FAFC;
  border: 1px solid var(--ib-border);
  border-radius: var(--ib-radius-sm);
  padding: 6px 8px;
  font-size: 11px;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 1px;
  transition: all 0.15s;
}
.profile-chip-btn:hover {
  border-color: var(--ib-accent);
  background: #EFF6FF;
}

.feature-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 11.5px;
  color: var(--ib-text-main);
}

.feature-icon {
  color: var(--ib-accent);
  font-size: 14px;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   ESTADOS DE ERROR Y AVISOS (401, 403)
   -------------------------------------------------------------------------- */
.alert-box {
  border-radius: var(--ib-radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid transparent;
}

.alert-box.warning {
  background: var(--ib-warning-subtle);
  border-color: #FDE68A;
  color: #92400E;
}

.alert-box.danger {
  background: var(--ib-danger-subtle);
  border-color: #FECACA;
  color: #991B1B;
}

.alert-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 13px;
}

.alert-message {
  font-size: 12px;
  line-height: 1.4;
  color: inherit;
}

/* --------------------------------------------------------------------------
   WORKSPACE AUTENTICADO
   -------------------------------------------------------------------------- */
/* Tarjeta de Usuario / Cuota Compacta */
.user-bar {
  background: var(--ib-card-bg);
  border: 1px solid var(--ib-border);
  border-radius: var(--ib-radius-sm);
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--ib-shadow-sm);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
}

.user-name {
  font-weight: 700;
  font-size: 11.5px;
  color: var(--ib-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-org {
  font-size: 10.5px;
  color: var(--ib-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

.user-meta-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quota-chip {
  background: var(--ib-accent-subtle);
  color: var(--ib-accent);
  padding: 2px 7px;
  border-radius: var(--ib-radius-full);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 3px;
  border: 1px solid rgba(0, 119, 255, 0.15);
  white-space: nowrap;
}

.user-actions-btn {
  background: none;
  border: none;
  color: var(--ib-text-subtle);
  cursor: pointer;
  font-size: 10.5px;
  text-decoration: underline;
  padding: 0;
  white-space: nowrap;
}
.user-actions-btn:hover {
  color: var(--ib-danger);
}

/* --------------------------------------------------------------------------
   BARRA UNIFICADA DE CONTEXTO Y HERRAMIENTAS (SMART CONTEXT BAR)
   -------------------------------------------------------------------------- */
.workspace-context-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--ib-card-bg);
  border: 1px solid var(--ib-border);
  border-radius: var(--ib-radius-sm);
  padding: 4px 8px;
  box-shadow: var(--ib-shadow-xs);
  flex-shrink: 0;
  position: relative;
  z-index: 30;
}

.context-pill-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  flex: 1;
  position: relative;
}

.smart-selection-pill {
  background: #F8FAFC;
  border: 1px solid var(--ib-border);
  border-radius: var(--ib-radius-full);
  padding: 3px 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  color: var(--ib-text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.smart-selection-pill:hover {
  background: #F1F5F9;
  border-color: #CBD5E1;
  color: var(--ib-text-main);
}

.smart-selection-pill.has-selection {
  background: #EFF6FF;
  border-color: #BFDBFE;
  color: #0066E0;
  font-weight: 600;
}

.smart-selection-pill.has-selection:hover {
  background: #DBEAFE;
  border-color: #93C5FD;
}

.smart-selection-pill .pill-icon {
  flex-shrink: 0;
  stroke: currentColor;
}

.smart-selection-pill .pill-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill-action-hint {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: rgba(0, 119, 255, 0.12);
  border: 1px solid rgba(0, 119, 255, 0.18);
  border-radius: var(--ib-radius-full);
  padding: 1px 6px 1px 5px;
  font-size: 9.5px;
  font-weight: 700;
  color: #0052B3;
  line-height: 1.2;
  margin-left: 2px;
  transition: all 0.15s ease;
}

.pill-action-hint:hover {
  background: rgba(0, 119, 255, 0.2);
}

.pill-chevron {
  stroke: currentColor;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
}

.smart-selection-pill.is-open .pill-chevron {
  transform: rotate(180deg);
}

.smart-selection-pill.is-open {
  border-color: #0077FF;
  box-shadow: 0 0 0 2px rgba(0, 119, 255, 0.15);
}

/* Popover flotante de selección completa */
.selection-preview-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 260px;
  max-width: calc(100vw - 24px);
  background: #FFFFFF;
  border: 1px solid var(--ib-border-strong);
  border-radius: var(--ib-radius-md);
  box-shadow: var(--ib-shadow-md);
  padding: 8px 10px;
  z-index: 100;
  animation: slideUpFade 0.15s ease-out;
}

.selection-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--ib-border);
}

.selection-popover-title {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ib-primary);
}

.btn-close-popover {
  background: transparent;
  border: none;
  color: var(--ib-text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 0 3px;
  line-height: 1;
}

.btn-close-popover:hover {
  color: var(--ib-danger);
}

.selection-preview-content {
  font-size: 11px;
  color: #1E293B;
  max-height: 110px;
  overflow-y: auto;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.selection-preview-content.empty {
  color: var(--ib-text-subtle);
  font-style: italic;
}

.context-session-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-new-chat-premium {
  background: #FFFFFF;
  border: 1px solid var(--ib-border);
  border-radius: var(--ib-radius-full);
  padding: 3px 9px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ib-primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: inherit;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  line-height: 1;
}

.btn-new-chat-premium svg {
  color: var(--ib-accent);
  stroke: var(--ib-accent);
  transition: transform 0.2s ease;
}

.btn-new-chat-premium:hover {
  background: var(--ib-accent-subtle);
  border-color: #BFDBFE;
  color: #0066E0;
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0, 119, 255, 0.15);
}

.btn-new-chat-premium:hover svg {
  transform: rotate(90deg);
}

.btn-new-chat-premium:active {
  transform: translateY(0);
}

/* Banner de estado de procesamiento IA */
.ia-status-banner {
  background: linear-gradient(135deg, #EFF6FF 0%, #F8FAFC 100%);
  border: 1px solid #BFDBFE;
  border-radius: var(--ib-radius-md);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: fadeIn 0.2s ease-in-out forwards;
  box-shadow: 0 2px 6px rgba(0, 119, 255, 0.08);
  flex-shrink: 0;
}

.ia-status-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 119, 255, 0.2);
  border-top-color: var(--ib-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.ia-status-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ia-status-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ib-primary);
  line-height: 1.3;
}

.ia-status-desc {
  font-size: 10px;
  color: #2563EB;
  line-height: 1.3;
}

/* Sección inferior de consulta (Anclada fija al pie del taskpane) */
.custom-query-section {
  position: relative;
  flex-shrink: 0;
  width: 100%;
  margin-top: auto;
  z-index: 40;
  padding-top: 2px;
}

/* Panel flotante emergente de acciones rápidas (se abre hacia arriba sobre el input) */
.quick-actions-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(203, 213, 225, 0.85);
  border-radius: var(--ib-radius-md);
  padding: 8px;
  box-shadow: var(--ib-shadow-float);
  z-index: 50;
  max-height: 230px;
  overflow-y: auto;
  animation: slideUpFade 0.18s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.quick-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.btn-quick-action {
  background: #FFFFFF;
  border: 1px solid var(--ib-border);
  border-radius: var(--ib-radius-sm);
  padding: 6px 8px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.btn-quick-action:hover {
  border-color: var(--ib-accent);
  background: #F8FAFC;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 119, 255, 0.1);
}

.btn-quick-action:active {
  transform: translateY(0);
}

.btn-quick-action.full-width {
  grid-column: 1 / -1;
}

.btn-quick-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  transform: none !important;
  box-shadow: none !important;
}

.btn-quick-action.is-active-action {
  opacity: 1 !important;
  border-color: var(--ib-accent) !important;
  background: var(--ib-accent-subtle) !important;
  box-shadow: 0 0 0 2px rgba(0, 119, 255, 0.25) !important;
}

.quick-action-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--ib-primary);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quick-action-desc {
  font-size: 9.5px;
  color: var(--ib-text-muted);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Barra de entrada unificada: [Textarea] [Acciones] [Botón Enviar] */
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  border-radius: var(--ib-radius-md);
  padding: 4px 6px;
  box-shadow: 0 2px 8px rgba(10, 37, 64, 0.05), 0 1px 2px rgba(10, 37, 64, 0.03);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-input-bar:focus-within {
  border-color: var(--ib-accent);
  box-shadow: 0 0 0 3px var(--ib-accent-glow), 0 4px 12px rgba(0, 119, 255, 0.08);
}

/* Botón toggle de acciones rápidas (icono compacto a la derecha) */
.btn-quick-toggle {
  background: #EFF6FF;
  border: 1px solid rgba(0, 119, 255, 0.2);
  border-radius: var(--ib-radius-sm);
  color: #0066E0;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  min-width: 32px;
  max-width: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.15s ease;
}

.btn-quick-toggle:hover {
  background: #DBEAFE;
  border-color: var(--ib-accent);
  color: #0052B3;
  transform: translateY(-1px);
}

.btn-quick-toggle:active {
  transform: translateY(0);
}

.btn-quick-toggle.is-open {
  background: #0077FF;
  border-color: #0077FF;
  color: #FFFFFF;
  box-shadow: 0 2px 6px rgba(0, 119, 255, 0.3);
}

.btn-quick-toggle.is-open svg {
  stroke: #FFFFFF;
}

/* Textarea inline integrada (ocupa todo el espacio central disponible desde la izquierda) */
.query-textarea-inline {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  border: none;
  background: transparent;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--ib-text-main);
  line-height: 1.45;
  resize: none;
  outline: none;
  height: 32px;
  min-height: 32px;
  max-height: 80px;
  overflow-y: auto;
  box-sizing: border-box;
}

.query-textarea-inline::placeholder {
  color: var(--ib-text-subtle);
  font-size: 11.5px;
}

/* Botón Enviar compacto (icono) */
.btn-send-icon,
.btn-send-inline {
  background: linear-gradient(135deg, #0077FF 0%, #005ECC 100%);
  border: none;
  border-radius: var(--ib-radius-sm);
  color: #FFFFFF;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  min-width: 32px;
  max-width: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  box-shadow: 0 2px 5px rgba(0, 119, 255, 0.25);
  padding: 0;
}

.btn-send-icon:hover:not(:disabled),
.btn-send-inline:hover:not(:disabled) {
  background: linear-gradient(135deg, #0084FF 0%, #0066E0 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 119, 255, 0.35);
}

.btn-send-icon:active:not(:disabled),
.btn-send-inline:active:not(:disabled) {
  transform: translateY(0);
}

.btn-send-icon:disabled,
.btn-send-inline:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none;
}

.send-icon {
  flex-shrink: 0;
  display: block;
}

.spinner-sm {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #FFFFFF;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

/* --------------------------------------------------------------------------
   HILO DE CONVERSACIÓN / MINI CHAT EN WORD
   -------------------------------------------------------------------------- */
.chat-thread-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-thread-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 0;
  flex-shrink: 0;
}

.section-label {
  font-weight: 700;
  font-size: 11.5px;
  color: var(--ib-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: -0.15px;
}

.section-label svg {
  color: var(--ib-accent);
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-counter-badge {
  background: var(--ib-accent-subtle);
  color: var(--ib-accent);
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--ib-radius-full);
  border: 1px solid rgba(0, 119, 255, 0.2);
  letter-spacing: 0.2px;
}

.chat-counter-badge.warning {
  background: #FEF3C7;
  color: #B45309;
  border-color: #FCD34D;
}

.chat-counter-badge.limit {
  background: #FEE2E2;
  color: #DC2626;
  border-color: #FCA5A5;
}

.btn-new-thread {
  background: #FFFFFF;
  border: 1px solid var(--ib-border);
  border-radius: var(--ib-radius-sm);
  padding: 2px 8px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ib-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.btn-new-thread:hover {
  background: #F8FAFC;
  border-color: var(--ib-accent);
  color: var(--ib-accent);
  transform: translateY(-1px);
}

/* Lista de mensajes con scroll fluido */
.chat-messages-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 2px 2px 6px 2px;
  scroll-behavior: smooth;
}

/* Estado inicial vacío con Quick Action Chips */
.chat-empty-state {
  border: 1px dashed var(--ib-border-strong);
  border-radius: var(--ib-radius-md);
  padding: 16px 12px;
  text-align: center;
  color: var(--ib-text-muted);
  font-size: 11.5px;
  line-height: 1.45;
  background: linear-gradient(180deg, #FFFFFF 0%, #F8FAFC 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: auto 0;
  box-shadow: var(--ib-shadow-xs);
}

.chat-empty-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-empty-icon {
  font-size: 18px;
  line-height: 1;
}

.chat-empty-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ib-primary);
}

.chat-empty-text {
  font-size: 11px;
  color: var(--ib-text-muted);
  max-width: 260px;
  line-height: 1.4;
}

.chat-empty-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  margin-top: 4px;
  width: 100%;
}

.btn-empty-chip {
  background: #FFFFFF;
  border: 1px solid var(--ib-border);
  border-radius: var(--ib-radius-full);
  padding: 4px 10px;
  font-size: 10.5px;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.btn-empty-chip:hover {
  border-color: var(--ib-accent);
  background: #EFF6FF;
  color: #0066E0;
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0, 119, 255, 0.12);
}

.btn-empty-chip:active {
  transform: translateY(0);
}

/* Mensajes individuales */
.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 11px;
  font-size: 12px;
  line-height: 1.5;
  word-break: break-word;
  animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.chat-msg-user {
  background: #EFF6FF;
  border: 1px solid #DBEAFE;
  border-radius: 12px 12px 3px 12px;
  align-self: flex-end;
  max-width: 92%;
  margin-left: auto;
  box-shadow: 0 1px 2px rgba(0, 119, 255, 0.05);
}

.chat-msg-ia {
  background: var(--ib-card-bg);
  border: 1px solid var(--ib-border);
  border-radius: 12px 12px 12px 3px;
  box-shadow: var(--ib-shadow-sm);
  width: 100%;
}

.chat-msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
}

.chat-msg-author {
  font-weight: 700;
  color: var(--ib-primary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-ia-avatar {
  height: 13px;
  width: auto;
  display: inline-block;
  object-fit: contain;
}

.chat-action-badge {
  background: #DBEAFE;
  color: #1E3A8A;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--ib-radius-full);
}

.chat-meta-badge {
  font-size: 9.5px;
  color: var(--ib-text-subtle);
  font-weight: 500;
  background: #F8FAFC;
  padding: 1px 6px;
  border-radius: var(--ib-radius-full);
  border: 1px solid var(--ib-border);
}

.chat-msg-body {
  color: var(--ib-text-main);
  white-space: pre-wrap;
  line-height: 1.5;
}

/* Micro-barra de acciones de respuesta (Micro-Chips horizontales de 22-24px) */
.chat-msg-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 5px;
  padding-top: 6px;
  border-top: 1px solid #F1F5F9;
  flex-wrap: wrap;
}

.btn-chat-doc-action {
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: var(--ib-radius-full);
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
  line-height: 1;
}

.btn-chat-doc-action svg {
  flex-shrink: 0;
  stroke: #64748B;
  transition: stroke 0.15s ease;
}

.btn-chat-doc-action:hover {
  background: #EFF6FF;
  border-color: #BFDBFE;
  color: #0066E0;
  transform: translateY(-1px);
}

.btn-chat-doc-action:hover svg {
  stroke: #0066E0;
}

.btn-chat-doc-action:active {
  transform: translateY(0);
}

/* Banner de Límite de 10 Consultas */
.chat-limit-banner {
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  border-radius: var(--ib-radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fadeIn 0.25s ease-in-out forwards;
}

.chat-limit-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #B45309;
}

.chat-limit-text {
  font-size: 11px;
  color: #78350F;
  line-height: 1.4;
}

.btn-reset-limit {
  padding: 8px 12px;
  font-size: 11.5px;
  margin-top: 2px;
}

/* --------------------------------------------------------------------------
   BOTONES PRINCIPALES Y COMPONENTES
   -------------------------------------------------------------------------- */
.btn-primary {
  background: linear-gradient(135deg, var(--ib-accent) 0%, #005ECC 100%);
  color: #FFFFFF;
  border: none;
  border-radius: var(--ib-radius-md);
  padding: 10px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 4px rgba(0, 119, 255, 0.25);
  transition: all 0.15s ease;
  width: 100%;
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #0084FF 0%, #0066E0 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 119, 255, 0.3);
}
.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: #FFFFFF;
  border: 1px solid var(--ib-border-strong);
  color: var(--ib-text-main);
  border-radius: var(--ib-radius-md);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}
.btn-secondary:hover {
  background: #F1F5F9;
  border-color: #94A3B8;
}

/* Spinner de carga */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #FFFFFF;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------------------
   RESPUESTA GENERADA E INSERCIÓN EN WORD
   -------------------------------------------------------------------------- */
.result-card {
  background: var(--ib-card-bg);
  border: 1px solid #CBD5E1;
  border-left: 3px solid var(--ib-accent);
  border-radius: var(--ib-radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--ib-shadow-md);
  animation: fadeIn 0.15s ease-out;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--ib-border);
  padding-bottom: 6px;
}

.result-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ib-primary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.result-meta-badge {
  font-size: 10px;
  color: #64748B;
  background: #F1F5F9;
  padding: 1px 6px;
  border-radius: var(--ib-radius-full);
}

.btn-close-result {
  background: transparent;
  border: none;
  color: #94A3B8;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
  transition: all 0.15s;
}
.btn-close-result:hover {
  background: #E2E8F0;
  color: #0F172A;
}

.result-body {
  font-size: 11.5px;
  line-height: 1.5;
  color: #1E293B;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  background: #FAFAFA;
  padding: 8px 10px;
  border-radius: var(--ib-radius-sm);
  border: 1px solid #E2E8F0;
}

/* Barra de acciones sobre el documento */
.insertion-actions-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.btn-action-insert {
  background: var(--ib-primary);
  color: #FFFFFF;
  border: none;
  border-radius: var(--ib-radius-sm);
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}
.btn-action-insert:hover {
  background: var(--ib-primary-hover);
}

.btn-action-replace {
  background: #FFFFFF;
  color: var(--ib-primary);
  border: 1px solid var(--ib-primary);
  border-radius: var(--ib-radius-sm);
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}
.btn-action-replace:hover {
  background: #F1F5F9;
}

.btn-action-copy {
  grid-column: span 2;
  background: transparent;
  color: var(--ib-text-muted);
  border: 1px dashed var(--ib-border-strong);
  border-radius: var(--ib-radius-sm);
  padding: 5px;
  font-size: 11px;
  cursor: pointer;
  text-align: center;
}
.btn-action-copy:hover {
  background: #F8FAFC;
  color: var(--ib-text-main);
}

.legal-disclaimer {
  font-size: 9.5px;
  color: var(--ib-text-subtle);
  line-height: 1.35;
  text-align: center;
  padding: 4px;
}

/* --------------------------------------------------------------------------
   SANDBOX / SIMULADOR INTERACTIVO DE WORD (MODO NAVEGADOR)
   -------------------------------------------------------------------------- */
.sandbox-banner {
  background: #FFFBEB;
  border-bottom: 1px solid #FDE68A;
  color: #92400E;
  padding: 8px 12px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sandbox-container {
  border-top: 2px solid #E2E8F0;
  background: #F1F5F9;
  padding: 12px;
  margin-top: 10px;
  border-radius: var(--ib-radius-md);
}

.sandbox-title {
  font-size: 11px;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.virtual-doc {
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  border-radius: 4px;
  box-shadow: var(--ib-shadow-sm);
  padding: 12px;
  min-height: 100px;
  font-family: 'Calibri', 'Segoe UI', serif;
  font-size: 12.5px;
  line-height: 1.5;
  color: #1E293B;
  outline: none;
}

/* --------------------------------------------------------------------------
   RESPONSIVE Y ADAPTABILIDAD AL TASKPANE DE WORD
   -------------------------------------------------------------------------- */
@media (max-width: 320px) {
  .main-content {
    padding: 5px 6px;
    gap: 5px;
  }
  .app-header {
    padding: 6px 10px;
  }
  .brand-logo-img {
    height: 26px;
  }
  .brand-subtitle {
    font-size: 8.5px;
  }
  .workspace-context-bar {
    padding: 3px 6px;
  }
  .chat-msg {
    padding: 8px 10px;
    font-size: 11.5px;
  }
  .btn-quick-action {
    padding: 5px 6px;
  }
  .quick-action-title {
    font-size: 10.5px;
  }
  .quick-action-desc {
    font-size: 9px;
  }
  .btn-chat-doc-action {
    padding: 3px 6px;
    font-size: 9.5px;
  }
}

@media (max-width: 275px) {
  .quick-actions-grid {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .btn-new-chat-premium span {
    display: none;
  }
  .selection-counter-chip {
    display: none !important;
  }
}
