/* ── AI Chat Widget — Side Panel ────────────────────────── */

/* Overlay backdrop */
.ai-chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 9997;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.ai-chat-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Side Panel */
.ai-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 480px;
  height: 100vh;
  background: #fff;
  z-index: 9998;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Outfit', sans-serif;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.ai-chat-panel.open {
  transform: translateX(0);
}

/* Header */
.ai-chat-header {
  background: var(--nissan-red, #c3002f);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.ai-chat-header-title {
  font-weight: 600;
  font-size: 16px;
}
.ai-chat-header-sub {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 2px;
}
.ai-chat-header-actions {
  display: flex;
  gap: 8px;
}
.ai-chat-header-actions button {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background 0.15s;
}
.ai-chat-header-actions button:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* Messages area */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-chat-messages::-webkit-scrollbar { width: 5px; }
.ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ai-chat-messages::-webkit-scrollbar-thumb { background: #d0d0d0; border-radius: 3px; }

/* Message bubbles */
.ai-chat-msg {
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
}
.ai-chat-msg.user {
  align-self: flex-end;
  background: var(--nissan-red, #c3002f);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.ai-chat-msg.assistant {
  align-self: flex-start;
  background: #f3f4f6;
  color: #1a1c21;
  border-bottom-left-radius: 4px;
  max-width: 100%;
}

/* Suggestion card */
.ai-suggestion-card {
  align-self: flex-start;
  max-width: 95%;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
}
.ai-suggestion-card .suggestion-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--nissan-red, #c3002f);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}
.ai-suggestion-card .suggestion-text {
  margin-bottom: 8px;
  line-height: 1.5;
  color: #1a1c21;
  white-space: pre-wrap;
}
.ai-suggestion-card .suggestion-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.ai-suggestion-card .suggestion-actions button {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  font-size: 12px;
  font-family: 'Outfit', sans-serif;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.ai-suggestion-card .suggestion-actions button:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

/* Confirmation card */
.ai-confirm-card {
  align-self: flex-start;
  max-width: 95%;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
}
.ai-confirm-card .confirm-title {
  font-weight: 600;
  color: #92400e;
  margin-bottom: 4px;
}
.ai-confirm-card .confirm-desc {
  color: #78350f;
  margin-bottom: 10px;
  line-height: 1.6;
}
.ai-confirm-card .confirm-desc p {
  margin: 0 0 6px;
}
.ai-confirm-card .confirm-desc p:last-child {
  margin-bottom: 0;
}
.ai-confirm-card .confirm-desc strong {
  color: #92400e;
}
.ai-confirm-card .confirm-desc ul {
  margin: 4px 0 8px;
  padding-left: 18px;
}
.ai-confirm-card .confirm-desc li {
  margin: 3px 0;
}
.ai-confirm-card .confirm-desc code {
  background: rgba(146, 64, 14, 0.1);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
.ai-confirm-card .confirm-actions {
  display: flex;
  gap: 8px;
}
.ai-confirm-card .confirm-actions button {
  padding: 6px 16px;
  border-radius: 6px;
  border: none;
  font-size: 12.5px;
  font-family: 'Outfit', sans-serif;
  cursor: pointer;
  font-weight: 500;
  transition: opacity 0.15s;
}
.ai-confirm-card .confirm-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.ai-confirm-card .confirm-actions .btn-confirm {
  background: var(--nissan-red, #c3002f);
  color: #fff;
}
.ai-confirm-card .confirm-actions .btn-confirm:hover:not(:disabled) {
  opacity: 0.9;
}
.ai-confirm-card .confirm-actions .btn-cancel {
  background: #e5e7eb;
  color: #374151;
}
.ai-confirm-card .confirm-actions .btn-cancel:hover:not(:disabled) {
  background: #d1d5db;
}

/* Quick action buttons */
.ai-chat-quick {
  display: flex;
  gap: 6px;
  padding: 8px 20px;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.ai-chat-quick button {
  padding: 5px 12px;
  border-radius: 16px;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #6b7280;
  font-size: 12px;
  font-family: 'Outfit', sans-serif;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.ai-chat-quick button:hover {
  background: var(--nissan-red, #c3002f);
  color: #fff;
  border-color: var(--nissan-red, #c3002f);
}

/* Input area */
.ai-chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
}
.ai-chat-input input {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-family: 'Outfit', sans-serif;
  outline: none;
  transition: border-color 0.15s;
}
.ai-chat-input input:focus {
  border-color: var(--nissan-red, #c3002f);
}
.ai-chat-input button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--nissan-red, #c3002f);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.ai-chat-input button:hover {
  opacity: 0.9;
}
.ai-chat-input button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Loading dots */
.ai-chat-loading {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 10px 14px;
}
.ai-chat-loading span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  animation: ai-dot-bounce 1.2s infinite ease-in-out;
}
.ai-chat-loading span:nth-child(2) {
  animation-delay: 0.15s;
}
.ai-chat-loading span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes ai-dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Context pill in header */
.ai-chat-context-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  margin-top: 2px;
}

/* Tables in assistant messages */
.ai-table-wrap {
  overflow-x: auto;
  margin: 6px 0;
}
.ai-table {
  border-collapse: collapse;
  font-size: 12px;
  width: 100%;
  min-width: 300px;
}
.ai-table th,
.ai-table td {
  border: 1px solid #d1d5db;
  padding: 5px 8px;
  text-align: left;
  white-space: nowrap;
}
.ai-table th {
  background: #e5e7eb;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #374151;
}
.ai-table tr:nth-child(even) td {
  background: #f9fafb;
}
.ai-table tr:hover td {
  background: #eef2ff;
}

/* Pagination buttons */
.ai-pagination {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 4px 0;
  flex-wrap: wrap;
}
.ai-pagination button {
  min-width: 32px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  font-size: 12px;
  font-family: 'Outfit', sans-serif;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.ai-pagination button:hover:not(:disabled) {
  background: var(--nissan-red, #c3002f);
  color: #fff;
  border-color: var(--nissan-red, #c3002f);
}
.ai-pagination button.active {
  background: var(--nissan-red, #c3002f);
  color: #fff;
  border-color: var(--nissan-red, #c3002f);
  cursor: default;
}

/* Markdown in assistant messages */
.ai-chat-msg.assistant h3 { font-size: 14px; margin: 8px 0 4px; }
.ai-chat-msg.assistant h4 { font-size: 13px; margin: 6px 0 3px; }
.ai-chat-msg.assistant ul { margin: 4px 0; padding-left: 18px; }
.ai-chat-msg.assistant li { margin: 2px 0; }
.ai-chat-msg.assistant code {
  background: #e5e7eb;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
.ai-chat-msg.assistant p { margin: 0; }

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