/* === Apple-Inspired Design System === */
/* Based on Apple's WWDC 2026 Design Principles */

/* === CSS Variables === */
:root {
  /* Colors - Monochrome Palette */
  --bg-primary: #ffffff;
  --bg-secondary: #fbfbfd;
  --bg-tertiary: #f5f5f7;
  --bg-hover: #f0f0f3;
  --bg-active: #e8e8ed;
  
  --text-primary: #1d1d1f;
  --text-secondary: #424245;
  --text-tertiary: #6e6e73;
  --text-muted: #86868b;
  
  --border-primary: #d2d2d7;
  --border-secondary: #e5e5ea;
  --border-tertiary: #f0f0f3;
  
  --accent: #1d1d1f;
  --accent-hover: #424245;
  --accent-bg: #f5f5f7;
  
  --think-bar: #d2d2d7;
  --think-bar-open: #424245;
  --bubble-user-bg: #f5f5f7;
  
  --danger: #ff3b30;
  --success: #34c759;
  --warning: #ff9500;
  
  --sidebar-bg: #fbfbfd;
  --chat-bg: #ffffff;
  
  /* Shadows - Subtle depth */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.16);
  
  /* Typography - Fluid Scale */
  --font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Consolas', 'Cascadia Code', monospace;
  
  --fs-xs: clamp(11px, 0.7vw + 9px, 13px);
  --fs-sm: clamp(13px, 0.8vw + 11px, 15px);
  --fs-base: clamp(15px, 1vw + 13px, 17px);
  --fs-lg: clamp(17px, 1.2vw + 14px, 20px);
  --fs-xl: clamp(20px, 1.5vw + 16px, 24px);
  --fs-2xl: clamp(24px, 2vw + 18px, 32px);
  
  /* Spacing - 4px Grid */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  
  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 50%;
  
  /* Transitions - Apple-style */
  --ease-default: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 350ms;
  
  /* Sidebar */
  --sidebar-w: clamp(240px, 20vw, 300px);
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-primary: #000000;
  --bg-secondary: #1c1c1e;
  --bg-tertiary: #2c2c2e;
  --bg-hover: #3a3a3c;
  --bg-active: #48484a;
  
  --text-primary: #f5f5f7;
  --text-secondary: #e5e5ea;
  --text-tertiary: #aeaeb2;
  --text-muted: #8e8e93;
  
  --border-primary: #38383a;
  --border-secondary: #2c2c2e;
  --border-tertiary: #1c1c1e;
  
  --accent: #f5f5f7;
  --accent-hover: #e5e5ea;
  --accent-bg: #2c2c2e;
  
  --think-bar: #48484a;
  --think-bar-open: #aeaeb2;
  --bubble-user-bg: #2c2c2e;
  
  --danger: #ff453a;
  --success: #30d158;
  --warning: #ff9f0a;
  
  --sidebar-bg: #1c1c1e;
  --chat-bg: #000000;
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.5);
}

/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  font-size: var(--fs-base);
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.5;
  letter-spacing: -0.01em;
}

input, button, textarea, select {
  font-family: inherit;
  font-size: inherit;
  outline: none;
  border: none;
  background: none;
}

a {
  color: inherit;
  text-decoration: none;
}

/* === Focus States - Accessibility === */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--duration-fast) var(--ease-default);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.btn:active {
  transform: scale(0.97);
  background: var(--bg-active);
}

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

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

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

.btn-primary:active {
  background: var(--text-secondary);
}

.btn-primary:disabled {
  background: var(--text-muted);
  border-color: var(--text-muted);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--fs-xs);
  border-radius: var(--radius-sm);
}

.btn-xs {
  padding: 3px 7px;
  font-size: var(--fs-xs);
  border-radius: var(--radius-sm);
}

.btn-icon {
  padding: var(--space-2);
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all var(--duration-fast) var(--ease-default);
}

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

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

/* === Form Elements === */
.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-tertiary);
  margin-bottom: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--fs-base);
  transition: all var(--duration-fast) var(--ease-default);
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 29, 31, 0.1);
}

[data-theme="dark"] .form-input:focus {
  box-shadow: 0 0 0 3px rgba(245, 245, 247, 0.1);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-error {
  font-size: var(--fs-xs);
  color: var(--danger);
  margin: var(--space-1) 0;
  min-height: 18px;
}

/* === Spinner === */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-primary);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.6s linear infinite;
}

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

/* === Layout === */
.page-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: var(--space-6);
  background: var(--bg-secondary);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: var(--space-8);
  background: var(--bg-primary);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: cardIn var(--duration-normal) var(--ease-out);
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.auth-card h1 {
  font-size: var(--fs-2xl);
  font-weight: 600;
  margin-bottom: var(--space-2);
  letter-spacing: -0.02em;
}

.auth-card .subtitle {
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  margin-bottom: var(--space-6);
}

.auth-card .footer {
  margin-top: var(--space-5);
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
}

.auth-card .footer a {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.app-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-secondary);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 99;
  transition: transform var(--duration-normal) var(--ease-out);
}

.sidebar-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-secondary);
}

.sidebar-header .btn-primary {
  width: 100%;
  font-size: var(--fs-sm);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
}

.conv-list {
  flex: 1;
  overflow-y: overlay;
  padding: var(--space-2);
}

/* Custom Scrollbar */
.conv-list::-webkit-scrollbar {
  width: 6px;
}

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

.conv-list::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 3px;
  transition: background var(--duration-normal) var(--ease-default);
}

.conv-list:hover::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  transition: background var(--duration-fast) 0s;
}

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

.conv-list {
  scrollbar-width: none;
}

.conv-list:hover {
  scrollbar-width: thin;
  scrollbar-color: var(--border-primary) transparent;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  margin-bottom: 2px;
  position: relative;
  transition: all var(--duration-fast) var(--ease-default);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.conv-item:active {
  background: var(--bg-active);
  transform: scale(0.98);
}

.conv-item.active {
  background: var(--accent-bg);
  color: var(--text-primary);
}

.conv-item .conv-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.conv-item .conv-delete {
  opacity: 0;
  flex-shrink: 0;
  padding: 4px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--duration-fast) var(--ease-default);
  color: var(--text-muted);
}

.conv-item:hover .conv-delete {
  opacity: 1;
}

.conv-item .conv-delete:hover {
  background: var(--bg-hover);
  color: var(--danger);
}

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

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

.avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--accent-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

/* === Chat Area === */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--chat-bg);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border-secondary);
  background: var(--bg-primary);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--space-8);
  scroll-behavior: auto;
  background: var(--chat-bg);
}

/* Chat messages scrollbar - always visible */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

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

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

/* Firefox scrollbar */
.chat-messages {
  scrollbar-width: thin;
  scrollbar-color: var(--border-primary) transparent;
}

/* === Messages === */
.msg-row {
  display: flex;
  margin-bottom: var(--space-6);
  animation: msgIn var(--duration-normal) var(--ease-out);
}

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

.msg-row.user {
  justify-content: flex-end;
}

.msg-row.assistant {
  align-items: flex-start;
  gap: var(--space-3);
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: 600;
  margin-top: 2px;
  background: var(--accent);
  color: var(--bg-primary);
}

.msg-avatar-model {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
  margin-top: 2px;
  overflow: hidden;
}

.msg-avatar-model img {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
  object-fit: cover;
}

.msg-error-bubble {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  font-size: var(--fs-sm);
  line-height: 1.5;
  word-break: break-word;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  max-width: 70%;
}

[data-theme="dark"] .msg-error-bubble {
  background: #3b1111;
  color: #fca5a5;
  border-color: #7f1d1d;
}

.msg-bubble {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-xl);
  max-width: 70%;
  font-size: var(--fs-base);
  line-height: 1.6;
  word-break: break-word;
  overflow-wrap: break-word;
}

.msg-bubble.user {
  background: var(--bubble-user-bg);
  color: var(--text-primary);
}

.msg-body {
  flex: 1;
  min-width: 0;
}

/* === Thinking Chain === */
/* Based on: review-animations STANDARDS.md, animation-vocabulary, apple-design */

/* Collapsed state - shows "已深度思考" with line */
.think-collapsed {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) 0;
  cursor: pointer;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-3);
  user-select: none;
  /* GPU-friendly: only transform and opacity */
  transition: opacity 150ms ease-out;
  /* For entry animation */
  opacity: 1;
}

.think-collapsed:hover {
  opacity: 0.8;
}

.think-collapsed .think-bar {
  width: 2px;
  height: 18px;
  background: var(--think-bar);
  border-radius: 1px;
  flex-shrink: 0;
  /* Scale in animation for line growth */
  transform-origin: top;
  transform: scaleY(1);
  transition: background 150ms ease-out;
}

.think-collapsed:hover .think-bar {
  background: var(--text-tertiary);
}

.think-collapsed svg {
  flex-shrink: 0;
  opacity: 0.4;
  transition: transform 150ms ease-out;
}

.think-collapsed:hover svg {
  opacity: 0.8;
}

/* Entry animation for collapsed state */
.think-collapsed.entering {
  opacity: 0;
  animation: thinkCollapsedEnter 200ms ease-out forwards;
}

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

/* Expanded state - shows full reasoning content */
.think-expanded {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  min-width: 0;
  /* Accordion/Collapse animation: scaleY + opacity */
  transform-origin: top;
  transform: scaleY(1);
  opacity: 1;
  transition: transform 200ms cubic-bezier(0.23, 1, 0.32, 1), 
              opacity 200ms cubic-bezier(0.23, 1, 0.32, 1);
}

.think-expanded > div:last-child {
  min-width: 0;
  flex: 1;
}

.think-expanded .think-bar {
  width: 2px;
  background: var(--think-bar-open);
  border-radius: 1px;
  flex-shrink: 0;
  /* Line grows from top */
  transform-origin: top;
  transform: scaleY(1);
  transition: transform 200ms cubic-bezier(0.23, 1, 0.32, 1);
}

.think-expanded .think-content {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  line-height: 1.7;
  padding: var(--space-1) 0;
  overflow-x: auto;
  /* Content fades in */
  opacity: 1;
  transition: opacity 150ms ease-out;
}

.think-expanded .think-content ul,
.think-expanded .think-content ol {
  padding-left: var(--space-5);
  list-style-position: outside;
  margin: var(--space-1) 0;
}

.think-expanded .think-content li {
  margin: var(--space-1) 0;
  line-height: 1.6;
}

.think-expanded .think-content p {
  margin: var(--space-2) 0;
  line-height: 1.7;
}

.think-expanded .think-content pre {
  font-size: 11px;
  padding: var(--space-3);
  margin: var(--space-2) 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.think-expanded .think-content code {
  font-size: 0.92em;
  font-family: var(--font-mono);
}

.think-expanded .think-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-2);
  cursor: pointer;
  user-select: none;
  transition: opacity 150ms ease-out;
}

.think-expanded .think-header:hover {
  opacity: 0.7;
}

.think-expanded .think-header svg {
  transition: transform 150ms ease-out;
  transform: rotate(0deg);
}

.think-expanded .think-header:hover svg {
  transform: rotate(180deg);
}

/* Entry animation for expanded state */
.think-expanded.entering {
  transform: scaleY(0);
  opacity: 0;
  animation: thinkExpandEnter 200ms cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

@keyframes thinkExpandEnter {
  from {
    transform: scaleY(0);
    opacity: 0;
  }
  to {
    transform: scaleY(1);
    opacity: 1;
  }
}

/* Exit animation for expanded state */
.think-expanded.exiting {
  animation: thinkExpandExit 200ms cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

@keyframes thinkExpandExit {
  from {
    transform: scaleY(1);
    opacity: 1;
  }
  to {
    transform: scaleY(0);
    opacity: 0;
  }
}

/* Streaming state - actively receiving content */
.think-streaming {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  min-width: 0;
  /* Entry animation */
  opacity: 0;
  animation: thinkStreamEnter 150ms ease-out forwards;
}

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

.think-streaming > div:last-child {
  min-width: 0;
  flex: 1;
}

.think-streaming .think-bar {
  width: 2px;
  background: var(--think-bar-open);
  border-radius: 1px;
  flex-shrink: 0;
  /* Pulse animation - opacity only (GPU-friendly) */
  animation: pulseBarOpacity 1.5s ease-in-out infinite;
}

@keyframes pulseBarOpacity {
  0%, 100% {
    opacity: 0.4;
  }
  50% {
    opacity: 1;
  }
}

.think-streaming .think-content {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  line-height: 1.7;
  padding: var(--space-1) 0;
  overflow-x: auto;
}

.think-streaming .think-content ul,
.think-streaming .think-content ol {
  padding-left: var(--space-5);
  list-style-position: outside;
  margin: var(--space-1) 0;
}

.think-streaming .think-content li {
  margin: var(--space-1) 0;
  line-height: 1.6;
}

.think-streaming .think-content p {
  margin: var(--space-2) 0;
  line-height: 1.7;
}

/* Thinking dots animation - GPU-friendly (opacity only) */
.think-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: 4px;
  vertical-align: middle;
  align-items: center;
}

.think-dots span {
  width: 5px;
  height: 5px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: dotPulse 1.2s infinite;
  display: inline-block;
}

.think-dots span:nth-child(1) {
  animation-delay: 0s;
}

.think-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.think-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes dotPulse {
  0%, 60%, 100% {
    opacity: 0.4;
  }
  30% {
    opacity: 1;
  }
}

/* No special closing animation needed - direct transition */

.msg-content {
  font-size: var(--fs-base);
  line-height: 1.6;
  color: var(--text-primary);
}

/* === Markdown === */
.msg-content h1,
.msg-content h2,
.msg-content h3,
.msg-content h4 {
  font-weight: 600;
  margin: var(--space-4) 0 var(--space-2);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.msg-content h1 {
  font-size: clamp(1.3em, 1.5vw + 0.6em, 1.8em);
  letter-spacing: -0.02em;
}

.msg-content h2 {
  font-size: clamp(1.15em, 1.2vw + 0.5em, 1.5em);
}

.msg-content h3 {
  font-size: clamp(1.05em, 0.8vw + 0.4em, 1.25em);
}

.msg-content h4 {
  font-size: 1em;
}

.msg-content p {
  margin: var(--space-2) 0;
}

.msg-content ul,
.msg-content ol {
  padding-left: clamp(18px, 1.5vw, 26px);
  margin: var(--space-2) 0;
}

.msg-content li {
  margin: var(--space-1) 0;
}

.msg-content blockquote {
  border-left: 3px solid var(--border-primary);
  padding: var(--space-2) var(--space-4);
  margin: var(--space-3) 0;
  color: var(--text-tertiary);
  background: var(--bg-secondary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.msg-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--duration-fast) var(--ease-default);
}

.msg-content a:hover {
  color: var(--accent-hover);
}

.msg-content table {
  border-collapse: collapse;
  width: 100%;
  margin: var(--space-3) 0;
  font-size: var(--fs-sm);
}

.msg-content th,
.msg-content td {
  border: 1px solid var(--border-primary);
  padding: var(--space-2) var(--space-3);
  text-align: left;
}

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

.msg-content hr {
  border: none;
  border-top: 1px solid var(--border-primary);
  margin: var(--space-4) 0;
}

.msg-content img {
  max-width: 100%;
  border-radius: var(--radius-md);
}

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

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

.msg-content del {
  opacity: 0.6;
}

/* Code blocks */
.msg-content pre {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  margin: var(--space-3) 0;
  font-size: clamp(12px, 0.8vw + 8px, 14px);
  line-height: 1.6;
}

.msg-content pre code {
  font-family: var(--font-mono);
  font-size: inherit;
  white-space: pre;
  display: block;
  overflow-x: auto;
}

.code-toolbar {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: flex;
  gap: var(--space-1);
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-default);
  z-index: 2;
}

.msg-content pre:hover .code-toolbar {
  opacity: 1;
}

.code-btn {
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: var(--fs-xs);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--duration-fast) var(--ease-default);
}

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

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

.code-btn.run-html {
  color: var(--accent);
  border-color: var(--accent);
}

.msg-content code:not(pre code) {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
  font-family: var(--font-mono);
}

.html-preview-wrap {
  margin: var(--space-3) 0;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  width: 100%;
  padding-top: 56.25%;
}

.html-preview-wrap iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* === Chat Input === */
.chat-input-bar {
  padding: var(--space-3) var(--space-6) var(--space-5);
  border-top: 1px solid var(--border-secondary);
  background: var(--bg-primary);
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  background: var(--bg-primary);
  transition: all var(--duration-fast) var(--ease-default);
}

.chat-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 29, 31, 0.1);
}

[data-theme="dark"] .chat-input-wrap:focus-within {
  box-shadow: 0 0 0 3px rgba(245, 245, 247, 0.1);
}

.chat-input-wrap textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: var(--fs-base);
  resize: none;
  line-height: 1.5;
  max-height: 180px;
  padding: var(--space-1) 0;
  field-sizing: content;
}

.chat-input-wrap textarea::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--accent);
  color: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--duration-fast) var(--ease-default);
}

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

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

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

/* === Model Selector === */
.model-select-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  max-width: 200px;
  overflow: hidden;
}

.model-select-btn span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-select-btn:hover {
  background: var(--bg-hover);
}

.model-select-btn:active {
  transform: scale(0.97);
}

.model-select-btn img {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

.model-dropdown {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  min-width: 220px;
  max-width: 340px;
  z-index: 1000;
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
}
  animation: dropdownIn var(--duration-fast) var(--ease-out);
}

@keyframes dropdownIn {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.model-dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  font-size: var(--fs-sm);
  transition: all var(--duration-fast) var(--ease-default);
  color: var(--text-secondary);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.model-dropdown-item:hover {
  background: var(--bg-hover);
}

.model-dropdown-item:active {
  background: var(--bg-active);
}

.model-dropdown-item.selected {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.model-dropdown-item img {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.model-logo-placeholder {
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

/* === Admin Panel === */
.admin-layout {
  max-width: 880px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
}

.admin-layout h2 {
  font-size: var(--fs-xl);
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.admin-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  transition: box-shadow var(--duration-fast) var(--ease-default);
}

.admin-section:focus-within {
  box-shadow: var(--shadow-md);
}

.admin-section h3 {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin-bottom: var(--space-4);
  color: var(--text-secondary);
}

.admin-row {
  display: flex;
  gap: var(--space-4);
  align-items: flex-end;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.admin-row .form-group {
  flex: 1;
  min-width: 180px;
  margin-bottom: 0;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.admin-table thead th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  color: var(--text-tertiary);
  font-weight: 500;
  font-size: var(--fs-xs);
  border-bottom: 1px solid var(--border-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.admin-table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-secondary);
  vertical-align: middle;
  white-space: nowrap;
}

.toggle-switch {
  width: 42px;
  height: 24px;
  border-radius: 12px;
  display: inline-block;
  position: relative;
  cursor: pointer;
  transition: background var(--duration-normal) var(--ease-default);
  vertical-align: middle;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.toggle-switch.on {
  background: var(--success);
}

.toggle-switch.off {
  background: var(--text-muted);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  transition: transform var(--duration-normal) var(--ease-spring);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch.on::after {
  transform: translateX(18px);
}

.toggle-switch.off::after {
  transform: translateX(2px);
}

.toggle-switch:active::after {
  width: 24px;
}

.model-logo-cell {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.model-logo-upload {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--bg-primary);
  transition: all var(--duration-fast) var(--ease-default);
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}

.model-logo-upload:hover {
  border-color: var(--text-tertiary);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.model-logo-upload img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

.model-logo-upload .upload-icon {
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-default);
  position: relative;
  z-index: 1;
}

.model-logo-upload:hover .upload-icon {
  opacity: 0.6;
}

.admin-logo-placeholder {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

/* === Empty State === */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: var(--space-12);
}

.empty-state svg {
  opacity: 0.15;
  margin-bottom: var(--space-5);
}

.empty-state h3 {
  font-size: var(--fs-lg);
  font-weight: 500;
  color: var(--text-tertiary);
  margin-bottom: var(--space-2);
}

.empty-state p {
  font-size: var(--fs-sm);
  max-width: 360px;
}

/* === Toast === */
.toast-container {
  position: fixed;
  top: var(--space-5);
  right: var(--space-5);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-lg);
  animation: toastSlide var(--duration-normal) var(--ease-out);
  max-width: 400px;
  word-break: break-word;
  pointer-events: auto;
}

.toast.success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.toast.error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

[data-theme="dark"] .toast.success {
  background: #052e16;
  color: #86efac;
  border-color: #166534;
}

[data-theme="dark"] .toast.error {
  background: #450a0a;
  color: #fca5a5;
  border-color: #991b1b;
}

@keyframes toastSlide {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Waiting indicator */
@keyframes waitBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* === Scroll anchors === */
.scroll-anchors {
  position: fixed;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2);
  pointer-events: auto;
}

.anchor-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--border-primary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  position: relative;
  flex-shrink: 0;
}

.anchor-dot:hover,
.anchor-dot.active {
  background: var(--text-secondary);
  transform: scale(1.35);
}

.anchor-dot.active {
  background: var(--accent);
}

.anchor-card {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--space-4);
  min-width: 240px;
  max-width: 320px;
  font-size: var(--fs-xs);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 280px;
  overflow-y: auto;
  z-index: 51;
  opacity: 0;
  pointer-events: none;
  transition: all var(--duration-fast) var(--ease-out);
  color: var(--text-secondary);
  line-height: 1.5;
}

.anchor-card.show {
  opacity: 1;
  pointer-events: auto;
}

.anchor-card .ac-msg {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-secondary);
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-default);
  line-height: 1.5;
}

.anchor-card .ac-msg:last-child {
  border-bottom: none;
}

.anchor-card .ac-msg:hover,
.anchor-card .ac-msg.current {
  color: var(--text-primary);
}

.anchor-card .ac-msg.other {
  color: var(--text-muted);
}

.anchor-card .ac-msg:hover {
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
}

/* === Smooth transitions & animations === */

/* === Mobile === */
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  transition: all var(--duration-fast) var(--ease-default);
}

.mobile-menu-btn:hover {
  background: var(--bg-hover);
}

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

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 98;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn var(--duration-fast) var(--ease-out);
}

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

.sidebar-overlay.show {
  display: block;
}

/* Dark mode adjustments */
[data-theme="dark"] .msg-content pre {
  background: #1c1c1e;
  border-color: #38383a;
}

[data-theme="dark"] .msg-content pre code {
  color: #e5e5ea;
}

[data-theme="dark"] .msg-content blockquote {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .auth-card {
  box-shadow: var(--shadow-xl);
}

[data-theme="dark"] .admin-section {
  background: var(--bg-tertiary);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  /* Thinking chain - use opacity only, no transforms */
  .think-collapsed,
  .think-expanded,
  .think-streaming {
    transform: none !important;
    animation: none !important;
    transition: opacity 100ms ease !important;
  }
  
  .think-expanded.entering,
  .think-expanded.exiting {
    transform: none !important;
    animation: none !important;
  }
  
  .think-collapsed.entering {
    animation: none !important;
    opacity: 1 !important;
  }
}

/* Hover & Pointer gating */
@media (hover: hover) and (pointer: fine) {
  .conv-item:hover {
    background: var(--bg-hover);
  }
  
  .btn:hover {
    background: var(--bg-hover);
  }
  
  .btn-icon:hover {
    background: var(--bg-hover);
  }
}

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Tablet & below (< 768px) */
@media (max-width: 767px) {
  :root {
    --fs-base: clamp(15px, 2.5vw + 10px, 16px);
    --sidebar-w: 280px;
  }
  
  .mobile-menu-btn {
    display: flex;
  }
  
  .sidebar {
    position: fixed;
    left: calc(var(--sidebar-w) * -1);
    top: 0;
    bottom: 0;
    z-index: 99;
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    box-shadow: none;
  }
  
  .sidebar.mobile-open {
    transform: translateX(var(--sidebar-w));
    box-shadow: var(--shadow-xl);
  }
  
  .chat-messages {
    padding: var(--space-4) var(--space-4);
  }
  
  .msg-bubble {
    max-width: 88%;
  }
  
  .msg-content pre {
    font-size: clamp(11px, 2vw + 6px, 13px);
  }
  
  .chat-input-bar {
    padding: var(--space-2) var(--space-3) var(--space-4);
  }
  
  .scroll-anchors {
    right: 2px;
  }
  
  .anchor-dot {
    width: 6px;
    height: 6px;
  }
  
  .admin-row {
    flex-direction: column;
  }
  
  .admin-table thead {
    display: none;
  }
  
  .admin-table tbody,
  .admin-table tr {
    display: block;
  }
  
  .admin-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-2);
    white-space: normal;
    flex-wrap: wrap;
    gap: var(--space-1);
  }
  
  .admin-table td::before {
    content: attr(data-label);
    font-size: var(--fs-xs);
    color: var(--text-muted);
    margin-right: var(--space-3);
    flex-shrink: 0;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
  
  .admin-layout {
    padding: var(--space-4) var(--space-3);
  }
  
  .admin-section {
    padding: var(--space-4);
  }
  
  .auth-card {
    padding: var(--space-6);
  }
}

/* Small phone (< 400px) */
@media (max-width: 399px) {
  :root {
    --fs-base: 15px;
    --sidebar-w: 260px;
  }
  
  .chat-messages {
    padding: var(--space-3) var(--space-2);
  }
  
  .msg-bubble {
    max-width: 92%;
    font-size: 15px;
  }
  
  .chat-input-bar {
    padding: var(--space-2) var(--space-2) var(--space-3);
  }
  
  .scroll-anchors {
    display: none !important;
  }
  
  .anchor-card {
    min-width: 180px;
    max-width: 220px;
  }
}

/* Desktop large (> 1200px) */
@media (min-width: 1200px) {
  :root {
    --fs-base: 16px;
    --sidebar-w: 300px;
  }
  
  .chat-messages {
    padding: var(--space-8) clamp(36px, 5vw, 60px);
  }
  
  .msg-bubble {
    max-width: 60%;
  }
  
  .chat-input-bar {
    padding: var(--space-4) clamp(30px, 4vw, 56px) var(--space-6);
  }
}

/* Medium desktop (768-1199px) */
@media (min-width: 768px) and (max-width: 1199px) {
  .msg-bubble {
    max-width: 70%;
  }
}
