:root {
    --bg-color: #1e1e2d;
    --text-color: #e0e0e0;
    --primary-color: #8d8df0;
    --user-bubble: #2d2d3d;
    --assistant-bubble: #252535;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --border-radius: 8px;
    --sidebar-width: 280px;
    --font-size-base: 1rem;
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --desktop-message-padding: 20px;
}

[data-theme="light"] {
    --bg-color: #ffffff;
    --text-color: #333333;
    --primary-color: #6e6edf;
    --user-bubble: #f0f0f0;
    --assistant-bubble: #f9f9f9;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    display: flex;
    flex-direction: column;
    font-size: var(--font-size-base);
    touch-action: pan-y;
    overflow: hidden;
}

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

/* ================= 侧边栏通用样式 ================= */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-color);
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    padding: 10px;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    overflow-y: auto;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 10px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background-color: var(--bg-color);
    z-index: 10;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    font-size: 1.2rem;
    margin-right: 10px;
    padding: 8px;
}

.new-chat-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
    flex-grow: 1;
}

.new-chat-btn:hover {
    background-color: #7a7ad8;
}

.conversation-list {
    flex-grow: 1;
    overflow-y: auto;
    padding-bottom: 10px;
}

.conversation-item {
    padding: 12px 10px;
    border-radius: var(--border-radius);
    margin-bottom: 5px;
    cursor: pointer;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.conversation-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.conversation-item.active {
    background-color: var(--primary-color);
    color: white;
}

.conversation-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
    transition: opacity 0.3s;
}

.conversation-time {
    font-size: 0.75rem;
    opacity: 0.7;
}

.conversation-preview {
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.8;
    transition: opacity 0.3s;
}

/* ================= 主内容区通用样式 ================= */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
    height: 100%;
    position: relative;
    transition: margin-left 0.3s ease;
}

.chat-header {
    padding: 12px 15px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background-color: var(--bg-color);
    z-index: 10;
}

.chat-title {
    font-weight: 600;
    font-size: 1.1rem;
    margin-left: 10px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-btn {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px;
}

.font-controls {
    position: absolute;
    right: 15px;
    top: 50px;
    background-color: var(--bg-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 10px;
    z-index: 20;
    display: none;
    flex-direction: column;
    gap: 5px;
}

.font-controls.show {
    display: flex;
}

.font-btn {
    padding: 5px 10px;
    border-radius: 4px;
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    text-align: left;
}

.font-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.model-params-controls {
    position: absolute;
    right: 15px;
    top: 50px;
    background-color: var(--bg-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 15px;
    z-index: 20;
    display: none;
    flex-direction: column;
    gap: 12px;
    width: 280px;
    max-width: 90vw;
}

.model-params-controls.show {
    display: flex;
}

.model-param-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.model-param-group label {
    font-size: 0.9rem;
    opacity: 0.9;
}

.model-param-group input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--assistant-bubble);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

.model-param-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

.model-param-group span {
    font-size: 0.85rem;
    text-align: right;
    opacity: 0.8;
}

.save-params-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
    margin-top: 5px;
}

.save-params-btn:hover {
    background-color: #7a7ad8;
}

/* ================= 聊天消息通用样式 ================= */
.chat-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px 15px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.message {
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease-out;
    position: relative;
    max-width: 90%;
}

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

.user-message {
    margin-left: auto;
}

.assistant-message {
    margin-right: auto;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    position: relative;
}

.user-message .message-bubble {
    background-color: var(--user-bubble);
    border-bottom-right-radius: 0;
}

.assistant-message .message-bubble {
    background-color: var(--assistant-bubble);
    border-bottom-left-radius: 0;
}

.message-content {
    line-height: 1.6;
    overflow-x: auto;
    position: relative;
}

.message-copy-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 4px;
    color: white;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 5;
}

.message-bubble:hover .message-copy-btn {
    opacity: 1;
}

.message-content pre {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    position: relative;
    max-height: 300px;
    transition: max-height 0.3s ease;
}

.message-content pre.collapsed {
    max-height: 100px;
    overflow: hidden;
}

.message-content pre .code-collapse-btn {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom, transparent, rgba(0,0,0,0.2));
    text-align: center;
    padding: 20px 0 5px;
    cursor: pointer;
    color: var(--text-color);
}

.message-content pre.collapsed .code-collapse-btn {
    background: rgba(0,0,0,0.1);
}

.message-content code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}

.copy-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 4px;
    color: white;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s;
}

pre:hover .copy-btn {
    opacity: 1;
}

.message-stats {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 8px;
    text-align: right;
    padding-right: 8px;
}

.reasoning-content {
    margin-bottom: 12px;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 6px;
}

.reasoning-header {
    font-weight: bold;
    margin-bottom: 6px;
    font-size: 0.85rem;
}

.reasoning-separator {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 10px 0;
}

/* ================= 模型切换器 ================= */
.model-switcher {
    display: flex;
    justify-content: center;
    padding: 10px;
    gap: 10px;
    background-color: var(--bg-color);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.model-btn {
    padding: 8px 16px;
    border-radius: var(--border-radius);
    background-color: var(--assistant-bubble);
    color: var(--text-color);
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    flex: 1;
    max-width: 200px;
    text-align: center;
}

.model-btn.active {
    background-color: var(--primary-color);
    color: white;
}

/* ================= 输入区域 ================= */
.input-container {
    padding: 15px;
    padding-bottom: calc(15px + var(--safe-area-inset-bottom));
    position: sticky;
    bottom: 0;
    background-color: var(--bg-color);
    z-index: 10;
}

.input-area {
    display: flex;
    align-items: center;
    background-color: var(--assistant-bubble);
    border-radius: var(--border-radius);
    padding: 8px 12px;
}

.message-input {
    flex-grow: 1;
    border: none;
    background: transparent;
    color: var(--text-color);
    padding: 10px;
    font-size: 1em;
    resize: none;
    max-height: 200px;
    outline: none;
    line-height: 1.5;
}

.button-group {
    display: flex;
    gap: 8px;
    margin-left: 8px;
}

.send-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    background-color: #7a7ad8;
}

.send-btn:disabled {
    background-color: #555;
    cursor: not-allowed;
}

.pause-btn {
    background-color: var(--assistant-bubble);
    color: var(--text-color);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

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

.pause-btn.active {
    background-color: var(--primary-color);
    color: white;
}

/* ================= 思考指示器 ================= */
.thinking-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    font-size: 14px;
    opacity: 1.0;
    display: none;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 120px;
    background-color: var(--assistant-bubble);
    padding: 5px 15px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    z-index: 5;
}

.thinking-indicator .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: var(--primary-color);
    border-radius: 50%;
    margin-right: 4px;
    opacity: 0.4;
    animation: typingAnimation 1.4s infinite ease-in-out;
}

.thinking-indicator .dot:nth-child(1) {
    animation-delay: 0s;
}

.thinking-indicator .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-indicator .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingAnimation {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-3px); opacity: 1; }
}

/* ================= 遮罩层 ================= */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 90;
    display: none;
}

/* ================= 流式消息特殊样式 ================= */
.message[data-streaming] pre {
    max-height: none !important;
    overflow: visible !important;
}

.message[data-streaming] .code-collapse-btn {
    display: none !important;
}

.message[data-streaming] .pending-code-block {
    background-color: rgba(0,0,0,0.1);
    border-left: 3px solid var(--primary-color);
    margin: 10px 0;
}

.message[data-streaming] .pending-code-header {
    color: var(--primary-color);
    font-weight: bold;
}

.message[data-streaming] {
    pointer-events: none;
}

.message[data-streaming] .message-copy-btn,
.message[data-streaming] .copy-btn {
    display: none;
}

/* ================= 代码高亮颜色配置 ================= */
.hljs {
  background: rgba(0, 0, 0, 0.2) !important;
  border-radius: 6px;
  padding: 1em !important;
}

:not(pre) > code {
  background: rgba(0, 0, 0, 0.1);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-size: 0.9em;
}

[data-theme="dark"] {
  --hljs-keyword: #ff7b72;
  --hljs-built_in: #79c0ff;
  --hljs-type: #d2a8ff;
  --hljs-literal: #ffa657;
  --hljs-string: #a5d6ff;
  --hljs-number: #79c0ff;
  --hljs-comment: #8b949e;
}

[data-theme="light"] {
  --hljs-keyword: #d73a49;
  --hljs-built_in: #6f42c1;
  --hljs-type: #005cc5;
  --hljs-literal: #e36209;
  --hljs-string: #032f62;
  --hljs-number: #005cc5;
  --hljs-comment: #6a737d;
}

.hljs-keyword       { color: var(--hljs-keyword) !important; }
.hljs-built_in      { color: var(--hljs-built_in) !important; }
.hljs-type          { color: var(--hljs-type) !important; }
.hljs-literal       { color: var(--hljs-literal) !important; }
.hljs-string        { color: var(--hljs-string) !important; }
.hljs-number        { color: var(--hljs-number) !important; }
.hljs-comment       { color: var(--hljs-comment) !important; }
.hljs-title         { color: var(--primary-color) !important; }
.hljs-attr          { color: var(--text-color) !important; opacity: 0.9; }
.hljs-tag           { color: var(--hljs-keyword) !important; }
.hljs-meta          { color: var(--hljs-literal) !important; }
.hljs-attribute     { color: var(--hljs-built_in) !important; }

/* ================= 桌面端专属样式 ================= */
@media (min-width: 769px) {
  .main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
  }

  .chat-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px 15px;
  }

  .message {
    max-width: calc(100% - 40px);
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .input-area {
    max-width: 800px;
    margin: 0 auto !important;
  }

  .sidebar {
    position: relative;
    transform: translateX(0);
    box-shadow: none;
  }

  .sidebar.collapsed {
    width: 0px;
  }

  .sidebar.collapsed .conversation-item > *:not(.sidebar-toggle) {
    opacity: 0;
  }

  .sidebar.collapsed .conversation-item {
    align-items: center;
    padding: 12px 5px;
  }

  .sidebar.collapsed .sidebar-toggle {
    margin-right: 0;
  }

  .sidebar.collapsed .new-chat-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .sidebar.collapsed .new-chat-btn span {
    display: none;
  }

  .sidebar.collapsed .new-chat-btn i {
    margin-right: 0;
  }

  .overlay {
    display: none !important;
  }
}

/* ================= 移动端专属样式 ================= */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 260px;
    --font-size-base: 0.95rem;
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
  }
  
  .sidebar.collapsed {
    transform: translateX(-100%);
  }
  
  .sidebar:not(.collapsed) {
    transform: translateX(0);
  }
  
  .overlay {
    display: block;
  }
  
  .message {
    max-width: 90%;
  }

  .header-controls {
    gap: 10px;
  }

  .chat-title {
    font-size: 1rem;
  }

  .sidebar-toggle, .header-btn {
    padding: 6px;
  }

  .chat-container {
    padding-bottom: 80px;
  }

  .input-area {
    margin: 0;
  }

  .thinking-indicator {
    bottom: 70px;
  }

  .model-switcher {
    padding: 8px;
  }

  .model-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
  }
}

@media (max-width: 480px) {
  :root {
    --font-size-base: 0.9rem;
  }

  .chat-container {
    padding: 15px;
    padding-bottom: 80px;
  }

  .message-bubble {
    padding: 10px 14px;
  }

  .input-container {
    padding: 10px;
    padding-bottom: calc(10px + var(--safe-area-inset-bottom));
  }

  .model-btn {
    padding: 5px 10px;
    font-size: 0.8rem;
  }

  .button-group {
    gap: 5px;
  }

  .send-btn, .pause-btn {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }

  .model-params-controls {
    width: 260px;
    right: 10px;
  }
}