/**
 * SideClaw - Clean Design System
 * Sidebar + Chat Layout
 */

/* ============================================================================
   CSS Variables
   ============================================================================ */

:root {
  /* Colors - Light Mode */
  --bg-primary: #F5F5F5;
  --bg-surface: #FFFFFF;
  --bg-elevated: #FAFAFA;
  --bg-sidebar: #FFFFFF;

  --text-primary: #1A1A1A;
  --text-secondary: #666666;
  --text-tertiary: #999999;

  --accent: #B593C6;
  --accent-hover: #A07DB5;
  --accent-light: rgba(181, 147, 198, 0.15);

  --border: #E8E8E8;
  --border-hover: #D0D0D0;

  --error: #DC3545;
  --error-bg: #FFF5F5;

  /* Typography */
  --font-display: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Layout */
  --sidebar-width: 260px;
  --header-height: 56px;
  --radius: 8px;
  --radius-sm: 4px;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
}

/* ============================================================================
   Reset & Base
   ============================================================================ */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

/* ============================================================================
   App Layout
   ============================================================================ */

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ============================================================================
   Sidebar
   ============================================================================ */

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
}

.logo-group {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.logo {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.logo-tag {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: white;
  background: var(--accent);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.sidebar-search {
  padding: var(--sp-3) var(--sp-4);
}

.sidebar-search input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.sidebar-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.sidebar-search input::placeholder {
  color: var(--text-tertiary);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-2);
}

.chat-item {
  display: flex;
  align-items: center;
  padding: var(--sp-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.1s;
  margin-bottom: 2px;
}

.chat-item:hover {
  background: var(--bg-elevated);
}

.chat-item.active {
  background: var(--accent-light);
}

.chat-item-content {
  flex: 1;
  min-width: 0;
}

.chat-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-preview {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-item-time {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-left: var(--sp-2);
  flex-shrink: 0;
}

.sidebar-footer {
  padding: var(--sp-4);
  border-top: 1px solid var(--border);
}

/* Sidebar toggle (mobile) */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: var(--sp-4);
  left: var(--sp-4);
  z-index: 60;
  width: 40px;
  height: 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

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

/* ============================================================================
   Main Content
   ============================================================================ */

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-surface);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 var(--sp-6);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ============================================================================
   Chat Container
   ============================================================================ */

.chat-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.messages {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/* ============================================================================
   Messages
   ============================================================================ */

.message {
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.2s ease;
}

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

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

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

.message-bubble {
  max-width: 85%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  line-height: 1.5;
}

.message.user .message-bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

.message.assistant .message-bubble {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--radius-sm);
}

.message-bubble p {
  margin: 0;
}

.message-bubble p + p {
  margin-top: var(--sp-2);
}

.message.error .message-bubble {
  background: var(--error-bg);
  border: 1px solid var(--error);
  color: var(--error);
}

/* Markdown Styles in Messages */
.message-bubble code {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
}

.message.user .message-bubble code {
  background: rgba(255, 255, 255, 0.2);
}

.message-bubble pre {
  margin: var(--sp-2) 0;
  padding: var(--sp-3);
  background: #1e1e1e;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.message-bubble pre code {
  background: none;
  padding: 0;
  color: #d4d4d4;
  font-size: 13px;
  line-height: 1.4;
}

.message-bubble strong {
  font-weight: 600;
}

.message-bubble em {
  font-style: italic;
}

.message-bubble a {
  color: var(--accent);
  text-decoration: underline;
}

.message.user .message-bubble a {
  color: white;
}

/* ============================================================================
   Input Area
   ============================================================================ */

.input-area {
  border-top: 1px solid var(--border);
  padding: var(--sp-4) var(--sp-6);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.input-container {
  max-width: 720px;
  margin: 0 auto;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-2);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

#user-input {
  flex: 1;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  padding: var(--sp-2);
}

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

.send-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.send-button:hover {
  background: var(--accent-hover);
}

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

.send-button:disabled {
  background: var(--border);
  color: var(--text-tertiary);
  cursor: not-allowed;
  transform: none;
}

.input-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: var(--sp-2);
  text-align: center;
}

kbd {
  font-family: var(--font-body);
  font-size: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
}

/* ============================================================================
   Loading
   ============================================================================ */

.loading {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.loading.hidden {
  display: none;
}

.loading-content {
  background: var(--bg-surface);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.loading-dots {
  display: flex;
  gap: 6px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ============================================================================
   Icon Button
   ============================================================================ */

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}

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

/* ============================================================================
   Modal
   ============================================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--sp-4);
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal.modal-small {
  max-width: 320px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  font-size: 24px;
  line-height: 1;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

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

.modal-content {
  padding: var(--sp-5);
  overflow-y: auto;
  flex: 1;
}

.modal-content p {
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
}

/* Settings */
.settings-section {
  margin-bottom: var(--sp-5);
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section h3 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: var(--sp-3);
}

.input-label {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-bottom: var(--sp-3);
}

.input-label:last-child {
  margin-bottom: 0;
}

.input-label span {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.input-label input {
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-body);
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-label input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.input-label input::placeholder {
  color: var(--text-tertiary);
}

/* Buttons */
.btn {
  padding: var(--sp-2) var(--sp-4);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

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

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

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

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

.btn-danger {
  background: var(--error);
  color: white;
}

.btn-danger:hover {
  background: #C82333;
}

/* ============================================================================
   Utilities
   ============================================================================ */

.hidden {
  display: none !important;
}

/* ============================================================================
   Responsive
   ============================================================================ */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 300px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 70;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .chat-header {
    padding-left: 60px;
  }

  .messages {
    padding: var(--sp-4);
  }

  .input-area {
    padding: var(--sp-3) var(--sp-4);
  }

  .input-hint {
    display: none;
  }
}

/* ============================================================================
   Dark Mode
   ============================================================================ */

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #0D0D0D;
    --bg-surface: #161616;
    --bg-elevated: #1E1E1E;
    --bg-sidebar: #141414;

    --text-primary: #F0F0F0;
    --text-secondary: #A0A0A0;
    --text-tertiary: #606060;

    --border: #2A2A2A;
    --border-hover: #3A3A3A;

    --error-bg: #2D1F1F;
  }
}

/* ============================================================================
   Reduced Motion
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================================
   Thinking Indicator
   ============================================================================ */

.thinking-indicator {
  position: fixed;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
}

.thinking-content {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  font-size: 13px;
  color: var(--text-secondary);
}

.thinking-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s ease-in-out infinite;
}

.thinking-icon svg {
  color: var(--accent);
}

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

/* Typing dots animation */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes typingBounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ============================================================================
   Thinking Steps in Messages
   ============================================================================ */

.thinking-steps {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: rgba(0, 0, 0, 0.03);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--accent);
}

.thinking-steps summary {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.thinking-steps summary::-webkit-details-marker {
  display: none;
}

.thinking-steps summary::before {
  content: '▶';
  font-size: 8px;
  transition: transform 0.2s;
}

.thinking-steps[open] summary::before {
  transform: rotate(90deg);
}

.thinking-steps ul {
  margin: var(--sp-2) 0 0 var(--sp-3);
  padding: 0;
  list-style: none;
}

.thinking-steps li {
  padding: 2px 0;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.thinking-steps li::before {
  content: '→';
  color: var(--accent);
  font-size: 10px;
}

/* ============================================================================
   Extended Settings Modal
   ============================================================================ */

.modal.modal-large {
  max-width: 540px;
}

.settings-section textarea {
  width: 100%;
  padding: var(--sp-3);
  font-family: var(--font-body);
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.settings-section textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.settings-section textarea::placeholder {
  color: var(--text-tertiary);
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
}

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

.settings-row {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
}

.settings-note {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: var(--sp-2);
}

/* Connected Accounts */
.connection-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.connection-info {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.connection-icon {
  font-size: 24px;
}

.connection-details {
  display: flex;
  flex-direction: column;
}

.connection-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.connection-status-text {
  font-size: 12px;
  color: var(--text-tertiary);
}

.connection-status-text.connected {
  color: #22C55E;
}

.connection-status-text.expired {
  color: var(--error);
}

/* ============================================================================
   Keyboard Shortcuts Modal
   ============================================================================ */

.shortcuts-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.shortcut-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
}

.shortcut-item:last-child {
  border-bottom: none;
}

.shortcut-keys {
  display: flex;
  gap: var(--sp-1);
  align-items: center;
}

.shortcut-keys kbd {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  min-width: 24px;
  text-align: center;
}

.shortcut-desc {
  color: var(--text-secondary);
  font-size: 13px;
}

/* ============================================================================
   Sidebar Footer Improvements
   ============================================================================ */

.sidebar-footer {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-4);
  border-top: 1px solid var(--border);
}

/* ============================================================================
   Empty State
   ============================================================================ */

.empty-state {
  padding: var(--sp-6);
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

/* ============================================================================
   Theme Toggle Support
   ============================================================================ */

html[data-theme="light"] {
  --bg-primary: #F5F5F5;
  --bg-surface: #FFFFFF;
  --bg-elevated: #FAFAFA;
  --bg-sidebar: #FFFFFF;
  --text-primary: #1A1A1A;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --border: #E8E8E8;
  --border-hover: #D0D0D0;
  --error-bg: #FFF5F5;
}

html[data-theme="dark"] {
  --bg-primary: #0D0D0D;
  --bg-surface: #161616;
  --bg-elevated: #1E1E1E;
  --bg-sidebar: #141414;
  --text-primary: #F0F0F0;
  --text-secondary: #A0A0A0;
  --text-tertiary: #606060;
  --border: #2A2A2A;
  --border-hover: #3A3A3A;
  --error-bg: #2D1F1F;
}

/* ============================================================================
   Chat Search Bar
   ============================================================================ */

.chat-search-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.chat-search-bar input {
  flex: 1;
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
}

.chat-search-bar input:focus {
  border-color: var(--accent);
}

#chat-search-results {
  font-size: 12px;
  color: var(--text-tertiary);
  min-width: 40px;
  text-align: center;
}

/* ============================================================================
   Chat Title Container with Pin
   ============================================================================ */

.chat-title-container {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.icon-btn-small {
  width: 24px;
  height: 24px;
}

.icon-btn-small svg {
  width: 14px;
  height: 14px;
}

#pin-chat-btn.pinned {
  color: var(--accent);
  background: var(--accent-light);
}

/* ============================================================================
   Pinned Chat Item
   ============================================================================ */

.chat-item.pinned {
  border-left: 2px solid var(--accent);
  background: var(--accent-light);
}

.chat-item.pinned .chat-item-title::before {
  content: "📌 ";
  font-size: 10px;
}

/* ============================================================================
   Message Actions (Copy, Edit, Retry, Regenerate, Fork, Reactions)
   ============================================================================ */

.message-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin-top: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--border);
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-tertiary);
  font-size: 14px;
  transition: all 0.15s;
}

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

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

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

/* Reaction buttons (emoji style) */
.action-btn.reaction-btn.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* Visual divider between action groups */
.action-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 var(--sp-1);
}

/* Toast notifications */
.toast-notification {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 13px;
  color: var(--text-primary);
  z-index: 1000;
  animation: toast-in 0.3s ease;
}

.toast-notification.fade-out {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* Legacy support - keep .message-reactions working */
.message-reactions {
  display: flex;
  gap: var(--sp-1);
  margin-top: var(--sp-2);
  opacity: 0;
  transition: opacity 0.15s;
}

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

.reaction-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-tertiary);
  font-size: 14px;
  transition: all 0.15s;
}

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

.reaction-btn.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================================
   Memory Dashboard Styles
   ============================================================================ */

.memory-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3);
  text-align: center;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  color: var(--accent);
}

.stat-label {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: var(--sp-1);
}

.memory-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-3);
}

.memory-list-header h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.memory-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.memory-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
}

.memory-item:last-child {
  border-bottom: none;
}

.memory-item-content {
  flex: 1;
}

.memory-item-fact {
  font-size: 13px;
  color: var(--text-primary);
  margin-bottom: var(--sp-1);
}

.memory-item-meta {
  font-size: 11px;
  color: var(--text-tertiary);
}

.memory-item-category {
  display: inline-block;
  padding: 2px 6px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  margin-right: var(--sp-2);
}

.memory-item-delete {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.memory-item-delete:hover {
  background: var(--error-bg);
  color: var(--error);
}

.memory-loading {
  padding: var(--sp-4);
  text-align: center;
  color: var(--text-tertiary);
}

.memory-empty {
  padding: var(--sp-4);
  text-align: center;
  color: var(--text-tertiary);
  font-style: italic;
}

/* ============================================================================
   Select Dropdown Styling
   ============================================================================ */

.settings-section select {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-body);
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.settings-section select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* ============================================================================
   Small Button Variant
   ============================================================================ */

.btn-small {
  padding: var(--sp-1) var(--sp-3);
  font-size: 12px;
}

/* ============================================================================
   Search Highlight
   ============================================================================ */

.search-highlight {
  background: rgba(255, 235, 59, 0.4);
  border-radius: 2px;
}

.search-highlight.current {
  background: rgba(255, 152, 0, 0.6);
}

/* ============================================================================
   Responsive Memory Stats
   ============================================================================ */

@media (max-width: 480px) {
  .memory-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================================================
   Analytics Modal
   ============================================================================ */

.modal-medium {
  max-width: 450px;
}

.analytics-info {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--color-background-secondary);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  text-align: center;
}

.analytics-info p {
  margin: 0;
}

/* ============================================================================
   OTR (Off-the-Record) Toggle
   ============================================================================ */

.otr-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all 0.15s;
  flex-shrink: 0;
}

.otr-toggle:hover {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-color: var(--border-hover);
}

.otr-toggle.active {
  background: rgba(245, 158, 11, 0.15);
  border-color: #f59e0b;
  color: #f59e0b;
}

.otr-toggle.active:hover {
  background: rgba(245, 158, 11, 0.25);
}

.otr-toggle .otr-icon-on,
.otr-toggle .otr-icon-off {
  display: flex;
}

/* ============================================================================
   Domain Badge
   ============================================================================ */

.domain-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  transition: all 0.2s;
}

.domain-badge .domain-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6b7280;
  transition: background 0.2s;
}

.domain-badge[data-domain="leisure"] {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.domain-badge[data-domain="leisure"] .domain-indicator {
  background: #10b981;
}

.domain-badge[data-domain="irl"] {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
}

.domain-badge[data-domain="irl"] .domain-indicator {
  background: #f59e0b;
}

.domain-badge[data-domain="meta"] {
  border-color: #8b5cf6;
  background: rgba(139, 92, 246, 0.1);
  color: #7c3aed;
}

.domain-badge[data-domain="meta"] .domain-indicator {
  background: #8b5cf6;
}

.domain-badge[data-domain="unknown"] {
  border-color: #6b7280;
  background: rgba(107, 114, 128, 0.1);
  color: #6b7280;
}

.domain-badge[data-domain="gaming_wow"] {
  border-color: #C79C6E;
  background: rgba(199, 156, 110, 0.1);
  color: #C79C6E;
}

.domain-badge[data-domain="gaming_wow"] .domain-indicator { background: #C79C6E; }

.domain-badge[data-domain="gaming_general"] {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.domain-badge[data-domain="gaming_general"] .domain-indicator { background: #10b981; }

.domain-badge[data-domain="tv_movies"] {
  border-color: #e879f9;
  background: rgba(232, 121, 249, 0.1);
  color: #d946ef;
}

.domain-badge[data-domain="tv_movies"] .domain-indicator { background: #e879f9; }

.domain-badge[data-domain="comics"] {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.domain-badge[data-domain="comics"] .domain-indicator { background: #ef4444; }

.domain-badge[data-domain="books"] {
  border-color: #a78bfa;
  background: rgba(167, 139, 250, 0.1);
  color: #8b5cf6;
}

.domain-badge[data-domain="books"] .domain-indicator { background: #a78bfa; }

.domain-badge[data-domain="music"] {
  border-color: #f472b6;
  background: rgba(244, 114, 182, 0.1);
  color: #ec4899;
}

.domain-badge[data-domain="music"] .domain-indicator { background: #f472b6; }

.domain-badge[data-domain="food_drink"] {
  border-color: #fb923c;
  background: rgba(251, 146, 60, 0.1);
  color: #f97316;
}

.domain-badge[data-domain="food_drink"] .domain-indicator { background: #fb923c; }

.domain-badge[data-domain="history"] {
  border-color: #fbbf24;
  background: rgba(251, 191, 36, 0.1);
  color: #d97706;
}

.domain-badge[data-domain="history"] .domain-indicator { background: #fbbf24; }

.domain-badge[data-domain="science_fun"] {
  border-color: #34d399;
  background: rgba(52, 211, 153, 0.1);
  color: #059669;
}

.domain-badge[data-domain="science_fun"] .domain-indicator { background: #34d399; }

.domain-badge[data-domain="sports"] {
  border-color: #60a5fa;
  background: rgba(96, 165, 250, 0.1);
  color: #3b82f6;
}

.domain-badge[data-domain="sports"] .domain-indicator { background: #60a5fa; }

.domain-badge[data-domain="anime_manga"] {
  border-color: #f87171;
  background: rgba(248, 113, 113, 0.1);
  color: #dc2626;
}

.domain-badge[data-domain="anime_manga"] .domain-indicator { background: #f87171; }

/* ============================================================================
   Profile Inspector Modal
   ============================================================================ */

.profile-tabs {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--sp-2);
}

.profile-tab {
  padding: var(--sp-2) var(--sp-4);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all 0.15s;
}

.profile-tab:hover {
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.profile-tab.active {
  background: var(--accent-light);
  color: var(--accent);
}

.profile-content {
  position: relative;
}

.profile-pane {
  display: none;
}

.profile-pane.active {
  display: block;
}

.profile-content pre.profile-content {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
  font-size: 12px;
  line-height: 1.5;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text-primary);
}

.profile-loading {
  padding: var(--sp-6);
  text-align: center;
  color: var(--text-tertiary);
  font-style: italic;
}

.profile-empty {
  padding: var(--sp-4);
  text-align: center;
  color: var(--text-tertiary);
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.profile-error {
  padding: var(--sp-4);
  text-align: center;
  color: var(--error);
  background: var(--error-bg);
  border: 1px solid var(--error);
  border-radius: var(--radius);
}

.profile-footer-info {
  margin-top: var(--sp-4);
  padding: var(--sp-3);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: center;
}

.profile-footer-info p {
  margin: 0;
}

/* World State Items */
.world-state-item {
  margin-bottom: var(--sp-3);
  padding: var(--sp-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.world-state-item:last-child {
  margin-bottom: 0;
}

.world-state-category {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: var(--sp-2);
}

.world-state-data {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
  font-size: 11px;
  line-height: 1.4;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-2);
  overflow-x: auto;
  margin: 0;
  color: var(--text-secondary);
}

/* ============================================================================
   OTR Mode Visual Feedback in Input Area
   ============================================================================ */

.input-wrapper:has(.otr-toggle.active) {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.05);
}

.input-wrapper:has(.otr-toggle.active):focus-within {
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

/* ============================================================================
   Login & Account Styles
   ============================================================================ */

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.login-form .input-label {
  margin-bottom: 0;
}

.login-form input[type="text"],
.login-form input[type="password"],
.login-form input[type="email"] {
  width: 100%;
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-body);
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.login-error,
.password-change-error {
  padding: var(--sp-3);
  background: var(--error-bg);
  border: 1px solid var(--error);
  border-radius: var(--radius);
  color: var(--error);
  font-size: 13px;
}

.login-success {
  padding: var(--sp-3);
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid #22C55E;
  border-radius: var(--radius);
  color: #22C55E;
  font-size: 13px;
}

/* Login modal - blocks ALL content until authenticated */
#login-modal {
  background: var(--bg-primary);  /* Solid background - no transparency */
}

#login-modal .modal {
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* OAuth Buttons */
.oauth-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.btn-oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-oauth:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

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

.oauth-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.btn-github {
  background: #24292e;
  color: white;
}

.btn-github:hover {
  background: #1b1f23;
}

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

.btn-google:hover {
  background: var(--bg-elevated);
}

/* Login Divider */
.login-divider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin: var(--sp-4) 0;
  color: var(--text-tertiary);
  font-size: 12px;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Login Tabs */
.login-tabs {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.login-tab {
  padding: var(--sp-2) var(--sp-4);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.login-tab:hover {
  color: var(--text-primary);
}

.login-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Login Actions */
.login-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: calc(-1 * var(--sp-2));
}

.login-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}

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

.login-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: var(--sp-1);
  line-height: 1.4;
}

/* Account Info */
.account-info {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  margin-bottom: var(--sp-3);
  font-size: 14px;
}

.account-info strong {
  color: var(--accent);
}

.account-provider {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-left: var(--sp-1);
}

.password-change-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
  padding: var(--sp-3);
  background: var(--bg-elevated);
  border-radius: var(--radius);
}

.password-change-form input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-body);
}

.password-change-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* Linked Accounts */
.linked-account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  margin-bottom: var(--sp-2);
}

.linked-account-row:last-child {
  margin-bottom: 0;
}

.linked-account-info {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.linked-account-icon {
  font-size: 18px;
  width: 28px;
  text-align: center;
}

.linked-account-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.linked-account-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.linked-account-status {
  font-size: 11px;
  color: var(--text-tertiary);
}

.linked-account-status.connected {
  color: #22C55E;
}

.linked-account-only {
  font-size: 11px;
  color: var(--text-tertiary);
  font-style: italic;
}

.btn-unlink {
  font-size: 12px;
  padding: var(--sp-1) var(--sp-2);
}

.btn-link-provider {
  font-size: 12px;
  padding: var(--sp-1) var(--sp-2);
}

/* ============================================================================
   The Codex Modal
   ============================================================================ */

.codex-modal {
  max-width: 600px;
}

.codex-section {
  margin-bottom: var(--sp-5);
}

.codex-section:last-child {
  margin-bottom: 0;
}

.codex-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}

.codex-section-header h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* Tier badges (RPG-style) */
.tier-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 20px;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

.tier-badge.tier-1 {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.tier-badge.tier-2 {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.tier-badge.tier-3 {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.tier-badge.tier-4 {
  background: rgba(139, 92, 246, 0.15);
  color: #8b5cf6;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.tier-tag {
  font-size: 11px;
  color: var(--text-tertiary);
  font-style: italic;
}

/* Codex tier sections */
.codex-tier {
  padding: var(--sp-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.codex-tier[data-tier="1"] {
  border-left: 3px solid #ef4444;
}

.codex-tier[data-tier="2"] {
  border-left: 3px solid #f59e0b;
}

.codex-tier[data-tier="3"] {
  border-left: 3px solid #3b82f6;
}

.codex-tier[data-tier="4"] {
  border-left: 3px solid #8b5cf6;
}

/* USER tab */
.codex-user-display {
  min-height: 60px;
}

.codex-user-rendered {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
  padding: var(--sp-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 300px;
  overflow-y: auto;
}

.codex-user-rendered h2 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: var(--sp-3) 0 var(--sp-2);
  color: var(--accent);
}

.codex-user-rendered h3,
.codex-user-rendered h4 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  margin: var(--sp-2) 0 var(--sp-1);
  color: var(--text-secondary);
}

.codex-user-rendered p {
  margin-bottom: var(--sp-2);
}

.codex-user-rendered ul {
  margin: var(--sp-1) 0 var(--sp-2) var(--sp-4);
}

.codex-user-rendered li {
  margin-bottom: var(--sp-1);
}

.codex-user-editor textarea {
  width: 100%;
  min-height: 200px;
  padding: var(--sp-3);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  resize: vertical;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.codex-user-editor textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.codex-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

/* Learned facts (inline memory) */
.codex-learned-list {
  max-height: 250px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.codex-learned-item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.codex-learned-item:last-child {
  border-bottom: none;
}

.codex-learned-fact {
  color: var(--text-primary);
  line-height: 1.4;
}

/* SOUL display */
.codex-soul-display {
  max-height: 300px;
  overflow-y: auto;
}

.codex-soul-rendered {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.codex-soul-rendered h2,
.codex-soul-rendered h3 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin: var(--sp-3) 0 var(--sp-1);
}

.codex-soul-rendered h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: var(--sp-2) 0 var(--sp-1);
}

.codex-soul-rendered p {
  margin-bottom: var(--sp-2);
}

.codex-soul-rendered ul {
  margin: var(--sp-1) 0 var(--sp-2) var(--sp-4);
}

.codex-soul-rendered li {
  margin-bottom: 2px;
}

/* Soul config items (T2) */
.codex-config-item {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
}

.codex-config-item:last-child {
  border-bottom: none;
}

.codex-config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-1);
}

.codex-config-value {
  font-size: 13px;
  color: var(--text-primary);
  margin-bottom: var(--sp-1);
}

.codex-config-original {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: var(--sp-2);
}

/* Proposals (T3) */
.codex-proposal-item {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
}

.codex-proposal-item:last-child {
  border-bottom: none;
}

.codex-proposal-item.approved {
  border-left: 3px solid #22C55E;
}

.codex-proposal-item.rejected {
  border-left: 3px solid var(--error);
  opacity: 0.6;
}

.codex-proposal-item.pending {
  border-left: 3px solid #3b82f6;
}

.codex-proposal-text {
  font-size: 13px;
  color: var(--text-primary);
  margin-bottom: var(--sp-1);
}

.codex-proposal-reason {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: var(--sp-2);
  font-style: italic;
}

.codex-proposal-actions {
  display: flex;
  gap: var(--sp-2);
}

.codex-proposal-status {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
}

/* Evolution items (T4) */
.codex-evolution-item {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
}

.codex-evolution-item:last-child {
  border-bottom: none;
}

.codex-evolution-item.overridden {
  opacity: 0.5;
}

.codex-evolution-trait {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--sp-1);
}

.codex-evolution-change {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
}

.codex-old-value {
  text-decoration: line-through;
  color: var(--text-tertiary);
}

.codex-new-value {
  color: var(--accent);
}

.codex-evolution-reason {
  font-size: 11px;
  color: var(--text-tertiary);
  font-style: italic;
  margin-bottom: var(--sp-2);
}

.codex-override-badge {
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.05em;
}

/* Empty state */
.codex-empty {
  padding: var(--sp-4);
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
  font-style: italic;
}

/* ============================================================================
   Settings Modal Reorganization
   ============================================================================ */

.settings-modal-reorg {
  max-width: 540px;
}

.settings-group {
  margin-bottom: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.settings-group:last-child {
  margin-bottom: 0;
}

.settings-group-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.settings-group-header .settings-group-icon {
  font-size: 16px;
}

.settings-group-header h3 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 0;
}

.settings-group > .settings-section {
  padding: var(--sp-4);
  margin-bottom: 0;
}

.settings-subsection-title {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: var(--sp-4);
  margin-bottom: var(--sp-2);
}

.settings-about-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-2) 0;
  font-size: 13px;
  color: var(--text-primary);
  margin-bottom: var(--sp-3);
}

.text-tertiary {
  color: var(--text-tertiary);
}

/* Memory stats wide (7 columns) */
.memory-stats-wide {
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
}

@media (max-width: 480px) {
  .memory-stats-wide {
    grid-template-columns: repeat(3, 1fr);
  }
}
