/* ═══════════════════════════════════════════════
   NexoConta AI — Widget del Asistente Inteligente
   Futurista · Premium · Independiente de style.css
═══════════════════════════════════════════════ */

/* ══════════════════════════════════════
   BURBUJA FLOTANTE
══════════════════════════════════════ */
.ai-widget { position: fixed; bottom: 28px; right: 28px; z-index: 9000; }

.ai-bubble {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #06b6d4);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 24px rgba(124,58,237,0.55), 0 0 0 0 rgba(124,58,237,0.4);
  transition: transform .2s cubic-bezier(.4,0,.2,1), box-shadow .2s;
  animation: bubblePulse 3s ease-in-out infinite;
}

@keyframes bubblePulse {
  0%, 100% { box-shadow: 0 4px 24px rgba(124,58,237,0.55), 0 0 0 0 rgba(124,58,237,0.35); }
  50%       { box-shadow: 0 4px 32px rgba(124,58,237,0.7),  0 0 0 12px rgba(124,58,237,0); }
}

.ai-bubble:hover { transform: scale(1.1); box-shadow: 0 8px 32px rgba(124,58,237,0.7); }
.ai-bubble:active { transform: scale(.96); }

.ai-bubble-icon { line-height: 1; }

.ai-bubble-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  background: #ef4444;
  border: 2px solid #050510;
  border-radius: 11px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  animation: badgePop .3s cubic-bezier(.34,1.56,.64,1);
}

@keyframes badgePop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* ══════════════════════════════════════
   PANEL LATERAL
══════════════════════════════════════ */
.ai-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  max-width: calc(100vw - 16px);
  height: 100vh;
  background: #09091c;
  border-left: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-direction: column;
  z-index: 8999;
  transition: right .35s cubic-bezier(.4,0,.2,1);
  box-shadow: -8px 0 48px rgba(0,0,0,0.6);
  overflow: hidden;
}

.ai-panel.open { right: 0; }

/* Backdrop */
.ai-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 8998;
}
.ai-backdrop.open { display: block; animation: fadeInBd .25s ease; }

@keyframes fadeInBd { from { opacity: 0; } to { opacity: 1; } }

/* ── Panel header ──────────────────── */
.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  background: rgba(124,58,237,0.07);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

.ai-panel-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-panel-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #7c3aed, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 0 18px rgba(124,58,237,0.5);
}

.ai-panel-name {
  font-size: 15px;
  font-weight: 700;
  color: #e2e8f0;
  letter-spacing: -.3px;
}

.ai-panel-status {
  font-size: 11px;
  color: #10b981;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.ai-panel-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
  animation: dotGreen 2s ease-in-out infinite;
}

@keyframes dotGreen {
  0%, 100% { box-shadow: 0 0 5px #10b981; }
  50%       { box-shadow: 0 0 12px #10b981; }
}

.ai-panel-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: #94a3b8;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
  font-family: inherit;
}

.ai-panel-close:hover { background: rgba(239,68,68,0.15); color: #ef4444; border-color: rgba(239,68,68,0.3); }

/* ── Tabs ──────────────────────────── */
.ai-tabs {
  display: flex;
  padding: 10px 12px;
  gap: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.2);
  flex-shrink: 0;
  overflow-x: auto;
}

.ai-tab {
  flex: 1;
  padding: 7px 8px;
  border: none;
  background: none;
  color: #64748b;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
  white-space: nowrap;
  position: relative;
}

.ai-tab:hover { background: rgba(255,255,255,0.06); color: #94a3b8; }
.ai-tab.active { background: linear-gradient(135deg, #7c3aed, #06b6d4); color: #fff; }

.ai-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  padding: 0 3px;
  margin-left: 4px;
  vertical-align: middle;
}

/* ── Panel body ────────────────────── */
.ai-panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(124,58,237,0.3) transparent;
  /* Needed so .ai-chat-wrap can fill 100% of this container */
  min-height: 0;
}

/* When chat tab is active, disable body scroll so only the chat messages scroll */
.ai-panel-body.tab-chat {
  overflow: hidden;
  padding: 0;
  gap: 0;
}

.ai-panel-body::-webkit-scrollbar { width: 4px; }
.ai-panel-body::-webkit-scrollbar-thumb { background: rgba(124,58,237,0.35); border-radius: 2px; }

/* ══════════════════════════════════════
   TAB: RESUMEN
══════════════════════════════════════ */
.ai-summary-kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.ai-kpi {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
  transition: border-color .2s;
}

.ai-kpi:hover { border-color: rgba(255,255,255,0.15); }

.ai-kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  border-radius: 12px 12px 0 0;
}

.ai-kpi.green::before  { background: linear-gradient(90deg, #10b981, #06b6d4); }
.ai-kpi.red::before    { background: linear-gradient(90deg, #ef4444, #f59e0b); }
.ai-kpi.yellow::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.ai-kpi.purple::before { background: linear-gradient(90deg, #7c3aed, #a855f7); }

.ai-kpi-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: #64748b; margin-bottom: 6px; }
.ai-kpi-value { font-size: 18px; font-weight: 800; letter-spacing: -.5px; line-height: 1; }
.ai-kpi.green  .ai-kpi-value { color: #10b981; }
.ai-kpi.red    .ai-kpi-value { color: #ef4444; }
.ai-kpi.yellow .ai-kpi-value { color: #f59e0b; }
.ai-kpi.purple .ai-kpi-value { color: #a855f7; }

.ai-summary-msg {
  background: rgba(124,58,237,0.08);
  border: 1px solid rgba(124,58,237,0.2);
  border-left: 3px solid #7c3aed;
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 13px;
  color: #e2e8f0;
  line-height: 1.6;
}

.ai-date-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-date-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 500;
  color: #94a3b8;
  cursor: pointer;
  transition: all .2s;
}

.ai-date-chip:hover { background: rgba(124,58,237,0.15); border-color: rgba(124,58,237,0.4); color: #c4b5fd; }
.ai-date-chip .chip-days { font-weight: 700; color: #f59e0b; }

/* ══════════════════════════════════════
   TAB: ALERTAS / INSIGHTS
══════════════════════════════════════ */
.ai-insight {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  border-left: 3px solid #64748b;
  border-radius: 10px;
  padding: 13px 14px;
  transition: border-color .2s, background .2s;
  animation: insightIn .25s ease;
}

@keyframes insightIn {
  from { opacity: 0; transform: translateX(10px); }
  to   { opacity: 1; transform: translateX(0); }
}

.ai-insight:hover { background: rgba(255,255,255,0.06); }
.ai-insight.critical { border-left-color: #ef4444; }
.ai-insight.high     { border-left-color: #f59e0b; }
.ai-insight.medium   { border-left-color: #7c3aed; }
.ai-insight.low      { border-left-color: #06b6d4; }

.ai-insight-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.ai-insight-title {
  font-size: 13px;
  font-weight: 700;
  color: #e2e8f0;
  line-height: 1.3;
  flex: 1;
}

.ai-priority-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  flex-shrink: 0;
}

.ai-priority-badge.critical { background: rgba(239,68,68,0.15);  color: #fca5a5;  border: 1px solid rgba(239,68,68,0.3); }
.ai-priority-badge.high     { background: rgba(245,158,11,0.15); color: #fcd34d;  border: 1px solid rgba(245,158,11,0.3); }
.ai-priority-badge.medium   { background: rgba(124,58,237,0.15); color: #c4b5fd;  border: 1px solid rgba(124,58,237,0.3); }
.ai-priority-badge.low      { background: rgba(6,182,212,0.12);  color: #67e8f9;  border: 1px solid rgba(6,182,212,0.3); }

.ai-insight-msg {
  font-size: 12px;
  color: #94a3b8;
  line-height: 1.55;
  margin-bottom: 10px;
}

.ai-insight-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.ai-insight-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: #94a3b8;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}

.ai-insight-btn:hover { background: rgba(124,58,237,0.2); border-color: rgba(124,58,237,0.4); color: #c4b5fd; }
.ai-insight-btn.primary { background: linear-gradient(135deg, #7c3aed, #06b6d4); color: #fff; border-color: transparent; }
.ai-insight-btn.primary:hover { opacity: .85; }
.ai-insight-btn.dismiss { background: none; border-color: rgba(239,68,68,0.2); color: #f87171; }
.ai-insight-btn.dismiss:hover { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.4); }

/* ══════════════════════════════════════
   TAB: CHAT
══════════════════════════════════════ */
.ai-chat-wrap {
  display: flex;
  flex-direction: column;
  /* Fill the panel body without negative margin hack — tab-chat sets padding:0 */
  flex: 1;
  min-height: 0;
  /* Stretch to fill when panel body has no padding */
  margin: 0;
  height: 100%;
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(124,58,237,0.3) transparent;
}

.ai-chat-messages::-webkit-scrollbar { width: 4px; }
.ai-chat-messages::-webkit-scrollbar-thumb { background: rgba(124,58,237,0.35); border-radius: 2px; }

.ai-chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  animation: msgPop .2s ease;
}

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

.ai-chat-msg.user {
  background: linear-gradient(135deg, #7c3aed, #06b6d4);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 3px 14px rgba(124,58,237,0.35);
}

.ai-chat-msg.model {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  color: #e2e8f0;
}

.ai-chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,0.07);
  background: rgba(0,0,0,0.25);
  flex-shrink: 0;
}

.ai-chat-input {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  color: #e2e8f0;
  padding: 10px 16px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: all .2s;
  resize: none;
}

.ai-chat-input:focus {
  border-color: #7c3aed;
  background: rgba(124,58,237,0.05);
  box-shadow: 0 0 0 2px rgba(124,58,237,0.15);
}

.ai-chat-input::placeholder { color: #64748b; }

.ai-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #06b6d4);
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
  flex-shrink: 0;
  align-self: flex-end;
}

.ai-send-btn:hover { transform: scale(1.08); box-shadow: 0 4px 16px rgba(124,58,237,0.5); }
.ai-send-btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ══════════════════════════════════════
   TAB: ACCIONES RÁPIDAS
══════════════════════════════════════ */
.ai-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ai-action-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 12px;
  padding: 16px 14px;
  text-align: left;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-action-btn:hover {
  background: rgba(124,58,237,0.1);
  border-color: rgba(124,58,237,0.35);
  transform: translateY(-1px);
}

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

.ai-action-icon { font-size: 22px; }
.ai-action-label { font-size: 12px; font-weight: 700; color: #e2e8f0; line-height: 1.3; }
.ai-action-desc  { font-size: 11px; color: #64748b; line-height: 1.3; }

.ai-action-btn.full { grid-column: 1/-1; flex-direction: row; align-items: center; gap: 12px; padding: 14px 16px; }
.ai-action-btn.full .ai-action-icon { font-size: 20px; }

.ai-action-btn.primary-action {
  background: linear-gradient(135deg, rgba(124,58,237,0.2), rgba(6,182,212,0.2));
  border-color: rgba(124,58,237,0.4);
}

.ai-action-btn.primary-action:hover {
  background: linear-gradient(135deg, rgba(124,58,237,0.3), rgba(6,182,212,0.3));
  border-color: rgba(124,58,237,0.6);
}

/* ══════════════════════════════════════
   COMPONENTES COMUNES
══════════════════════════════════════ */
.ai-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #64748b;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 20px;
  color: #64748b;
  font-size: 13px;
}

.ai-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(124,58,237,0.2);
  border-top-color: #a855f7;
  border-radius: 50%;
  animation: aiSpin .7s linear infinite;
}

@keyframes aiSpin { to { transform: rotate(360deg); } }

.ai-empty {
  text-align: center;
  padding: 40px 20px;
  color: #64748b;
}

.ai-empty .emoji { font-size: 36px; margin-bottom: 10px; display: block; }
.ai-empty p { font-size: 13px; color: #64748b; }

.ai-error {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  border-left: 3px solid #ef4444;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  color: #fca5a5;
}

.ai-divider {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin: 4px 0;
}

/* Analysis output */
.ai-analysis-output {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 16px;
  font-size: 13px;
  color: #e2e8f0;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ══════════════════════════════════════
   BARRA DE CUOTA IA
══════════════════════════════════════ */
.ai-quota-bar {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 4px;
}

.ai-quota-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.ai-quota-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #64748b;
}

.ai-quota-count {
  font-size: 12px;
  font-weight: 700;
}

.ai-quota-track {
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  height: 4px;
  overflow: hidden;
}

.ai-quota-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
  min-width: 4px;
}

.ai-quota-warn {
  font-size: 11px;
  color: #ef4444;
  margin-top: 7px;
  line-height: 1.4;
}

.ai-quota-info {
  font-size: 11px;
  color: #64748b;
  margin-top: 6px;
}

/* ══════════════════════════════════════
   BADGES DE RESULTADO IA
══════════════════════════════════════ */
.ai-result-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 7px;
  margin-bottom: 8px;
}

.ai-result-badge.cache {
  background: rgba(6,182,212,0.1);
  border: 1px solid rgba(6,182,212,0.25);
  color: #67e8f9;
}

.ai-result-badge.ai-gen {
  background: rgba(124,58,237,0.12);
  border: 1px solid rgba(124,58,237,0.3);
  color: #c4b5fd;
}

.ai-result-badge.fallback {
  background: rgba(245,158,11,0.1);
  border: 1px solid rgba(245,158,11,0.25);
  color: #fcd34d;
}

/* ══════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════ */
@media (max-width: 768px) {
  .ai-widget { bottom: 20px; right: 16px; }
  .ai-bubble { width: 52px; height: 52px; font-size: 22px; }
  .ai-panel  { width: 100vw; max-width: 100vw; right: -100vw; }
  .ai-actions-grid { grid-template-columns: 1fr; }
  .ai-summary-kpi-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .ai-tabs { padding: 8px; }
  .ai-tab  { font-size: 11px; padding: 6px 6px; }
  .ai-panel-body { padding: 12px; }
}
