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

:root {
  --bg-primary: #1a1a1a;
  --bg-secondary: #252525;
  --bg-tertiary: #2f2f2f;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0a0;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --user-msg: #4f46e5;
  --assistant-msg: #2f2f2f;
  --border: #3a3a3a;
  --shadow: rgba(0, 0, 0, 0.5);

  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  font-weight: 400;

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: linear-gradient(135deg, #1a1a1a 0%, #2a1a2a 100%);
  position: relative;
}

.app-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 300px;
  background: radial-gradient(circle at top center, rgba(99, 102, 241, 0.1) 0%, transparent 70%);
  pointer-events: none;
}

/* Header */
.app-header {
  background: rgba(37, 37, 37, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(58, 58, 58, 0.5);
  padding: 12px 16px;
  user-select: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.character-display {
  display: flex;
  align-items: center;
  gap: 8px;
}

.avatar-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}

.avatar-circle-large {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  background-size: cover;
  background-position: center;
}

.avatar-upload {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-preview {
  flex-shrink: 0;
}

#character-header-name {
  font-weight: 500;
  color: var(--text-primary);
}

.character-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.character-select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 13px;
  transition: border-color 0.2s ease;
}

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

.select-wrapper {
  position: relative;
  display: inline-block;
}

.select-wrapper::after {
  content: "▼";
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-secondary);
  pointer-events: none;
}

.character-select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: transparent;
  padding-right: 30px;
}

.btn-danger {
  background-color: #ef4444;
  color: white;
}

.btn-danger:hover {
  background-color: #dc2626;
}
.header-controls {
  display: flex;
  gap: 8px;
}

/* Feature Badges */
.feature-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.feature-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  white-space: nowrap;
  transition: all 0.2s ease;
}

.feature-badge:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.5);
}

.feature-badge-icon {
  width: 10px;
  height: 10px;
  opacity: 0.8;
}

.feature-badge-count {
  font-weight: 600;
  color: var(--accent);
}

.icon-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

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

.icon-btn.close:hover {
  background: #ef4444;
  color: white;
}

/* Chat Container */
.chat-container {
  flex: 1;
  overflow: hidden;
  background: var(--bg-primary);
}

.messages-list {
  height: 100%;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.messages-list::-webkit-scrollbar {
  width: 8px;
}

.messages-list::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

.messages-list::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.messages-list::-webkit-scrollbar-thumb:hover {
  background: var(--border);
}

.message {
  display: flex;
  animation: slideIn 0.3s ease;
  position: relative;
}

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

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.fade-in {
  animation: fadeIn 0.3s ease;
}

.message.user {
  justify-content: flex-end;
}

.message.assistant {
  justify-content: flex-start;
  gap: 10px;
}

.message-content {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.6;
}

.message.user .message-content {
  background: linear-gradient(135deg, var(--accent) 0%, var(--user-msg) 100%);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--user-msg) 30%, transparent);
}

.message.assistant .message-content {
  background: rgba(47, 47, 47, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(58, 58, 58, 0.5);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.message-content p {
  margin: 0;
  word-wrap: break-word;
}

.message-content p + p {
  margin-top: 12px;
}

/* Message timestamp */
.message-timestamp {
  font-size: 10px;
  color: var(--text-secondary);
  opacity: 0.6;
  margin-top: 4px;
  user-select: none;
}

.message.user .message-timestamp {
  text-align: right;
}

.message.assistant .message-timestamp {
  text-align: left;
  margin-left: 4px;
}

/* Character name indicator */
.character-name-indicator {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
  opacity: 0.9;
  user-select: none;
}

/* Message action buttons */
.message-actions {
  position: absolute;
  top: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.message.user .message-actions {
  right: 8px;
}

.message.assistant .message-actions {
  right: 8px;
}

.message:hover .message-actions {
  opacity: 1;
}

.message-action-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
}

.message-action-btn:hover {
  background: rgba(0, 0, 0, 0.7);
  color: var(--text-primary);
  transform: scale(1.1);
}

.message-action-btn:active {
  transform: scale(0.9);
}

.message-action-btn svg {
  width: 14px;
  height: 14px;
}

/* Enhanced message control buttons */
.message-delete-btn:hover {
  background: rgba(239, 68, 68, 0.8) !important;
  color: white !important;
}

.message-pin-btn.active,
.message-hide-btn.active {
  background: var(--accent);
  color: white;
}

.message-pin-btn.active:hover,
.message-hide-btn.active:hover {
  background: var(--accent-hover);
}

/* Pinned message indicator */
.message.pinned::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 8px var(--accent);
}

.message.pinned .message-content {
  border-left: 2px solid var(--accent);
}

/* Hidden message styling */
.message.hidden-message {
  opacity: 0.4;
  filter: blur(2px);
  transition: all 0.2s ease;
}

.message.hidden-message:hover {
  opacity: 0.7;
  filter: blur(1px);
}

.message.hidden-message .message-actions {
  opacity: 1 !important;
}

/* Swipe navigation */
.swipe-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  width: fit-content;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.message.assistant:hover .swipe-controls {
  opacity: 1;
}

.swipe-controls.always-visible {
  opacity: 1;
}

.swipe-btn {
  width: 20px;
  height: 20px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
}

.swipe-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
}

.swipe-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.swipe-btn svg {
  width: 12px;
  height: 12px;
}

.swipe-counter {
  font-size: 11px;
  color: var(--text-secondary);
  min-width: 32px;
  text-align: center;
  user-select: none;
}

/* Edit mode for messages */
.message-edit-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-edit-textarea {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 12px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
}

.message-edit-textarea:focus {
  outline: none;
  border-color: var(--accent-hover);
}

.message-edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.message-edit-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.message-edit-btn.save {
  background: var(--accent);
  color: white;
}

.message-edit-btn.save:hover {
  background: var(--accent-hover);
}

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

.message-edit-btn.cancel:hover {
  background: var(--border);
}

.message-content code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 0.9em;
}

.message-content pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-content pre code {
  background: none;
  padding: 0;
}

/* Copy button for code blocks */
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  opacity: 0;
  transition: all 0.2s ease;
}

.message-content pre:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

.copy-btn.copied {
  color: #22c55e;
  border-color: #22c55e;
}

/* Enhanced markdown styles */
.message-content h1,
.message-content h2,
.message-content h3 {
  margin-top: 16px;
  margin-bottom: 8px;
  font-weight: 600;
}

.message-content h1 {
  font-size: 1.5em;
}

.message-content h2 {
  font-size: 1.3em;
}

.message-content h3 {
  font-size: 1.1em;
}

.message-content ul,
.message-content ol {
  margin: 8px 0;
  padding-left: 24px;
}

.message-content li {
  margin: 4px 0;
}

.message-content a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

.message-content a:hover {
  border-bottom-color: var(--accent);
}

.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.message-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.message-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}

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

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

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-8px);
  }
}

/* Input Container */
.input-container {
  background: rgba(37, 37, 37, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(58, 58, 58, 0.5);
  padding: 16px;
  box-shadow: 0 -4px 6px rgba(0, 0, 0, 0.1);
}

.chat-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 8px;
}

#message-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  transition: border-color 0.2s ease;
}

#message-input:focus {
  outline: none;
  border-color: var(--accent);
}

#message-input::placeholder {
  color: var(--text-secondary);
}

.send-btn {
  width: 44px;
  height: 44px;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.send-btn:active {
  transform: scale(0.95);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status-text {
  font-size: 12px;
  color: var(--text-secondary);
  transition: color 0.2s ease;
}

.status-text.streaming {
  color: var(--accent);
  animation: pulse 2s ease-in-out infinite;
}

.status-text.error {
  color: #ef4444;
}

.status-text.success {
  color: #22c55e;
}

/* Token Counter */
.token-counter {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.token-count {
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.token-details-btn {
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
}

.token-details-btn:hover {
  background: var(--bg-tertiary);
  color: var(--accent);
}

.token-breakdown {
  position: absolute;
  bottom: 52px;
  right: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 100;
  min-width: 250px;
}

.token-breakdown-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.token-breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.token-breakdown-item {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}

.token-breakdown-item span:first-child {
  color: var(--text-secondary);
}

.token-breakdown-item span:last-child {
  color: var(--text-primary);
  font-weight: 500;
}

.token-breakdown-total {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

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

/* Loading spinner */
.loading-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: currentColor;
  animation: spin 0.8s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}

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

/* Button loading state */
.btn-primary.loading,
.btn-secondary.loading,
.message-action-btn.loading {
  opacity: 0.7;
  cursor: wait;
  position: relative;
}

.btn-primary.loading::after,
.btn-secondary.loading::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

/* Theme System */
/* Dark theme (default) */
:root,
[data-theme="dark"] {
  --bg-primary: #1a1a1a;
  --bg-secondary: #252525;
  --bg-tertiary: #2f2f2f;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0a0;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --user-msg: #4f46e5;
  --assistant-msg: #2f2f2f;
  --border: #3a3a3a;
  --shadow: rgba(0, 0, 0, 0.5);
}

/* Light theme */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-tertiary: #e8e8e8;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --user-msg: #6366f1;
  --assistant-msg: #f5f5f5;
  --border: #e0e0e0;
  --shadow: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .app-container {
  background: linear-gradient(135deg, #ffffff 0%, #f5f5f5 100%);
}

[data-theme="light"] .app-container::before {
  background: radial-gradient(circle at top center, rgba(99, 102, 241, 0.05) 0%, transparent 70%);
}

[data-theme="light"] .message.assistant .message-content {
  border: 1px solid var(--border);
}

/* Abyss theme - Deep purple/blue */
[data-theme="abyss"] {
  --bg-primary: #0f0f1e;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #252538;
  --text-primary: #e0e0ff;
  --text-secondary: #8888bb;
  --accent: #9d4edd;
  --accent-hover: #7b2cbf;
  --user-msg: #7b2cbf;
  --assistant-msg: #252538;
  --border: #2f2f48;
  --shadow: rgba(0, 0, 0, 0.7);
}

[data-theme="abyss"] .app-container {
  background: linear-gradient(135deg, #0f0f1e 0%, #1a1033 100%);
}

[data-theme="abyss"] .app-container::before {
  background: radial-gradient(circle at top center, rgba(157, 78, 221, 0.15) 0%, transparent 70%);
}

/* Nord theme - Cool blues and grays */
[data-theme="nord"] {
  --bg-primary: #2e3440;
  --bg-secondary: #3b4252;
  --bg-tertiary: #434c5e;
  --text-primary: #eceff4;
  --text-secondary: #d8dee9;
  --accent: #88c0d0;
  --accent-hover: #81a1c1;
  --user-msg: #5e81ac;
  --assistant-msg: #434c5e;
  --border: #4c566a;
  --shadow: rgba(0, 0, 0, 0.4);
}

[data-theme="nord"] .app-container {
  background: linear-gradient(135deg, #2e3440 0%, #3b4252 100%);
}

[data-theme="nord"] .app-container::before {
  background: radial-gradient(circle at top center, rgba(136, 192, 208, 0.1) 0%, transparent 70%);
}

/* Mocha theme - Warm browns */
[data-theme="mocha"] {
  --bg-primary: #1e1e2e;
  --bg-secondary: #2a2837;
  --bg-tertiary: #3a3850;
  --text-primary: #cdd6f4;
  --text-secondary: #bac2de;
  --accent: #f5c2e7;
  --accent-hover: #cba6f7;
  --user-msg: #cba6f7;
  --assistant-msg: #3a3850;
  --border: #45475a;
  --shadow: rgba(0, 0, 0, 0.5);
}

[data-theme="mocha"] .app-container {
  background: linear-gradient(135deg, #1e1e2e 0%, #2a2440 100%);
}

[data-theme="mocha"] .app-container::before {
  background: radial-gradient(circle at top center, rgba(245, 194, 231, 0.1) 0%, transparent 70%);
}

/* Settings Panel - Slide-in Sidebar */
.settings-panel {
  position: fixed;
  top: 0;
  right: -500px;
  width: 500px;
  height: 100vh;
  background: var(--bg-primary);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  overflow-y: auto;
  padding: 20px;
  transition: right 0.3s ease;
}

.settings-panel.open {
  right: 0;
}

/* Settings overlay backdrop */
.settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.settings-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.settings-header h2 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.settings-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.tab-btn {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.tab-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Collapsible sections */
.settings-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-secondary);
}

.settings-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  cursor: pointer;
  user-select: none;
  transition: background 0.2s ease;
}

.settings-section-header:hover {
  background: var(--border);
}

.settings-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-section-icon {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.settings-section.collapsed .settings-section-icon {
  transform: rotate(-90deg);
}

.settings-section-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 2000px;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
}

.settings-section.collapsed .settings-section-content {
  max-height: 0;
  padding: 0 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Fix theming for textareas with inline styles */
#preset-system-editable,
#preset-authors-note-editable {
  background: var(--bg-tertiary) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px;
  padding: 12px;
  color: var(--text-primary) !important;
  font-family: inherit;
  resize: vertical;
}

#preset-system-editable:focus,
#preset-authors-note-editable:focus {
  outline: none;
  border-color: var(--accent) !important;
}

.form-group select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: var(--bg-tertiary) url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236B7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e") no-repeat right 0.75rem center/1.5em 1.5em;
}

.btn-danger {
  background-color: #ef4444;
  color: white;
}

.btn-danger:hover {
  background-color: #dc2626;
}

.btn-primary,
.btn-secondary {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

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

.btn-secondary:hover {
  background: var(--border);
}

.validation-message {
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
}

.validation-message.success {
  display: block;
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.validation-message.error {
  display: block;
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Avatar Modal */
.avatar-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
}

.avatar-modal-content {
  position: relative;
  z-index: 1;
  max-width: 90vw;
  max-height: 90vh;
  pointer-events: none;
}

.avatar-modal-content img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  object-fit: contain;
}

/* Make avatars clickable */
.avatar-circle,
.avatar-circle-large {
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.avatar-circle:hover,
.avatar-circle-large:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.avatar-circle:active,
.avatar-circle-large:active {
  transform: scale(0.95);
}

/* New Character Modal */
.new-character-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
}

.new-character-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
}

.new-character-content {
  position: relative;
  z-index: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.new-character-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.new-character-header h3 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.new-character-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.new-character-actions button {
  flex: 1;
}

/* Theme Preview */
.theme-preview-container {
  margin-top: 20px;
}

.theme-preview-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.theme-preview {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.theme-preview-message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: none;
}

.theme-preview-message.user-preview {
  justify-content: flex-end;
}

.theme-preview-message.assistant-preview {
  justify-content: flex-start;
}

.theme-preview-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  opacity: 0.6;
}

.theme-preview-content {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  max-width: 70%;
}

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

.theme-preview-message.assistant-preview .theme-preview-content {
  background: var(--assistant-msg);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.theme-select {
  cursor: pointer;
}

/* Font size slider */
.font-size-slider {
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.font-size-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.font-size-slider::-webkit-slider-thumb:hover {
  background: var(--accent-hover);
  transform: scale(1.1);
}

.font-size-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.font-size-slider::-moz-range-thumb:hover {
  background: var(--accent-hover);
  transform: scale(1.1);
}

.font-size-slider::-moz-range-track {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  height: 6px;
}

#font-size-value {
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
}

/* View Mode Styles */

/* Compact Mode */
body.view-compact .messages-list {
  gap: 10px;
  padding: 16px;
}

body.view-compact .message-content {
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 10px;
}

body.view-compact .avatar-circle {
  width: 24px;
  height: 24px;
}

body.view-compact .character-name-indicator {
  font-size: 10px;
  margin-bottom: 2px;
}

body.view-compact .message-timestamp {
  font-size: 9px;
  margin-top: 2px;
}

body.view-compact .swipe-controls {
  margin-top: 6px;
  padding: 3px 6px;
}

body.view-compact .message-content h1 {
  font-size: 1.3em;
}

body.view-compact .message-content h2 {
  font-size: 1.2em;
}

body.view-compact .message-content h3 {
  font-size: 1.05em;
}

body.view-compact .message-content code {
  font-size: 0.85em;
}

/* Cozy Mode (Default) - Already defined in base styles */
body.view-cozy .messages-list {
  gap: 16px;
  padding: 20px;
}

/* Comfortable Mode */
body.view-comfortable .messages-list {
  gap: 24px;
  padding: 24px;
}

body.view-comfortable .message-content {
  padding: 16px 20px;
  font-size: 15px;
  line-height: 1.7;
  border-radius: 14px;
}

body.view-comfortable .avatar-circle {
  width: 32px;
  height: 32px;
}

body.view-comfortable .character-name-indicator {
  font-size: 12px;
  margin-bottom: 6px;
}

body.view-comfortable .message-timestamp {
  font-size: 11px;
  margin-top: 6px;
}

body.view-comfortable .swipe-controls {
  margin-top: 10px;
  padding: 5px 10px;
}

body.view-comfortable .message-content h1 {
  font-size: 1.6em;
  margin-top: 20px;
  margin-bottom: 12px;
}

body.view-comfortable .message-content h2 {
  font-size: 1.4em;
  margin-top: 18px;
  margin-bottom: 10px;
}

body.view-comfortable .message-content h3 {
  font-size: 1.2em;
  margin-top: 16px;
  margin-bottom: 8px;
}

body.view-comfortable .message-content p + p {
  margin-top: 16px;
}

body.view-comfortable .message-content code {
  font-size: 0.95em;
  padding: 3px 8px;
}

body.view-comfortable .message-content pre {
  padding: 16px;
  margin: 12px 0;
}

/* Roleplay Panel - Slide-in from Left */
.roleplay-panel {
  position: fixed;
  top: 0;
  left: -500px;
  width: 500px;
  height: 100vh;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  overflow-y: auto;
  padding: 20px;
  transition: left 0.3s ease;
}

.roleplay-panel.open {
  left: 0;
}

.roleplay-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.roleplay-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.roleplay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.roleplay-header h2 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.roleplay-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.roleplay-tab-btn {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.roleplay-tab-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

.roleplay-tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.roleplay-tab-content {
  display: none;
}

.roleplay-tab-content.active {
  display: block;
}

.roleplay-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.worldinfo-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.worldinfo-entry {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  transition: all 0.2s ease;
}

.worldinfo-entry:hover {
  border-color: var(--accent);
}

.worldinfo-entry-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.worldinfo-entry-header input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.worldinfo-keys {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.worldinfo-priority {
  font-size: 11px;
  color: var(--text-secondary);
  background: rgba(99, 102, 241, 0.1);
  padding: 2px 8px;
  border-radius: 4px;
}

.worldinfo-entry-actions {
  display: flex;
  gap: 6px;
}

.worldinfo-btn {
  padding: 4px 12px;
  font-size: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.worldinfo-btn:hover {
  background: var(--border);
  border-color: var(--accent);
}

.worldinfo-btn-danger {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.worldinfo-btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
}

.worldinfo-entry-content {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  padding: 8px;
  background: var(--bg-secondary);
  border-radius: 6px;
  word-wrap: break-word;
}

.worldinfo-edit-form,
.worldinfo-inline-edit {
  background: var(--bg-secondary);
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 16px;
}

.worldinfo-edit-form input,
.worldinfo-edit-form textarea,
.worldinfo-inline-edit input,
.worldinfo-inline-edit textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
}

.worldinfo-edit-form input:focus,
.worldinfo-edit-form textarea:focus,
.worldinfo-inline-edit input:focus,
.worldinfo-inline-edit textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.worldinfo-edit-form textarea,
.worldinfo-inline-edit textarea {
  resize: vertical;
  min-height: 80px;
}

.header-left-controls {
  display: flex;
  gap: 8px;
}

/* Responsive */
@media (max-width: 600px) {
  .messages-list {
    padding: 12px;
  }

  .message-content {
    max-width: 90%;
  }

  .input-container {
    padding: 12px;
  }

  .settings-panel {
    width: 100%;
    right: -100%;
  }

  .settings-panel.open {
    right: 0;
  }

  .roleplay-panel {
    width: 100%;
    left: -100%;
  }

  .roleplay-panel.open {
    left: 0;
  }
}
