/* CSS Variables for theming */
:root {
  --bg-primary: #f7f8fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f0f0;
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #888888;
  --border-color: #e0e0e0;
  --border-light: #f0f0f0;
  --accent-primary: #007bff;
  --accent-primary-hover: #0056b3;
  --accent-danger: #dc3545;
  --accent-danger-hover: #c82333;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --input-bg: #ffffff;
  --code-bg: rgba(0, 0, 0, 0.08);
  --code-block-bg: #1e1e1e;
  --code-block-text: #d4d4d4;
}

/* Dark mode */
[data-theme="dark"] {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --text-primary: #e8e8e8;
  --text-secondary: #b8b8b8;
  --text-muted: #888888;
  --border-color: #2a2a4a;
  --border-light: #252545;
  --accent-primary: #4dabf7;
  --accent-primary-hover: #339af0;
  --accent-danger: #ff6b6b;
  --accent-danger-hover: #fa5252;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --input-bg: #1a1a2e;
  --code-bg: rgba(255, 255, 255, 0.1);
  --code-block-bg: #0d1117;
  --code-block-text: #c9d1d9;
}

body, html {
  margin: 0;
  height: 100%;
  font-family: 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  display: flex;
  justify-content: center;
  transition: background 0.3s ease;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 95vh;
  width: 900px;
  background: var(--bg-secondary);
  border-radius: 12px;
  box-shadow: 0 10px 25px var(--shadow-color);
  overflow: hidden;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

header {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

header h1 {
  color: var(--text-primary);
  margin: 0;
  font-size: 1.5rem;
  transition: color 0.3s ease;
}

/* Logo */
.logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.logo {
  height: 160px;
  width: auto;
  object-fit: contain;
}

/* Dark mode toggle */
.dark-mode-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.dark-mode-toggle:hover {
  background: var(--border-color);
}

.dark-mode-toggle .icon-light,
.dark-mode-toggle .icon-dark {
  pointer-events: none;
}

.dark-mode-toggle .icon-dark {
  display: none;
}

[data-theme="dark"] .dark-mode-toggle .icon-light {
  display: none;
}

[data-theme="dark"] .dark-mode-toggle .icon-dark {
  display: inline;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.download-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Beautified model dropdown */
.model-select {
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  min-width: 140px;
  transition: all 0.2s ease;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.model-select:hover {
  border-color: var(--accent-primary);
}

.model-select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

/* Beautified buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-icon {
  font-size: 0.9rem;
}

.btn-primary {
  background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
  color: white;
  box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 123, 255, 0.4);
}

.btn-primary:disabled {
  background: var(--text-muted);
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--border-color);
  transform: translateY(-1px);
}

.btn-danger {
  background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
  color: white;
  box-shadow: 0 2px 4px rgba(220, 53, 69, 0.3);
}

.btn-danger:hover {
  background: linear-gradient(135deg, #c82333 0%, #a71d2a 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(220, 53, 69, 0.4);
}

#download-status {
  flex: 1;
  height: 6px;
  background: #d3d3d3;
  border-radius: 3px;
  overflow: hidden;
  margin-left: 10px;
}

#download-status::after {
  content: '';
  display: block;
  width: 0%;
  height: 100%;
  background: #007bff;
  transition: width 0.2s ease;
}

.content {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* Sidebar toggle button - hidden on desktop */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1001;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1.2rem;
  box-shadow: 0 2px 8px var(--shadow-color);
  transition: all 0.2s ease;
}

.sidebar-toggle:hover {
  background: var(--bg-tertiary);
}

.sidebar-toggle-icon {
  display: block;
  line-height: 1;
}

/* Sidebar overlay - hidden on desktop */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.visible {
  opacity: 1;
}

.sidebar {
  width: 240px;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  transition: border-color 0.3s ease, background 0.3s ease;
}

.sidebar-header {
  padding: 10px 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-primary);
  transition: border-color 0.3s ease, color 0.3s ease;
}

.new-conversation-btn {
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  padding: 0;
  flex-shrink: 0;
}

.new-conversation-btn:hover {
  background: var(--accent-primary-hover);
}

.new-conversation-btn:active {
  background: var(--accent-primary-hover);
}

.conversation-list {
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.2s ease, color 0.3s ease;
}

.conversation-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  flex-shrink: 0;
  background: var(--bg-tertiary);
}

/* Avatar placeholder for characters without images */
.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-primary-hover) 100%) !important;
  color: white;
  font-weight: 600;
}

.conversation-avatar.avatar-placeholder {
  font-size: 1.3rem;
}

.conversation-item:hover {
  background: var(--bg-tertiary);
}

.conversation-item.active {
  background: var(--bg-tertiary);
}

.conversation-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.conversation-delete {
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.3s ease;
}

.chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  background: var(--bg-secondary);
  transition: background 0.3s ease;
}

.chat-main {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-primary);
  transition: background 0.3s ease;
}

.chat-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-container {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.message-container.user {
  flex-direction: row-reverse;
}

.message-container.assistant {
  flex-direction: row;
}

.message-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  flex-shrink: 0;
  box-shadow: 0 2px 6px var(--shadow-color);
  background: var(--bg-tertiary);
}

.message-avatar.avatar-placeholder {
  font-size: 1.4rem;
}

.message-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  gap: 8px;
}

.message-content {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 6px;
}

.tts-button {
  background: none;
  border: none;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.2s ease, transform 0.1s ease, opacity 0.2s ease;
  opacity: 0.6;
  flex-shrink: 0;
  min-width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tts-button:hover:not(:disabled) {
  background: var(--bg-secondary);
  opacity: 1;
  transform: scale(1.15);
}

.tts-button:disabled {
  cursor: not-allowed;
}

.tts-button.playing {
  opacity: 1;
  background: var(--accent-primary);
  color: white;
}

.tts-button.loading {
  animation: ttsLoading 1s infinite;
}

@keyframes ttsLoading {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.message {
  padding: 12px 16px;
  border-radius: 20px;
  box-shadow: 0 2px 6px var(--shadow-color);
  word-wrap: break-word;
  transition: background 0.3s ease, color 0.3s ease;
}

.message-container.user .message {
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-primary-hover) 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-container.assistant .message {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

/* Markdown content styling */
.markdown-content {
  line-height: 1.6;
}

.markdown-content p {
  margin: 0 0 0.75em 0;
}

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

.markdown-content code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.9em;
}

.markdown-content pre {
  background: var(--code-block-bg);
  color: var(--code-block-text);
  padding: 12px 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.75em 0;
}

.markdown-content pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 0.85em;
}

.markdown-content ul, .markdown-content ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.markdown-content li {
  margin: 0.25em 0;
}

.markdown-content h1, .markdown-content h2, .markdown-content h3,
.markdown-content h4, .markdown-content h5, .markdown-content h6 {
  margin: 0.75em 0 0.5em 0;
  font-weight: 600;
}

.markdown-content h1 { font-size: 1.4em; }
.markdown-content h2 { font-size: 1.25em; }
.markdown-content h3 { font-size: 1.1em; }

.markdown-content blockquote {
  border-left: 3px solid var(--accent-primary);
  margin: 0.75em 0;
  padding-left: 12px;
  color: #666;
}

.markdown-content strong {
  font-weight: 600;
}

.markdown-content em {
  font-style: italic;
}

.markdown-content a {
  color: #007bff;
  text-decoration: none;
}

.markdown-content a:hover {
  text-decoration: underline;
}

.markdown-content hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 1em 0;
}

/* Math (KaTeX) styling */
.markdown-content .katex {
  font-size: 1.05em;
}

.markdown-content .katex-display {
  margin: 0.75em 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 0;
}

.markdown-content .katex-display > .katex {
  text-align: left;
}

.markdown-content table {
  border-collapse: collapse;
  margin: 0.75em 0;
  width: 100%;
}

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

.markdown-content th {
  background: var(--code-bg);
  font-weight: 600;
}

.chat-footer {
  display: flex;
  padding: 12px 15px;
  border-top: 1px solid var(--border-color);
  gap: 10px;
  align-items: center;
  background: var(--bg-secondary);
  transition: background 0.3s ease, border-color 0.3s ease;
}

#user-input {
  flex: 1;
  padding: 14px 18px;
  border-radius: 25px;
  border: 1px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text-primary);
  outline: none;
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

#user-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

#user-input::placeholder {
  color: var(--text-muted);
}

#send {
  border-radius: 25px;
  border: none;
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-primary-hover) 100%);
  color: white;
  padding: 14px 24px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 123, 255, 0.3);
}

#send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.4);
}

#send:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* Custom tooltip system */
.has-tooltip {
  position: relative;
}

.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: #333;
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  width: 200px;
  white-space: normal;
  text-align: center;
  line-height: 1.4;
}

.has-tooltip::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  right: 12px;
  border: 6px solid transparent;
  border-top-color: #333;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
}

.has-tooltip:hover::after,
.has-tooltip:hover::before {
  opacity: 1;
  visibility: visible;
}

.thinking-toggle {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
}

.thinking-toggle:hover {
  background: #f0f0f0;
}

.thinking-toggle input[type="checkbox"] {
  display: none;
}

.thinking-toggle span {
  font-size: 1.2rem;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.thinking-toggle input[type="checkbox"]:checked + span {
  opacity: 1;
}

.thinking-toggle input[type="checkbox"]:not(:checked) + span {
  opacity: 0.3;
}

.hidden {
  display: none;
}

.chat-stats {
  background-color: #D3ECEB;
  padding: 10px;
  font-size: 0.75rem;
  border-radius: 10px;
  margin-top: 5px;
}

/* Download progress bar */
#download-status {
  flex: 1;
  height: 6px;
  background: #d3d3d3;
  border-radius: 3px;
  overflow: hidden;
  margin-left: 10px;
  position: relative;
}

#download-status {
  width: 100%;
  height: 30px; /* taller */
  background: #d3d3d3;
  border-radius: 6px;
  overflow: hidden;
  margin-top: 10px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: bold;
  color: #333;
}

.progress-bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 0%;
  background: #007bff;
  transition: width 0.2s ease;
}

#progress-text {
  z-index: 1;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-content {
  width: 360px;
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 10px 25px var(--shadow-color);
  transition: background 0.3s ease;
}

.modal-content h3 {
  margin: 0 0 10px 0;
  color: var(--text-primary);
}

.modal-content select,
.modal-content input[type="text"],
.modal-content textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  box-sizing: border-box;
  background: var(--input-bg);
  color: var(--text-primary);
  transition: border-color 0.2s ease, background 0.3s ease;
}

.modal-content select:focus,
.modal-content input[type="text"]:focus,
.modal-content textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.modal-content textarea {
  resize: vertical;
  min-height: 80px;
}

.modal-content label {
  display: block;
  margin-top: 12px;
  margin-bottom: 4px;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.modal-content label:first-of-type {
  margin-top: 0;
}

/* Voice selection specific styling */
.voice-select {
  margin-bottom: 12px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px !important;
}

/* Ensure labels have consistent spacing */
.modal-content label {
  display: block;
  margin-top: 12px;
  margin-bottom: 4px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Character selection with avatar */
.character-select-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.character-avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  border: 2px solid var(--border-color);
  flex-shrink: 0;
  background: var(--bg-tertiary);
  background-size: cover;
  background-position: center top;
}

.character-avatar-preview.avatar-placeholder {
  font-size: 1.6rem;
}

.character-select-row select {
  flex: 1;
}

.add-character-btn {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  width: 100%;
  color: var(--text-primary);
  transition: background 0.2s ease;
}

.add-character-btn:hover {
  background: var(--border-color);
}

.delete-character-btn {
  padding: 6px 10px;
  background: var(--accent-danger);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: background 0.2s;
}

.delete-character-btn:hover {
  background: #cc0000;
}

.delete-character-btn.hidden {
  display: none;
}

.edit-character-btn {
  padding: 6px 10px;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: background 0.2s;
}

.edit-character-btn:hover {
  background: #0056b3;
}

.preset-notice {
  background: #fff3cd;
  border: 1px solid #ffc107;
  color: #856404;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 0.85rem;
  margin-top: 8px;
}

.preset-notice.hidden {
  display: none;
}

#add-character-section h4 {
  margin-top: 0;
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* Typing animation for assistant */
@keyframes typingDots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

.message.typing::after {
  content: '';
  display: inline-block;
  width: 1em;
  text-align: left;
  animation: typingDots 1s infinite;
}

/* Thinking animation */
@keyframes thinkingDots {
  0% { content: '.'; }
  33% { content: '..'; }
  66% { content: '...'; }
  100% { content: '.'; }
}

.message.thinking::after {
  content: '.';
  display: inline-block;
  animation: thinkingDots 1.5s infinite;
}

.thinking-container {
  opacity: 0.7;
  font-style: italic;
}

/* Thoughts bubble */
.thoughts-bubble {
  margin-bottom: 8px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-tertiary);
  overflow: hidden;
  transition: all 0.2s ease;
  width: 100%;
}

.thoughts-header {
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #666;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s;
}

.thoughts-header:hover {
  background: #e9ecef;
}

.thoughts-content {
  padding: 10px 12px;
  font-size: 0.85rem;
  color: #555;
  white-space: pre-wrap;
  word-wrap: break-word;
  border-top: 1px solid #e9ecef;
  background: #fff;
  max-height: 400px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  line-height: 1.5;
}

.thoughts-bubble.expanded .thoughts-content {
  display: block;
}

/* Disclaimer Modal Styles */
.disclaimer-modal {
  z-index: 2000;
}

#full-disclaimer-modal {
  z-index: 2100;
}

.disclaimer-content {
  width: 440px;
  max-width: 90vw;
  text-align: left;
}

.welcome-header {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  text-align: center;
  justify-content: center;
}

.welcome-logo {
  width: 128px;
  height: 128px;
  object-fit: contain;
}

.welcome-header h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 1.4rem;
}

.welcome-body {
  margin-bottom: 16px;
}

.welcome-highlight {
  text-align: center;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  margin: 0 0 16px 0;
}

.welcome-features {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-tertiary);
  padding: 14px;
  border-radius: 10px;
}

.welcome-feature {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.welcome-feature span:first-child {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.disclaimer-summary {
  background: linear-gradient(135deg, rgba(255, 193, 7, 0.1) 0%, rgba(255, 152, 0, 0.1) 100%);
  padding: 12px;
  border-radius: 8px;
  border-left: 3px solid #ffc107;
  margin-bottom: 16px;
}

.disclaimer-summary p {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.disclaimer-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.disclaimer-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.disclaimer-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent-primary);
}

.disclaimer-footer .btn {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
}

.disclaimer-footer .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.disclaimer-link {
  color: var(--accent-primary);
  font-size: inherit;
  text-decoration: none;
}

.disclaimer-link:hover {
  text-decoration: underline;
}

.info-button {
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 1rem;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.info-button:hover {
  background: var(--border-color);
  transform: translateY(-1px);
}

/* Features Modal */
.features-content {
  width: 520px;
  max-width: 92vw;
  text-align: left;
}

.features-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.features-close {
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.95rem;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.features-close:hover {
  background: var(--border-color);
  transform: translateY(-1px);
}

/* Full Disclaimer Modal */
.full-disclaimer-content {
  width: 600px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}

.full-disclaimer-body {
  text-align: left;
}

.full-disclaimer-body h4 {
  margin: 20px 0 10px 0;
  color: var(--text-primary);
  font-size: 1.05rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
}

.full-disclaimer-body h4:first-child {
  margin-top: 8px;
}

.full-disclaimer-body p {
  margin: 0 0 10px 0;
  line-height: 1.6;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.full-disclaimer-body ul {
  margin: 0 0 10px 0;
  padding-left: 24px;
}

.full-disclaimer-body li {
  margin: 6px 0;
  line-height: 1.5;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ============================================
   MOBILE RESPONSIVENESS
   ============================================ */

/* Tablet and smaller */
@media screen and (max-width: 900px) {
  body, html {
    font-size: 16px;
    padding: 8px;
  }
  
  .app-container {
    width: 100%;
    height: calc(100vh - 16px);
    border-radius: 0;
    box-shadow: none;
  }
  
  .logo {
    height: 100px;
  }
  
  .download-section {
    flex-wrap: wrap;
  }
  
  .model-select {
    min-width: 120px;
    font-size: 1rem;
  }
  
  .btn {
    padding: 10px 12px;
    font-size: 0.9rem;
  }
  
  .sidebar {
    width: 200px;
  }
}

/* Mobile phones */
@media screen and (max-width: 680px) {
  body, html {
    font-size: 18px;
  }
  
  .app-container {
    height: calc(100dvh - 16px); /* Dynamic viewport height for mobile browsers */
  }
  
  header {
    padding: 8px 12px;
    padding-left: 50px; /* Space for sidebar toggle */
  }
  
  .header-top {
    margin-bottom: 8px;
  }
  
  .logo-container {
    flex: 1;
    justify-content: center;
  }
  
  .logo {
    height: 60px;
  }
  
  .dark-mode-toggle {
    padding: 8px 12px;
    font-size: 1.1rem;
  }
  
  .top-actions {
    gap: 6px;
  }
  
  .download-section {
    gap: 6px;
    width: 100%;
  }
  
  .model-select {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    font-size: 1rem;
  }
  
  .btn {
    padding: 10px 10px;
    font-size: 0.85rem;
  }
  
  .btn .btn-icon {
    display: none; /* Hide icons on mobile to save space */
  }
  
  #download-status {
    height: 24px;
    font-size: 0.8rem;
    margin-top: 8px;
  }
  
  /* Show sidebar toggle on mobile */
  .sidebar-toggle {
    display: block;
  }
  
  /* Show overlay when sidebar is open */
  .sidebar-overlay {
    display: block;
    pointer-events: none;
  }
  
  .sidebar-overlay.visible {
    pointer-events: auto;
  }
  
  /* Sidebar as sliding drawer on mobile */
  .content {
    flex-direction: row;
  }
  
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    max-height: none;
    border-right: 1px solid var(--border-color);
    border-bottom: none;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .sidebar-header {
    padding: 16px 12px 16px 52px;
    font-size: 1rem;
  }
  
  .conversation-list {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 8px;
    gap: 8px;
  }
  
  .conversation-item {
    flex-direction: row;
    padding: 10px 12px;
    min-width: auto;
    text-align: left;
  }
  
  .conversation-avatar {
    width: 44px;
    height: 44px;
    margin-bottom: 0;
  }
  
  .conversation-title {
    font-size: 0.9rem;
    white-space: nowrap;
    max-width: none;
    flex: 1;
  }
  
  .conversation-delete {
    position: static;
    font-size: 16px;
  }
  
  /* Chat area */
  .chat-container {
    flex: 1;
    min-height: 0;
    width: 100%;
  }
  
  .chat-main {
    padding: 10px;
    gap: 8px;
  }
  
  .message-container {
    gap: 8px;
  }
  
  .message-avatar {
    width: 36px;
    height: 36px;
  }
  
  .message-avatar.avatar-placeholder {
    font-size: 1rem;
  }
  
  .message-wrapper {
    max-width: 85%;
  }
  
  .message {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 1rem;
    line-height: 1.5;
  }
  
  /* Markdown content on mobile */
  .markdown-content {
    font-size: 1rem;
    line-height: 1.6;
  }
  
  .markdown-content pre {
    padding: 10px 12px;
    font-size: 0.8rem;
    overflow-x: auto;
  }
  
  .markdown-content code {
    font-size: 0.9em;
  }
  
  /* Chat footer */
  .chat-footer {
    padding: 10px 12px;
    gap: 8px;
  }
  
  #user-input {
    padding: 12px 16px;
    font-size: 1rem;
    border-radius: 20px;
  }
  
  .thinking-toggle {
    padding: 10px;
  }
  
  .thinking-toggle span {
    font-size: 1.3rem;
  }
  
  #send {
    padding: 12px 18px;
    font-size: 1rem;
    border-radius: 20px;
  }
  
  /* Tooltips on mobile - position them better */
  .has-tooltip::after {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    width: 160px;
    font-size: 11px;
  }
  
  .has-tooltip::before {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
  }
  
  /* Modals on mobile */
  .modal-content {
    width: 95%;
    max-width: 360px;
    padding: 14px;
    max-height: 90vh;
    overflow-y: auto;
  }
  
  .modal-content h3 {
    font-size: 1.1rem;
    margin-bottom: 12px;
  }
  
  .modal-content label {
    font-size: 0.95rem;
    margin-top: 10px;
  }
  
  .modal-content select,
  .modal-content input[type="text"],
  .modal-content textarea {
    padding: 12px;
    font-size: 1rem;
  }
  
  .character-avatar-preview {
    width: 50px;
    height: 50px;
  }
  
  .character-avatar-preview.avatar-placeholder {
    font-size: 1.3rem;
  }
  
  .modal-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .modal-actions button {
    flex: 1;
    min-width: 100px;
    padding: 12px;
    font-size: 1rem;
  }
  
  /* Welcome/Disclaimer modals */
  .disclaimer-content {
    width: 95%;
    max-width: 400px;
  }
  
  .welcome-header h3 {
    font-size: 1.2rem;
  }
  
  .welcome-highlight {
    font-size: 0.95rem;
  }
  
  .welcome-features {
    padding: 12px;
  }
  
  .welcome-feature {
    font-size: 0.85rem;
  }
  
  .disclaimer-summary p {
    font-size: 0.8rem;
  }
  
  .disclaimer-checkbox {
    font-size: 0.9rem;
  }
  
  .full-disclaimer-content {
    width: 95%;
    max-width: 500px;
  }
  
  .full-disclaimer-body p,
  .full-disclaimer-body li {
    font-size: 0.85rem;
  }
  
  /* Thoughts bubble on mobile */
  .thoughts-bubble {
    width: 100%;
  }
  
  .thoughts-header {
    padding: 8px 10px;
    font-size: 0.8rem;
  }
  
  .thoughts-content {
    padding: 8px 10px;
    font-size: 0.8rem;
    max-height: 250px;
  }
}

/* Extra small phones */
@media screen and (max-width: 380px) {
  body, html {
    font-size: 16px;
  }
  
  header {
    padding-left: 45px;
  }
  
  .sidebar-toggle {
    padding: 6px 10px;
    font-size: 1rem;
  }
  
  .logo {
    height: 45px;
  }
  
  .btn {
    padding: 8px 8px;
    font-size: 0.8rem;
  }
  
  .model-select {
    padding: 8px 10px;
    font-size: 0.9rem;
  }
  
  .sidebar {
    width: 260px;
  }
  
  .conversation-avatar {
    width: 36px;
    height: 36px;
  }
  
  .message-avatar {
    width: 30px;
    height: 30px;
  }
  
  .message {
    padding: 8px 12px;
    font-size: 0.95rem;
  }
  
  #user-input {
    padding: 10px 14px;
    font-size: 0.95rem;
  }
  
  #send {
    padding: 10px 14px;
    font-size: 0.95rem;
  }
}
