/* ==========================================================================
   WELP — Pure Minimalist Gallery Aesthetic (ChatGPT / Meta Muse Design)
   Cardless Assistant Typography + Direct LatticeLoader Integration
   Full GFM Markdown Tables, Quotes, Lists + Live Mermaid Diagrams
   ========================================================================== */

:root {
  --bg-main: #fbfbfc;
  --bg-surface: #ffffff;
  --bg-subtle: #f4f4f6;
  --bg-elevated: #e4e4e7;

  --border-hairline: rgba(0, 0, 0, 0.06);
  --border-subtle: rgba(0, 0, 0, 0.09);
  --border-medium: rgba(0, 0, 0, 0.16);
  --border-focus: rgba(0, 0, 0, 0.32);

  --text-primary: #09090b;
  --text-charcoal: #18181b;
  --text-ash: #52525b;
  --text-muted: #71717a;
  --text-faint: #a1a1aa;

  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body.light-theme {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-image: 
    radial-gradient(circle at 50% 0%, rgba(0, 0, 0, 0.015) 0%, transparent 55%),
    radial-gradient(circle at 50% 100%, rgba(0, 0, 0, 0.02) 0%, transparent 60%);
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}

/* Minimalist App Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 24px 8px 24px;
  flex-shrink: 0;
}

/* Logo Clickable to Reset / New Chat */
.header-logo-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 9999px;
  padding: 4px 8px;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
  user-select: none;
}

.header-logo-wrap:hover {
  transform: scale(1.05);
  opacity: 0.85;
}

.header-logo-wrap:active,
.header-logo-wrap.logo-reset-active {
  transform: scale(0.92);
  opacity: 0.6;
}

.brand-logo-small {
  height: 30px;
  width: auto;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Chat Viewport */
.chat-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px;
  scroll-behavior: smooth;
}

.chat-viewport::-webkit-scrollbar {
  width: 4px;
}
.chat-viewport::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: 9999px;
}

.chat-stream {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-bottom: 24px;
}

/* Hero Welcome State (ChatGPT / Muse Tier) */
.welcome-card {
  text-align: center;
  padding: 48px 0 24px 0;
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fade-in 0.3s ease-out;
}

.welcome-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 32px;
}

.welcome-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
  margin-bottom: 18px;
  user-select: none;
}

.welcome-title {
  font-size: 26px;
  font-weight: 550;
  letter-spacing: -0.025em;
  color: var(--text-charcoal);
  margin-bottom: 8px;
}

.welcome-subtitle {
  font-size: 14.5px;
  font-weight: 400;
  color: var(--text-muted);
  max-width: 420px;
  line-height: 1.45;
}

/* Capsule Suggestion Pills */
.suggestion-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 640px;
}

.capsule-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 9999px; /* Strictly Capsule Cylinder */
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-ash);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

.capsule-pill svg {
  opacity: 0.65;
  transition: opacity 0.15s ease;
}

.capsule-pill:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border-medium);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.capsule-pill:hover svg {
  opacity: 0.95;
}

/* Chat Messages */
.message-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fade-in 0.2s ease-out;
}

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

.message-row.user {
  align-items: flex-end;
}

.message-row.assistant {
  align-items: flex-start;
}

/* User Message Bubble */
.bubble.user-bubble {
  background: #18181b;
  border: none;
  color: #ffffff;
  border-radius: 20px; /* Refined capsule bubble */
  padding: 9px 18px;
  font-size: 14.5px;
  line-height: 1.5;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  max-width: 80%;
  word-break: break-word;
}

.user-bubble p {
  margin: 0;
}

/* Pure LatticeLoader Wrapper: ABSOLUTELY NO CARD LAYOUT */
.loader-pure-wrapper {
  display: flex;
  align-items: center;
  padding: 4px 0 8px 0;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--text-charcoal);
}

/* Assistant Typography: CARDLESS, DIRECT FLOWING TEXT */
.bubble.assistant-bubble {
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--text-charcoal);
  padding: 2px 0 8px 0;
  font-size: 15.5px;
  line-height: 1.68;
  max-width: 100%;
  width: 100%;
  word-break: break-word;
}

.assistant-bubble p {
  margin-bottom: 12px;
}
.assistant-bubble p:last-child {
  margin-bottom: 0;
}

/* Markdown Headings */
.assistant-bubble h1, 
.assistant-bubble h2, 
.assistant-bubble h3, 
.assistant-bubble h4 {
  color: var(--text-primary);
  font-weight: 600;
  margin: 18px 0 8px 0;
  line-height: 1.35;
}
.assistant-bubble h1 { font-size: 20px; }
.assistant-bubble h2 { font-size: 17.5px; }
.assistant-bubble h3 { font-size: 15.5px; }

/* Markdown Lists */
.assistant-bubble ul, 
.assistant-bubble ol {
  margin: 8px 0 12px 20px;
  padding-left: 4px;
}

.assistant-bubble li {
  margin-bottom: 4px;
  line-height: 1.6;
}

/* Markdown Blockquotes */
.assistant-bubble blockquote {
  border-left: 3px solid #27272a;
  padding-left: 14px;
  color: var(--text-ash);
  margin: 12px 0;
  font-style: italic;
}

/* Markdown Tables */
.assistant-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 14px;
  background: #ffffff;
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
}

.assistant-bubble th, 
.assistant-bubble td {
  padding: 9px 13px;
  border: 1px solid var(--border-subtle);
  text-align: left;
}

.assistant-bubble th {
  background: var(--bg-subtle);
  font-weight: 600;
  color: var(--text-primary);
}

.assistant-bubble tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.015);
}

/* Mermaid Diagrams Container (Interactive Click Preview) */
.mermaid-container {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 18px;
  margin: 16px 0;
  overflow-x: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
  cursor: pointer;
  position: relative;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.mermaid-container:hover {
  border-color: var(--border-focus);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.07);
  transform: translateY(-1px);
}

.mermaid-container::after {
  content: 'Click to zoom & export';
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 11px;
  font-family: var(--font-sans);
  color: var(--text-faint);
  background: var(--bg-subtle);
  padding: 2px 8px;
  border-radius: 9999px;
  border: 1px solid var(--border-hairline);
  opacity: 0;
  transform: translateY(2px);
  transition: all 0.15s ease;
  pointer-events: none;
}

.mermaid-container:hover::after {
  opacity: 1;
  transform: translateY(0);
}

.mermaid-diagram {
  display: flex;
  justify-content: center;
  width: 100%;
}

.mermaid-diagram svg {
  max-width: 100%;
  height: auto;
}

/* Inline Code */
.inline-code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--text-primary);
}

/* Code Blocks: REFINED LIGHT THEME (As Requested) */
.code-container {
  background: #f8f8fa;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  margin: 14px 0;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
  transition: border-color 0.15s ease;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  background: #f1f1f4;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

.code-lang {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #52525b;
}

.copy-code-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 9999px; /* Capsule */
  color: #3f3f46;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 500;
  padding: 3px 10px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
  transition: all 0.15s ease;
}

.copy-code-btn:hover {
  background: #e4e4e7;
  color: #09090b;
  border-color: rgba(0, 0, 0, 0.2);
}

.copy-code-btn.copied {
  color: #16a34a;
  border-color: #16a34a;
}

.code-container pre {
  margin: 0;
  padding: 13px 15px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.55;
  color: #18181b;
  background: #f8f8fa;
}

.code-container pre code {
  font-family: inherit;
  background: transparent !important;
  padding: 0 !important;
  color: inherit;
}

.mermaid-loading-pulse {
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: pulse-op 1.5s infinite ease-in-out;
}

@keyframes pulse-op {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.95; }
}

.code-fallback {
  background: #f4f4f6;
  border-radius: 8px;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-charcoal);
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  width: 100%;
}

/* ==========================================================================
   Diagram Modal Zoom & Download Popup
   ========================================================================== */
.diagram-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.diagram-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fade-in 0.2s ease-out;
}

.diagram-modal-dialog {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 980px;
  max-height: 90vh;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-scale 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-scale {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.diagram-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-hairline);
  background: #fafafa;
}

.diagram-modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-charcoal);
}

.diagram-modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-btn {
  padding: 6px 14px;
  font-size: 12.5px;
  background: #ffffff;
  border: 1px solid var(--border-medium);
}

.modal-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-focus);
}

.modal-close-btn {
  width: 32px;
  height: 32px;
  background: var(--bg-subtle);
  color: var(--text-ash);
  border: 1px solid var(--border-hairline);
}

.modal-close-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.diagram-modal-viewport {
  flex: 1;
  overflow: auto;
  padding: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  min-height: 280px;
}

.diagram-modal-viewport svg {
  max-width: 100%;
  height: auto;
}

/* Floating Input Dock Area */
.input-dock-area {
  padding: 10px 24px 18px 24px;
  background: transparent;
  z-index: 20;
}

.dock-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #ffffff;
  border: 1px solid var(--border-medium);
  border-radius: 26px; /* Smooth rounded capsule dock */
  padding: 7px 9px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.dock-form:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

.capsule-cylinder-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px; /* Strictly Capsule Cylinder */
  border: none;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
}

.btn-voice {
  width: 36px;
  height: 36px;
  background: var(--bg-subtle);
  color: var(--text-ash);
  border: 1px solid var(--border-hairline);
  margin-bottom: 1px;
}

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

.btn-voice.listening {
  background: #18181b;
  color: #ffffff;
}

.dock-input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  min-height: 36px;
}

/* Auto-expanding Textarea */
.dock-textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--text-primary);
  padding: 7px 8px;
  max-height: 180px;
  min-height: 24px;
  overflow-y: auto;
}

.dock-textarea::placeholder {
  color: var(--text-faint);
}

.dock-textarea::-webkit-scrollbar {
  width: 3px;
}
.dock-textarea::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: 9999px;
}

/* Dynamic Morphing Send / Stop Button */
.btn-send {
  width: 36px;
  height: 36px;
  background: #18181b;
  color: #ffffff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12);
  margin-bottom: 1px;
}

.btn-send .icon-send {
  display: block;
}

.btn-send .icon-stop {
  display: none;
}

.btn-send:hover {
  background: #27272a;
  transform: translateY(-1px);
}

.btn-send:active {
  transform: translateY(0);
}

.btn-send.is-generating {
  background: #18181b;
  border: 1px solid #3f3f46;
}

.btn-send.is-generating .icon-send {
  display: none;
}

.btn-send.is-generating .icon-stop {
  display: block;
  color: #ffffff;
}

.btn-send.is-generating:hover {
  background: #27272a;
  transform: scale(1.04);
}

/* Footnote below dock */
.dock-footnote {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 8px;
}

/* Typing cursor */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 15px;
  background: #18181b;
  margin-left: 2px;
  animation: blink 0.8s infinite;
  vertical-align: middle;
}

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

@media (max-width: 640px) {
  .chat-viewport {
    padding: 8px 16px;
  }
  .input-dock-area {
    padding: 8px 16px 14px 16px;
  }
  .welcome-title {
    font-size: 22px;
  }
  .welcome-card {
    padding: 24px 0 16px 0;
  }
}
