/* City Triangles AI Chat Widget Styles */

/* CSS Variables for theming */
:root {
  --ct-chat-primary: #5e64ff;
  --ct-chat-primary-dark: #4b52cc;
  --ct-chat-bg: #ffffff;
  --ct-chat-panel-bg: #f8f9fa;
  --ct-chat-border: #d1d8dd;
  --ct-chat-text: #36414c;
  --ct-chat-text-muted: #8d99a6;
  --ct-chat-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  --ct-chat-radius: 12px;
  --ct-chat-fab-size: 56px;
  --ct-chat-panel-width: 480px;
}

/* Dark mode support */
[data-theme="dark"] {
  --ct-chat-bg: #1f2937;
  --ct-chat-panel-bg: #111827;
  --ct-chat-border: #374151;
  --ct-chat-text: #f9fafb;
  --ct-chat-text-muted: #9ca3af;
}

/* Main widget container */
.ct-chat-widget {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Backdrop overlay */
.ct-chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease;
  z-index: 9998;
}

.ct-chat-backdrop.open {
  opacity: 1;
  visibility: visible;
}

/* FAB Button */
.ct-chat-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: var(--ct-chat-fab-size);
  height: var(--ct-chat-fab-size);
  border-radius: 50%;
  background: var(--ct-chat-primary);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--ct-chat-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: all 0.3s ease;
  z-index: 10000;
}

/* FAB Button */
.ct-chat-fab {
  width: var(--ct-chat-fab-size);
  height: var(--ct-chat-fab-size);
  border-radius: 50%;
  background: var(--ct-chat-primary);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--ct-chat-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: all 0.3s ease;
  position: relative;
}

.ct-chat-fab:hover {
  background: var(--ct-chat-primary-dark);
  transform: scale(1.05);
}

.ct-chat-fab:active {
  transform: scale(0.95);
}

/* Unread badge */
.ct-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ff5858;
  color: white;
  font-size: 11px;
  font-weight: bold;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* Chat Panel — right-side slide-in drawer */
.ct-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--ct-chat-panel-width);
  height: 100vh;
  max-height: 100vh;
  background: var(--ct-chat-bg);
  box-shadow: -4px 0 30px rgba(0, 0, 0, 0.15);
  border-left: 1px solid var(--ct-chat-border);
  border-radius: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
}

.ct-chat-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

/* Panel Header */
.ct-chat-header {
  background: var(--ct-chat-primary);
  color: white;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ct-chat-header-title {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ct-chat-header-status {
  width: 8px;
  height: 8px;
  background: #2ecc71;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.ct-chat-header-actions {
  display: flex;
  gap: 8px;
}

.ct-chat-header-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.2s;
}

.ct-chat-header-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Messages Area */
.ct-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--ct-chat-panel-bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Message Bubbles */
.ct-chat-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.ct-chat-message.user {
  align-self: flex-end;
  background: var(--ct-chat-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.ct-chat-message.assistant {
  align-self: flex-start;
  background: var(--ct-chat-bg);
  color: var(--ct-chat-text);
  border: 1px solid var(--ct-chat-border);
  border-bottom-left-radius: 4px;
}

.ct-chat-message.assistant code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: "SF Mono", Monaco, monospace;
  font-size: 12px;
}

/* Markdown rendering styles */
.ct-chat-message-content p {
  margin: 0 0 8px 0;
}
.ct-chat-message-content p:last-child {
  margin-bottom: 0;
}

.ct-chat-message-content h1,
.ct-chat-message-content h2,
.ct-chat-message-content h3,
.ct-chat-message-content h4,
.ct-chat-message-content h5,
.ct-chat-message-content h6 {
  margin: 12px 0 6px 0;
  font-weight: 600;
  color: var(--ct-chat-text);
}
.ct-chat-message-content h1 { font-size: 16px; }
.ct-chat-message-content h2 { font-size: 15px; }
.ct-chat-message-content h3 { font-size: 14px; }
.ct-chat-message-content h4,
.ct-chat-message-content h5,
.ct-chat-message-content h6 { font-size: 13px; }

.ct-chat-message-content ul,
.ct-chat-message-content ol {
  margin: 8px 0;
  padding-left: 20px;
}
.ct-chat-message-content li {
  margin-bottom: 4px;
  line-height: 1.5;
}

.ct-chat-message-content blockquote {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--ct-chat-primary);
  background: rgba(94, 100, 255, 0.06);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  color: var(--ct-chat-text-muted);
}

.ct-chat-message-content hr {
  border: none;
  border-top: 1px solid var(--ct-chat-border);
  margin: 12px 0;
}

.ct-chat-message-content a {
  color: var(--ct-chat-primary);
  text-decoration: underline;
}
.ct-chat-message-content a:hover {
  color: var(--ct-chat-primary-dark);
}

.ct-chat-message-content pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: "SF Mono", Monaco, monospace;
  font-size: 12px;
  line-height: 1.5;
  margin: 8px 0;
}
.ct-chat-message-content pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
  border-radius: 0;
}

/* Dark mode overrides for markdown */
[data-theme="dark"] .ct-chat-message-content pre {
  background: #11111b;
  color: #cdd6f4;
}
[data-theme="dark"] .ct-chat-message-content blockquote {
  background: rgba(94, 100, 255, 0.1);
}

.ct-chat-message-time {
  font-size: 11px;
  opacity: 0.6;
  margin-top: 4px;
}

/* Typing indicator */
.ct-chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}

.ct-chat-typing-dot {
  width: 8px;
  height: 8px;
  background: var(--ct-chat-text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}

.ct-chat-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ct-chat-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.ct-chat-input-area {
  padding: 12px;
  background: var(--ct-chat-bg);
  border-top: 1px solid var(--ct-chat-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.ct-chat-textarea {
  flex: 1;
  border: 1px solid var(--ct-chat-border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  resize: none;
  max-height: 120px;
  font-family: inherit;
  background: var(--ct-chat-bg);
  color: var(--ct-chat-text);
}

.ct-chat-textarea:focus {
  outline: none;
  border-color: var(--ct-chat-primary);
}

.ct-chat-textarea:disabled {
  background: var(--ct-chat-panel-bg);
  cursor: not-allowed;
}

.ct-chat-send-btn,
.ct-chat-attach-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s;
}

.ct-chat-send-btn {
  background: var(--ct-chat-primary);
  color: white;
}

.ct-chat-send-btn:hover:not(:disabled) {
  background: var(--ct-chat-primary-dark);
}

.ct-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ct-chat-attach-btn {
  background: transparent;
  color: var(--ct-chat-text-muted);
  border: 1px solid var(--ct-chat-border);
}

.ct-chat-attach-btn:hover {
  background: var(--ct-chat-panel-bg);
  color: var(--ct-chat-text);
}

/* Attachments */
.ct-chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ct-chat-attachment {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--ct-chat-panel-bg);
  border-radius: 12px;
  font-size: 12px;
  border: 1px solid var(--ct-chat-border);
}

.ct-chat-attachment-remove {
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.ct-chat-attachment-remove:hover {
  opacity: 1;
}

/* Drag Overlay */
.ct-chat-drag-overlay {
  position: absolute;
  inset: 0;
  background: rgba(94, 100, 255, 0.1);
  border: 2px dashed var(--ct-chat-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
  pointer-events: none;
}

.ct-chat-drag-overlay.active {
  opacity: 1;
  visibility: visible;
}

.ct-chat-drag-icon {
  font-size: 48px;
  color: var(--ct-chat-primary);
}

.ct-chat-drag-text {
  color: var(--ct-chat-text);
  font-size: 14px;
}

/* Login Form */
.ct-chat-login {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
}

.ct-chat-login-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ct-chat-text);
  text-align: center;
}

.ct-chat-login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ct-chat-login-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ct-chat-text-muted);
}

.ct-chat-login-field input {
  padding: 10px 12px;
  border: 1px solid var(--ct-chat-border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--ct-chat-bg);
  color: var(--ct-chat-text);
}

.ct-chat-login-field input:focus {
  outline: none;
  border-color: var(--ct-chat-primary);
}

.ct-chat-login-btn {
  padding: 12px;
  background: var(--ct-chat-primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.ct-chat-login-btn:hover {
  background: var(--ct-chat-primary-dark);
}

.ct-chat-login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ct-chat-login-error {
  color: #ff5858;
  font-size: 13px;
  text-align: center;
}

/* Action Confirmation Cards */
.ct-chat-action-card {
  background: var(--ct-chat-bg);
  border: 1px solid var(--ct-chat-border);
  border-radius: 8px;
  padding: 12px;
  margin-top: 8px;
}

.ct-chat-action-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--ct-chat-text);
  margin-bottom: 8px;
}

.ct-chat-action-preview {
  background: var(--ct-chat-panel-bg);
  padding: 10px;
  border-radius: 6px;
  font-family: "SF Mono", Monaco, monospace;
  font-size: 12px;
  color: var(--ct-chat-text);
  overflow-x: auto;
  margin-bottom: 12px;
}

.ct-chat-action-buttons {
  display: flex;
  gap: 8px;
}

.ct-chat-action-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.ct-chat-action-btn.confirm {
  background: var(--ct-chat-primary);
  color: white;
  border: none;
}

.ct-chat-action-btn.confirm:hover {
  background: var(--ct-chat-primary-dark);
}

.ct-chat-action-btn.cancel {
  background: transparent;
  color: var(--ct-chat-text-muted);
  border: 1px solid var(--ct-chat-border);
}

.ct-chat-action-btn.cancel:hover {
  background: var(--ct-chat-panel-bg);
  color: var(--ct-chat-text);
}

/* Empty state */
.ct-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--ct-chat-text-muted);
  text-align: center;
  padding: 24px;
}

.ct-chat-empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.ct-chat-empty-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.ct-chat-empty-text {
  font-size: 14px;
  line-height: 1.5;
}

/* Context indicator */
.ct-chat-context {
  padding: 8px 16px;
  background: var(--ct-chat-panel-bg);
  border-bottom: 1px solid var(--ct-chat-border);
  font-size: 12px;
  color: var(--ct-chat-text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ct-chat-context-doctype {
  font-weight: 500;
  color: var(--ct-chat-primary);
}

/* User info (displayed when logged in) */
.ct-chat-user-info {
  padding: 8px 16px;
  background: var(--ct-chat-panel-bg);
  border-bottom: 1px solid var(--ct-chat-border);
  font-size: 12px;
  color: var(--ct-chat-text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ct-chat-user-name {
  font-weight: 500;
  color: var(--ct-chat-text);
}

/* Mobile responsiveness */
@media (max-width: 520px) {
  .ct-chat-fab {
    bottom: 12px;
    right: 12px;
  }

  .ct-chat-panel {
    width: 100vw;
    max-width: 100vw;
    border-left: none;
  }
}

/* Animation for new messages */
@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Feedback form */
.ct-feedback-form {
  padding: 16px;
}

.ct-feedback-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ct-chat-text);
  margin-bottom: 4px;
}

.ct-feedback-subtitle {
  font-size: 13px;
  color: var(--ct-chat-text-muted);
  margin-bottom: 16px;
}

.ct-feedback-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ct-chat-text-muted);
  margin-bottom: 4px;
  margin-top: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ct-feedback-select,
.ct-feedback-input,
.ct-feedback-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--ct-chat-border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--ct-chat-text);
  background: var(--ct-chat-bg);
  box-sizing: border-box;
  font-family: inherit;
}

.ct-feedback-select:focus,
.ct-feedback-input:focus,
.ct-feedback-textarea:focus {
  outline: none;
  border-color: var(--ct-chat-primary);
  box-shadow: 0 0 0 2px rgba(94, 100, 255, 0.15);
}

.ct-feedback-textarea {
  resize: vertical;
  min-height: 80px;
}

.ct-feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.ct-feedback-cancel {
  padding: 8px 16px;
  border: 1px solid var(--ct-chat-border);
  border-radius: 6px;
  background: transparent;
  color: var(--ct-chat-text-muted);
  cursor: pointer;
  font-size: 13px;
}

.ct-feedback-cancel:hover {
  background: var(--ct-chat-panel-bg);
}

.ct-feedback-submit {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: var(--ct-chat-primary);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.ct-feedback-submit:hover {
  background: var(--ct-chat-primary-dark);
}

.ct-feedback-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ct-chat-message {
  animation: message-in 0.3s ease;
}
