/* =============================================
   ChatGPT-Style Chat Interface
   Clean, minimal, and modern
   ============================================= */

/* CSS Variables */
:root {
  --chat-bg: #ffffff;
  --chat-bg-alt: #f7f7f8;
  --chat-border: #e5e5e5;
  --chat-text: #0d0d0d;
  --chat-text-secondary: #666666;
  --chat-text-muted: #8e8e93;
  --chat-accent: #10a37f;
  --chat-user-bg: #ffffff;
  --chat-radius: 16px;
}

/* Main Container */
.modern-chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
  min-height: calc(100vh - 80px);
  background: var(--chat-bg);
  margin: 0;
  position: relative;
  overflow: hidden;
}

.main-content .modern-chat-container {
  height: calc(100vh - 80px);
  min-height: calc(100vh - 80px);
  margin: 0;
}

/* Override dashboard background for chat page */
.dashboard-container .main-content {
  padding: 0;
  background: var(--chat-bg);
}

/* Ensure no safe area or extra padding at the bottom */
.dashboard-container .main-content:has(.modern-chat-container) {
  overflow: hidden;
  background: var(--chat-bg);
}

/* =============================================
   Chat Header - Minimal
   ============================================= */
.modern-chat-header {
  background: var(--chat-bg);
  border-bottom: 1px solid var(--chat-border);
  padding: 14px 20px;
  flex-shrink: 0;
}

.chat-title-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.back-button {
  display: flex;
  align-items: center;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--chat-text-secondary);
  text-decoration: none;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  transition: background 0.15s ease;
}

.back-link:hover {
  background: var(--chat-bg-alt);
  text-decoration: none;
}

.back-link svg {
  width: 18px;
  height: 18px;
}

.chat-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.chat-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--chat-text);
  margin: 0;
}

.template-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--chat-bg-alt);
  color: var(--chat-text-secondary);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.template-badge svg {
  width: 12px;
  height: 12px;
}

/* =============================================
   Messages Area
   ============================================= */
.modern-chat-content {
  flex: 1;
  overflow: hidden;
  background: var(--chat-bg);
}

.messages-area {
  height: 100%;
  overflow-y: auto;
  padding: 0;
}

/* =============================================
   Welcome State
   ============================================= */
.welcome-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 40px;
}

.welcome-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  color: var(--chat-text-muted);
}

.welcome-icon svg {
  width: 48px;
  height: 48px;
}

.welcome-state h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--chat-text);
  margin: 0 0 8px 0;
}

.welcome-state p {
  font-size: 14px;
  color: var(--chat-text-secondary);
  margin: 0;
}

/* =============================================
   Message Rows - ChatGPT Style
   ============================================= */
.message-wrapper {
  display: flex;
  padding: 24px 0;
  opacity: 1;
  animation: fadeIn 0.2s ease;
  width: 100%;
}

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

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

/* Inner container for centering - ChatGPT style */
.message-inner {
  max-width: 768px;
  margin: 0 auto;
  width: 100%;
  padding: 0 24px;
  box-sizing: border-box;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.message-inner .message-avatar {
  flex-shrink: 0;
}

.message-inner .message-bubble {
  flex: 1;
  min-width: 0;
}

/* =============================================
   Message Avatars
   ============================================= */
.message-avatar {
  flex-shrink: 0;
}

.avatar-icon {
  width: 30px;
  height: 30px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
}

.avatar-icon.assistant {
  background: var(--chat-accent);
  color: white;
}

.avatar-icon.assistant svg {
  width: 18px;
  height: 18px;
}

.avatar-icon.user {
  background: #5436da;
  color: white;
}

/* =============================================
   Message Bubbles - No bubble, just text (ChatGPT style)
   ============================================= */
.message-bubble {
  max-width: none !important;
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
  border: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
  box-shadow: none !important;
}

.assistant-bubble,
.user-bubble,
.message-wrapper .message-bubble,
.message-wrapper.user-message .message-bubble,
.message-wrapper.user-message .user-bubble,
.message-inner .user-bubble {
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
  border: none !important;
  padding: 0 !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}

.assistant-bubble:hover,
.user-bubble:hover {
  box-shadow: none !important;
  transform: none !important;
  background: transparent !important;
}

.message-content {
  font-size: 15px;
  line-height: 1.7;
  color: var(--chat-text);
  margin: 0;
}

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

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

.user-bubble .message-content,
.user-bubble .message-content p {
  color: var(--chat-text) !important;
}

/* =============================================
   Message Meta
   ============================================= */
.message-meta {
  display: none; /* Hide timestamps for cleaner look like ChatGPT */
}

.style-tag {
  display: none;
}

/* =============================================
   Input Section - ChatGPT Style
   ============================================= */
.modern-chat-input {
  background: var(--chat-bg);
  padding: 0;
  flex-shrink: 0;
  border-top: none;
}

.input-wrapper {
  max-width: 768px;
  margin: 0 auto;
  width: 100%;
  padding: 0 24px;
  box-sizing: border-box;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  padding: 10px 12px;
  box-shadow: 0 0 15px rgba(0,0,0,0.05);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-container:focus-within {
  border-color: #c5c5c5;
  box-shadow: 0 0 15px rgba(0,0,0,0.1);
}

.input-controls {
  display: flex;
  align-items: flex-end;
  flex: 1;
  gap: 0;
  min-width: 0;
}

.file-upload-btn {
  background: transparent;
  border: none;
  color: var(--chat-text-muted);
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-upload-btn:hover {
  color: var(--chat-text);
}

.file-upload-btn svg {
  width: 20px;
  height: 20px;
}

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

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

.chat-textarea:disabled {
  opacity: 0.5;
}

.send-btn {
  background: var(--chat-text);
  color: white;
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  min-width: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease;
  flex-shrink: 0;
  margin-left: 8px;
}

.send-btn:hover:not(:disabled) {
  opacity: 0.8;
}

.send-btn:disabled {
  background: #d1d1d1;
  cursor: not-allowed;
}

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

.input-info {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 6px;
  margin-bottom: 2px;
  font-size: 11px;
  color: var(--chat-text-muted);
}

.char-count {
  font-weight: 400;
}

.template-info {
  display: none;
}

/* Footer disclaimer - ChatGPT style */
.chat-footer-disclaimer {
  text-align: center;
  font-size: 12px;
  color: var(--chat-text-muted);
  padding: 4px 0 0 0;
}

/* =============================================
   Generated Media
   ============================================= */
.generated-image-container,
.generated-video-container {
  margin: 16px 0;
  position: relative;
  display: inline-block;
  line-height: 0;
  border-radius: 8px;
  overflow: hidden;
}

.generated-image,
.generated-video {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.generated-image:hover {
  cursor: pointer;
}

.media-download-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
  text-decoration: none;
}

.generated-image-container:hover .media-download-btn,
.generated-video-container:hover .media-download-btn {
  opacity: 1;
}

.media-download-btn svg {
  width: 16px;
  height: 16px;
}

@media (hover: none) {
  .media-download-btn { opacity: 1; }
}

/* =============================================
   Job Status
   ============================================= */
.job-status {
  margin: 12px 0;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.job-status.processing {
  color: var(--chat-accent);
  background: rgba(16, 163, 127, 0.08);
}

.job-status.error {
  color: #d00;
  background: rgba(221, 0, 0, 0.08);
}

.processing-indicator svg {
  animation: spin 1s linear infinite;
}

/* =============================================
   Animations
   ============================================= */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

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

/* =============================================
   Thinking/Loading States
   ============================================= */
.generation-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  color: var(--chat-text-muted);
  font-size: 14px;
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

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

.thinking-dot:nth-child(2) { animation-delay: 0.16s; }
.thinking-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* =============================================
   Scrollbar
   ============================================= */
.messages-area::-webkit-scrollbar {
  width: 8px;
}

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

.messages-area::-webkit-scrollbar-thumb {
  background: #c5c5c5;
  border-radius: 4px;
}

.messages-area::-webkit-scrollbar-thumb:hover {
  background: #a0a0a0;
}

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 768px) {
  .modern-chat-header {
    padding: 12px 16px;
  }
  
  .chat-title {
    font-size: 0.875rem;
  }
  
  .message-wrapper {
    padding: 16px 0;
  }
  
  .message-wrapper > * {
    padding: 0 16px;
  }
  
  .input-wrapper {
    padding: 0 16px;
  }
  
  .avatar-icon {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }
  
  .message-content {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .modern-chat-container,
  .main-content .modern-chat-container {
    height: calc(100vh - 60px);
  }
  
  .message-wrapper > * {
    gap: 12px;
  }
  
  .avatar-icon {
    width: 24px;
    height: 24px;
  }
}

/* =============================================
   File Upload
   ============================================= */
.file-upload-area {
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  margin-bottom: 12px;
  overflow: hidden;
}

.file-upload-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--chat-bg-alt);
  border-bottom: 1px solid var(--chat-border);
  font-size: 13px;
  font-weight: 500;
}

.close-upload-btn {
  background: none;
  border: none;
  color: var(--chat-text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-upload-btn:hover {
  background: var(--chat-border);
}

.file-upload-content {
  padding: 16px;
}

.file-drop-zone {
  border: 2px dashed var(--chat-border);
  border-radius: 8px;
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
  border-color: var(--chat-text-muted);
}

.file-drop-zone svg {
  color: var(--chat-text-muted);
  margin-bottom: 8px;
}

.file-drop-zone p {
  color: var(--chat-text-secondary);
  margin: 0;
  font-size: 14px;
}

.file-browse-link {
  color: var(--chat-accent);
  font-weight: 500;
  cursor: pointer;
}

.uploaded-files-list {
  margin-top: 12px;
}

.uploaded-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--chat-bg-alt);
  border-radius: 8px;
  margin-bottom: 8px;
}

.uploaded-file:last-child {
  margin-bottom: 0;
}

.file-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--chat-accent);
  border-radius: 6px;
  color: white;
}

.file-icon svg {
  width: 16px;
  height: 16px;
}

.file-name {
  font-weight: 500;
  font-size: 13px;
}

.file-size {
  font-size: 12px;
  color: var(--chat-text-muted);
}

.remove-file-btn {
  background: none;
  border: none;
  color: var(--chat-text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.remove-file-btn:hover {
  color: #d00;
}

/* =============================================
   Links
   ============================================= */
.editor-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--chat-accent);
  color: white !important;
  padding: 10px 20px;
  border-radius: 8px;
  text-decoration: none !important;
  font-weight: 500;
  margin-top: 12px;
  transition: opacity 0.15s ease;
}

.editor-link:hover {
  opacity: 0.9;
}

.editor-link.redirecting {
  animation: pulse 1s ease-in-out infinite;
}

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

.chat-link {
  color: var(--chat-accent);
  text-decoration: underline;
}

/* =============================================
   Markdown Styling
   ============================================= */
.message-content strong,
.message-content b {
  font-weight: 600;
}

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

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

.message-content code {
  background: rgba(0,0,0,0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.9em;
}

.message-content pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
}

.message-content pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}