/* ============================================================
   刻俄柏聊天 — "荒野炊火" 主题
   围坐在篝火旁，粗糙但有温度的手作质感
   ============================================================ */

:root {
  --bg-night: #1a1a24;
  --bg-sidebar: #14141c;
  --bg-chat: #fdf6e3;
  --bg-chat-alt: #fef9f0;
  --accent-ember: #e67e22;
  --accent-fire: #d35400;
  --accent-glow: #f39c12;
  --text-primary: #3e2723;
  --text-secondary: #8d6e63;
  --text-muted: #a1887f;
  --bubble-ceobe: #fff8e1;
  --bubble-user: #ffe0b2;
  --border-warm: #e8d5b7;
  --danger: #c0392b;
  --font-display: 'PingFang SC', 'Microsoft YaHei', serif;
  --font-body: 'PingFang SC', 'Microsoft YaHei', 'SimSun', serif;
  --shadow-soft: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-glow: 0 0 24px rgba(230,126,34,0.15);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-night);
}

/* ------ 篝火粒子画布 ------ */
#embers {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.6;
}

/* ------ App Container ------ */
.app-container {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  box-shadow: 0 0 80px rgba(230,126,34,0.08);
}

/* ------ Sidebar ------ */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.05);
  position: relative;
}

/* 侧边栏纹理叠加 */
.sidebar::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255,255,255,0.008) 2px,
      rgba(255,255,255,0.008) 4px
    );
  pointer-events: none;
  z-index: 0;
}

.sidebar-header {
  position: relative;
  z-index: 1;
  padding: 28px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.logo-icon {
  font-size: 32px;
  filter: drop-shadow(0 0 8px rgba(243,156,18,0.4));
  animation: flicker 3s ease-in-out infinite;
}

@keyframes flicker {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: 0.85; }
}

.logo-text {
  font-family: var(--font-display);
  font-size: 20px;
  color: #fdf6e3;
  line-height: 1.35;
  letter-spacing: 0.04em;
}

.btn-new-chat {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  background: rgba(230,126,34,0.12);
  border: 1px solid rgba(230,126,34,0.2);
  border-radius: var(--radius-sm);
  color: var(--accent-ember);
  font-family: var(--font-display);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.25s;
}
.btn-new-chat:hover {
  background: rgba(230,126,34,0.22);
  border-color: rgba(230,126,34,0.4);
  box-shadow: 0 0 20px rgba(230,126,34,0.12);
}
.btn-new-icon {
  font-size: 18px;
  font-weight: bold;
}

/* 对话列表 */
.conv-list {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
}

.conv-item {
  padding: 12px 14px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  border-left: 2px solid transparent;
}
.conv-item:hover {
  background: rgba(255,255,255,0.04);
}
.conv-item.active {
  background: rgba(230,126,34,0.1);
  border-left-color: var(--accent-ember);
}

.conv-item-title {
  font-size: 13px;
  color: #d5d0c8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.conv-item.active .conv-item-title {
  color: #fdf6e3;
}

.conv-item-meta {
  font-size: 11px;
  color: rgba(255,255,255,0.25);
}

/* Sidebar Footer */
.sidebar-footer {
  position: relative;
  z-index: 1;
  padding: 12px 20px 20px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.btn-settings {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.5);
  font-family: var(--font-display);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.25s;
}
.btn-settings:hover {
  border-color: rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.8);
}

/* ------ Chat Area ------ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  position: relative;
  overflow: hidden;
}

/* 纸张纹理 */
.chat-area::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='60' height='60' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 1;
}

/* 空状态 */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  z-index: 2;
  opacity: 1;
  transition: opacity 0.4s;
}
.chat-empty.hidden {
  opacity: 0;
  pointer-events: none;
}

.empty-illustration {
  position: relative;
  margin-bottom: 16px;
}

.campfire-glow {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(230,126,34,0.25) 0%, transparent 70%);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation: breathe 3s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.6; }
  50% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
}

.campfire-icon {
  font-size: 48px;
  position: relative;
  z-index: 1;
  display: block;
  text-align: center;
  animation: flicker 3s ease-in-out infinite;
}

.chat-empty h2 {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--text-primary);
  position: relative;
  z-index: 2;
}
.chat-empty p {
  font-size: 14px;
  color: var(--text-secondary);
  position: relative;
  z-index: 2;
}
.empty-hint {
  font-size: 12px !important;
  color: var(--text-muted) !important;
  font-style: italic;
}

/* 消息列表 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  position: relative;
  z-index: 2;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 3px;
}

/* 消息气泡 */
.message-row {
  display: flex;
  margin-bottom: 20px;
  animation: msgIn 0.35s ease-out;
}

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

.message-row.user { justify-content: flex-end; }
.message-row.ceobe { justify-content: flex-start; }

.message-bubble {
  max-width: 72%;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  position: relative;
  line-height: 1.7;
  font-size: 15px;
}

.message-row.user .message-bubble {
  background: var(--bubble-user);
  border: 1px solid #f0d9b5;
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-soft);
}

.message-row.ceobe .message-bubble {
  background: var(--bubble-ceobe);
  border: 1px solid #f5ecd7;
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-soft);
}

.message-sender {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  letter-spacing: 0.03em;
}

.message-row.ceobe .message-sender { color: var(--accent-fire); }
.message-row.user .message-sender { color: var(--text-secondary); text-align: right; }

/* 系统消息 */
.message-system {
  text-align: center;
  margin: 12px 0;
  font-size: 12px;
  color: var(--text-muted);
  animation: msgIn 0.3s ease-out;
}

/* 状态栏 */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 32px;
  position: relative;
  z-index: 2;
  border-top: 1px solid rgba(0,0,0,0.04);
  background: rgba(253,246,227,0.6);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #bdc3c7;
  transition: background 0.3s;
}
.status-dot.thinking {
  background: var(--accent-ember);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.5); }
}

.status-text {
  font-size: 12px;
  color: var(--text-muted);
}

/* 输入区 */
.input-area {
  padding: 12px 24px 20px;
  position: relative;
  z-index: 2;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: white;
  border: 2px solid var(--border-warm);
  border-radius: var(--radius-lg);
  padding: 10px 12px 10px 18px;
  transition: all 0.3s;
  box-shadow: var(--shadow-soft);
}

.input-wrapper:focus-within {
  border-color: var(--accent-ember);
  box-shadow: var(--shadow-glow);
}

#messageInput {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: transparent;
  max-height: 120px;
  padding: 4px 0;
}
#messageInput::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.btn-send {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border: none;
  border-radius: 50%;
  background: var(--accent-ember);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s;
  box-shadow: 0 4px 12px rgba(230,126,34,0.3);
}
.btn-send:hover {
  background: var(--accent-fire);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(230,126,34,0.4);
}
.btn-send:active {
  transform: scale(0.95);
}
.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ------ 设置面板 ------ */
.settings-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(20,20,28,0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.settings-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.settings-panel {
  background: #1e1e2a;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 400px;
  max-width: 90vw;
  color: #d5d0c8;
}

.settings-panel h2 {
  font-family: var(--font-display);
  color: #fdf6e3;
  margin-bottom: 20px;
  font-size: 20px;
}

.settings-panel label {
  display: block;
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  margin: 14px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.settings-panel input,
.settings-panel select {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  color: #fdf6e3;
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
}
.settings-panel input:focus,
.settings-panel select:focus {
  border-color: var(--accent-ember);
}

.settings-panel select option {
  background: #1e1e2a;
  color: #fdf6e3;
}

.key-row {
  display: flex;
  gap: 8px;
}
.key-row input { flex: 1; }

.btn-sm {
  padding: 8px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  color: #d5d0c8;
  cursor: pointer;
  font-size: 16px;
}

.settings-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.btn-save, .btn-cancel {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}
.btn-save {
  background: var(--accent-ember);
  color: white;
}
.btn-save:hover { background: var(--accent-fire); }
.btn-cancel {
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.5);
}
.btn-cancel:hover { background: rgba(255,255,255,0.1); }

/* ------ 右键菜单 ------ */
.context-menu {
  position: fixed;
  background: #1e1e2a;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 6px;
  min-width: 140px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95);
  transition: opacity 0.15s, transform 0.15s;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.context-menu.show {
  opacity: 1;
  pointer-events: all;
  transform: scale(1);
}

.ctx-item {
  padding: 8px 14px;
  border-radius: 4px;
  font-size: 13px;
  color: #d5d0c8;
  cursor: pointer;
  transition: background 0.15s;
}
.ctx-item:hover { background: rgba(255,255,255,0.06); }
.ctx-danger { color: var(--danger); }
.ctx-danger:hover { background: rgba(192,57,43,0.15); }

/* ------ Responsive ------ */
@media (max-width: 680px) {
  .sidebar { width: 72px; min-width: 72px; }
  .logo-text, .btn-new-chat span, .conv-item-meta,
  .btn-settings, .sidebar-footer { display: none; }
  .conv-item-title { font-size: 0; }
  .conv-item-title::first-letter {
    font-size: 16px;
    display: inline-block;
  }
  .chat-messages { padding: 16px; }
  .message-bubble { max-width: 88%; }
}
