/* ==========================================================================
   ChatLPM Custom Theme & Styling
   ==========================================================================
   Tweak the CSS custom properties below to customize the pastel lavender/rose
   palette, surface tones, borders, and typography across Light and Dark modes.
   ========================================================================== */

:root {
  /* --- Light Mode Palette (Pastel Lavender & Rose) --- */
  --bg-app: #faf8fc;
  --bg-sidebar: #f3eef9;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f5effa;
  --bg-user-bubble: #efe6fa;
  --bg-assistant-bubble: #ffffff;
  --bg-input: #ffffff;
  --bg-code: #f6f3fa;
  --bg-think: #f9f5fc;

  /* --- Brand Accents --- */
  --accent-primary: #8b5cf6;       /* Soft Lavender */
  --accent-primary-hover: #7c3aed;
  --accent-secondary: #ec4899;     /* Pastel Rose */
  --accent-soft: rgba(139, 92, 246, 0.12);
  --accent-rose-soft: rgba(236, 72, 153, 0.12);

  /* --- Text & Borders --- */
  --text-primary: #1f1b29;
  --text-secondary: #5c536e;
  --text-muted: #8a809c;
  --border-subtle: #e5dcf0;
  --border-strong: #d3c3e6;

  /* --- Elevation & Geometry --- */
  --shadow-sm: 0 1px 3px rgba(31, 27, 41, 0.05);
  --shadow-md: 0 6px 20px rgba(139, 92, 246, 0.08);
  --radius-lg: 1rem;
  --radius-md: 0.75rem;
}

[data-theme="dark"] {
  /* --- Dark Mode Palette (Deep Plum & Dusk Lavender/Rose) --- */
  --bg-app: #13101a;
  --bg-sidebar: #191524;
  --bg-surface: #1e192b;
  --bg-surface-hover: #282138;
  --bg-user-bubble: #2d2242;
  --bg-assistant-bubble: #1e192b;
  --bg-input: #1e192b;
  --bg-code: #15111f;
  --bg-think: #231d32;

  /* --- Brand Accents --- */
  --accent-primary: #a78bfa;
  --accent-primary-hover: #c4b5fd;
  --accent-secondary: #f472b6;
  --accent-soft: rgba(167, 139, 250, 0.16);
  --accent-rose-soft: rgba(244, 114, 182, 0.15);

  /* --- Text & Borders --- */
  --text-primary: #f3effa;
  --text-secondary: #b9afc9;
  --text-muted: #7f7494;
  --border-subtle: #2e2640;
  --border-strong: #43375c;

  /* --- Elevation --- */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ==========================================================================
   Base Layout & Scrollbars
   ========================================================================== */
* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  transition: background-color 0.2s ease, color 0.2s ease;
}

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

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

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 9999px;
}

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

/* ==========================================================================
   Component Surface Helpers
   ========================================================================== */
.app-sidebar {
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
}

.app-header {
  background-color: var(--bg-app);
  border-bottom: 1px solid var(--border-subtle);
}

.surface-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.input-shell {
  background-color: var(--bg-input);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-shell:focus-within {
  border-color: var(--accent-primary);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: #ffffff;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.92;
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-ghost {
  color: var(--text-secondary);
  transition: background-color 0.15s ease, color 0.15s ease;
}

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

/* Logo SVG adapts cleanly to Light/Dark theme via currentColor */
.brand-logo svg {
  height: 34px;
  width: auto;
  display: block;
}

.brand-logo #bear-strokes {
  stroke: var(--text-primary);
}

.brand-logo #bear-fills,
.brand-logo #wordmark-ChatLPM {
  fill: var(--text-primary);
}

/* ==========================================================================
   Message Bubbles & Collapsible Thinking Blocks
   ========================================================================== */
.msg-user {
  background-color: var(--bg-user-bubble);
  border: 1px solid var(--border-subtle);
}

.msg-assistant {
  background-color: var(--bg-assistant-bubble);
  border: 1px solid var(--border-subtle);
}

.think-box {
  background-color: var(--bg-think);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--accent-secondary);
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.think-box summary {
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.think-box summary:hover {
  background-color: var(--accent-soft);
}

.think-content {
  padding: 0.65rem 0.85rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-subtle);
  white-space: pre-wrap;
  line-height: 1.55;
}

/* ==========================================================================
   Markdown Typography & Code Blocks
   ========================================================================== */
.markdown-body {
  line-height: 1.65;
  font-size: 0.95rem;
  word-wrap: break-word;
}

.markdown-body p {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.markdown-body p:last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-weight: 700;
  margin-top: 1.1rem;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.markdown-body ul,
.markdown-body ol {
  margin-top: 0.25rem;
  margin-bottom: 0.75rem;
  padding-left: 1.4rem;
}

.markdown-body ul {
  list-style-type: disc;
}

.markdown-body ol {
  list-style-type: decimal;
}

.markdown-body blockquote {
  border-left: 3px solid var(--accent-primary);
  background-color: var(--accent-soft);
  padding: 0.4rem 0.85rem;
  margin: 0.75rem 0;
  border-radius: 0 0.5rem 0.5rem 0;
  color: var(--text-secondary);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.88rem;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border-strong);
  padding: 0.45rem 0.65rem;
  text-align: left;
}

.markdown-body th {
  background-color: var(--accent-soft);
  font-weight: 600;
}

.markdown-body :not(pre) > code {
  background-color: var(--bg-code);
  border: 1px solid var(--border-subtle);
  padding: 0.12rem 0.38rem;
  border-radius: 0.35rem;
  font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.code-block-wrapper {
  position: relative;
  margin: 0.75rem 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-code);
  overflow: hidden;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.75rem;
  background-color: var(--accent-soft);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.copy-code-btn {
  padding: 0.2rem 0.55rem;
  border-radius: 0.375rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: 0.72rem;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.copy-code-btn:hover {
  background-color: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

.code-block-wrapper pre {
  margin: 0;
  padding: 0.85rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}

/* KaTeX overflow protection */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25rem 0;
}

/* Subtle pulsing cursor while streaming */
.streaming-cursor::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  color: var(--accent-secondary);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}
