:root {
    --bg: #FFFFFF;
    --bg-secondary: #F8F8F8;
    --sidebar-bg: #F5F5F5;
    --sidebar-hover: #EBEBEB;
    --sidebar-active: #E0E0E0;
    --text: #1A1A1A;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --border: #E5E5E5;
    --border-light: #F0F0F0;
    --accent: #2C2C2C;
    --accent-hover: #3D3D3D;
    --accent-light: #F5F5F5;
    --user-bubble: #F5F5F5;
    --assistant-bubble: transparent;
    --error: #DC2626;
    --error-bg: #FEF2F2;
    --success: #16A34A;
    --warning: #D97706;
    --thinking-bg: #FAFAFA;
    --thinking-border: #E5E5E5;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --sidebar-width: 280px;
    --sidebar-collapsed: 0px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
}

[data-theme="dark"] {
    --bg: #1A1A1A;
    --bg-secondary: #242424;
    --sidebar-bg: #1F1F1F;
    --sidebar-hover: #2A2A2A;
    --sidebar-active: #333333;
    --text: #F5F5F5;
    --text-secondary: #A0A0A0;
    --text-tertiary: #707070;
    --border: #333333;
    --border-light: #2A2A2A;
    --accent: #E0E0E0;
    --accent-hover: #CCCCCC;
    --accent-light: #2A2A2A;
    --user-bubble: #2A2A2A;
    --thinking-bg: #242424;
    --thinking-border: #333333;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background 0.3s, color 0.3s;
}

#app {
    display: flex;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, min-width 0.3s ease, transform 0.3s ease;
    overflow: hidden;
    position: relative;
    z-index: 100;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
}

.sidebar-header {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.logo-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    flex-shrink: 0;
}

.logo-fallback {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.logo-text {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--text);
}

.sidebar-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
    flex-shrink: 0;
    touch-action: manipulation;
}

.icon-btn:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

.icon-btn:active {
    transform: scale(0.95);
}

.sidebar-search {
    padding: 0 16px 12px;
    flex-shrink: 0;
}

.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.sidebar-search input:focus {
    border-color: var(--accent);
}

.sidebar-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0 12px;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 16px;
    font-family: var(--font);
}

.new-chat-btn:hover {
    background: var(--sidebar-hover);
    border-color: var(--text-tertiary);
}

.recent-label {
    font-size: 12px;
    color: var(--text-tertiary);
    padding: 0 8px 8px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.conversation-list::-webkit-scrollbar {
    width: 6px;
}

.conversation-list::-webkit-scrollbar-track {
    background: transparent;
}

.conversation-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.conversation-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.conv-item {
    display: flex;
    align-items: center;
    padding: 9px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 2px;
    position: relative;
    gap: 8px;
}

.conv-item:hover {
    background: var(--sidebar-hover);
}

.conv-item.active {
    background: var(--sidebar-active);
}

.conv-item-title {
    flex: 1;
    font-size: 14px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item-actions {
    display: none;
    gap: 2px;
    flex-shrink: 0;
}

.conv-item:hover .conv-item-actions {
    display: flex;
}

.conv-item-actions .icon-btn {
    padding: 4px;
}

.conv-item-actions .icon-btn svg {
    width: 14px;
    height: 14px;
}

.empty-state {
    text-align: center;
    color: var(--text-tertiary);
    font-size: 13px;
    padding: 24px 8px;
}

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

#logoutBtn {
    position: relative;
    z-index: 5;
    cursor: pointer;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: var(--radius-md);
    transition: background 0.2s;
}

.user-info:hover {
    background: var(--sidebar-hover);
}

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

.user-name {
    flex: 1;
    font-size: 14px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.auth-buttons {
    display: flex;
    gap: 8px;
}

.btn-login,
.btn-register {
    flex: 1;
    padding: 9px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
}

.btn-login {
    background: var(--accent);
    color: #fff;
    border: none;
}

.btn-login:hover {
    background: var(--accent-hover);
}

.btn-register {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-register:hover {
    background: var(--sidebar-hover);
    border-color: var(--text-tertiary);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: var(--bg);
}

.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.mobile-title {
    font-size: 16px;
    font-weight: 600;
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow-y: auto;
}

.welcome-content {
    width: 100%;
    max-width: 820px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 20px;
}

.greeting-text {
    font-size: 32px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 32px;
    text-align: center;
    transition: opacity 0.3s;
    letter-spacing: 0.5px;
}

.input-wrapper {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 16px 20px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow-sm);
}

#welcomeScreen .input-wrapper {
    padding: 22px 24px 16px;
    border-radius: var(--radius-lg);
}

#welcomeScreen .chat-input {
    min-height: 72px;
    font-size: 17px;
}

.input-wrapper:focus-within {
    border-color: var(--text-tertiary);
    box-shadow: var(--shadow-md);
}

.file-preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.file-preview-list:empty {
    display: none;
}

.file-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--sidebar-hover);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text);
    max-width: 240px;
}

.file-chip-icon {
    flex-shrink: 0;
    color: var(--text-secondary);
}

.file-chip-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.file-chip-size {
    color: var(--text-tertiary);
    font-size: 12px;
    flex-shrink: 0;
}

.file-chip-remove {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    border-radius: 4px;
    flex-shrink: 0;
}

.file-chip-remove:hover {
    color: var(--error);
    background: var(--error-bg);
}

.chat-input {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 17px;
    font-family: var(--font);
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 200px;
    overflow-y: auto;
}

.chat-input::placeholder {
    color: var(--text-tertiary);
}

.input-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    gap: 8px;
}

.input-left,
.input-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.upload-btn {
    padding: 6px;
}

.file-count {
    font-size: 12px;
    color: var(--text-tertiary);
    background: var(--sidebar-hover);
    padding: 2px 8px;
    border-radius: 10px;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
    max-width: 200px;
}

.model-selector:hover {
    background: var(--sidebar-hover);
    border-color: var(--text-tertiary);
}

.model-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.send-btn {
    background: var(--accent);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.15s;
    flex-shrink: 0;
    touch-action: manipulation;
}

.send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--text-tertiary);
    cursor: not-allowed;
    transform: none;
}

.send-btn svg {
    width: 18px;
    height: 18px;
}

.input-hint {
    text-align: center;
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 16px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.messages-list {
    max-width: 820px;
    margin: 0 auto;
    padding: 24px 24px 100px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.message-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    content-visibility: auto;
    contain-intrinsic-size: auto 200px;
}

.message-row {
    display: flex;
    gap: 16px;
}

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

.message-row.assistant {
    justify-content: flex-start;
}

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

.message-avatar.assistant {
    background: linear-gradient(135deg, var(--accent), #B85A3E);
}

.message-avatar.user {
    background: var(--text-secondary);
}

.message-bubble {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.7;
    word-break: break-word;
}

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

.message-row.assistant .message-bubble {
    background: transparent;
    border: none;
    border-bottom-left-radius: 4px;
    max-width: 80%;
    padding-left: 0;
    padding-right: 0;
}

.message-bubble p {
    margin-bottom: 8px;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4,
.message-bubble h5,
.message-bubble h6 {
    margin: 16px 0 8px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text);
}

.message-bubble h1 {
    font-size: 22px;
}

.message-bubble h2 {
    font-size: 20px;
}

.message-bubble h3 {
    font-size: 18px;
}

.message-bubble h4 {
    font-size: 16px;
}

.message-bubble h5 {
    font-size: 15px;
}

.message-bubble h6 {
    font-size: 14px;
    color: var(--text-secondary);
}

.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child,
.message-bubble h4:first-child,
.message-bubble h5:first-child,
.message-bubble h6:first-child {
    margin-top: 0;
}

.message-bubble code {
    font-family: var(--font-mono);
    font-size: 13px;
}

.message-bubble p>code {
    background: var(--sidebar-hover);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--text);
}

.message-bubble strong {
    font-weight: 600;
    color: var(--text);
}

.message-bubble mark {
    background: rgba(255, 213, 79, 0.35);
    color: var(--text);
    padding: 1px 4px;
    border-radius: 3px;
}

[data-theme="dark"] .message-bubble mark {
    background: rgba(255, 213, 79, 0.25);
}

.message-content strong,
.message-content em,
.message-content mark,
.message-content del,
.message-content p>code {
    cursor: pointer;
    border-radius: 3px;
    transition: background-color 0.15s ease;
}

.message-content strong:hover,
.message-content em:hover,
.message-content del:hover {
    background: var(--sidebar-hover);
}

.message-content mark:hover {
    background: rgba(255, 213, 79, 0.55);
}

.message-content p>code:hover {
    background: var(--sidebar-active);
}

.message-bubble hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

.message-content.error-message,
.message-content.error-message p,
.message-content.error-message li {
    color: var(--error);
}

.message-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 8px 0;
    display: block;
}

.code-block {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin: 10px 0;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    contain: layout style;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
    user-select: none;
}

.code-lang {
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.code-copy-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    transition: all 0.2s;
    position: relative;
    z-index: 2;
    touch-action: manipulation;
    pointer-events: auto;
}

.code-copy-btn:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

.code-copy-btn svg {
    width: 14px;
    height: 14px;
}

.code-body {
    display: flex;
    overflow-x: auto;
}

.line-numbers {
    flex-shrink: 0;
    padding: 12px 8px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    text-align: right;
    user-select: none;
    background-image: linear-gradient(rgba(128, 128, 128, 0.12) 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: -1px -1px;
}

.line-num {
    display: block;
    min-width: 20px;
}

.code-body pre {
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: 12px 14px;
    background: var(--bg);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    background-image:
        linear-gradient(rgba(128, 128, 128, 0.16) 1px, transparent 1px),
        linear-gradient(90deg, rgba(128, 128, 128, 0.16) 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: -1px -1px;
}

.code-body pre code {
    display: block;
    background: none;
    padding: 0;
}

.code-line {
    display: block;
    white-space: pre;
}

.message-bubble ul,
.message-bubble ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-bubble li {
    margin-bottom: 4px;
}

.message-bubble a {
    color: var(--accent);
    text-decoration: none;
}

.message-bubble a:hover {
    text-decoration: underline;
}

.message-bubble table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
}

.message-bubble th,
.message-bubble td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}

.message-bubble th {
    background: var(--sidebar-hover);
    font-weight: 600;
}

.message-bubble blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
}

.thinking-block {
    background: var(--thinking-bg);
    border: 1px solid var(--thinking-border);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    overflow: hidden;
}

.thinking-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    user-select: none;
    transition: background 0.2s;
}

.thinking-header:hover {
    background: var(--sidebar-hover);
}

.thinking-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.thinking-header .thinking-icon {
    animation: pulse 1.5s ease-in-out infinite;
}

.thinking-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.thinking-copy-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.thinking-copy-btn:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

.thinking-copy-btn svg {
    width: 14px;
    height: 14px;
}

.thinking-arrow {
    transition: transform 0.2s;
}

.thinking-header.collapsed .thinking-arrow {
    transform: rotate(-90deg);
}

.thinking-content {
    padding: 0 14px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
}

.thinking-content.collapsed {
    display: none;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

.message-files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.message-file-tag {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 12px;
    background: var(--sidebar-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.message-file-tag:hover {
    background: var(--sidebar-active);
    border-color: var(--text-tertiary);
}

.message-file-icon {
    flex-shrink: 0;
    color: var(--text-secondary);
    margin-top: 2px;
}

.message-file-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.message-file-name {
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}

.message-file-size {
    color: var(--text-tertiary);
    font-size: 12px;
    flex-shrink: 0;
}

.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message-group:hover .message-actions {
    opacity: 1;
}

.message-group.user-group .message-actions {
    justify-content: flex-end;
    margin-top: 8px;
}

.message-group.assistant-group .message-actions {
    justify-content: flex-start;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
    touch-action: manipulation;
}

.action-btn:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

.action-btn.liked {
    color: var(--success);
}

.action-btn.disliked {
    color: var(--error);
}

.action-btn svg {
    width: 16px;
    height: 16px;
}

.typing-cursor {
    display: inline-block;
    width: 8px;
    height: 16px;
    background: var(--accent);
    margin-left: 2px;
    animation: blink 1s step-end infinite;
    vertical-align: text-bottom;
    border-radius: 1px;
}

@keyframes blink {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 0;
}

.thinking-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: thinking-pulse 1.4s ease-in-out infinite;
}

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

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

.thinking-indicator span:nth-child(4) {
    animation-delay: 0.45s;
}

@keyframes thinking-pulse {

    0%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }
}

.bottom-input-area {
    flex-shrink: 0;
    padding: 12px 24px 20px;
    background: var(--bg);
    position: relative;
}

.bottom-input-area .input-wrapper {
    max-width: 820px;
    margin: 0 auto;
    border-radius: var(--radius-lg);
}

.scroll-btn-wrapper {
    max-width: 820px;
    margin: 0 auto 4px;
    display: flex;
    justify-content: center;
    position: relative;
}

.scroll-btn {
    position: absolute;
    bottom: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background-color 0.2s, color 0.2s, transform 0.15s;
    box-shadow: var(--shadow-sm);
    touch-action: manipulation;
    will-change: transform;
}

.scroll-btn:hover {
    background: var(--sidebar-hover);
    color: var(--text);
    transform: scale(1.1);
}

.scroll-btn.scroll-top svg {
    transform: rotate(180deg);
}

.model-dropdown {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    width: 320px;
    max-height: 360px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.model-search {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.model-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    outline: none;
}

.model-search input:focus {
    border-color: var(--accent);
}

.model-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.model-list::-webkit-scrollbar {
    width: 6px;
}

.model-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.model-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}

.model-item:hover {
    background: var(--sidebar-hover);
}

.model-item.selected {
    background: var(--accent-light);
}

.model-item-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    background: var(--sidebar-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    overflow: hidden;
}

.model-item-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.model-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 2px;
}

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

.model-item-meta {
    font-size: 10px;
    color: var(--text-tertiary);
    margin-top: 3px;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal {
    background: var(--bg);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s;
    overflow: hidden;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-sm {
    max-width: 360px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
}

.modal-close {
    padding: 4px;
}

.modal-body {
    padding: 20px 24px 24px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    color: var(--text);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: var(--font);
}

.form-group input:focus {
    border-color: var(--accent);
}

.form-error {
    color: var(--error);
    font-size: 13px;
    min-height: 18px;
    margin-bottom: 12px;
}

.btn-primary {
    width: 100%;
    padding: 11px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    font-family: var(--font);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    background: var(--text-tertiary);
    cursor: not-allowed;
}

.btn-secondary {
    padding: 9px 20px;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
}

.btn-secondary:hover {
    background: var(--sidebar-hover);
}

.btn-danger {
    padding: 9px 20px;
    background: var(--error);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    font-family: var(--font);
}

.btn-danger:hover {
    background: #B91C1C;
}

.modal-footer-link {
    text-align: center;
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}

.modal-footer-link a {
    color: var(--accent);
    text-decoration: none;
}

.modal-footer-link a:hover {
    text-decoration: underline;
}

.confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

#confirmText {
    font-size: 15px;
    color: var(--text);
    line-height: 1.6;
}

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 240px;
    max-width: 400px;
    animation: slideInRight 0.3s;
    pointer-events: auto;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success,
.toast.error,
.toast.warning,
.toast.info {
    border-left: none;
}

.toast-icon {
    flex-shrink: 0;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99;
    backdrop-filter: blur(2px);
}

.edit-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 15px;
    font-family: var(--font);
    outline: none;
    line-height: 1.6;
    resize: vertical;
    min-height: 60px;
}

.edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 8px;
}

@media (max-width: 1024px) {
    :root {
        --sidebar-width: 260px;
    }

    .messages-list {
        max-width: 100%;
        padding: 20px 20px 100px;
    }

    .bottom-input-area .input-wrapper {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 200;
        transform: translateX(-100%);
        width: 82vw;
        max-width: 300px;
        min-width: auto;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .mobile-header {
        display: flex;
    }

    .greeting-text {
        font-size: 26px;
        margin-bottom: 22px;
    }

    .welcome-content {
        max-width: 100%;
        padding-bottom: 16px;
    }

    .input-wrapper {
        border-radius: var(--radius-lg);
        padding: 12px 16px 10px;
    }

    #welcomeScreen .input-wrapper {
        padding: 16px 18px 12px;
    }

    #welcomeScreen .chat-input {
        min-height: 56px;
        font-size: 16px;
    }

    .chat-input {
        font-size: 16px;
    }

    .messages-list {
        padding: 16px 12px 100px;
        gap: 18px;
    }

    .message-bubble {
        max-width: 88%;
        font-size: 14px;
    }

    .message-row.assistant .message-bubble {
        max-width: 92%;
    }

    .message-row {
        gap: 10px;
    }

    .bottom-input-area {
        padding: 8px 12px 14px;
    }

    .model-dropdown {
        width: calc(100vw - 24px);
        max-width: 320px;
        max-height: 320px;
    }

    .input-hint {
        font-size: 11px;
    }

    .conv-item-actions {
        display: flex;
    }

    .message-actions {
        opacity: 1;
    }

    .message-file-name {
        max-width: 120px;
    }

    .code-body pre {
        padding: 10px 12px;
        font-size: 12px;
    }

    .line-numbers {
        padding: 10px 6px;
        font-size: 12px;
    }

    .scroll-btn {
        width: 34px;
        height: 34px;
    }

    .scroll-btn svg {
        width: 18px;
        height: 18px;
    }

    .toast-container {
        top: 12px;
        right: 12px;
        left: 12px;
    }

    .toast {
        min-width: 0;
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .greeting-text {
        font-size: 22px;
        margin-bottom: 18px;
    }

    .input-footer {
        flex-wrap: wrap;
        gap: 6px;
    }

    .model-selector {
        max-width: 130px;
        font-size: 12px;
        padding: 5px 10px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .welcome-screen {
        padding: 14px;
    }

    .input-wrapper {
        padding: 10px 14px 8px;
    }

    #welcomeScreen .input-wrapper {
        padding: 14px 16px 10px;
    }

    #welcomeScreen .chat-input {
        min-height: 48px;
        font-size: 15px;
    }

    .chat-input {
        font-size: 15px;
    }

    .messages-list {
        padding: 12px 10px 90px;
        gap: 14px;
    }

    .message-bubble {
        max-width: 90%;
        padding: 12px 14px;
    }

    .send-btn {
        width: 34px;
        height: 34px;
    }

    .send-btn svg {
        width: 16px;
        height: 16px;
    }

    .icon-btn {
        padding: 7px;
    }

    .new-chat-btn {
        padding: 9px 12px;
        font-size: 13px;
    }

    .modal {
        width: 94%;
        max-width: 360px;
    }

    .modal-header h2 {
        font-size: 18px;
    }

    .btn-primary {
        padding: 10px;
        font-size: 14px;
    }

    .code-header {
        padding: 6px 10px;
    }

    .code-copy-btn {
        padding: 3px 6px;
        font-size: 11px;
    }
}

@media (max-width: 360px) {
    .greeting-text {
        font-size: 20px;
    }

    .message-row {
        gap: 8px;
    }

    .message-avatar {
        width: 26px;
        height: 26px;
        font-size: 11px;
    }

    .input-left,
    .input-right {
        gap: 6px;
    }

    .model-selector {
        max-width: 110px;
    }
}

.sidebar.collapsed .sidebar-header,
.sidebar.collapsed .sidebar-body,
.sidebar.collapsed .sidebar-footer,
.sidebar.collapsed .sidebar-search {
    opacity: 0;
    pointer-events: none;
}

.sidebar-expand-btn {
    position: fixed;
    top: 14px;
    left: 8px;
    z-index: 90;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.sidebar-expand-btn:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

@media (max-width: 768px) {
    .sidebar-expand-btn {
        display: none !important;
    }
}

.login-required-overlay {
    position: absolute;
    inset: 0;
    background: rgba(250, 249, 245, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    border-radius: var(--radius-xl);
}

[data-theme="dark"] .login-required-overlay {
    background: rgba(31, 30, 29, 0.85);
}

.login-required-content {
    text-align: center;
    padding: 24px;
}

.login-required-content p {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.login-required-content .btn-primary {
    width: auto;
    padding: 10px 32px;
}

@media (min-width: 1400px) {
    .messages-list {
        max-width: 900px;
    }

    .bottom-input-area .input-wrapper {
        max-width: 900px;
    }

    .welcome-content {
        max-width: 900px;
    }

    .greeting-text {
        font-size: 34px;
    }
}

@media (min-width: 1800px) {
    .messages-list {
        max-width: 1000px;
    }

    .bottom-input-area .input-wrapper {
        max-width: 1000px;
    }

    .welcome-content {
        max-width: 1000px;
    }
}

.sidebar-footer {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.mobile-header {
    padding-top: max(10px, env(safe-area-inset-top));
}

.bottom-input-area {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.toast-container {
    top: max(20px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
}

.sidebar-expand-btn {
    top: max(14px, env(safe-area-inset-top));
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 900px) {
    .greeting-text {
        font-size: 22px;
        margin-bottom: 14px;
    }

    .welcome-content {
        padding-bottom: 10px;
    }

    #welcomeScreen .chat-input {
        min-height: 40px;
        font-size: 15px;
    }

    .messages-list {
        padding: 12px 16px 80px;
        gap: 12px;
    }

    .bottom-input-area {
        padding: 6px 16px 10px;
    }

    .message-bubble {
        font-size: 14px;
    }
}