/* =============================================
   PROTAC-DB Chat — ChatGPT-style Interface
   ============================================= */

/* --- CSS Variables --- */
:root {
  --chat-font: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --chat-mono: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, Consolas, monospace;
  --chat-accent: #05cbb8;
  --chat-accent-hover: #04a99b;
  --chat-accent-light: #e6faf7;
  --chat-bg: #ffffff;
  --chat-surface: #f7f7f8;
  --chat-surface-hover: #eeeeef;
  --chat-border: #e5e5e5;
  --chat-text: #1a1a1a;
  --chat-text-secondary: #6b7280;
  --chat-text-tertiary: #9ca3af;
  --chat-shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --chat-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --chat-shadow-lg: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --chat-radius: 12px;
  --chat-radius-sm: 8px;
  --chat-radius-xs: 6px;
  --chat-transition: 180ms ease;
}

/* =============================================
   PAGE MODE — Full ChatGPT-style Chat Page
   ============================================= */

/* Reset & baseline — only for chat page */
html.chat-page,
html.chat-page body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

/* Fixed navbar stays on top (Bootstrap handles positioning).
   Everything below navbar fills the remaining viewport. */
.chat-page-wrapper {
  position: fixed;
  top: 50px;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 768px;
  padding: 0 20px;
  font-family: var(--chat-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--chat-bg);
}

/* --- Messages Area --- */

.chat-page-messages {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px 0 8px;
  scroll-behavior: smooth;
}

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

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

.chat-page-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.chat-page-messages::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* --- Welcome Screen --- */

.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin: auto;
  padding: 40px 20px;
}

.chat-welcome h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--chat-text);
  margin: 0 0 8px;
  letter-spacing: -0.3px;
}

.chat-welcome p {
  font-size: 14px;
  color: var(--chat-text-secondary);
  margin: 0 0 32px;
  max-width: 420px;
  line-height: 1.5;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 520px;
}

.chat-suggestion-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  font-size: 13px;
  font-family: var(--chat-font);
  color: var(--chat-text);
  cursor: pointer;
  transition: all var(--chat-transition);
  white-space: nowrap;
}

.chat-suggestion-chip:hover {
  background: var(--chat-surface-hover);
  border-color: #ccc;
  transform: translateY(-1px);
  box-shadow: var(--chat-shadow-sm);
}

.chat-suggestion-chip:active {
  transform: translateY(0);
}

.chat-suggestion-chip svg {
  width: 14px;
  height: 14px;
  stroke: var(--chat-text-secondary);
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
}

/* --- Input Area --- */

.chat-input-area {
  flex-shrink: 0;
  padding: 0 0 24px;
  position: relative;
}

.chat-input-area::before {
  content: '';
  position: absolute;
  top: -16px;
  left: 0;
  right: 0;
  height: 16px;
  background: linear-gradient(to top, var(--chat-bg), transparent);
  pointer-events: none;
}

.chat-input-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  padding: 6px 8px 6px 16px;
  box-shadow: var(--chat-shadow);
  transition: border-color var(--chat-transition), box-shadow var(--chat-transition);
}

.chat-input-form:focus-within {
  border-color: var(--chat-accent);
  box-shadow: 0 0 0 3px rgba(5, 203, 184, 0.15), var(--chat-shadow);
}

.chat-input-form textarea {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  font-family: var(--chat-font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--chat-text);
  background: transparent;
  padding: 6px 0;
  max-height: 200px;
  min-height: 24px;
}

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

.chat-send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 0;
  background: var(--chat-accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--chat-transition);
  padding: 0;
}

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

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

.chat-send-btn:disabled {
  background: #d1d5db;
  cursor: not-allowed;
  transform: none;
}

.chat-send-btn svg {
  width: 18px;
  height: 18px;
}

.chat-disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--chat-text-tertiary);
  margin: 10px 0 0;
  line-height: 1.4;
}

/* =============================================
   SHARED MESSAGE STYLES
   ============================================= */

.chat-message-row {
  display: flex;
  gap: 12px;
  padding: 16px 0;
  animation: chatMessageIn 300ms ease both;
}

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

.chat-message-row + .chat-message-row {
  border-top: 1px solid var(--chat-border);
}

.chat-message-avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  margin-top: 2px;
}

.chat-message-avatar--user {
  background: #123a55;
  color: #fff;
  font-size: 13px;
}

.chat-message-avatar--assistant {
  background: var(--chat-accent);
  color: #fff;
}

.chat-message-avatar--error {
  background: #ef4444;
  color: #fff;
  font-size: 13px;
}

.chat-message-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chat-message-role {
  font-size: 12px;
  font-weight: 600;
  color: var(--chat-text);
  margin-bottom: 4px;
  letter-spacing: 0.2px;
}

.chat-message-content {
  font-size: 15px;
  line-height: 1.65;
  color: var(--chat-text);
  word-break: break-word;
}

.chat-message-content p {
  margin: 0 0 12px;
}

.chat-message-content p:last-child {
  margin-bottom: 0;
}

.chat-message-content ul,
.chat-message-content ol {
  margin: 8px 0;
  padding-left: 20px;
}

.chat-message-content li {
  margin-bottom: 4px;
}

.chat-message-content li:last-child {
  margin-bottom: 0;
}

.chat-message-content strong {
  font-weight: 600;
  color: #0d0d0d;
}

.chat-message-content em {
  font-style: italic;
}

.chat-message-content a {
  color: var(--chat-accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--chat-transition);
}

.chat-message-content a:hover {
  border-bottom-color: var(--chat-accent);
}

/* --- Code blocks --- */

.chat-message-content code {
  font-family: var(--chat-mono);
  font-size: 13px;
  background: var(--chat-surface);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--chat-border);
}

.chat-message-content pre {
  background: #1e1e1e;
  color: #e0e0e0;
  font-family: var(--chat-mono);
  font-size: 13px;
  line-height: 1.5;
  padding: 14px 16px;
  border-radius: var(--chat-radius-sm);
  overflow-x: auto;
  margin: 12px 0;
}

.chat-message-content pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

/* --- Tables --- */

.chat-message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

.chat-message-content th,
.chat-message-content td {
  padding: 8px 12px;
  text-align: left;
  border: 1px solid var(--chat-border);
}

.chat-message-content th {
  background: var(--chat-surface);
  font-weight: 600;
  color: var(--chat-text);
}

.chat-message-content td {
  background: var(--chat-bg);
}

/* --- Blockquotes --- */

.chat-message-content blockquote {
  margin: 12px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--chat-accent);
  background: var(--chat-accent-light);
  border-radius: 0 var(--chat-radius-xs) var(--chat-radius-xs) 0;
  color: #17423d;
  font-size: 14px;
}

.chat-message-content blockquote p {
  margin: 0;
}

/* --- Headings --- */

.chat-message-content h1, .chat-message-content h2,
.chat-message-content h3, .chat-message-content h4 {
  font-weight: 600;
  color: var(--chat-text);
  margin: 16px 0 8px;
  line-height: 1.3;
}

.chat-message-content h1 { font-size: 18px; }
.chat-message-content h2 { font-size: 16px; }
.chat-message-content h3 { font-size: 15px; }
.chat-message-content h4 { font-size: 14px; }

/* --- Horizontal rules --- */

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

/* --- Message actions --- */

.chat-message-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity var(--chat-transition);
}

.chat-message-row:hover .chat-message-actions {
  opacity: 1;
}

.chat-message-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-xs);
  background: var(--chat-bg);
  color: var(--chat-text-secondary);
  font-size: 12px;
  font-family: var(--chat-font);
  cursor: pointer;
  transition: all var(--chat-transition);
}

.chat-message-action:hover {
  background: var(--chat-surface);
  border-color: #ccc;
}

.chat-message-action svg {
  width: 13px;
  height: 13px;
}

.chat-message-action--copied {
  color: var(--chat-accent);
  border-color: var(--chat-accent);
  background: var(--chat-accent-light);
}

/* =============================================
   ERROR MESSAGE
   ============================================= */

.chat-message-content--error {
  color: #991b1b;
}

/* =============================================
   TYPING INDICATOR
   ============================================= */

.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-text-tertiary);
  animation: chatTypingBounce 1.4s infinite both;
}

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

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

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

/* =============================================
   STATUS BAR (page mode)
   ============================================= */

.chat-page-status {
  font-size: 12px;
  color: var(--chat-text-tertiary);
  text-align: center;
  padding: 0 0 8px;
  min-height: 18px;
  transition: color var(--chat-transition);
}

.chat-page-status--active {
  color: var(--chat-text-secondary);
}

/* =============================================
   WIDGET MODE — Floating Chat Widget
   ============================================= */

.protacdb-chat-widget {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 2000;
  font-family: var(--chat-font);
}

.protacdb-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--chat-accent);
  color: #ffffff;
  font-weight: 600;
  font-size: 13px;
  font-family: var(--chat-font);
  box-shadow: 0 8px 24px rgba(5, 203, 184, 0.35);
  cursor: pointer;
  transition: all var(--chat-transition);
  letter-spacing: 0.3px;
}

.protacdb-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 28px rgba(5, 203, 184, 0.45);
}

.protacdb-chat-toggle:active {
  transform: scale(0.95);
}

.protacdb-chat-panel {
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 520px;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: 0 20px 48px rgba(0,0,0,0.18), 0 4px 12px rgba(0,0,0,0.08);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: chatPanelIn 250ms ease both;
}

@keyframes chatPanelIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.protacdb-chat-panel[hidden] {
  display: none;
}

.protacdb-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #123a55;
  color: #ffffff;
  flex-shrink: 0;
}

.protacdb-chat-header strong {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.protacdb-chat-header button {
  background: transparent;
  border: 0;
  color: rgba(255,255,255,0.75);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color var(--chat-transition);
}

.protacdb-chat-header button:hover {
  color: #ffffff;
}

.protacdb-chat-status {
  padding: 8px 16px;
  background: #eef7f6;
  color: #31565a;
  font-size: 11px;
  flex-shrink: 0;
  min-height: 32px;
  display: flex;
  align-items: center;
}

.protacdb-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  background: var(--chat-bg);
}

.protacdb-chat-messages::-webkit-scrollbar {
  width: 5px;
}

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

.protacdb-chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

/* Widget message overrides (more compact) */
.protacdb-chat-messages .chat-message-row {
  padding: 10px 0;
  gap: 8px;
}

.protacdb-chat-messages .chat-message-avatar {
  width: 24px;
  height: 24px;
  font-size: 11px;
  border-radius: 3px;
}

.protacdb-chat-messages .chat-message-content {
  font-size: 13px;
  line-height: 1.5;
}

.protacdb-chat-messages .chat-message-role {
  font-size: 11px;
}

.protacdb-chat-messages .chat-message-actions {
  opacity: 1;
}

.protacdb-chat-form {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-bg);
  flex-shrink: 0;
}

.protacdb-chat-input {
  flex: 1;
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: var(--chat-font);
  outline: none;
  transition: border-color var(--chat-transition);
}

.protacdb-chat-input:focus {
  border-color: var(--chat-accent);
}

.protacdb-chat-form button {
  border: 0;
  border-radius: 50%;
  background: var(--chat-accent);
  color: #ffffff;
  width: 34px;
  height: 34px;
  padding: 0;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--chat-transition);
}

.protacdb-chat-form button:hover {
  background: var(--chat-accent-hover);
}

.protacdb-chat-form button:disabled {
  background: #d1d5db;
  cursor: not-allowed;
}

/* =============================================
   RESPONSIVE
   ============================================= */

@media (max-width: 640px) {
  .chat-page-wrapper {
    padding: 0 12px;
    max-width: 100%;
  }

  .chat-page-messages {
    padding: 16px 0 8px;
  }

  .chat-welcome {
    padding: 40px 12px 24px;
  }

  .chat-welcome h2 {
    font-size: 20px;
  }

  .chat-suggestions {
    gap: 8px;
  }

  .chat-suggestion-chip {
    font-size: 12px;
    padding: 6px 12px;
  }

  .chat-message-row {
    gap: 8px;
    padding: 12px 0;
  }

  .chat-message-content {
    font-size: 14px;
  }

  .chat-input-area {
    padding: 0 0 16px;
  }

  .chat-input-form {
    padding: 4px 6px 4px 12px;
  }

  .chat-input-form textarea {
    font-size: 14px;
  }

  .chat-disclaimer {
    font-size: 10px;
  }

  /* Widget */
  .protacdb-chat-widget {
    right: 12px;
    bottom: 12px;
  }

  .protacdb-chat-panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 100px);
    max-width: none;
  }
}

@media (max-width: 380px) {
  .chat-page-wrapper {
    padding: 0 8px;
    max-width: 100%;
  }

  .chat-message-content {
    font-size: 13px;
  }
}
