:root {
  --bg-main: #2b2a27;
  --bg-sidebar: #1a1915;
  --bg-input: #393834;
  --bg-bubble: #3d3c37;
  --bg-hover: #35342f;
  --text-primary: #ececec;
  --text-secondary: #a8a29e;
  --text-hint: #6b6560;
  --border-subtle: rgba(255,255,255,0.06);
  --border-input: rgba(255,255,255,0.08);
  --accent: #D97757;
  --accent-light: #e8956f;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --sidebar-width: 280px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  font-family: 'Söhne', -apple-system, BlinkMacSystemFont, 'Helvetica Neue',
               'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, a { font-family: inherit; }

.app {
  display: flex;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* ========== Sidebar Overlay ========== */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.sidebar-overlay.active { opacity: 1; pointer-events: auto; }

/* ========== Sidebar ========== */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding-top: var(--safe-top);
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  height: 52px;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
}

.sidebar-brand .brand-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-brand .brand-icon svg { width: 24px; height: 24px; }

.sidebar-new-chat {
  width: 36px; height: 36px;
  border: none; background: none;
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  margin-left: auto;
}
.sidebar-new-chat:hover { background: var(--bg-hover); }
.sidebar-new-chat svg { width: 20px; height: 20px; }

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.sidebar-section-label {
  padding: 12px 12px 6px;
  font-size: 12px;
  color: var(--text-hint);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-item {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-hover); color: var(--text-primary); }

.sidebar-footer {
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.hub-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--text-hint);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
.hub-link:hover { background: var(--bg-hover); color: var(--text-secondary); }
.hub-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: #fff;
  flex-shrink: 0;
}

.user-name { font-size: 14px; color: var(--text-primary); }

/* ========== Main ========== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
}

/* ========== Top Bar ========== */
.topbar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  flex-shrink: 0;
  padding-top: var(--safe-top);
  position: relative;
  z-index: 10;
}

.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); }
.icon-btn svg { width: 22px; height: 22px; }

.model-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none; border: none;
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.model-selector:hover { background: var(--bg-hover); }
.model-selector svg { width: 14px; height: 14px; opacity: 0.5; flex-shrink: 0; }

/* ========== Chat Area ========== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

.messages {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-area.empty { justify-content: center; }
.chat-area.empty .messages { flex: 1; display: flex; }

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 8px;
}

.empty-icon { width: 36px; height: 36px; margin-bottom: 8px; }
.empty-icon svg { width: 36px; height: 36px; }

.empty-state h1 {
  font-size: 22px;
  font-weight: 500;
  color: var(--text-primary);
  text-align: center;
}

.empty-state p {
  font-size: 15px;
  color: var(--text-secondary);
  text-align: center;
}

/* ========== Messages ========== */
.message { animation: msgFadeIn 0.3s ease; }

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

.message-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 8px 0;
}

.message-bubble {
  background: var(--bg-bubble);
  border-radius: var(--radius-lg);
  padding: 10px 18px;
  max-width: 85%;
  font-size: 16px;
  line-height: 1.6;
  word-break: break-word;
  color: var(--text-primary);
}

.message-assistant {
  padding: 12px 0 16px;
}

.assistant-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.claude-icon {
  width: 24px; height: 24px;
  flex-shrink: 0;
}
.claude-icon svg { width: 24px; height: 24px; }

.assistant-content {
  font-size: 16px;
  line-height: 1.75;
  color: var(--text-primary);
}

.assistant-content p { margin-bottom: 14px; }
.assistant-content p:last-child { margin-bottom: 0; }

.assistant-content h4 {
  font-size: 16px;
  font-weight: 700;
  margin: 20px 0 8px;
  color: var(--text-primary);
}
.assistant-content h4:first-child { margin-top: 4px; }

.assistant-content ul { padding-left: 20px; margin-bottom: 14px; }
.assistant-content li { margin-bottom: 6px; color: var(--text-primary); line-height: 1.7; }

.assistant-actions {
  display: flex;
  gap: 2px;
  margin-top: 14px;
}

.msg-action-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  color: var(--text-hint);
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.msg-action-btn:hover { background: var(--bg-hover); color: var(--text-secondary); }
.msg-action-btn svg { width: 16px; height: 16px; }

.typing-dots {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}
.typing-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotBlink 1.4s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBlink {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

/* ========== Input Area ========== */
.input-area {
  padding: 0 12px;
  padding-bottom: calc(8px + var(--safe-bottom));
  flex-shrink: 0;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.input-container {
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-lg);
  padding: 0 16px;
  transition: border-color 0.15s;
}
.input-container:focus-within { border-color: rgba(255,255,255,0.16); }

.input-box {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 16px;
  font-family: inherit;
  line-height: 1.5;
  padding: 14px 0;
  outline: none;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
}
.input-box::placeholder { color: var(--text-hint); }

.input-toolbar {
  display: flex;
  align-items: center;
  padding: 0 0 10px;
  gap: 6px;
}

.tool-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: 1px solid var(--border-input);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.tool-btn:hover { background: var(--bg-hover); }
.tool-btn svg { width: 18px; height: 18px; }

.toolbar-spacer { flex: 1; }

.send-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, background 0.15s;
  background: var(--accent);
  color: #fff;
}
.send-btn:disabled { opacity: 0.3; cursor: default; }
.send-btn svg { width: 18px; height: 18px; }

.input-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-hint);
  padding: 8px 0 2px;
  line-height: 1.4;
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ========== Desktop ========== */
.sidebar-collapse-btn { display: none; }

@media (min-width: 768px) {
  .sidebar {
    position: relative;
    transform: none;
    border-right: 1px solid var(--border-subtle);
    width: 260px;
    flex-shrink: 0;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .sidebar-overlay { display: none; }
  .sidebar-collapse-btn { display: flex; }
  .topbar .menu-btn { display: none; }

  .app.sidebar-collapsed .sidebar { margin-left: -260px; }
  .app.sidebar-collapsed .topbar .menu-btn { display: flex; }

  .messages { padding: 8px 24px 24px; }
  .input-area { padding: 0 24px; padding-bottom: 16px; }
  .message-bubble { max-width: 70%; }
}
