/* ============================================
   AI CHAT PANEL - CUTTING EDGE DESIGN
   ============================================ */

.ai-chat-panel {
  position: fixed;
  top: 0;
  right: -450px;
  width: 450px;
  height: 100vh;
  border-left: 1px solid var(--border);
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.8);
  z-index: 4000;
  display: flex;
  flex-direction: column;
  transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(20px);
  overflow: hidden;
}

/* Prevent scroll events from propagating to the canvas */
.ai-chat-panel * {
  overscroll-behavior: contain;
}

.ai-chat-panel,
.ai-chat-messages,
.ai-settings-modal {
  /* Capture all scroll/wheel events */
  touch-action: pan-y;
  overflow-y: auto;
}

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

/* Header */
.ai-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  flex-shrink: 0;
}

.ai-chat-header-left {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex: 1;
  padding-left: 10px;
}

.ai-chat-buddy {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  color: var(--text-secondary);
}

.ai-chat-header-right {
  display: flex;
  gap: 8px;
}

.ai-chat-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.ai-status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

.ai-status-indicator.ai-status-idle {
  background: #10b981;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.ai-status-indicator.ai-status-thinking {
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
  animation: pulse 1.5s ease-in-out infinite;
}

.ai-status-indicator.ai-status-error {
  background: #ef4444;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
}

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

.ai-chat-model-info {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.ai-header-btn {
  width: 32px;
  height: 32px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
}

.ai-header-btn:hover {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
  transform: scale(1.05);
}

.ai-header-btn svg {
  width: 16px;
  height: 16px;
}

/* Messages Container */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* Welcome Message */
.ai-welcome-message {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.ai-welcome-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 20px;
  background: var(--bg-accent-glow);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--accent);
}

.ai-welcome-icon svg {
  width: 32px;
  height: 32px;
  color: var(--accent);
}

.ai-welcome-message h3 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 12px 0;
}

.ai-welcome-message p {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 16px;
}

.ai-welcome-message ul {
  list-style: none;
  padding: 0;
  margin: 20px 0;
  text-align: left;
}

.ai-welcome-message li {
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  font-size: 13px;
}

.ai-welcome-shortcut {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.ai-welcome-shortcut kbd {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  color: var(--accent);
  font-weight: 600;
}

/* Messages */
.ai-message {
  display: flex;
  gap: 12px;
  animation: messageSlideIn 0.3s ease-out;
}

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

.ai-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-message-user .ai-message-avatar {
  background: var(--accent);
  color: var(--text-on-accent);
}

.ai-message-assistant .ai-message-avatar {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--accent);
}

.ai-message-avatar svg {
  width: 18px;
  height: 18px;
}

.ai-message-content {
  flex: 1;
  min-width: 0;
}

.ai-message-text {
  background: var(--bg-tertiary);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  word-wrap: break-word;
}

.ai-message-user .ai-message-text {
  background: var(--accent);
  color: var(--text-on-accent);
}

.ai-message-assistant .ai-message-text {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
}

.ai-message-text strong {
  font-weight: 600;
  color: var(--accent-light);
}

.ai-message-user .ai-message-text strong {
  color: var(--text-on-accent);
}

.ai-message-text em {
  font-style: italic;
}

.ai-message-text code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  color: var(--accent-light);
}

.ai-message-user .ai-message-text code {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-on-accent);
}

.ai-message-text pre {
  background: var(--bg);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.ai-message-text pre code {
  background: none;
  padding: 0;
  display: block;
  white-space: pre;
}

.ai-message-text ul {
  margin: 8px 0;
  padding-left: 1.5em;
  list-style: disc;
}

.ai-message-text ol {
  margin: 8px 0;
  padding-left: 1.5em;
  list-style: decimal;
}

.ai-message-text ul li {
  margin: 4px 0;
  padding-left: 0;
}

.ai-message-text ol li {
  margin: 4px 0;
  padding-left: 0;
}

/* Keep list markers visible even in flex/inline contexts */
.ai-message-text ul,
.ai-message-text ol {
  list-style-position: outside;
}

/* Nested lists */
.ai-message-text li > ul,
.ai-message-text li > ol {
  margin-top: 4px;
  margin-bottom: 4px;
  padding-left: 1.5em;
}

/* Command badges */
.ai-command-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--text-on-accent);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-weight: 600;
  margin: 2px 4px;
  opacity: 0.8;
  white-space: wrap;
}

/* Thinking animation - Modern gradient wave */
.ai-thinking-dots {
  display: inline-flex;
  gap: 2px;
  align-items: center;
  height: 20px;
  padding: 0 4px;
}

.ai-thinking-dots span {
  width: 3px;
  height: 12px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-light) 100%);
  border-radius: 2px;
  animation: thinkingWave 1.2s ease-in-out infinite;
  box-shadow: 0 0 8px var(--accent-glow);
}

.ai-thinking-dots span:nth-child(1) {
  animation-delay: 0s;
}

.ai-thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.ai-thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes thinkingWave {
  0%, 100% {
    height: 12px;
    opacity: 0.4;
  }
  50% {
    height: 20px;
    opacity: 1;
  }
}

/* Thinking Section - Collapsible */
.ai-thinking-section {
  margin-bottom: 12px;
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
  transition: all 0.3s ease;
}

.ai-thinking-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  background: var(--bg-tertiary);
  border-bottom: 1px solid transparent;
  transition: all 0.2s ease;
}

.ai-thinking-header:hover {
  background: var(--bg);
  border-bottom-color: var(--border);
}

.ai-thinking-icon {
  width: 16px;
  height: 16px;
  color: var(--accent);
  flex-shrink: 0;
}

.ai-thinking-header span {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ai-thinking-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  transition: transform 0.3s ease;
  flex-shrink: 0;
}

.ai-thinking-section[data-expanded="true"] .ai-thinking-chevron {
  transform: rotate(180deg);
}

.ai-thinking-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 12px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-tertiary);
  font-family: 'SF Mono', Monaco, Consolas, monospace;
}

.ai-thinking-section[data-expanded="true"] .ai-thinking-content {
  max-height: 500px;
  padding: 12px;
  overflow-y: auto;
}

.ai-thinking-content::-webkit-scrollbar {
  width: 4px;
}

.ai-thinking-content::-webkit-scrollbar-track {
  background: transparent;
}

.ai-thinking-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.ai-thinking-content::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* Input Container */
.ai-chat-input-container {
  flex-shrink: 0;
  padding: 16px 20px 20px;
}

.ai-chat-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.ai-chat-input {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: all 0.2s ease;
  max-height: 150px;
  line-height: 1.5;
}

.ai-chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.ai-chat-input::placeholder {
  color: var(--text-tertiary);
}

.ai-send-btn {
  width: 44px;
  height: 44px;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: var(--text-on-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.ai-send-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.ai-send-btn:hover::before {
  width: 100px;
  height: 100px;
}

.ai-send-btn:hover {
  background: var(--accent-dark);
  transform: scale(1.05);
}

.ai-send-btn:active {
  transform: scale(0.95);
}

.ai-send-btn svg {
  width: 20px;
  height: 20px;
  position: relative;
  z-index: 1;
}

.ai-input-hints {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-tertiary);
  justify-content: flex-end;
}

.ai-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Settings Modal */
.ai-settings-modal {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  animation: fadeIn 0.2s ease-out forwards;
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

.ai-settings-content {
  padding: 10px;
  width: 100%;
  max-width: 400px;
  max-height: 95vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
}

.ai-settings-content::-webkit-scrollbar {
  width: 6px;
}

.ai-settings-content::-webkit-scrollbar-track {
  background: transparent;
}

.ai-settings-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.ai-settings-content::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

.ai-settings-content h3 {
  margin: 0 0 20px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.ai-settings-field {
  margin-bottom: 20px;
}

.ai-settings-field label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ai-prompt-show-default {
  float: right;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
  font-weight: normal;
  transition: all 0.2s ease;
}

.ai-prompt-show-default:hover {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}

.ai-settings-field input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  outline: none;
  transition: all 0.2s ease;
}

.ai-settings-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.ai-settings-field input[readonly] {
  opacity: 1;
  cursor: text;
}

.ai-settings-field input[readonly]:focus {
  cursor: text;
}

.ai-settings-field textarea {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all 0.2s ease;
  resize: vertical;
  min-height: 80px;
}

.ai-settings-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.ai-settings-field small {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

.ai-settings-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.ai-settings-btn {
  flex: 1;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--border);
}

.ai-settings-save {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}

.ai-settings-save:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.ai-settings-cancel {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.ai-settings-cancel:hover {
  background: var(--bg);
  color: var(--text);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .ai-chat-panel {
    width: 100vw;
    right: -100vw;
  }

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

  .ai-chat-header {
    padding: 16px;
  }

  .ai-chat-messages {
    padding: 16px;
  }

  .ai-chat-input-container {
    padding: 12px 16px 16px;
  }

  .ai-welcome-message {
    padding: 20px;
  }

  .ai-settings-content {
    width: 95%;
    padding: 10px;
  }
}

/* Smooth transitions for all interactive elements */
* {
  -webkit-tap-highlight-color: transparent;
}

.ai-chat-panel button,
.ai-chat-panel input,
.ai-chat-panel textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* Accessibility improvements */
.ai-chat-input:focus-visible,
.ai-send-btn:focus-visible,
.ai-header-btn:focus-visible,
.ai-settings-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Character SVG theme color support */
.accent-stroke {
  stroke: var(--accent) !important;
}

.accent-fill {
  fill: var(--accent) !important;
}

.accent-stop-1 {
  stop-color: var(--accent) !important;
}

.accent-stop-2 {
  stop-color: var(--accent-light) !important;
}
