/* ========== 特斯拉 · 模电助教 — Tesla 主题样式 ========== */

:root {
  --bg-primary: #0a0e27;
  --bg-secondary: #111638;
  --bg-tertiary: #1a1f4e;
  --accent-blue: #00d4ff;
  --accent-purple: #7b2ff7;
  --accent-gold: #ffd700;
  --text-primary: #e0e6ff;
  --text-secondary: #8892b0;
  --text-dim: #5a6380;
  --bubble-user: #1e2a5a;
  --bubble-ai: #0d1a3a;
  --border: #2a3066;
  --danger: #ff4757;
  --radius: 12px;
  --max-width: 800px;
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
}

/* ====== App Layout ====== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: var(--max-width);
  margin: 0 auto;
  position: relative;
}

/* ====== Header ====== */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

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

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
  flex-shrink: 0;
}

.header-text h1 {
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.3;
}

.subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

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

.icon-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.icon-btn:hover {
  background: var(--border);
  color: var(--accent-blue);
}

/* ====== Messages Area ====== */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ====== Message Bubbles ====== */
.message {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  animation: fadeIn 0.3s ease;
}

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

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

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  margin-top: 4px;
}

.message.assistant .msg-avatar {
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.2);
}

.message.user .msg-avatar {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
}

.msg-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.7;
  font-size: 0.93rem;
  word-break: break-word;
}

.message.assistant .msg-bubble {
  background: var(--bubble-ai);
  border: 1px solid rgba(0, 212, 255, 0.15);
  border-top-left-radius: 4px;
}

.message.user .msg-bubble {
  background: var(--bubble-user);
  border: 1px solid var(--border);
  border-top-right-radius: 4px;
}

/* ====== Markdown Content in Bubbles ====== */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  font-family: Georgia, "Noto Serif SC", serif;
  color: var(--accent-blue);
  margin: 12px 0 6px;
}
.msg-bubble h1 { font-size: 1.15rem; }
.msg-bubble h2 { font-size: 1.05rem; }
.msg-bubble h3 { font-size: 0.95rem; }

.msg-bubble p { margin: 6px 0; }

.msg-bubble ul, .msg-bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}

.msg-bubble li { margin: 3px 0; }

.msg-bubble code {
  background: rgba(0, 212, 255, 0.1);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: "Fira Code", "Source Code Pro", monospace;
  font-size: 0.88em;
  color: var(--accent-blue);
}

.msg-bubble pre {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.msg-bubble pre code {
  background: none;
  padding: 0;
  color: var(--text-primary);
}

.msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.88em;
}

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

.msg-bubble th {
  background: var(--bg-tertiary);
  color: var(--accent-blue);
  font-weight: 600;
}

.msg-bubble blockquote {
  border-left: 3px solid var(--accent-purple);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
}

.msg-bubble strong { color: var(--accent-gold); }

/* KaTeX overrides */
.msg-bubble .katex-display {
  margin: 10px 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
}

.msg-bubble .katex { font-size: 1.05em; }

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

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-blue);
  animation: pulse 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ====== Sources Bar ====== */
#sources-bar {
  padding: 4px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
  min-height: 0;
}

.source-tag {
  font-size: 0.7rem;
  background: rgba(123, 47, 247, 0.15);
  color: var(--accent-purple);
  border: 1px solid rgba(123, 47, 247, 0.3);
  border-radius: 10px;
  padding: 2px 8px;
  cursor: default;
}

/* ====== Input Area ====== */
#input-area {
  padding: 8px 16px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

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

.input-wrapper:focus-within {
  border-color: var(--accent-blue);
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.15);
}

#input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.93rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 120px;
  font-family: inherit;
}

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

#send-btn {
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  border: none;
  color: white;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
}

#send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
}

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

.disclaimer {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-top: 6px;
}

/* ====== Info Modal ====== */
.modal { position: fixed; inset: 0; z-index: 100; }
.modal.hidden { display: none; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  max-width: 520px;
  margin: 10vh auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  max-height: 80vh;
  overflow-y: auto;
  animation: modalIn 0.25s ease;
}

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

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
}
.modal-close:hover { color: var(--text-primary); }

.modal-content h2 {
  font-family: Georgia, serif;
  font-size: 1.2rem;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 16px;
}

.modal-body section { margin-bottom: 16px; }

.modal-body h3 {
  font-size: 0.9rem;
  color: var(--accent-blue);
  margin-bottom: 6px;
}

.modal-body p, .modal-body li {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.modal-body ul { padding-left: 16px; }
.modal-body li { margin: 3px 0; }

.modal-body .warning {
  background: rgba(255, 71, 87, 0.1);
  border: 1px solid rgba(255, 71, 87, 0.3);
  border-radius: 8px;
  padding: 10px;
}
.modal-body .warning p { color: var(--danger); }

/* ====== Error Message ====== */
.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
  padding: 8px;
}

/* ====== Responsive ====== */
@media (max-width: 768px) {
  :root { --max-width: 100%; }

  #header { padding: 10px 12px; }
  .avatar { width: 36px; height: 36px; font-size: 18px; }
  .header-text h1 { font-size: 1rem; }
  .subtitle { display: none; }

  #messages { padding: 12px; }
  .msg-bubble { max-width: 90%; font-size: 0.88rem; }

  #input-area { padding: 6px 12px 10px; }
  .disclaimer { font-size: 0.62rem; }

  .modal-content { margin: 5vh 12px; max-height: 90vh; }
}

/* ====== Welcome State ====== */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 20px;
}

.welcome .big-avatar {
  font-size: 64px;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 20px rgba(0, 212, 255, 0.4));
}

.welcome h2 {
  font-family: Georgia, serif;
  font-size: 1.4rem;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.welcome p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 400px;
  line-height: 1.6;
}
