/* Satoshi font */
@font-face {
    font-family: 'Satoshi';
    src: url('../fonts/Satoshi-Variable.woff2') format('woff2'),
         url('../fonts/Satoshi-Variable.woff') format('woff'),
         url('../fonts/Satoshi-Variable.ttf') format('truetype');
    font-weight: 100 900;
    font-display: swap;
    font-style: normal;
}

/* Base styles */
:root {
    /* Light theme */
    --light-bg: #ffffff;
    --light-surface: #f8f9fa;
    --light-surface-hover: #e9ecef;
    --light-border: #dee2e6;
    --light-text: #212529;
    --light-text-secondary: #6c757d;
    --light-primary: #0d6efd;
    
    /* Dark theme */
    --dark-bg: #000000;
    --dark-surface: #121212;
    --dark-surface-hover: #1e1e1e;
    --dark-border: #2d2d2d;
    --dark-text: #e9ecef;
    --dark-text-secondary: #adb5bd;
    --dark-primary: #3b82f6;
}

/* Prevent page scroll */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-size: 18px;
}

/* Dark mode styles */
.dark {
    color-scheme: dark;
    background-color: var(--dark-bg);
    color: var(--dark-text);
}

.dark .bg-light-surface {
    background-color: var(--dark-surface);
}

.dark .bg-light-surface-hover {
    background-color: var(--dark-surface-hover);
}

.dark .border-light-border {
    border-color: var(--dark-border);
}

.dark .text-light-text {
    color: var(--dark-text);
}

.dark .text-light-text-secondary {
    color: var(--dark-text-secondary);
}

.dark .text-light-primary {
    color: var(--dark-primary);
}

/* Chat container */
.chat-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background-color: var(--light-bg);
}

.dark .chat-container {
    background-color: var(--dark-bg);
}

/* Sidebar */
.sidebar {
    width: 300px;
    border-right: 1px solid var(--light-border);
    display: flex;
    flex-direction: column;
    background-color: var(--light-surface);
}

.dark .sidebar {
    border-color: var(--dark-border);
    background-color: var(--dark-surface);
}

/* Chat list */
.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.chat-list::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-list::-webkit-scrollbar-thumb {
    background-color: var(--light-border);
    border-radius: 3px;
}

.dark .chat-list::-webkit-scrollbar-thumb {
    background-color: var(--dark-border);
}

/* Chat messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

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

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

/* Message styles */
.message {
    max-width: 100%;
    margin-bottom: 1rem;
    padding: 1rem;
    border-radius: 0.5rem;
    background-color: var(--light-surface);
    word-break: break-word;
    overflow-wrap: anywhere;
}

.dark .message {
    background-color: var(--dark-surface);
}

.user-message {
    background-color: var(--light-surface-hover);
}

.dark .user-message {
    background-color: var(--dark-surface-hover);
}

/* Loading dots animation */
@keyframes loadingDots {
    0%, 20% {
        content: "";
    }
    40% {
        content: ".";
    }
    60% {
        content: "..";
    }
    80%, 100% {
        content: "...";
    }
}

.loading-dots::after {
    content: "";
    animation: loadingDots 1.5s infinite;
}

/* Chat input */
.chat-input-container {
    padding: 1rem;
    border-top: 1px solid var(--light-border);
    background-color: var(--light-surface);
}

.dark .chat-input-container {
    border-color: var(--dark-border);
    background-color: var(--dark-surface);
}

.chat-form {
    display: flex;
    gap: 0.5rem;
}

.chat-input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--light-border);
    border-radius: 0.375rem;
    background-color: var(--light-bg);
    color: var(--light-text);
}

.dark .chat-input {
    border-color: var(--dark-border);
    background-color: var(--dark-surface);
    color: var(--dark-text);
}

/* Theme toggle */
.theme-toggle {
    padding: 0.5rem;
    border-radius: 0.375rem;
    background-color: var(--light-surface);
    border: 1px solid var(--light-border);
    cursor: pointer;
    transition: background-color 0.2s;
}

.dark .theme-toggle {
    background-color: var(--dark-surface);
    border-color: var(--dark-border);
}

.theme-toggle:hover {
    background-color: var(--light-surface-hover);
}

.dark .theme-toggle:hover {
    background-color: var(--dark-surface-hover);
}

.theme-toggle-icon {
    display: none;
    width: 1.5rem;
    height: 1.5rem;
}

.dark .theme-toggle-dark-icon {
    display: block;
}

:not(.dark) .theme-toggle-light-icon {
    display: block;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

/* Citation styling */
.citation-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.25rem;
    margin: 0 0.125rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    background-color: rgba(147, 51, 234, 0.1);
    color: white !important; /* Force white color */
    border: 1px solid rgba(147, 51, 234, 0.2);
}

.citation-link:hover {
    background-color: rgba(147, 51, 234, 0.2);
    border-color: rgba(147, 51, 234, 0.3);
    box-shadow: 0 0 0 2px rgba(147, 51, 234, 0.1);
    color: white !important; /* Force white color on hover */
}

/* Dark mode citation styling */
.dark .citation-link {
    background-color: rgba(168, 85, 247, 0.15);
    color: white !important; /* Force white color */
    border-color: rgba(168, 85, 247, 0.3);
}

.dark .citation-link:hover {
    background-color: rgba(168, 85, 247, 0.25);
    border-color: rgba(168, 85, 247, 0.4);
    box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.15);
    color: white !important; /* Force white color on hover */
}

/* References styling */
.references {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--light-border);
}

.dark .references {
    border-top-color: var(--dark-border);
}

.references .font-medium {
    color: var(--light-text);
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.dark .references .font-medium {
    color: var(--dark-text);
}

.references ol {
    list-style-type: decimal;
    list-style-position: inside;
    margin-left: 0.5rem;
}

.references li {
    margin-bottom: 0.5rem;
    color: var(--light-text);
}

.dark .references li {
    color: var(--dark-text);
}

/* Reference links (at bottom of message) */
.references a:not(.citation-link) {
    color: var(--light-text);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.dark .references a:not(.citation-link) {
    color: var(--dark-text);
}

.references a:not(.citation-link):hover {
    text-decoration: underline;
    color: var(--light-primary);
}

.dark .references a:not(.citation-link):hover {
    color: var(--dark-primary);
}

/* Prose styles for markdown content */
.prose {
    max-width: none;
}

.prose a:not(.citation-link) {
    color: var(--light-text);
    text-decoration: none;
}

.dark .prose a:not(.citation-link) {
    color: var(--dark-text);
}

.prose a:not(.citation-link):hover {
    text-decoration: underline;
    color: var(--light-primary);
}

.dark .prose a:not(.citation-link):hover {
    color: var(--dark-primary);
}

/* Room select */
.room-select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--light-border);
    border-radius: 0.375rem;
    background-color: var(--light-bg);
    color: var(--light-text);
    margin-bottom: 1rem;
}

.dark .room-select {
    border-color: var(--dark-border);
    background-color: var(--dark-surface);
    color: var(--dark-text);
}

/* New chat button */
.new-chat-button {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--light-primary);
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    font-weight: 500;
}

.dark .new-chat-button {
    background-color: var(--dark-primary);
}

.new-chat-button:hover {
    opacity: 0.9;
}

/* Chat item */
.chat-item {
    padding: 1rem;
    border-bottom: 1px solid var(--light-border);
    cursor: pointer;
}

.dark .chat-item {
    border-color: var(--dark-border);
}

.chat-item:hover {
    background-color: var(--light-surface-hover);
}

.dark .chat-item:hover {
    background-color: var(--dark-surface-hover);
}

/* Message header */
.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--light-text-secondary);
}

.dark .message-header {
    color: var(--dark-text-secondary);
}

/* Message content */
.message-content {
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Message status */
.message-status {
    font-size: 0.875rem;
    color: var(--light-text-secondary);
    margin-top: 0.5rem;
}

.dark .message-status {
    color: var(--dark-text-secondary);
} 

/* ── Markdown body — breathable, readable output ──────────────────────────── */

.markdown-body {
  font-size: 1rem;
  line-height: 1.9;
  letter-spacing: 0.01em;
}

.markdown-body p {
  margin: 0.7em 0;
}

.markdown-body p + p {
  margin-top: 1.1em;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin: 1.8em 0 0.7em;
  font-weight: 700;
  line-height: 1.3;
}
.markdown-body h1 { font-size: 1.6em; }
.markdown-body h2 { font-size: 1.35em; }
.markdown-body h3 { font-size: 1.15em; }

.markdown-body strong {
  font-weight: 700;
}

/* Tables */
.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5em 0;
  font-size: 0.92em;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--light-border);
}
.dark .markdown-body table { border-color: var(--dark-border); }

.markdown-body th,
.markdown-body td {
  padding: 10px 14px;
  text-align: left;
  border: 1px solid var(--light-border);
}
.dark .markdown-body th,
.dark .markdown-body td { border-color: var(--dark-border); }

.markdown-body th {
  background: #f0f1f3;
  font-weight: 700;
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #555;
}
.dark .markdown-body th {
  background: #1a1a2e;
  color: #aaa;
}

.markdown-body tr:nth-child(even) td {
  background: rgba(0,0,0,0.02);
}
.dark .markdown-body tr:nth-child(even) td {
  background: rgba(255,255,255,0.02);
}

/* Lists */
.markdown-body ol,
.markdown-body ul {
  margin: 1em 0 1em 1em;
  padding-left: 1.5em;
}

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

.markdown-body li {
  margin-bottom: 0.35em;
  line-height: 1.7;
}

.markdown-body li p {
  margin: 0.3em 0;
}

/* Blockquotes */
.markdown-body blockquote {
  border-left: 4px solid #261649;
  background: #f7f8fa;
  color: #444;
  margin: 1.5em 0;
  padding: 0.8em 1.2em;
  border-radius: 0 6px 6px 0;
  font-style: italic;
}
.dark .markdown-body blockquote {
  border-left-color: #7c4dff;
  background: #1a1a2e;
  color: #ccc;
}

/* Code */
.markdown-body pre {
  background: #f4f4f6;
  color: #222;
  padding: 1em 1.2em;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1.2em 0;
  font-size: 0.88em;
  line-height: 1.6;
}
.dark .markdown-body pre {
  background: #1a1a2e;
  color: #eee;
}

.markdown-body code:not(pre code) {
  background: rgba(38, 22, 73, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
.dark .markdown-body code:not(pre code) {
  background: rgba(124, 77, 255, 0.15);
}

/* Images — inline, clickable to expand */
.markdown-body img {
  max-width: 100%;
  max-height: 400px;
  border-radius: 8px;
  margin: 1em 0;
  cursor: zoom-in;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 1px solid var(--light-border);
  display: block;
}
.dark .markdown-body img { border-color: var(--dark-border); }
.markdown-body img:hover {
  transform: scale(1.01);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

/* Inline page thumbnails from uploaded PDFs */
.inline-page-thumb {
  max-width: 480px;
  max-height: 340px;
  border-radius: 8px;
  margin: 0.6em 0;
  cursor: zoom-in;
  border: 1px solid var(--light-border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: transform 0.2s, box-shadow 0.2s;
}
.dark .inline-page-thumb { border-color: var(--dark-border); box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.inline-page-thumb:hover { transform: scale(1.01); box-shadow: 0 4px 16px rgba(0,0,0,0.2); }

/* Plotly chart containers */
.plotly-chart {
  width: 100%;
  min-height: 320px;
  margin: 1em 0;
  border-radius: 8px;
  border: 1px solid var(--light-border);
  overflow: hidden;
}
.dark .plotly-chart { border-color: var(--dark-border); }

/* Lightbox overlay for expanded images */
.img-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: 2rem;
}
.img-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

/* Horizontal rules */
.markdown-body hr {
  border: none;
  border-top: 1px solid var(--light-border);
  margin: 2em 0;
}
.dark .markdown-body hr { border-color: var(--dark-border); }

.markdown-body code {
  background: #ececec;
  color: #b80000;
  padding: 0.2em 0.4em;
  border-radius: 0.2em;
  font-size: 0.97em;
}

.dark .markdown-body code {
  background: #23233a;
  color: #ffb4b4;
}

.markdown-body hr {
  border: none;
  border-top: 2px solid var(--light-border);
  margin: 2em 0;
}

.dark .markdown-body hr {
  border-top: 2px solid var(--dark-border);
}

/* General link styling with Babylon purple */
a {
  color: #261649; /* Babylon primary purple */
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: #3a2369; /* Babylon secondary purple */
  text-decoration: underline;
}

.dark a {
  color: #8b5cf6; /* Lighter purple for dark mode */
}

.dark a:hover {
  color: #a78bfa; /* Even lighter purple for dark mode hover */
  text-decoration: underline;
}

/* Override for citation links to keep their special styling */
.citation-link {
  color: white !important;
}

.citation-link:hover {
  color: white !important;
}

/* Markdown content links */
.markdown-body a:not(.citation-link) {
  color: #261649 !important; /* Babylon primary purple */
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.markdown-body a:not(.citation-link):hover {
  color: #3a2369 !important; /* Babylon secondary purple */
  text-decoration: underline;
}

.dark .markdown-body a:not(.citation-link) {
  color: #8b5cf6 !important; /* Lighter purple for dark mode */
}

.dark .markdown-body a:not(.citation-link):hover {
  color: #a78bfa !important; /* Even lighter purple for dark mode hover */
  text-decoration: underline;
}

/* Reference links styling */
.references a:not(.citation-link) {
  color: #261649 !important; /* Babylon primary purple */
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.references a:not(.citation-link):hover {
  color: #3a2369 !important; /* Babylon secondary purple */
  text-decoration: underline;
}

.dark .references a:not(.citation-link) {
  color: #8b5cf6 !important; /* Lighter purple for dark mode */
}

.dark .references a:not(.citation-link):hover {
  color: #a78bfa !important; /* Even lighter purple for dark mode hover */
  text-decoration: underline;
}

/* Session panel tab styles */
.session-tab-active {
  background: #261649;
  color: #fff !important;
}
.session-tab-inactive {
  background: transparent;
  color: var(--light-text-secondary);
}
.session-tab-inactive:hover {
  background: var(--light-surface-hover);
}
.dark .session-tab-inactive {
  color: var(--dark-text-secondary);
}
.dark .session-tab-inactive:hover {
  background: var(--dark-surface-hover);
}

/* Analyst progress fill overlay */
.analyst-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 0%;
  background: rgba(255, 255, 255, 0.12);
  transition: width 0.5s ease-out, opacity 0.5s ease;
  z-index: 0;
  pointer-events: none;
  border-radius: inherit;
}

.dark .analyst-progress-fill {
  background: rgba(255, 255, 255, 0.06);
}

/* Pinned chat */
.chat-pinned .chat-swipe-content {
  background: rgba(230, 126, 34, 0.12) !important;
}
.dark .chat-pinned .chat-swipe-content {
  background: rgba(230, 126, 34, 0.15) !important;
}
.pin-icon {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  vertical-align: middle;
  background: #e67e22;
  border-radius: 4px;
  padding: 2px;
}

/* Chat status indicators — centered in cell */
.chat-status-indicator {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-complete-check {
  animation: check-fade 3s ease forwards;
}

@keyframes check-fade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Chat swipe-to-reveal actions */
.chat-swipe-wrapper {
  position: relative;
  overflow: hidden;
}

.chat-swipe-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 140px;
  display: flex;
}

.chat-swipe-actions button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  color: #fff;
}

.chat-action-pin {
  background: #e67e22;
}
.chat-action-pin:hover {
  background: #d35400;
}

.chat-action-archive {
  background: #6b7280;
}
.chat-action-archive:hover {
  background: #4b5563;
}

.chat-swipe-content {
  position: relative;
  z-index: 1;
  background: inherit;
  will-change: transform;
}

/* Inherit surface background so content covers actions when not swiped */
.chat-swipe-content {
  background: var(--light-surface, #f8f9fa);
}
.dark .chat-swipe-content {
  background: var(--dark-surface, #121212);
}

/* 3D Pill Loader (Three.js canvas) */
.pill-sentinel-center {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
}

/* Once chats are loaded, sentinel becomes a simple bottom element */
.pill-sentinel-bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 0;
}

.pill-loader-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.pill-loader-wrap canvas {
  width: 160px !important;
  height: 108px !important;
  flex-shrink: 0;
}

/* Analysis progress bar — animated shimmer */
.analysis-bar {
  background: linear-gradient(90deg, #261649 0%, #7c4dff 40%, #261649 80%);
  background-size: 300% 100%;
  animation: analysis-shimmer 1.8s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(74, 45, 143, 0.5);
}

@keyframes analysis-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.pill-loader-text {
  font-size: 20px;
  color: #6c757d;
  min-width: 52px;
}
.pill-loader-text::after {
  content: '';
  animation: pill-dots 1.5s steps(1) infinite;
}
@keyframes pill-dots {
  0%        { content: '.'; }
  33%       { content: '..'; }
  66%       { content: '...'; }
}

/* Pull-to-load elastic stretch */
#chat-list-sentinel {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s;
}
#chat-list-sentinel.pull-stretch {
  transform: scaleY(1.6);
  opacity: 0.7;
}