/* ============================================
   米豆奶 AI 客服中心 — Design System
   Brand: 米豆奶科技 / Product: 小安
   ============================================ */

/* --- CSS Variables (Design Tokens) --- */
:root {
  /* Brand Palette */
  --brand-primary: #7c3aed;
  --brand-primary-light: #a78bfa;
  --brand-primary-dark: #6d28d9;
  --brand-accent: #06b6d4;
  --brand-accent-light: #22d3ee;
  --brand-gradient: linear-gradient(135deg, #7c3aed 0%, #2563eb 50%, #06b6d4 100%);
  --brand-gradient-subtle: linear-gradient(135deg, rgba(124,58,237,0.12) 0%, rgba(37,99,235,0.08) 100%);

  /* Surface Colors (Dark Theme) */
  --bg-app: #0f0f1a;
  --bg-sidebar: rgba(17, 17, 34, 0.85);
  --bg-main: #13132a;
  --bg-chat: #0d0d1f;
  --bg-card: rgba(30, 30, 60, 0.6);
  --bg-card-hover: rgba(40, 40, 70, 0.8);
  --bg-input: rgba(30, 30, 55, 0.8);
  --bg-bubble-ai: rgba(30, 30, 60, 0.7);
  --bg-bubble-user: var(--brand-gradient);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-accent: rgba(124, 58, 237, 0.3);

  /* Text */
  --text-primary: #f1f1f8;
  --text-secondary: #a0a0c0;
  --text-muted: #6b6b8a;
  --text-accent: var(--brand-primary-light);
  --text-on-brand: #ffffff;
  --text-danger: #f87171;
  --text-success: #34d399;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px rgba(124, 58, 237, 0.15);
  --shadow-brand: 0 4px 15px rgba(124, 58, 237, 0.3);

  /* Radius */
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'Cascadia Code', Menlo, monospace;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --sidebar-width: 280px;
  --header-height: 64px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  background: none;
  color: inherit;
}

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

/* --- Main Layout --- */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
  right: auto;
  z-index: 30;
  transform: translateX(-100%);
  transition: transform var(--transition-base);
}

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

@media (min-width: 768px) {
  .sidebar {
    position: relative;
    transform: translateX(0);
  }
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 20;
  display: none;
}

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

@media (min-width: 768px) {
  .sidebar-overlay { display: none !important; }
}

/* Sidebar Header */
.sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: var(--brand-gradient);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: var(--shadow-brand);
}

.brand-icon [data-lucide] { width: 20px; height: 20px; }

.brand-name {
  font-size: 1rem;
  font-weight: 700;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.sidebar-close {
  display: flex;
  color: var(--text-muted);
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}
.sidebar-close:hover { color: var(--text-primary); }

@media (min-width: 768px) { .sidebar-close { display: none; } }

/* Sidebar Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 10px; }

.btn-new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--brand-gradient);
  color: white;
  border-radius: var(--radius-xl);
  font-weight: 700;
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-brand);
}

.btn-new-chat:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.4);
}

.btn-new-chat:active { transform: scale(0.97); }
.btn-new-chat [data-lucide] { width: 18px; height: 18px; }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  text-align: left;
}

.nav-btn:hover { background: rgba(124, 58, 237, 0.08); color: var(--text-primary); }
.nav-btn.active { background: rgba(124, 58, 237, 0.15); color: var(--text-accent); font-weight: 600; }
.nav-btn [data-lucide] { width: 18px; height: 18px; }

.nav-section-title {
  padding: 1rem 0.75rem 0.375rem;
  font-size: 0.625rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Guest Session List in sidebar */
.session-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 35vh;
  overflow-y: auto;
}

.session-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-btn:hover { background: rgba(255,255,255,0.04); color: var(--text-secondary); }
.session-btn.active { background: rgba(124,58,237,0.12); color: var(--text-accent); font-weight: 600; }
.session-btn [data-lucide] { width: 14px; height: 14px; flex-shrink: 0; }

/* Admin Nav */
.admin-section { display: none; }
.admin-section.show { display: block; }

/* Sidebar Footer */
.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border-subtle);
}

.btn-logout {
  display: none;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-danger);
  transition: all var(--transition-fast);
}

.btn-logout:hover { background: rgba(248, 113, 113, 0.1); }
.btn-logout.show { display: flex; }
.btn-logout [data-lucide] { width: 18px; height: 18px; }

/* --- Main Content --- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  position: relative;
  background: var(--bg-main);
}

/* Header */
.app-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: rgba(19, 19, 42, 0.9);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  z-index: 10;
}

@media (min-width: 768px) { .app-header { padding: 0 1.5rem; } }

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-menu {
  padding: 0.5rem;
  margin-left: -0.5rem;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}

.btn-menu:hover { color: var(--text-primary); }
@media (min-width: 768px) { .btn-menu { display: none; } }

.header-avatar {
  position: relative;
  width: 42px;
  height: 42px;
  background: var(--brand-gradient);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: var(--shadow-glow);
}

.header-avatar [data-lucide] { width: 20px; height: 20px; }

.header-status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 12px;
  height: 12px;
  background: var(--text-success);
  border: 2px solid var(--bg-main);
  border-radius: 50%;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(52, 211, 153, 0); }
}

.header-info h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.header-info p {
  font-size: 0.7rem;
  color: var(--text-success);
  font-weight: 600;
}

.header-tools {
  display: flex;
  gap: 0.25rem;
}

.header-tool-btn {
  padding: 0.5rem;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  display: none;
}

.header-tool-btn.show { display: flex; }
.header-tool-btn:hover { color: var(--text-accent); background: rgba(124,58,237,0.1); }

/* --- View Container --- */
.view-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.view-section {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}

.view-section.active {
  display: flex;
  animation: view-enter 0.3s ease-out;
}

@keyframes view-enter {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Chat View --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scroll-behavior: smooth;
}

@media (min-width: 768px) { .chat-messages { padding: 2rem; } }

.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 10px; }

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 1.5rem;
  padding: 2rem;
  animation: fade-up 0.6s ease-out;
}

.welcome-avatar {
  width: 80px;
  height: 80px;
  background: var(--brand-gradient);
  border-radius: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: var(--shadow-brand), var(--shadow-glow);
  animation: float 3s ease-in-out infinite;
}

.welcome-avatar [data-lucide] { width: 40px; height: 40px; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.welcome-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

.welcome-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
  max-width: 400px;
}

.welcome-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  max-width: 500px;
}

.suggestion-chip {
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.suggestion-chip:hover {
  border-color: var(--brand-primary);
  color: var(--text-accent);
  background: rgba(124,58,237,0.1);
  transform: translateY(-1px);
}

/* Message Bubbles */
.msg-row {
  display: flex;
  gap: 0.75rem;
  animation: msg-in 0.35s ease-out;
}

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

@keyframes msg-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  font-size: 0.7rem;
  font-weight: 800;
}

.msg-avatar.ai {
  background: var(--brand-gradient);
  color: white;
  box-shadow: var(--shadow-glow);
}

.msg-avatar.human {
  background: rgba(255,255,255,0.08);
  color: var(--text-secondary);
}

.msg-avatar [data-lucide] { width: 16px; height: 16px; }

.msg-bubble {
  max-width: 80%;
  border-radius: var(--radius-xl);
  padding: 0.875rem 1.125rem;
  font-size: 0.9rem;
  line-height: 1.7;
  position: relative;
}

@media (min-width: 768px) { .msg-bubble { max-width: 70%; } }

.msg-bubble.ai {
  background: var(--bg-bubble-ai);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-top-left-radius: var(--radius-sm);
}

.msg-bubble.user {
  background: var(--brand-gradient);
  color: white;
  border-top-right-radius: var(--radius-sm);
  box-shadow: var(--shadow-brand);
}

.msg-bubble.error {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.2);
  color: var(--text-danger);
}

/* Typing Indicator */
.typing-indicator {
  display: none;
  padding: 0 1rem 1rem;
  gap: 0.75rem;
}

.typing-indicator.show { display: flex; }

.typing-dots {
  background: var(--bg-bubble-ai);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  border-top-left-radius: var(--radius-sm);
  padding: 0.875rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}

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

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Chat Input Area */
.chat-input-area {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border-subtle);
  background: rgba(19, 19, 42, 0.8);
  backdrop-filter: blur(12px);
}

body.read-only-mode .chat-input-area {
  display: none !important;
}
body.read-only-mode #open-sidebar {
  display: none !important;
}

@media (min-width: 768px) { .chat-input-area { padding: 1rem 1.5rem 1.25rem; } }

.chat-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 800px;
  margin: 0 auto;
  position: relative;
}

.chat-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  font-size: 0.9rem;
  border-radius: var(--radius-full);
  padding: 0.875rem 3rem 0.875rem 1.25rem;
  transition: all var(--transition-fast);
}

.chat-input::placeholder { color: var(--text-muted); }
.chat-input:focus { border-color: var(--brand-primary); box-shadow: 0 0 0 3px rgba(124,58,237,0.15); }

.btn-send {
  position: absolute;
  right: 0.375rem;
  padding: 0.5rem;
  background: var(--brand-gradient);
  color: white;
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-brand);
}

.btn-send:hover { transform: scale(1.05); }
.btn-send:active { transform: scale(0.95); }
.btn-send [data-lucide] { width: 18px; height: 18px; }

.chat-disclaimer {
  text-align: center;
  margin-top: 0.375rem;
  font-size: 0.625rem;
  color: var(--text-muted);
}

/* --- Auth View --- */
.auth-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 26, 0.95);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 1rem;
}

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

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-2xl);
  padding: 2.5rem;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: fade-up 0.4s ease-out;
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-icon {
  width: 64px;
  height: 64px;
  background: rgba(124,58,237,0.15);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  color: var(--text-accent);
}

.auth-icon [data-lucide] { width: 32px; height: 32px; }

.auth-header h2 {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-primary);
}

.auth-header p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

.form-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: all var(--transition-fast);
}

.form-input::placeholder { color: var(--text-muted); }
.form-input:focus { border-color: var(--brand-primary); box-shadow: 0 0 0 3px rgba(124,58,237,0.15); }

.btn-primary {
  width: 100%;
  padding: 0.875rem;
  background: var(--brand-gradient);
  color: white;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  font-weight: 700;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-brand);
  margin-top: 0.5rem;
}

.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(124,58,237,0.35); }
.btn-primary:active { transform: scale(0.98); }

/* --- Admin History View --- */
.history-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.history-sidebar {
  width: 320px;
  border-right: 1px solid var(--border-subtle);
  background: rgba(19, 19, 42, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Filter Tabs */
.filter-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.75rem 0.75rem 0;
  flex-shrink: 0;
}

.filter-tab {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all var(--transition-fast);
  text-align: center;
}

.filter-tab:hover { color: var(--text-secondary); background: rgba(255,255,255,0.03); }
.filter-tab.active { background: rgba(124,58,237,0.15); color: var(--text-accent); }

/* Search */
.search-box {
  padding: 0.75rem;
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  color: var(--text-primary);
  font-size: 0.8rem;
}

.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--brand-primary); }

/* Records List */
.records-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.records-list::-webkit-scrollbar { width: 4px; }
.records-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 10px; }

/* Owner Group */
.owner-group { margin-bottom: 0.5rem; }

.owner-group-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.owner-group-header:hover { background: rgba(255,255,255,0.03); }
.owner-group-header [data-lucide] { width: 12px; height: 12px; transition: transform var(--transition-fast); }
.owner-group-header.collapsed [data-lucide] { transform: rotate(-90deg); }

.owner-group-content { display: flex; flex-direction: column; gap: 2px; }
.owner-group-content.collapsed { display: none; }

.record-item {
  width: 100%;
  text-align: left;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.record-item:hover { background: rgba(255,255,255,0.03); border-color: var(--border-subtle); }
.record-item.active { background: rgba(124,58,237,0.1); border-color: var(--border-accent); }

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

.record-item-title { font-size: 0.8rem; font-weight: 600; color: var(--text-primary); }
.record-item-time { font-size: 0.625rem; color: var(--text-muted); white-space: nowrap; }
.record-item-meta { font-size: 0.7rem; color: var(--text-muted); }

/* History Detail */
.history-detail {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.history-detail::-webkit-scrollbar { width: 5px; }
.history-detail::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 10px; }

.detail-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  flex-direction: column;
  gap: 0.75rem;
  color: var(--text-muted);
}

.detail-empty [data-lucide] { width: 48px; height: 48px; opacity: 0.3; }

.detail-header {
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.detail-header-info h3 { font-size: 0.9rem; font-weight: 700; color: var(--text-primary); }
.detail-header-info p { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.25rem; }

.btn-delete {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.2);
  color: var(--text-danger);
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.btn-delete:hover { background: rgba(248, 113, 113, 0.2); border-color: rgba(248, 113, 113, 0.3); }
.btn-delete [data-lucide] { width: 14px; height: 14px; }

.detail-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* --- Settings View --- */
.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.settings-content::-webkit-scrollbar { width: 5px; }
.settings-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 10px; }

.settings-inner { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.5rem; }

.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.settings-card-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.settings-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-card-icon.purple { background: rgba(124,58,237,0.15); color: var(--text-accent); }
.settings-card-icon.orange { background: rgba(251,146,60,0.15); color: #fb923c; }

.settings-card-header h3 { font-size: 1rem; font-weight: 700; }

.settings-card-body { padding: 1.25rem; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-grid .full-width { grid-column: 1 / -1; }

.form-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  appearance: none;
}

.form-select:focus { border-color: var(--brand-primary); }

.btn-save {
  padding: 0.75rem 1.5rem;
  background: var(--brand-gradient);
  color: white;
  border-radius: var(--radius-lg);
  font-weight: 700;
  font-size: 0.875rem;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-brand);
  margin-top: 0.5rem;
}

.btn-save:hover { transform: translateY(-1px); }

.btn-debug {
  padding: 0.75rem 1.5rem;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  border-radius: var(--radius-lg);
  font-weight: 700;
  font-size: 0.875rem;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.btn-debug:hover { background: rgba(255,255,255,0.12); }

.debug-output {
  background: rgba(0, 0, 0, 0.4);
  color: var(--text-accent);
  padding: 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  overflow-x: auto;
  min-height: 120px;
  border: 1px solid var(--border-subtle);
}

.debug-summary { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.5rem; }

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

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

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: fade-up 0.3s ease-out;
  text-align: center;
}

.modal-card h3 { font-size: 1.125rem; font-weight: 700; margin-bottom: 0.5rem; }
.modal-card p { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 1.5rem; }

.modal-actions {
  display: flex;
  gap: 0.75rem;
}

.btn-cancel {
  flex: 1;
  padding: 0.75rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 600;
  transition: all var(--transition-fast);
}

.btn-cancel:hover { background: rgba(255,255,255,0.1); }

.btn-danger {
  flex: 1;
  padding: 0.75rem;
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-md);
  color: var(--text-danger);
  font-weight: 700;
  transition: all var(--transition-fast);
}

.btn-danger:hover { background: rgba(248, 113, 113, 0.25); }

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius-xl);
  background: rgba(30, 30, 60, 0.95);
  border: 1px solid var(--border-default);
  backdrop-filter: blur(12px);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.85rem;
  font-weight: 500;
  transform: translateY(120%);
  transition: transform var(--transition-base);
  pointer-events: none;
}

.toast.show { transform: translateY(0); }
.toast [data-lucide] { width: 18px; height: 18px; flex-shrink: 0; }

/* --- Markdown/Prose (in bubbles) --- */
.prose { line-height: 1.7; }
.prose p { margin-bottom: 0.625rem; }
.prose p:last-child { margin-bottom: 0; }

.prose h1, .prose h2, .prose h3 {
  font-weight: 700;
  margin-top: 0.75rem;
  margin-bottom: 0.375rem;
  color: var(--text-primary);
}

.prose h1 { font-size: 1.25rem; }
.prose h2 { font-size: 1.1rem; }
.prose h3 { font-size: 1rem; }

.prose ul, .prose ol { margin-left: 1.25rem; margin-bottom: 0.625rem; }
.prose li { margin-bottom: 0.2rem; }

.prose code {
  background: rgba(124, 58, 237, 0.15);
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--text-accent);
}

.prose pre {
  background: rgba(0, 0, 0, 0.5);
  color: #a5b4fc;
  padding: 1rem;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-bottom: 0.625rem;
  font-size: 0.8rem;
  border: 1px solid var(--border-subtle);
}

.prose pre code { background: transparent; padding: 0; color: inherit; }

.prose blockquote {
  border-left: 3px solid var(--brand-primary);
  padding-left: 0.75rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 0.625rem;
}

.prose img {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  max-width: 100%;
  margin: 0.375rem 0;
}

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

/* User bubble prose overrides */
.msg-bubble.user .prose a { color: rgba(255,255,255,0.85); }

/* --- Animations --- */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Utility --- */
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
