/* ============================================
   Convos — Conversation Viewer Styles
   ============================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Server-rendered article for Telegram IV / crawlers — hidden once JS loads */
#app > article {
  max-width: 768px;
  margin: 2rem auto;
  padding: 0 1rem;
  line-height: 1.6;
}

#app > article h1 { font-size: 1.5rem; margin-bottom: 1rem; }
#app > article h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; color: var(--text-secondary, #666); }
#app > article p { margin-bottom: 0.75rem; }
#app > article pre { background: var(--bg-secondary, #f7f7f8); padding: 1rem; border-radius: 8px; overflow-x: auto; margin-bottom: 0.75rem; }

.js-loaded > article { display: none; }

:root {
  /* Light theme */
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-tertiary: #ececf1;
  --bg-user-bubble: #2563eb;
  --bg-assistant-bubble: #f0f0f5;
  --bg-assistant-strip: #f7f7f8;
  --bg-user-strip: #ffffff;
  --text-primary: #0d0d0d;
  --text-secondary: #6b6b7b;
  --text-tertiary: #8e8ea0;
  --text-user-bubble: #ffffff;
  --text-assistant-bubble: #0d0d0d;
  --border-color: #e5e5ea;
  --border-subtle: #f0f0f5;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --code-bg: #1e1e2e;
  --code-text: #cdd6f4;
  --header-bg: rgba(255,255,255,0.85);
  --header-border: rgba(0,0,0,0.08);
  --toggle-bg: #e5e5ea;
  --toggle-active: #2563eb;
  --avatar-user: #2563eb;
  --avatar-assistant: #e8834a;
  --summary-bg: #f0f7ff;
  --summary-border: #bfdbfe;
  --summary-text: #1e40af;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', monospace;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-bubble: 20px;
  --max-chat-width: 680px;
  --max-desktop-width: 768px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-primary: #0d0d0d;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #2a2a3e;
  --bg-user-bubble: #2563eb;
  --bg-assistant-bubble: #1e1e2e;
  --bg-assistant-strip: #16161e;
  --bg-user-strip: #0d0d0d;
  --text-primary: #e5e5e5;
  --text-secondary: #9999aa;
  --text-tertiary: #6b6b7b;
  --text-user-bubble: #ffffff;
  --text-assistant-bubble: #e5e5e5;
  --border-color: #2a2a3e;
  --border-subtle: #1e1e2e;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --header-bg: rgba(13,13,13,0.88);
  --header-border: rgba(255,255,255,0.06);
  --toggle-bg: #2a2a3e;
  --toggle-active: #3b82f6;
  --summary-bg: #1a1a3e;
  --summary-border: #3b4f8a;
  --summary-text: #93b4f5;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

body {
  overflow-x: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
}

/* ============================================
   Loading State
   ============================================ */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 1rem;
  color: var(--text-secondary);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-color);
  border-top-color: var(--toggle-active);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
   Not Found State
   ============================================ */

.not-found {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 0.5rem;
  color: var(--text-secondary);
}

.not-found h1 {
  font-size: 4rem;
  font-weight: 700;
  color: var(--text-tertiary);
}

.not-found p {
  font-size: 1.1rem;
}

/* ============================================
   Header
   ============================================ */

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--header-border);
  padding: 12px 20px;
  transition: background var(--transition);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.header-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* Toggle buttons */
.toggle-group {
  display: flex;
  background: var(--toggle-bg);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.toggle-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
  white-space: nowrap;
}

.toggle-btn:hover {
  color: var(--text-primary);
}

.toggle-btn.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.lang-group .toggle-btn {
  padding: 5px 8px;
  font-size: 0.75rem;
}

.theme-btn {
  border: none;
  background: var(--toggle-bg);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition);
}

.theme-btn:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

/* ============================================
   Summary
   ============================================ */

.summary {
  max-width: var(--max-desktop-width);
  margin: 20px auto;
  padding: 16px 20px;
  background: var(--summary-bg);
  border: 1px solid var(--summary-border);
  border-radius: var(--radius-md);
  color: var(--summary-text);
  font-size: 0.9rem;
  line-height: 1.6;
  transition: all var(--transition);
}

.summary-label {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  opacity: 0.7;
}

/* ============================================
   Messages Container
   ============================================ */

.messages {
  padding: 20px;
  padding-bottom: 80px;
  max-width: 100%;
  overflow-x: hidden;
}

/* ============================================
   Chat View (Mobile / iMessage Style)
   ============================================ */

.view-chat .messages {
  max-width: var(--max-chat-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.view-chat .message {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: fadeInUp 0.25s ease;
}

.view-chat .message-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.view-chat .message-assistant {
  align-self: flex-start;
}

.view-chat .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 2px;
}

.view-chat .avatar-user {
  background: var(--avatar-user);
  color: white;
}

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

.view-chat .bubble {
  padding: 10px 16px;
  border-radius: var(--radius-bubble);
  line-height: 1.5;
  font-size: 0.938rem;
  word-break: break-word;
  overflow: hidden;
  min-width: 0;
  transition: background var(--transition);
}

.view-chat .message-user .bubble {
  background: var(--bg-user-bubble);
  color: var(--text-user-bubble);
  border-bottom-right-radius: 6px;
}

.view-chat .message-assistant .bubble {
  background: var(--bg-assistant-bubble);
  color: var(--text-assistant-bubble);
  border-bottom-left-radius: 6px;
}

/* User bubble links in chat view */
.view-chat .message-user .bubble a {
  color: var(--text-user-bubble);
  text-decoration: underline;
}

/* Assistant bubble markdown */
.view-chat .message-assistant .bubble p {
  margin: 0 0 0.5em;
}
.view-chat .message-assistant .bubble p:last-child {
  margin-bottom: 0;
}

/* ============================================
   Desktop View (Claude AI Style)
   ============================================ */

.view-desktop .messages {
  max-width: var(--max-desktop-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.view-desktop .message {
  padding: 24px 0;
  border-bottom: 1px solid var(--border-subtle);
  animation: fadeInUp 0.25s ease;
}

.view-desktop .message:last-child {
  border-bottom: none;
}

.view-desktop .message-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.view-desktop .avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  flex-shrink: 0;
}

.view-desktop .avatar-user {
  background: var(--avatar-user);
  color: white;
}

.view-desktop .avatar-assistant {
  background: var(--avatar-assistant);
  color: white;
}

.view-desktop .role-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.view-desktop .message-body {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-primary);
  overflow: hidden;
  min-width: 0;
}

.view-desktop .message-body p {
  margin: 0 0 1em;
}
.view-desktop .message-body p:last-child {
  margin-bottom: 0;
}

/* ============================================
   Shared Markdown Styles
   ============================================ */

.bubble h1, .message-body h1,
.bubble h2, .message-body h2,
.bubble h3, .message-body h3,
.bubble h4, .message-body h4 {
  margin: 1em 0 0.5em;
  line-height: 1.3;
}
.bubble h1:first-child, .message-body h1:first-child,
.bubble h2:first-child, .message-body h2:first-child,
.bubble h3:first-child, .message-body h3:first-child {
  margin-top: 0;
}

.bubble h1, .message-body h1 { font-size: 1.4em; }
.bubble h2, .message-body h2 { font-size: 1.2em; }
.bubble h3, .message-body h3 { font-size: 1.05em; }

.bubble ul, .message-body ul,
.bubble ol, .message-body ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.bubble li, .message-body li {
  margin: 0.25em 0;
}

.bubble blockquote, .message-body blockquote {
  border-left: 3px solid var(--border-color);
  padding-left: 1em;
  margin: 0.5em 0;
  color: var(--text-secondary);
}

.bubble a, .message-body a {
  color: var(--toggle-active);
  text-decoration: none;
}
.bubble a:hover, .message-body a:hover {
  text-decoration: underline;
}

.bubble strong, .message-body strong {
  font-weight: 600;
}

/* Inline code */
.bubble code, .message-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Code blocks */
.bubble pre, .message-body pre {
  margin: 0.75em 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}

.bubble pre code, .message-body pre code {
  display: block;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 16px;
  font-size: 0.85rem;
  line-height: 1.5;
  overflow-x: auto;
  border-radius: 0;
}

/* Standalone pre (no code-header above it) gets full rounding */
.bubble pre:not(.code-header + pre) code,
.message-body pre:not(.code-header + pre) code {
  border-radius: var(--radius-sm);
}

/* Code block language label */
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #161622;
  padding: 6px 12px;
  font-size: 0.75rem;
  color: #888;
  font-family: var(--font-mono);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  margin-top: 0.75em;
}

.code-header + pre {
  margin-top: 0;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.code-header + pre code {
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.copy-btn {
  border: none;
  background: transparent;
  color: #888;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: var(--font-sans);
  padding: 2px 8px;
  border-radius: 4px;
  transition: all var(--transition);
}

.copy-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #ccc;
}

/* Tables */
.bubble table, .message-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75em 0;
  font-size: 0.9em;
}

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

.bubble th, .message-body th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

/* Horizontal rule */
.bubble hr, .message-body hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 1em 0;
}

/* ============================================
   Footer CTA
   ============================================ */

.footer-cta {
  text-align: center;
  padding: 40px 20px;
  margin: 0 auto;
  max-width: 480px;
}

.footer-cta p {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.cta-link {
  display: inline-block;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff !important;
  background: #2563eb;
  padding: 10px 28px;
  border-radius: 10px;
  text-decoration: none !important;
  transition: background 0.2s, transform 0.15s;
}

.cta-link:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  text-decoration: none !important;
}

.cta-sub {
  display: block;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

/* ============================================
   Footer
   ============================================ */

.footer {
  text-align: center;
  padding: 20px;
  color: var(--text-tertiary);
  font-size: 0.8rem;
}

.footer a {
  color: var(--text-tertiary);
  text-decoration: none;
}

.footer a:hover {
  color: var(--text-secondary);
}

/* ============================================
   Animations
   ============================================ */

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

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 640px) {
  .header {
    padding: 8px 12px;
  }

  .header-inner {
    padding: 0;
    gap: 6px;
  }

  .header-title {
    font-size: 0.85rem;
    flex-basis: 100%;
  }

  .header-controls {
    width: 100%;
    justify-content: flex-start;
  }

  .toggle-btn {
    font-size: 0.75rem;
    padding: 4px 8px;
  }

  .lang-group .toggle-btn {
    padding: 4px 6px;
    font-size: 0.7rem;
  }

  .theme-btn {
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
  }

  .view-chat .message {
    max-width: 90%;
  }

  .view-chat .bubble {
    font-size: 0.9rem;
  }

  .view-desktop .message {
    padding: 16px 0;
  }

  .view-desktop .message-body {
    font-size: 0.9rem;
  }

  .summary {
    margin: 12px;
    padding: 12px 16px;
  }

  .messages {
    padding: 12px;
  }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  .header, .footer { display: none; }
  .messages { padding: 0; }
  .view-chat .message { max-width: 100%; }
  body { background: white; color: black; }
}
