/* ============================================
   CHATGPT-INSPIRED DESIGN SYSTEM
   FlaskWebHook - Modern Chat Interface
   ============================================ */

/* ============================================
   CSS VARIABLES - Color Palette & Design Tokens
   ============================================ */

:root {
  /* ChatGPT Color Palette */
  --bg-main: #ffffff;
  --bg-alt: #f7f7f8;
  --bg-sidebar: #1a1a1a;
  --bg-sidebar-hover: #2a2a2a;
  
  --text-primary: #0d0d0d;
  --text-secondary: #676767;
  --text-tertiary: #8e8e8e;
  
  --border-light: #e5e5e5;
  --border-medium: #d1d1d1;
  
  --message-user-bg: #f7f7f8;
  --message-assistant-bg: #ffffff;
  
  --accent-primary: #10a37f;
  --accent-hover: #0e9070;
  
  --input-border: #d1d5db;
  --input-focus: #10a37f;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  
  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
  --transition-slow: 300ms ease;
}

/* ============================================
   BASE STYLES
   ============================================ */

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Chat messages scrollbar - cleaner look */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

/* ============================================
   CHAT WRAPPER - Main Container
   ============================================ */

.chat-wrapper {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px);
  background: var(--bg-alt);
  position: relative;
}

/* ============================================
   MESSAGES CONTAINER
   ============================================ */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 24px;
}

/* ============================================
   MESSAGE ROWS
   ============================================ */

.message-row {
  width: 100%;
  padding: 24px 0;
  border-bottom: 1px solid var(--border-light);
  transition: background-color var(--transition-fast);
}

.message-user {
  background-color: var(--message-user-bg);
}

.message-assistant {
  background-color: var(--message-assistant-bg);
}

.message-row:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

/* Message fade-in animation */
.message-row {
  animation: message-fade-in 0.3s ease-out;
}

@keyframes message-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   MESSAGE CONTENT WRAPPER (Centered)
   ============================================ */

.message-content-wrapper {
  max-width: 768px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

/* ============================================
   MESSAGE AVATARS
   ============================================ */

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  color: white;
}

.message-user .message-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.message-assistant .message-avatar {
  background: var(--accent-primary);
}

/* ============================================
   MESSAGE CONTENT
   ============================================ */

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

.message-content > p {
  margin: 0 0 12px 0;
  line-height: 1.75;
  color: var(--text-primary);
  font-size: 16px;
}

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

/* ============================================
   MESSAGE ACTIONS (Copy button, etc.)
   ============================================ */

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

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

.action-btn {
  padding: 6px 12px;
  border: 1px solid var(--border-light);
  background: white;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-btn:hover {
  background: var(--bg-alt);
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.action-btn i {
  font-size: 12px;
}

/* ============================================
   CHAT INPUT AREA (Sticky Bottom)
   ============================================ */

.chat-input-area {
  position: sticky;
  bottom: 0;
  background: var(--bg-alt);
  border-top: 1px solid var(--border-light);
  padding: 20px 0 24px;
  z-index: 10;
}

.chat-input-wrapper {
  max-width: 768px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ============================================
   INPUT CONTAINER
   ============================================ */

.input-container {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: white;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-normal);
}

.input-container:focus-within {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.1);
}

/* ============================================
   TEXTAREA
   ============================================ */

.chat-textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-primary);
  background: transparent;
  max-height: 200px;
  overflow-y: auto;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 24px;
}

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

/* ============================================
   SEND BUTTON
   ============================================ */

.send-button {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--accent-primary);
  color: white;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.send-button:disabled {
  background: var(--border-medium);
  cursor: not-allowed;
  opacity: 0.5;
}

.send-button i {
  font-size: 14px;
}

/* ============================================
   INPUT FOOTER
   ============================================ */

.input-footer {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-tertiary);
}

/* ============================================
   WELCOME MESSAGE
   ============================================ */

.welcome-message {
  max-width: 768px;
  margin: 48px auto;
  padding: 0 24px;
  text-align: center;
}

.welcome-message h2 {
  font-size: 24px;
  color: var(--text-primary);
  margin-bottom: 12px;
  font-weight: 600;
}

.welcome-message p {
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 8px;
}

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

.typing-indicator {
  display: flex;
  gap: 6px;
  padding: 4px 0;
}

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

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.7;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* ============================================
   STREAMING CURSOR
   ============================================ */

.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 18px;
  background: var(--accent-primary);
  margin-left: 2px;
  animation: cursor-blink 1s infinite;
  vertical-align: text-bottom;
}

@keyframes cursor-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* ============================================
   HEADER STYLING
   ============================================ */

header {
  background: white;
  border-bottom: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
}

header h2 {
  color: var(--text-primary);
  font-weight: 600;
}

#webhook-selector {
  background: white;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 8px 32px 8px 12px;
  font-size: 14px;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

#webhook-selector:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.1);
}

/* ============================================
   SIDEBAR ENHANCEMENTS
   ============================================ */

#sidebar {
  background: var(--bg-sidebar);
  transition: width var(--transition-normal);
}

.conversation-item {
  padding: 12px 16px;
  margin: 4px 8px;
  border-radius: var(--radius-sm);
  color: #d1d1d1;
  transition: all var(--transition-fast);
  cursor: pointer;
  position: relative;
}

.conversation-item:hover {
  background: var(--bg-sidebar-hover);
  color: white;
}

.conversation-item.active {
  background: var(--bg-sidebar-hover);
  border-left: 3px solid var(--accent-primary);
  color: white;
}

/* ============================================
   MARKDOWN CONTENT STYLING
   ============================================ */

/* Paragraphs */
.message-content p {
  margin-bottom: 0.75rem;
  line-height: 1.75;
}

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

/* Headings */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
  margin-top: 1.25rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

.message-content h1 { font-size: 1.5rem; }
.message-content h2 { font-size: 1.25rem; }
.message-content h3 { font-size: 1.1rem; }
.message-content h4 { font-size: 1rem; }

/* Lists */
.message-content ul,
.message-content ol {
  margin-left: 1.5rem;
  margin-bottom: 0.75rem;
  line-height: 1.75;
}

.message-content ul {
  list-style-type: disc;
}

.message-content ol {
  list-style-type: decimal;
}

.message-content li {
  margin-bottom: 0.25rem;
}

.message-content li > ul,
.message-content li > ol {
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
}

/* Blockquotes */
.message-content blockquote {
  border-left: 4px solid var(--border-medium);
  padding-left: 1rem;
  margin-left: 0;
  margin-bottom: 0.75rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* Inline code */
.message-content code {
  background-color: rgba(175, 184, 193, 0.2);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'Monaco', 'Menlo', 'Consolas', 'Courier New', monospace;
  color: #c7254e;
}

/* Code blocks */
.message-content pre {
  background-color: #1e1e1e;
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0;
  position: relative;
}

.message-content pre code {
  background-color: transparent;
  padding: 0;
  font-size: 0.875rem;
  color: #e6edf3;
  font-family: 'Monaco', 'Menlo', 'Consolas', 'Courier New', monospace;
  line-height: 1.6;
}

/* Code block header with language label */
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #2d2d2d;
  padding: 8px 16px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  margin: 1rem 0 0;
}

.code-language {
  font-size: 12px;
  color: #8e8e8e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.code-copy-btn {
  padding: 4px 12px;
  background: #3a3a3a;
  border: 1px solid #4a4a4a;
  color: #d1d1d1;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.code-copy-btn:hover {
  background: #4a4a4a;
  color: white;
}

.code-copy-btn.copied {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
}

/* Code block wrapper with header */
.code-block-wrapper {
  position: relative;
  margin: 1rem 0;
}

.code-block-wrapper pre {
  margin: 0;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

/* Tables */
.message-content table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.message-content table th,
.message-content table td {
  border: 1px solid var(--border-light);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.message-content table th {
  background-color: var(--bg-alt);
  font-weight: 600;
  color: var(--text-primary);
}

.message-content table tr:nth-child(even) {
  background-color: var(--bg-alt);
}

/* Links */
.message-content a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.message-content a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Horizontal rules */
.message-content hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 1.5rem 0;
}

/* Strong/Bold */
.message-content strong {
  font-weight: 600;
  color: var(--text-primary);
}

/* Emphasis/Italic */
.message-content em {
  font-style: italic;
}

/* ============================================
   EQUATION STYLING (KaTeX)
   ============================================ */

.message-content .katex {
  font-size: 1.05em;
}

.message-content .katex-display {
  margin: 1rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.5rem 0;
}

.message-content .katex-display > .katex {
  text-align: left;
}

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

@media (max-width: 768px) {
  .message-content-wrapper {
    padding: 0 16px;
    gap: 12px;
  }
  
  .chat-input-wrapper {
    padding: 0 16px;
  }
  
  .message-row {
    padding: 16px 0;
  }
  
  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
  
  .message-content p,
  .message-content > p {
    font-size: 15px;
  }
  
  .input-container {
    padding: 10px 12px;
  }
  
  .chat-textarea {
    font-size: 16px; /* Prevent iOS zoom on focus */
  }
  
  .welcome-message {
    margin: 24px auto;
  }
  
  .message-content pre {
    font-size: 0.75rem;
  }
  
  .message-content .katex-display {
    font-size: 0.9rem;
  }
  
  .message-content table {
    font-size: 0.8rem;
  }
  
  aside {
    position: fixed;
    z-index: 1000;
    left: -100%;
    transition: left var(--transition-normal);
  }
  
  aside.show {
    left: 0;
  }
}

@media (max-width: 480px) {
  .action-btn {
    padding: 4px 8px;
    font-size: 12px;
  }
  
  .send-button {
    width: 32px;
    height: 32px;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.hidden {
  display: none !important;
}

.no-underline {
  text-decoration: none !important;
}

.loading-dots {
  display: inline-block;
}

.loading-dots::after {
  content: '.';
  animation: dots 1.5s steps(5, end) infinite;
}

@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}
