/* ===========================
   Inne 酒馆 — 深色木质感样式
   =========================== */

:root {
  --bg-primary: #1a1410;       /* 深木色 */
  --bg-secondary: #241c14;      /* 略浅木色 */
  --bg-card: #2d2218;          /* 卡片背景 */
  --bg-input: #1e1810;         /* 输入框背景 */
  --accent-gold: #D4AF37;      /* 金色强调 */
  --accent-gold-light: #e8c76b;
  --accent-gold-dim: #8a7030;
  --text-primary: #f0e6d3;      /* 主文字（羊皮纸色） */
  --text-secondary: #a89880;   /* 次文字 */
  --text-muted: #6b5a42;       /* 弱化文字 */
  --border: #3d2f1f;           /* 边框色 */
  --border-gold: #6a5020;      /* 金色边框 */
  --shadow: rgba(0, 0, 0, 0.6);
  --glow: rgba(212, 175, 55, 0.15);
  --glow-strong: rgba(212, 175, 55, 0.3);
  --radius: 8px;
  --radius-lg: 12px;
  --font-title: 'Cinzel', 'Noto Serif SC', serif;
  --font-body: 'Noto Sans SC', sans-serif;
  --font-serif: 'Noto Serif SC', serif;
}

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

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* === 顶栏 === */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: linear-gradient(180deg, #2d1f10 0%, #1a1410 100%);
  border-bottom: 1px solid var(--border-gold);
  box-shadow: 0 2px 12px var(--shadow), 0 0 20px var(--glow);
  z-index: 100;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 32px;
  height: 32px;
}

.app-name {
  font-family: var(--font-title);
  font-size: 18px;
  font-weight: 600;
  color: var(--accent-gold);
  letter-spacing: 2px;
  text-shadow: 0 0 10px var(--glow-strong);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* === 按钮基础 === */
button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  outline: none;
  transition: all 0.2s ease;
}

.btn-icon {
  background: transparent;
  color: var(--text-secondary);
  font-size: 18px;
  padding: 6px;
  border-radius: var(--radius);
  line-height: 1;
}

.btn-icon:hover {
  color: var(--accent-gold);
  background: var(--glow);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-gold) 0%, #c49a28 100%);
  color: #1a1000;
  font-weight: 600;
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(212, 175, 55, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-gold-light) 0%, var(--accent-gold) 100%);
  box-shadow: 0 4px 16px rgba(212, 175, 55, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  padding: 8px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 14px;
}

.btn-secondary:hover {
  border-color: var(--accent-gold-dim);
  color: var(--text-primary);
}

/* === 主布局 === */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* === 侧边栏 === */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sidebar-header h2 {
  font-family: var(--font-title);
  font-size: 13px;
  color: var(--accent-gold);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.character-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.character-list::-webkit-scrollbar { width: 4px; }
.character-list::-webkit-scrollbar-track { background: transparent; }
.character-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* === 角色项 === */
.char-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  margin-bottom: 4px;
  position: relative;
}

.char-item:hover {
  background: var(--bg-card);
  border-color: var(--border);
}

.char-item.active {
  background: var(--bg-card);
  border-color: var(--accent-gold-dim);
  box-shadow: inset 0 0 0 1px var(--glow), 0 0 8px var(--glow);
}

.char-item-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-primary);
}

.char-item.active .char-item-avatar {
  border-color: var(--accent-gold);
  box-shadow: 0 0 8px var(--glow);
}

.char-item-info {
  flex: 1;
  min-width: 0;
}

.char-item-name {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.char-item-desc {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.char-item-delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.2s;
}

.char-item:hover .char-item-delete {
  opacity: 1;
}

.char-item-delete:hover {
  color: #e74c3c;
}

.char-item.custom-tag::after {
  content: '✦';
  position: absolute;
  left: 4px;
  top: 4px;
  font-size: 8px;
  color: var(--accent-gold-dim);
}

/* === 聊天区 === */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(212, 175, 55, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(180, 100, 20, 0.06) 0%, transparent 50%),
    var(--bg-primary);
}

/* === 角色信息卡 === */
.character-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(36, 28, 20, 0.8) 0%, transparent 100%);
  flex-shrink: 0;
}

.char-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--accent-gold);
  object-fit: cover;
  box-shadow: 0 0 12px var(--glow);
  background: var(--bg-secondary);
}

.char-info h3 {
  font-family: var(--font-title);
  font-size: 16px;
  color: var(--accent-gold);
  letter-spacing: 1px;
  margin-bottom: 2px;
}

.char-info p {
  font-size: 12px;
  color: var(--text-secondary);
}

/* === 消息列表 === */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

/* === 空状态 === */
.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-serif);
  font-size: 16px;
  pointer-events: none;
}

.empty-state p {
  margin-top: 12px;
  font-size: 14px;
}

/* === 消息气泡 === */
.message {
  display: flex;
  gap: 12px;
  max-width: 80%;
  animation: fadeIn 0.3s ease;
}

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

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

.message.assistant {
  align-self: flex-start;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
  align-self: flex-end;
}

.msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.7;
  position: relative;
  box-shadow: 0 2px 8px var(--shadow);
}

.message.user .msg-bubble {
  background: linear-gradient(135deg, #3a2a10 0%, #2d2218 100%);
  border-color: var(--accent-gold-dim);
  color: var(--text-primary);
}

.message.assistant .msg-bubble {
  background: var(--bg-card);
}

.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }

.msg-bubble code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  color: var(--accent-gold-light);
}

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

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

/* 加载动画 */
.msg-loading {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}

.msg-loading span {
  width: 6px;
  height: 6px;
  background: var(--accent-gold-dim);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.msg-loading span:nth-child(1) { animation-delay: -0.32s; }
.msg-loading span:nth-child(2) { animation-delay: -0.16s; }
.msg-loading span:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* === 输入区 === */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.input-box {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.2s;
  outline: none;
}

.input-box:focus {
  border-color: var(--accent-gold-dim);
  box-shadow: 0 0 0 2px var(--glow);
}

.input-box::placeholder {
  color: var(--text-muted);
}

.input-box::-webkit-scrollbar { width: 4px; }
.input-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.btn-send {
  background: linear-gradient(135deg, var(--accent-gold) 0%, #c49a28 100%);
  color: #1a1000;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 22px;
  border-radius: var(--radius-lg);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(212, 175, 55, 0.3);
  transition: all 0.2s;
}

.btn-send:hover {
  background: linear-gradient(135deg, var(--accent-gold-light) 0%, var(--accent-gold) 100%);
  box-shadow: 0 4px 16px rgba(212, 175, 55, 0.5);
  transform: translateY(-1px);
}

.btn-send:active { transform: translateY(0); }
.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* === 模态框 === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  width: 420px;
  max-width: 90vw;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.8), 0 0 30px var(--glow);
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(212, 175, 55, 0.05) 0%, transparent 100%);
}

.modal-header h3 {
  font-family: var(--font-title);
  font-size: 15px;
  color: var(--accent-gold);
  letter-spacing: 1px;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* === 设置表单 === */
.setting-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-group label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.5px;
}

.setting-group input,
.setting-group select,
.setting-group textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.setting-group input:focus,
.setting-group select:focus,
.setting-group textarea:focus {
  border-color: var(--accent-gold-dim);
  box-shadow: 0 0 0 2px var(--glow);
}

.setting-group textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.6;
}

.setting-group select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a89880' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.setting-group select option {
  background: var(--bg-secondary);
}

/* Toggle Switch */
.toggle-group {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 24px;
  transition: all 0.3s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--text-muted);
  border-radius: 50%;
  transition: all 0.3s ease;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-gold-dim);
  border-color: var(--accent-gold);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateY(-50%) translateX(20px);
  background: var(--accent-gold);
}

/* Thinking Block */
.thinking-wrapper {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.thinking-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.thinking-toggle:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.thinking-arrow {
  font-size: 10px;
  transition: transform 0.2s;
}

.thinking-block {
  display: none;
  padding: 10px;
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.6;
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  font-family: var(--font-body);
}

/* === 移动端适配 === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 52px;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: 260px;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }

  .mobile-menu-btn {
    display: flex !important;
  }

  .topbar-right {
    opacity: 1 !important;
  }

  .topbar {
    padding: 8px 14px;
  }

  .app-name { font-size: 15px; }

  .message {
    max-width: 90%;
  }

  .input-area {
    padding: 10px 14px;
  }

  .character-card {
    padding: 10px 16px;
  }
}

@media (max-width: 480px) {
  .modal-overlay {
    align-items: flex-end;
    justify-content: stretch;
  }

  .modal-overlay.active .modal {
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }

  .modal-overlay.active .modal {
    transform: translateY(0);
  }

  .modal-body {
    padding: 16px;
    gap: 12px;
  }

  .setting-group label {
    font-size: 11px;
  }

  .setting-group input,
  .setting-group select {
    font-size: 15px;
    padding: 10px 12px;
  }
}

/* === 辅助类 === */
.hidden { display: none !important; }

/* === 辅助类 === */
.hidden { display: none !important; }

/* === 酒馆氛围光效 === */
.chat-area::before {
  content: '';
  position: absolute;
  top: -50%;
  left: 50%;
  transform: translateX(-50%);
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, rgba(212, 175, 55, 0.08) 0%, transparent 70%);
  pointer-events: none;
}

/* === 移动端设置弹窗优化 === */
@media (max-width: 480px) {
  .topbar-right {
    opacity: 1 !important;
  }

  .modal-overlay {
    align-items: flex-end;
    justify-content: stretch;
  }

  .modal-overlay.active .modal {
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }

  .modal-overlay.active .modal {
    transform: translateY(0);
  }

  .modal-body {
    padding: 16px;
    gap: 12px;
  }

  .setting-group label {
    font-size: 11px;
  }

  .setting-group input,
  .setting-group select {
    font-size: 15px;
    padding: 10px 12px;
  }
}
