/* === Micro Chat - Material Minimal Design System === */

:root {
  /* Primary palette */
  --primary: #6C5CE7;
  --primary-light: #A29BFE;
  --primary-dark: #4834D4;
  --primary-surface: rgba(108, 92, 231, 0.08);

  /* Surface & Background */
  --bg: #0F0F14;
  --bg-secondary: #16161D;
  --surface: #1C1C26;
  --surface-hover: #24242F;
  --surface-active: #2A2A38;
  --surface-elevated: #22222E;

  /* Text */
  --text-primary: #F0F0F5;
  --text-secondary: #9494A8;
  --text-tertiary: #5E5E72;
  --text-inverse: #0F0F14;

  /* Status */
  --online: #00D68F;
  --away: #FFB057;
  --offline: #5E5E72;
  --error: #FF6B6B;
  --success: #00D68F;

  /* AI */
  --ai-gradient: linear-gradient(135deg, #6C5CE7 0%, #A29BFE 50%, #74B9FF 100%);
  --ai-surface: rgba(108, 92, 231, 0.12);
  --ai-border: rgba(108, 92, 231, 0.3);

  /* Borders & Shadows */
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

  /* Layout */
  --sidebar-width: 260px;
  --members-width: 240px;
  --header-height: 56px;
  --input-height: 72px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

a { color: var(--primary-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* === Auth Screen === */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}

.auth-card {
  width: 400px;
  padding: 48px 40px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo h1 {
  font-size: 24px;
  font-weight: 700;
  background: var(--ai-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

.auth-logo p {
  color: var(--text-secondary);
  font-size: 13px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 3px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 7px;
  transition: all 0.2s;
}

.auth-tab.active {
  background: var(--primary);
  color: white;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  transition: border-color 0.2s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--primary);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
}

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: white;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
}

.btn-ghost:hover { background: var(--surface-hover); color: var(--text-primary); }

.btn-sm { padding: 6px 12px; font-size: 12px; }

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

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

.auth-error {
  padding: 10px 14px;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

/* === Main Layout === */
.app {
  display: none;
  height: 100vh;
  overflow: hidden;
}

.app.active { display: flex; }
.auth-container.hidden { display: none; }

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

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

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 700;
  background: var(--ai-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* 侧栏主导航：分段控件式「首页 / 助手」 */
.sidebar-nav {
  padding: 0 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-nav-track {
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.sidebar-nav-pill {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 10px;
  border: none;
  border-radius: 11px;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  font-family: var(--font);
  transition: color 0.18s, background 0.18s, box-shadow 0.18s, transform 0.12s;
}

.sidebar-nav-pill:hover {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
}

.sidebar-nav-pill:active {
  transform: scale(0.98);
}

.sidebar-nav-pill-ic {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.75;
  transition: opacity 0.18s, color 0.18s;
}

.sidebar-nav-pill-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.sidebar-nav-pill.active {
  color: var(--text-primary);
  background: linear-gradient(160deg, rgba(108, 92, 231, 0.22) 0%, var(--surface-hover) 55%, var(--surface-elevated) 100%);
  box-shadow:
    0 0 0 1px rgba(162, 155, 254, 0.35),
    0 4px 14px rgba(0, 0, 0, 0.35);
}

.sidebar-nav-pill.active .sidebar-nav-pill-ic {
  opacity: 1;
  color: var(--primary-light);
}

.sidebar-nav-pill.active .sidebar-nav-pill-label {
  background: var(--ai-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-section {
  margin-bottom: 20px;
}

.sidebar-section-grow {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
}

.sidebar-userlist {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  margin-bottom: 4px;
}

.sidebar-section-header span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-secondary);
  font-size: 14px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font);
}

.sidebar-item:hover { background: var(--surface-hover); color: var(--text-primary); }
.sidebar-item.active { background: var(--primary-surface); color: var(--primary-light); }

.sidebar-item .hash {
  font-size: 16px;
  font-weight: 700;
  opacity: 0.5;
  width: 20px;
  text-align: center;
}

.sidebar-item .room-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-item .badge {
  font-size: 11px;
  padding: 1px 6px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-full);
  font-weight: 600;
}

.sidebar-user {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.sidebar-user-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-user-tokens {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.45;
  padding-left: 4px;
  font-family: var(--font-mono);
}

.sidebar-user-tokens .token-line {
  margin-top: 2px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
  position: relative;
}

.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 48px; height: 48px; font-size: 18px; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
  position: absolute;
  bottom: -1px;
  right: -1px;
}

.status-dot.online { background: var(--online); }
.status-dot.away { background: var(--away); }
.status-dot.offline { background: var(--offline); }

.sidebar-user-info {
  flex: 1;
  overflow: hidden;
}

.sidebar-user-info .name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-info .status-text {
  font-size: 11px;
  color: var(--text-tertiary);
}

/* Main Chat Area */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

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

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-info h3 {
  font-size: 16px;
  font-weight: 700;
}

.chat-header-info .description {
  font-size: 12px;
  color: var(--text-tertiary);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.message {
  display: flex;
  gap: 12px;
  padding: 6px 0;
  position: relative;
}

.message:hover { background: var(--surface-hover); margin: 0 -20px; padding: 6px 20px; border-radius: var(--radius-sm); }

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

.message-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.message-author {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
}

.message-time {
  font-size: 11px;
  color: var(--text-tertiary);
}

.message-content {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  word-wrap: break-word;
}

.message-content p { margin-bottom: 4px; }
.message-content p:last-child { margin-bottom: 0; }

.message-content code {
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.message-content pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 8px 0;
  overflow-x: auto;
}

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

.message-reactions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.reaction-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.reaction-badge:hover {
  border-color: var(--primary);
  background: var(--primary-surface);
}

/* AI Message styling */
.message.ai-message {
  border-left: 2px solid var(--primary);
  padding-left: 12px;
  margin-left: 0;
}

.message.ai-message .message-author {
  background: var(--ai-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.message.ai-message .ai-badge {
  font-size: 10px;
  padding: 1px 6px;
  background: var(--ai-surface);
  border: 1px solid var(--ai-border);
  border-radius: var(--radius-full);
  color: var(--primary-light);
  font-weight: 600;
}

/* Typing indicator */
.typing-indicator {
  padding: 4px 20px;
  font-size: 12px;
  color: var(--text-tertiary);
  min-height: 24px;
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: 4px;
}

.typing-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typingDot 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 100% { opacity: 0.3; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-3px); }
}

/* Message Input */
.message-input-container {
  padding: 12px 20px 20px;
  flex-shrink: 0;
}

.message-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  transition: border-color 0.2s;
}

.message-input-wrapper:focus-within {
  border-color: var(--primary);
}

.message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 24px;
  line-height: 1.5;
}

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

.input-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.model-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--ai-surface);
  border: 1px solid var(--ai-border);
  border-radius: var(--radius-full);
  font-size: 11px;
  color: var(--primary-light);
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-family: var(--font);
  font-weight: 600;
}

.model-selector:hover { background: rgba(108, 92, 231, 0.2); }

.model-selector .model-icon {
  font-size: 14px;
}

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

.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled { opacity: 0.3; cursor: default; }

/* Members Panel */
.members-panel {
  width: var(--members-width);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: none;
  flex-direction: column;
  flex-shrink: 0;
}

.members-panel.active { display: flex; }

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

.members-header h4 { font-size: 14px; font-weight: 700; }

.members-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.members-group-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
  padding: 8px 8px 4px;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.member-item:hover { background: var(--surface-hover); }

.member-item .name {
  font-size: 13px;
  color: var(--text-secondary);
}

.member-item.online .name { color: var(--text-primary); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal-overlay.active { display: flex; }

.modal {
  width: 440px;
  max-height: 80vh;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

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

.modal-header h3 { font-size: 16px; font-weight: 700; }

.modal-body { padding: 24px; overflow-y: auto; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Model dropdown */
.model-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 260px;
  z-index: 50;
  display: none;
}

.model-dropdown.active { display: block; }

.model-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font);
  color: var(--text-primary);
}

.model-option:hover { background: var(--surface-hover); }
.model-option.selected { background: var(--primary-surface); }

.model-option-info h5 { font-size: 13px; font-weight: 600; }
.model-option-info p { font-size: 11px; color: var(--text-tertiary); }

.model-option .check {
  margin-left: auto;
  color: var(--primary);
  font-size: 16px;
  display: none;
}

.model-option.selected .check { display: block; }

/* Browse rooms panel */
.browse-rooms {
  flex: 1;
  display: none;
  flex-direction: column;
}

.browse-rooms.active { display: flex; }

.browse-header {
  padding: 24px 24px 16px;
}

.browse-header h2 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 4px;
}

.browse-header p {
  color: var(--text-secondary);
  font-size: 13px;
}

.browse-search {
  margin: 0 24px 16px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  width: calc(100% - 48px);
}

.browse-search:focus { border-color: var(--primary); }

.browse-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px;
}

.browse-room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.browse-room-item:hover { border-color: var(--primary); background: var(--surface-hover); }

.browse-room-info h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.browse-room-info p {
  font-size: 12px;
  color: var(--text-tertiary);
}

.browse-room-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: right;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  animation: slideIn 0.3s ease;
  max-width: 360px;
}

.toast.error { border-color: var(--error); color: var(--error); }
.toast.success { border-color: var(--success); color: var(--success); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Welcome screen */
.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  color: var(--text-tertiary);
}

.welcome-screen .welcome-icon {
  font-size: 64px;
  opacity: 0.3;
}

.welcome-screen h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-secondary);
}

.welcome-screen p {
  font-size: 14px;
  max-width: 400px;
  text-align: center;
  line-height: 1.6;
}

/* System message */
.system-message {
  text-align: center;
  padding: 8px 0;
  color: var(--text-tertiary);
  font-size: 12px;
}

/* Date separator */
.date-separator {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0 8px;
}

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

.date-separator span {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Loading spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* Context menu / command palette hint */
.command-hint {
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-tertiary);
}

.command-hint kbd {
  padding: 1px 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* Admin Panel */
.admin-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.admin-header {
  padding: 24px 24px 0;
  border-bottom: 1px solid var(--border);
}

.admin-header h2 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 16px;
}

.admin-tabs {
  display: flex;
  gap: 0;
}

.admin-tab {
  padding: 10px 16px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  font-family: var(--font);
}

.admin-tab:hover { color: var(--text-primary); }
.admin-tab.active { color: var(--primary-light); border-bottom-color: var(--primary); }

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border);
}

.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.admin-table tr:hover td { background: var(--surface-hover); }

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}

.role-badge.admin { background: var(--ai-surface); color: var(--primary-light); }
.role-badge.member { background: var(--surface); color: var(--text-secondary); }

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}

.status-badge.online { background: rgba(0, 214, 143, 0.15); color: var(--online); }
.status-badge.offline { background: var(--surface); color: var(--text-tertiary); }

.export-card {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.export-card h4 { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.export-card p { font-size: 12px; color: var(--text-tertiary); }

.export-section h3 { font-size: 16px; font-weight: 700; }

/* —— 统计助手页（DeepSeek + tools）—— */
.chatbox-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 24px 28px 28px;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(108, 92, 231, 0.22), transparent 55%),
    var(--bg);
}

.chatbox-page-inner {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 0;
  flex: 1;
}

.chatbox-hero {
  position: relative;
  flex-shrink: 0;
  padding: 20px 22px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: linear-gradient(135deg, var(--surface-elevated) 0%, var(--surface) 100%);
  overflow: hidden;
}

.chatbox-hero-glow {
  position: absolute;
  inset: -40% -20% auto;
  height: 120px;
  background: var(--ai-gradient);
  opacity: 0.12;
  filter: blur(40px);
  pointer-events: none;
}

.chatbox-hero-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.chatbox-hero-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ai-surface);
  border: 1px solid var(--ai-border);
  color: var(--primary-light);
  flex-shrink: 0;
}

.chatbox-hero-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.chatbox-hero-sub {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
  max-width: 52ch;
}

.chatbox-hero-chips {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.chip {
  font-size: 11px;
  font-weight: 600;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--primary-light);
}

.chip.chip-muted {
  color: var(--text-tertiary);
  border-style: dashed;
}

/* 助手页：业务表可分析维度（展示在对话记录上方） */
.chatbox-dimensions {
  flex-shrink: 0;
  max-height: min(42vh, 520px);
  overflow-y: auto;
  padding: 14px 16px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(28, 28, 38, 0.92), var(--surface));
  box-shadow: var(--shadow-sm);
}

.chatbox-dimensions-head {
  margin-bottom: 12px;
}

.chatbox-dimensions-title {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-primary);
}

.chatbox-dimensions-note {
  margin: 0;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-tertiary);
}

.chatbox-dimensions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
  gap: 10px;
}

.chatbox-dim-card {
  padding: 12px 12px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
}

.chatbox-dim-card-title {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary-light);
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.chatbox-dim-card-desc {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.chatbox-dim-list {
  margin: 0;
  padding-left: 16px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-secondary);
}

.chatbox-dim-list li {
  margin-bottom: 4px;
}

.chatbox-dim-list strong {
  color: var(--text-primary);
  font-weight: 600;
}

.chatbox-page-log {
  flex: 1;
  min-height: 220px;
  max-height: none;
  overflow-y: auto;
  padding: 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background:
    radial-gradient(ellipse 120% 90% at 20% 10%, rgba(108, 92, 231, 0.12), transparent 55%),
    radial-gradient(ellipse 120% 90% at 80% 0%, rgba(116, 185, 255, 0.08), transparent 55%),
    linear-gradient(180deg, rgba(255,255,255,0.03), transparent 40%),
    var(--surface);
  scroll-behavior: smooth;
}

.chatbox-empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.chatbox-empty-icon {
  font-size: 28px;
  opacity: 0.35;
  margin-bottom: 12px;
}

.chatbox-empty-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.chatbox-empty-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
}

.chat-bubble {
  margin-bottom: 16px;
  max-width: 78%;
}

.chat-bubble-user { margin-left: auto; }

.chat-bubble-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.chat-bubble-user .chat-bubble-label { text-align: right; }

.chat-bubble-body {
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 12px 14px;
  border-radius: 14px;
}

.chat-bubble-user .chat-bubble-body {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: var(--text-inverse);
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-md);
}

.chat-bubble-assistant .chat-bubble-body {
  background: linear-gradient(180deg, var(--surface-elevated), var(--surface-hover));
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

/* 助手气泡：Markdown 渲染（marked + DOMPurify） */
.chat-bubble-assistant .chat-bubble-body.chat-bubble-md {
  white-space: normal;
  overflow-x: auto;
}

.chat-bubble-md p {
  margin: 0 0 0.65em;
}

.chat-bubble-md p:last-child {
  margin-bottom: 0;
}

.chat-bubble-md h1,
.chat-bubble-md h2,
.chat-bubble-md h3,
.chat-bubble-md h4 {
  margin: 0.85em 0 0.45em;
  line-height: 1.25;
  font-weight: 700;
  color: var(--text-primary);
}

.chat-bubble-md h1:first-child,
.chat-bubble-md h2:first-child,
.chat-bubble-md h3:first-child {
  margin-top: 0;
}

.chat-bubble-md h1 { font-size: 1.25rem; }
.chat-bubble-md h2 { font-size: 1.12rem; }
.chat-bubble-md h3 { font-size: 1.04rem; }

.chat-bubble-md ul,
.chat-bubble-md ol {
  margin: 0.4em 0 0.65em;
  padding-left: 1.35em;
}

.chat-bubble-md li {
  margin-bottom: 0.25em;
}

.chat-bubble-md code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.88em;
  padding: 0.12em 0.4em;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
}

.chat-bubble-md pre {
  margin: 0.65em 0;
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-strong);
}

.chat-bubble-md pre code {
  padding: 0;
  border: none;
  background: transparent;
  font-size: 0.82rem;
  line-height: 1.5;
}

.chat-bubble-md blockquote {
  margin: 0.5em 0;
  padding: 0.35em 0 0.35em 12px;
  border-left: 3px solid rgba(162, 155, 254, 0.55);
  color: var(--text-secondary);
}

.chat-bubble-md a {
  color: var(--primary-light);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-bubble-md a:hover {
  color: #a29bfe;
}

.chat-bubble-md hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.85em 0;
}

.chat-bubble-md table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.65em 0;
  font-size: 0.92em;
}

.chat-bubble-md th,
.chat-bubble-md td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.chat-bubble-md th {
  background: rgba(108, 92, 231, 0.12);
  font-weight: 600;
}

.chatbox-composer {
  flex-shrink: 0;
}

.chatbox-composer-card {
  position: relative;
  border-radius: 16px;
  padding: 14px 16px 12px;
  background: linear-gradient(165deg, var(--surface-elevated) 0%, var(--surface) 100%);
  border: 1px solid var(--border-strong);
  box-shadow:
    0 0 0 1px rgba(108, 92, 231, 0.08),
    0 12px 40px rgba(0, 0, 0, 0.35);
}

.chatbox-composer-card::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 17px;
  background: linear-gradient(135deg, rgba(162, 155, 254, 0.30), rgba(116, 185, 255, 0.12), rgba(255,255,255,0.03));
  opacity: 0.5;
  pointer-events: none;
  filter: blur(10px);
}

.chatbox-input-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}

.chatbox-input-shell {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: stretch;
  gap: 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chatbox-input-shell:focus-within {
  border-color: rgba(162, 155, 254, 0.55);
  box-shadow: 0 0 0 3px var(--primary-surface);
}

.chatbox-input-leading {
  display: flex;
  align-items: flex-start;
  padding: 14px 0 14px 14px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.chatbox-input-shell:focus-within .chatbox-input-leading {
  color: var(--primary-light);
}

.chatbox-input-ico {
  display: block;
}

.chatbox-input-field {
  flex: 1;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  min-height: 56px;
  max-height: 200px;
  resize: vertical;
  padding: 14px 16px 14px 10px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

.chatbox-input-field::placeholder {
  color: var(--text-tertiary);
  opacity: 0.9;
}

.chatbox-input-field:focus {
  outline: none;
}

.chatbox-composer-bar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.chatbox-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.5;
}

.chatbox-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  margin: 0 1px;
  border-radius: 4px;
  font-size: 10px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.chatbox-composer-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.chatbox-toolbar-btn {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.chatbox-toolbar-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.chatbox-send-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px 9px 20px;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #5b4cdb 0%, var(--primary) 45%, #74b9ff 130%);
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.45);
  transition: transform 0.12s, box-shadow 0.2s, filter 0.2s;
}

.chatbox-send-btn:hover {
  filter: brightness(1.06);
  box-shadow: 0 6px 22px rgba(108, 92, 231, 0.5);
}

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

.chatbox-send-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  filter: grayscale(0.15);
  box-shadow: none;
}

.chatbox-input-field:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.chatbox-send-btn svg {
  flex-shrink: 0;
  opacity: 0.95;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}
