/* ============================================
   AI Assistant — ShiftRest
   Estilos del Asistente IA
   ============================================ */

/* ---- Layout principal ---- */
.ai-chat-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  padding: 0;
}

.ai-chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-primary);
  gap: var(--space-3);
  flex-wrap: wrap;
}

.ai-model-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(79, 124, 255, 0.12);
  border: 1px solid rgba(79, 124, 255, 0.3);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-blue);
  letter-spacing: 0.02em;
}

.ai-model-badge .ai-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: ai-pulse 2s infinite;
}

@keyframes ai-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}

.ai-model-badge.offline .ai-dot {
  background: var(--accent-red);
  animation: none;
}

/* ---- Messages Area ---- */
.ai-messages-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  scroll-behavior: smooth;
}

.ai-messages-area::-webkit-scrollbar { width: 4px; }
.ai-messages-area::-webkit-scrollbar-track { background: transparent; }
.ai-messages-area::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* ---- Messages ---- */
.ai-message {
  display: flex;
  gap: var(--space-3);
  max-width: 100%;
  animation: ai-msg-in 0.25s ease-out;
}

@keyframes ai-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-message.user {
  flex-direction: row-reverse;
}

.ai-message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  font-weight: 700;
}

.ai-message.assistant .ai-message-avatar {
  background: var(--gradient-primary);
  color: white;
  font-size: 1rem;
}

.ai-message.user .ai-message-avatar {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.ai-message-bubble {
  max-width: calc(100% - 50px);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}

.ai-message.assistant .ai-message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  color: var(--text-primary);
  border-top-left-radius: 4px;
}

.ai-message.user .ai-message-bubble {
  background: var(--gradient-primary);
  color: white;
  border-top-right-radius: 4px;
}

/* Markdown dentro del bubble */
.ai-message-bubble h1,
.ai-message-bubble h2,
.ai-message-bubble h3 {
  font-weight: 700;
  margin: var(--space-3) 0 var(--space-2);
  color: var(--text-primary);
}
.ai-message-bubble h1 { font-size: 1.1rem; }
.ai-message-bubble h2 { font-size: 1rem; }
.ai-message-bubble h3 { font-size: 0.95rem; }
.ai-message-bubble p  { margin: 0 0 var(--space-2) 0; }
.ai-message-bubble p:last-child { margin-bottom: 0; }

.ai-message-bubble ul,
.ai-message-bubble ol {
  margin: var(--space-2) 0;
  padding-left: 20px;
}
.ai-message-bubble li { margin-bottom: 4px; }

.ai-message-bubble strong { font-weight: 700; color: var(--text-primary); }
.ai-message-bubble em     { font-style: italic; color: var(--text-secondary); }

.ai-message-bubble code {
  background: rgba(79, 124, 255, 0.1);
  border: 1px solid rgba(79, 124, 255, 0.2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'Courier New', monospace;
  color: var(--accent-blue);
}

.ai-message-bubble pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  overflow-x: auto;
  margin: var(--space-2) 0;
  font-size: 12px;
}

.ai-message-bubble pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-primary);
}

.ai-message-bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: var(--space-3) 0;
}
.ai-message-bubble th {
  background: var(--bg-secondary);
  padding: var(--space-2) var(--space-3);
  text-align: left;
  font-weight: 700;
  border-bottom: 1px solid var(--border-primary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.ai-message-bubble td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-primary);
}
.ai-message-bubble tr:last-child td { border-bottom: none; }
.ai-message-bubble tr:hover td { background: var(--bg-secondary); }

.ai-message-bubble blockquote {
  border-left: 3px solid var(--accent-blue);
  margin: var(--space-2) 0;
  padding: var(--space-2) var(--space-3);
  background: rgba(79, 124, 255, 0.06);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-style: italic;
}

.ai-message-bubble hr {
  border: none;
  border-top: 1px solid var(--border-primary);
  margin: var(--space-3) 0;
}

/* ---- Tool Use Indicator ---- */
.ai-tool-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: rgba(79, 124, 255, 0.06);
  border: 1px solid rgba(79, 124, 255, 0.15);
  border-radius: var(--radius-md);
  font-size: 11px;
  color: var(--accent-blue);
  font-weight: 600;
  margin-bottom: var(--space-1);
  animation: ai-msg-in 0.2s ease-out;
}

.ai-tool-indicator.done {
  background: rgba(16, 185, 129, 0.06);
  border-color: rgba(16, 185, 129, 0.2);
  color: var(--accent-green);
}

.ai-tool-indicator.error {
  background: rgba(239, 68, 68, 0.06);
  border-color: rgba(239, 68, 68, 0.2);
  color: var(--accent-red);
}

.ai-tool-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

/* ---- Typing Indicator ---- */
.ai-typing {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.ai-typing-dots {
  display: flex;
  gap: 4px;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  border-top-left-radius: 4px;
}

.ai-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: ai-typing-bounce 1.2s ease-in-out infinite;
}

.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* ---- Confirmation Banner ---- */
.ai-confirm-banner {
  background: rgba(245, 158, 11, 0.06);
  border: 1.5px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-top: var(--space-2);
  animation: ai-msg-in 0.3s ease-out;
}

.ai-confirm-banner-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-orange);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ai-confirm-banner-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-3);
}

.ai-confirm-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  border: 1.5px solid;
  transition: all 0.15s ease;
}

.ai-confirm-btn.accept {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.35);
  color: var(--accent-green);
}

.ai-confirm-btn.accept:hover {
  background: rgba(16, 185, 129, 0.2);
  transform: translateY(-1px);
}

.ai-confirm-btn.cancel {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.25);
  color: var(--accent-red);
}

.ai-confirm-btn.cancel:hover {
  background: rgba(239, 68, 68, 0.15);
  transform: translateY(-1px);
}

/* ---- Quick Suggestions ---- */
.ai-suggestions {
  flex-shrink: 0;
  padding: var(--space-3) var(--space-6);
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  border-top: 1px solid var(--border-primary);
  background: var(--bg-secondary);
}

.ai-suggestion-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.ai-suggestion-chip:hover {
  background: var(--bg-elevated);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(79, 124, 255, 0.15);
}

/* ---- Input Area ---- */
.ai-input-area {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  padding: 16px 24px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-primary);
}

.ai-textarea-wrapper {
  flex: 1;
  position: relative;
}

.ai-textarea {
  width: 100%;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.15s ease;
  max-height: 150px;
  overflow-y: auto;
  display: block;
}

.ai-textarea:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.1);
}

.ai-textarea::placeholder { color: var(--text-muted); }

.ai-send-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-lg);
  background: var(--gradient-primary);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
  box-shadow: 0 2px 10px rgba(79, 124, 255, 0.3);
}

.ai-send-btn:hover { transform: scale(1.06); box-shadow: 0 4px 14px rgba(79, 124, 255, 0.4); }
.ai-send-btn:disabled { opacity: 0.5; transform: none; cursor: not-allowed; }

.ai-stop-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-lg);
  background: rgba(239, 68, 68, 0.12);
  border: 1.5px solid rgba(239, 68, 68, 0.3);
  color: var(--accent-red);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.ai-stop-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  transform: scale(1.06);
}

/* ---- Welcome / Empty State ---- */
.ai-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  padding: var(--space-8);
  gap: var(--space-4);
}

.ai-welcome-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  box-shadow: 0 12px 32px rgba(79, 124, 255, 0.3);
  animation: ai-float 3s ease-in-out infinite;
}

@keyframes ai-float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

.ai-welcome h2 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.ai-welcome p {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 380px;
  line-height: 1.6;
}

/* ---- Not configured banner ---- */
.ai-not-configured {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-8);
  text-align: center;
}

/* ---- Audit Log ---- */
.ai-audit-row {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr 80px;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  font-size: 12px;
  align-items: center;
}

.ai-audit-row:not(:last-child) { margin-bottom: var(--space-2); }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .ai-chat-header { padding: var(--space-3) var(--space-4); }
  .ai-messages-area { padding: var(--space-3) var(--space-4); }
  .ai-input-area { padding: var(--space-3) var(--space-4); }
  .ai-suggestions { padding: var(--space-2) var(--space-4); }
  .ai-message-bubble { max-width: calc(100% - 44px); font-size: 13px; }
}
