/* ========= Font Face ========= */
@font-face {
  font-family: '乐米春序晚星体';
  src: url('乐米春序晚星体.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* ========= Reset & Base ========= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Cute palette - Soft pink & lavender */
  --bg-base: #fff5f7;
  --bg-surface: #ffffff;
  --bg-elevated: #ffeef2;
  --bg-hover: #ffe4e9;
  --bg-active: #ffd6de;

  --text-main: #3d2c3a;
  --text-secondary: #8b6f82;
  --text-muted: #8b6f82;
  --text-dim: #b096a8;

  /* Accent - Candy pink */
  --accent: #ff6b9d;
  --accent-hover: #ff4d88;
  --accent-glow: rgba(255, 107, 157, 0.18);
  --accent-dim: rgba(255, 107, 157, 0.08);

  /* Secondary - Soft lavender */
  --secondary: #c9b1ff;
  --secondary-glow: rgba(201, 177, 255, 0.18);
  --secondary-dim: rgba(201, 177, 255, 0.08);

  /* Semantic */
  --success: #6bcb77;
  --success-dim: rgba(107, 203, 119, 0.1);
  --danger: #ff6b6b;
  --danger-dim: rgba(255, 107, 107, 0.1);
  --warning: #ffd93d;

  /* Borders */
  --border: #f0dce6;
  --border-light: #f8eaf0;

  /* Radius - extra round */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(255, 107, 157, 0.06), 0 1px 3px rgba(255, 107, 157, 0.04);
  --shadow-md: 0 4px 16px rgba(255, 107, 157, 0.1), 0 2px 6px rgba(255, 107, 157, 0.06);
  --shadow-lg: 0 8px 32px rgba(255, 107, 157, 0.12);
  --shadow-glow: 0 0 20px rgba(255, 107, 157, 0.15);

  /* Sizes */
  --sidebar-w: 280px;
  --header-h: 56px;

  /* Fonts - Nunito for cute rounded feel */
  --font: '乐米春序晚星体', 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-main);
  font-size: 17px;
  line-height: 1.9;
  letter-spacing: 0.04em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: var(--accent-glow);
  color: var(--text-main);
}

/* ========= Cute floating decorations ========= */
#app::before {
  content: '✦ ✧ ✦ ✧ ✦';
  position: fixed;
  top: 12px;
  right: 24px;
  font-size: 14px;
  letter-spacing: 8px;
  color: var(--accent-dim);
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
}

#app::after {
  content: '♡';
  position: fixed;
  bottom: 80px;
  right: 30px;
  font-size: 24px;
  color: var(--accent-dim);
  pointer-events: none;
  z-index: 0;
  opacity: 0.3;
  animation: floatHeart 4s ease-in-out infinite;
}

@keyframes floatHeart {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.3; }
  50% { transform: translateY(-12px) scale(1.1); opacity: 0.5; }
}

/* ========= Layout ========= */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  position: relative;
}

/* ========= Sidebar ========= */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
  position: relative;
}

#sidebar::after {
  content: '';
  position: absolute;
  top: 0;
  right: -1px;
  width: 1px;
  height: 100%;
  background: linear-gradient(to bottom, transparent, var(--accent-dim), transparent);
  opacity: 0.6;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  text-align: center;
  position: relative;
}

/* Cute sparkle on header */
.sidebar-header::after {
  content: '✧';
  position: absolute;
  top: 8px;
  right: 16px;
  font-size: 12px;
  color: var(--accent-dim);
  animation: sparkle 2s ease-in-out infinite;
}

@keyframes sparkle {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 0.8; transform: scale(1.2); }
}

.logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-main);
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.logo {
  font-size: 22px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#new-chat-btn {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-full) !important;
  background: linear-gradient(135deg, var(--accent), #ff8fab) !important;
}

#new-chat-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow) !important;
}

#new-chat-btn:active {
  transform: scale(0.97);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  cursor: pointer;
  gap: 10px;
  transition: all 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  justify-content: center;
  border: 1px solid transparent;
}

.chat-item:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  transform: scale(1.02);
}

.chat-item.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  border-color: rgba(255, 107, 157, 0.15);
}

.chat-item .chat-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color 0.15s;
}

.chat-item.active .chat-icon { color: var(--accent); }

.chat-item .chat-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 22px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color 0.15s;
  text-align: center;
}

.chat-item.active .chat-title { color: var(--text-main); font-weight: 600; }
.chat-item:hover .chat-title { color: var(--text-main); }

.chat-item .chat-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  flex-shrink: 0;
  font-size: 14px;
}

.chat-item:hover .chat-delete { opacity: 1; }
.chat-item .chat-delete:hover {
  color: var(--danger);
  background: var(--danger-dim);
}

/* ========= Main ========= */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* Ambient gradient - pink */
#main::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(255, 107, 157, 0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(201, 177, 255, 0.03) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 16px;
  scroll-behavior: smooth;
  position: relative;
  z-index: 1;
}

/* ========= Messages ========= */
.message {
  display: flex;
  gap: 14px;
  margin-bottom: 20px;
  animation: messageIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 820px;
}

.message.user { flex-direction: row-reverse; margin-left: auto; }

@keyframes messageIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  overflow: hidden;
  box-shadow: 0 3px 10px var(--accent-glow);
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-body {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
  max-width: calc(100% - 50px);
}

.message.user .message-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message-body .content {
  font-size: 22px;
  line-height: 1.7;
  word-wrap: break-word;
  color: var(--text-main);
  padding: 14px 20px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: inline-block;
  max-width: 100%;
  box-shadow: var(--shadow-sm);
}

.message.assistant .content {
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
}

.message.user .content {
  background: linear-gradient(135deg, var(--accent-dim), rgba(255, 143, 171, 0.08));
  border-color: rgba(255, 107, 157, 0.12);
  border-bottom-right-radius: 4px;
}

.message.assistant .content > :first-child { margin-top: 0; }
.message.assistant .content > :last-child { margin-bottom: 0; }

.message-body .content p { margin-bottom: 10px; }
.message-body .content p:last-child { margin-bottom: 0; }

/* ========= Markdown within messages ========= */
.content h1, .content h2, .content h3, .content h4 {
  margin: 18px 0 10px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.content h1 { font-size: 22px; }
.content h2 { font-size: 22px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.content h3 { font-size: 22px; }
.content h4 { font-size: 22px; }

.content ul, .content ol { padding-left: 22px; margin-bottom: 10px; }
.content li { margin-bottom: 4px; }

.content blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 18px;
  margin: 12px 0;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.content a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}

.content a:hover {
  border-bottom-color: var(--accent);
}

.content table {
  border-collapse: separate;
  border-spacing: 0;
  margin: 12px 0;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.content th, .content td {
  padding: 8px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.content th {
  background: var(--bg-elevated);
  font-weight: 600;
  font-size: 22px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.content td { font-size: 22px; }
.content tr:last-child td { border-bottom: none; }

.content code {
  font-family: var(--font-mono);
  font-size: 22px;
  background: var(--bg-elevated);
  padding: 2px 7px;
  border-radius: 4px;
  color: #c084fc;
  border: 1px solid var(--border);
}

.content pre {
  margin: 12px 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fafafc !important;
  position: relative;
}

.content pre > code {
  display: block;
  padding: 16px 18px;
  overflow-x: auto;
  font-size: 22px;
  line-height: 1.65;
  background: none !important;
  border: none;
  color: #3d2c3a;
  font-weight: 400;
}

/* Inline images */
.content img {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 8px 0;
  border: 1px solid var(--border);
}

/* Horizontal rule */
.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ========= Input Area ========= */
.input-area {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  position: relative;
  z-index: 1;
}

.input-area::before {
  content: '';
  position: absolute;
  top: -16px;
  left: 0;
  right: 0;
  height: 16px;
  background: linear-gradient(to top, var(--bg-surface), transparent);
  pointer-events: none;
}

.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  padding: 10px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  border: 1px dashed var(--border-light);
}

.file-preview-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-family: var(--font);
}

.file-preview-item .remove-file {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  background: none;
  border: none;
  padding: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.15s;
}

.file-preview-item .remove-file:hover {
  color: var(--danger);
  background: var(--danger-dim);
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.message-input {
  flex: 1;
  min-height: 46px;
  max-height: 200px;
  padding: 12px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 9999px;
  color: var(--text-main);
  font-family: var(--font);
  font-size: 22px;
  line-height: 1.5;
  outline: none;
  overflow-y: auto;
  word-wrap: break-word;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.message-input:focus {
  border-color: var(--border);
  box-shadow: 0 0 0 2px rgba(255, 107, 157, 0.15), var(--shadow-md);
  border-radius: 9999px;
}

/* Placeholder for contenteditable */
.message-input:empty:before {
  content: attr(placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

.message-input:empty:focus:before {
  content: attr(placeholder);
  color: var(--text-dim);
}

.send-btn {
  height: 46px;
  min-width: 80px;
  padding: 0 24px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.3px;
  border-radius: var(--radius-full) !important;
  background: linear-gradient(135deg, var(--accent), #ff8fab) !important;
  color: #fff;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.send-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow) !important;
}

.send-btn:active { transform: scale(0.97); }

.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  pointer-events: none;
}

.send-btn.sending {
  opacity: 0.7;
  cursor: wait;
  pointer-events: none;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#upload-btn {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-xl);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: all 0.15s;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#upload-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.05);
}

#upload-btn:active {
  transform: scale(0.95);
}

.input-hint {
  margin-top: 10px;
  font-size: 22px;
  color: var(--text-dim);
  text-align: right;
  letter-spacing: 0.2px;
}

/* ========= Buttons ========= */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #ff8fab);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  transition: all 0.15s ease;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.btn-icon:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ========= Scrollbar ========= */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--text-dim);
  border-radius: 3px;
  transition: background 0.15s;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ========= Empty State ========= */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 40px;
  position: relative;
}

.empty-state .icon {
  margin-bottom: 20px;
  color: var(--text-dim);
  position: relative;
}

/* Cute sparkle behind empty state icon */
.empty-state .icon::after {
  content: '✦';
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: 14px;
  color: var(--accent-dim);
  animation: sparkle 2.5s ease-in-out infinite;
}

.empty-state h2 {
  font-size: 28px;
  margin-bottom: 12px;
  color: var(--text-secondary);
  font-weight: 700;
  letter-spacing: -0.3px;
}

.empty-state p {
  font-size: 22px;
  max-width: 300px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ========= Typing Indicator ========= */
.typing .content::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 15px;
  background: var(--accent);
  margin-left: 3px;
  animation: blink 0.7s step-end infinite;
  vertical-align: text-bottom;
  border-radius: 2px;
}

@keyframes blink { 50% { opacity: 0; } }

/* ========= Focus visible ========= */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ========= Hidden ========= */
.hidden { display: none !important; }

/* ========= Sidebar Toggle (Mobile) ========= */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 15;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(255, 107, 157, 0.15);
  transition: transform 0.15s;
}

.sidebar-toggle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sidebar-toggle:hover {
  transform: scale(1.05);
}

.sidebar-toggle:active {
  transform: scale(0.95);
}

/* ========= Responsive ========= */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: calc(var(--sidebar-w) * -1);
    top: 0;
    height: 100vh;
    transition: left 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 30;
    box-shadow: none;
  }

  #sidebar.open {
    left: 0;
    box-shadow: 4px 0 24px rgba(255, 107, 157, 0.1);
  }

  .sidebar-toggle { display: flex; }
  .messages { padding-top: 56px; }
  .message { max-width: 100%; }
}