/* ============================================================
   AI-PANEL.CSS — Atlas global AI assistant panel
   Loaded on every dashboard page via <link> in <head>.
   ============================================================ */

/* ─── FAB Trigger ────────────────────────────────────────── */
#ai-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 20px;
  cursor: pointer;
  z-index: 98;
  box-shadow: 0 4px 20px color-mix(in srgb, var(--accent) 45%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

#ai-fab:hover {
  background: var(--accent-dim);
  transform: scale(1.08);
  box-shadow: 0 6px 28px color-mix(in srgb, var(--accent) 65%, transparent);
}

#ai-fab.panel-open {
  background: var(--bg-card);
  color: var(--text-muted);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

#ai-fab-icon {
  display: inline-block;
  transition: transform 220ms ease;
}

#ai-fab.panel-open #ai-fab-icon {
  transform: rotate(45deg);
}

/* ─── Overlay ─────────────────────────────────────────────── */
#ai-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 99;
}

#ai-overlay.open {
  display: block;
}

/* ─── Panel Shell ─────────────────────────────────────────── */
#ai-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 520px;
  max-width: 100vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 250ms ease;
  overflow: hidden;
}

#ai-panel.open {
  transform: translateX(0);
}

/* ─── Panel Header ────────────────────────────────────────── */
#ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-card);
}

#ai-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#ai-panel-icon {
  color: var(--accent);
  font-size: 16px;
}

#ai-panel-controls {
  display: flex;
  gap: 4px;
}

#ai-clear-btn,
#ai-close-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

#ai-clear-btn:hover,
#ai-close-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ─── Context Status Bar ─────────────────────────────────── */
#ai-context-bar {
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 6px;
}

#ai-context-status {
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 500;
}

#ai-context-status.ready {
  color: var(--success);
}

#ai-context-status.error {
  color: var(--warning);
}

#ai-context-status.loading::after {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: atlas-spin 0.7s linear infinite;
  margin-left: 6px;
  vertical-align: middle;
}

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

/* ─── Message List ────────────────────────────────────────── */
#ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

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

/* ─── Empty State ─────────────────────────────────────────── */
#ai-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-faint);
  text-align: center;
  padding: 32px;
  gap: 8px;
  min-height: 200px;
}

.ai-empty-icon {
  font-size: 32px;
  color: var(--accent);
  opacity: 0.4;
  margin-bottom: 4px;
}

.ai-empty-label {
  font-size: 13px;
  color: var(--text-muted);
}

.ai-empty-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 4px;
}

.ai-chip {
  padding: 5px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.ai-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── Chat Bubbles ────────────────────────────────────────── */
.ai-msg {
  display: flex;
  flex-direction: column;
  max-width: 90%;
}

.ai-msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.ai-msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.ai-msg-bubble {
  padding: 10px 13px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.ai-msg.user .ai-msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}

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

.ai-msg-time {
  font-size: 10px;
  color: var(--text-faint);
  margin-top: 3px;
  padding: 0 2px;
}

/* ─── Typing Indicator ────────────────────────────────────── */
.ai-msg.loading .ai-msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 13px 16px;
}

.ai-typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

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

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

@keyframes atlas-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* ─── Action Blocks ───────────────────────────────────────── */
.ai-action-block {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 420px;
}

.ai-action-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.ai-action-footer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-apply-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background var(--transition);
}

.ai-apply-btn:hover:not(:disabled) {
  background: var(--accent-dim);
}

.ai-apply-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ai-action-status {
  font-size: 11px;
  color: var(--text-faint);
}

.ai-action-status.success { color: var(--success); }
.ai-action-status.error   { color: var(--danger); }

/* ─── Input Area ──────────────────────────────────────────── */
#ai-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

#ai-input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  transition: border-color var(--transition);
}

#ai-input:focus {
  border-color: var(--accent);
}

#ai-input::placeholder {
  color: var(--text-faint);
}

#ai-send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: var(--font);
  transition: background var(--transition), transform var(--transition);
}

#ai-send-btn:hover:not(:disabled) {
  background: var(--accent-dim);
}

#ai-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ─── On-demand fetch UI ──────────────────────────────────── */

.ai-fetch-bubble {
  font-style: italic;
  opacity: 0.75;
  font-size: 12px;
}

.ai-data-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 12px 4px auto;
  padding: 5px 10px;
  background: rgba(124, 106, 247, 0.08);
  border: 1px solid rgba(124, 106, 247, 0.25);
  border-radius: 99px;
  font-size: 11px;
  color: var(--accent);
  width: fit-content;
  max-width: 80%;
  align-self: flex-end;
}

.ai-data-pill-icon {
  font-size: 13px;
  opacity: 0.8;
}

/* ─── Settings Button ────────────────────────────────────── */
#ai-settings-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

#ai-settings-btn:hover {
  color: var(--accent);
  background: var(--bg-hover);
}

/* ─── Settings View ──────────────────────────────────────── */
#ai-settings-view {
  flex: 1;
  overflow: hidden;
}

#ai-settings-view.ai-settings-hidden {
  display: none;
}

#ai-settings-view.ai-settings-visible {
  display: flex;
  flex-direction: column;
}

.ai-settings-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-settings-scroll::-webkit-scrollbar { width: 4px; }
.ai-settings-scroll::-webkit-scrollbar-track { background: transparent; }
.ai-settings-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.ai-settings-loading {
  padding: 32px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

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

.ai-settings-header span {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.03em;
}

.ai-settings-add-btn {
  padding: 4px 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background var(--transition);
}

.ai-settings-add-btn:hover {
  background: var(--accent-dim);
}

/* ── Section Groups */
.ai-settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-settings-group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.ai-settings-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ai-settings-section-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: capitalize;
  padding: 2px 0;
}

/* ── Context Rows */
.ai-ctx-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.5;
}

.ai-ctx-key {
  color: var(--text-muted);
  font-weight: 600;
  min-width: 80px;
  flex-shrink: 0;
  word-break: break-word;
}

.ai-ctx-value {
  color: var(--text-primary);
  flex: 1;
  word-break: break-word;
  white-space: pre-wrap;
}

.ai-ctx-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition);
}

.ai-ctx-row:hover .ai-ctx-actions {
  opacity: 1;
}

.ai-ctx-edit-btn,
.ai-ctx-delete-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  transition: color var(--transition), border-color var(--transition);
}

.ai-ctx-edit-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.ai-ctx-delete-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* ── Inline Edit */
.ai-ctx-edit-input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  padding: 4px 8px;
  resize: vertical;
  outline: none;
}

.ai-ctx-edit-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.ai-ctx-save-edit-btn,
.ai-ctx-cancel-edit-btn {
  padding: 2px 8px;
  font-size: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  border: none;
}

.ai-ctx-save-edit-btn {
  background: var(--accent);
  color: #fff;
}

.ai-ctx-cancel-edit-btn {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ── Add Form */
.ai-settings-add-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ai-settings-form-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.ai-settings-input {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  transition: border-color var(--transition);
}

.ai-settings-input:focus {
  border-color: var(--accent);
}

.ai-settings-textarea {
  resize: vertical;
  min-height: 40px;
}

.ai-settings-form-actions {
  display: flex;
  gap: 8px;
}

.ai-settings-save-btn {
  padding: 4px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
}

.ai-settings-cancel-btn {
  padding: 4px 12px;
  background: var(--bg-primary);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font);
}

/* ─── Voice Mode Button (in panel header) ─────────────── */
#ai-voice-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: color 150ms, background 150ms;
  display: flex;
  align-items: center;
  justify-content: center;
}
#ai-voice-btn:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* ─── Voice Overlay (full-screen) ─────────────────────── */
#atlas-voice-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--bg-primary, #0a0a0f);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 350ms ease;
}
#atlas-voice-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.atlas-voice-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  user-select: none;
}

/* ─── Orb ──────────────────────────────────────────────── */
.atlas-voice-orb-wrap {
  position: relative;
  width: 160px;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.atlas-voice-orb {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--accent, #6c5ce7), color-mix(in srgb, var(--accent, #6c5ce7) 60%, #000));
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  z-index: 2;
  transition: transform 300ms ease, box-shadow 300ms ease;
  box-shadow: 0 0 40px color-mix(in srgb, var(--accent, #6c5ce7) 30%, transparent);
}

.atlas-voice-orb-inner {
  font-size: 36px;
  color: #fff;
  line-height: 1;
  filter: drop-shadow(0 0 8px rgba(255,255,255,0.4));
}

/* Rings */
.atlas-voice-ring {
  position: absolute;
  top: 50%; left: 50%;
  width: 120px; height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent, #6c5ce7) 25%, transparent);
  opacity: 0;
  z-index: 1;
}

/* ── Listening: pulsing rings ──────────────────────────── */
.atlas-voice-listening .atlas-voice-ring { animation: atlas-ring-pulse 2.4s ease-out infinite; }
.atlas-voice-listening .atlas-voice-ring-2 { animation-delay: 0.8s; }
.atlas-voice-listening .atlas-voice-ring-3 { animation-delay: 1.6s; }
.atlas-voice-listening {
  animation: atlas-orb-breathe 2.4s ease-in-out infinite;
  box-shadow: 0 0 60px color-mix(in srgb, var(--accent, #6c5ce7) 40%, transparent);
}

/* ── Thinking: slow rotation + glow ────────────────────── */
.atlas-voice-thinking {
  animation: atlas-orb-spin 2s linear infinite;
  box-shadow: 0 0 60px color-mix(in srgb, var(--accent, #6c5ce7) 50%, transparent),
              0 0 120px color-mix(in srgb, var(--accent, #6c5ce7) 20%, transparent);
}
.atlas-voice-thinking .atlas-voice-ring { display: none; }

/* ── Speaking: bouncy scale ────────────────────────────── */
.atlas-voice-speaking {
  animation: atlas-orb-speak 0.6s ease-in-out infinite alternate;
  box-shadow: 0 0 80px color-mix(in srgb, var(--accent, #6c5ce7) 50%, transparent),
              0 0 160px color-mix(in srgb, var(--accent, #6c5ce7) 15%, transparent);
}
.atlas-voice-speaking .atlas-voice-ring { display: none; }

/* ─── Labels & Transcript ──────────────────────────────── */
.atlas-voice-label {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-secondary, #aaa);
  letter-spacing: 0.5px;
  font-family: var(--font);
}

.atlas-voice-transcript {
  max-width: 500px;
  min-height: 24px;
  font-size: 15px;
  color: var(--text-primary, #ddd);
  text-align: center;
  line-height: 1.5;
  font-family: var(--font);
  padding: 0 20px;
  opacity: 0.8;
}

/* ─── End Button ───────────────────────────────────────── */
.atlas-voice-end-btn {
  margin-top: 16px;
  padding: 12px 32px;
  background: color-mix(in srgb, var(--danger, #e74c3c) 15%, transparent);
  color: var(--danger, #e74c3c);
  border: 1px solid color-mix(in srgb, var(--danger, #e74c3c) 30%, transparent);
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 150ms, transform 150ms;
}
.atlas-voice-end-btn:hover {
  background: color-mix(in srgb, var(--danger, #e74c3c) 25%, transparent);
  transform: scale(1.04);
}

/* ─── Keyframes ────────────────────────────────────────── */
@keyframes atlas-ring-pulse {
  0%   { transform: scale(1);   opacity: 0.5; }
  100% { transform: scale(2.2); opacity: 0; }
}

@keyframes atlas-orb-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

@keyframes atlas-orb-spin {
  0%   { transform: rotate(0deg)   scale(1); }
  50%  { transform: rotate(180deg) scale(0.95); }
  100% { transform: rotate(360deg) scale(1); }
}

@keyframes atlas-orb-speak {
  0%   { transform: scale(1); }
  100% { transform: scale(1.1); }
}

/* ─── Mobile Responsive ─────────────────────────────────── */
@media (max-width: 768px) {
  #ai-fab {
    bottom: 20px;
    right: 16px;
    width: 44px;
    height: 44px;
    font-size: 17px;
  }

  #ai-panel {
    width: 100vw;
  }

  .atlas-voice-orb-wrap {
    width: 140px;
    height: 140px;
  }
  .atlas-voice-orb {
    width: 100px;
    height: 100px;
  }
  .atlas-voice-ring {
    width: 100px; height: 100px;
    margin: -50px 0 0 -50px;
  }
  .atlas-voice-transcript {
    max-width: 90vw;
    font-size: 14px;
  }
}
