/* style.css */
:root {
    --bg-main: #212121;
    --bg-sidebar: #171717;
    --bg-input: #2f2f2f;
    --bg-hover: #2a2a2a;
    --bg-message-user: #2f2f2f;
    --bg-message-ai: transparent;

    --text-primary: #ececec;
    --text-secondary: #9b9b9b;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;

    --border-color: rgba(255, 255, 255, 0.1);

    --font-family: 'Inter', -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: #555 transparent;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #777;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* 应用根节点容器 */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
    z-index: 10;
    position: relative;
}

/* 侧边导航栏设定 */
.sidebar {
    width: 260px;
    background-color: rgba(23, 23, 23, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
}

.brand i {
    color: var(--accent);
    font-size: 1.5rem;
}

.brand-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background-color 0.2s;
    width: 100%;
    text-align: left;
}

.new-chat-btn:hover {
    background-color: var(--bg-hover);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-list::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 3px;
}

.chat-item {
    padding: 0.75rem;
    border-radius: 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-primary);
    transition: background-color 0.2s;
}

.chat-item i {
    font-size: 1.125rem;
    color: var(--text-secondary);
}

.chat-item:hover {
    background-color: var(--bg-hover);
}

.chat-item.active {
    background-color: rgba(47, 47, 47, 0.6);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-item .title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-item .del-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.chat-item:hover .del-btn {
    display: block;
}

.chat-item .del-btn:hover {
    color: #ef4444;
}


.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.settings-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    width: 100%;
    padding: 0.75rem;
    border-radius: 0.5rem;
    transition: background-color 0.2s;
    font-size: 0.875rem;
}

.settings-btn:hover {
    background-color: var(--bg-hover);
}

/* 核心交互区设定 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    max-width: 100%;
    min-width: 0;
}

.topbar {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background-color: rgba(33, 33, 33, 0.5);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 50;
}

.menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    margin-right: 1rem;
}

.current-chat-title {
    font-weight: 500;
}

/* 会话流容器设定 */
.chat-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding-bottom: 2rem;
    display: flex;
    flex-direction: column;
}

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    text-align: center;
}

.welcome-screen h1 {
    font-size: 2rem;
    margin-bottom: 2rem;
    font-weight: 600;
}

.preset-items {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
}

.preset-item {
    background: rgba(47, 47, 47, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    font-size: 0.95rem;
    padding: 0.875rem 1.25rem;
    border-radius: 1.2rem;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.preset-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--text-secondary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.preset-item:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.suggestion-cards {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 600px;
}

.card {
    background-color: rgba(47, 47, 47, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 1rem;
    border-radius: 1.2rem;
    cursor: pointer;
    transition: background-color 0.2s;
    text-align: left;
    width: 280px;
}

.card:hover {
    border-color: var(--text-secondary);
    background-color: var(--bg-hover);
}

.card p {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.card span {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.messages {
    display: flex;
    flex-direction: column;
    padding: 1rem 0;
}

.message {
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: center;
}

.message.user {
    background-color: transparent;
}

.message-inner {
    max-width: 800px;
    width: 100%;
    display: flex;
    gap: 1.5rem;
    line-height: 1.6;
}

.message.user .message-inner {
    flex-direction: row-reverse;
    text-align: right;
}

.message.user .message-actions {
    justify-content: flex-start;
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.2rem;
}

.avatar.user {
    background-color: transparent;
    overflow: hidden;
}

.avatar.ai {
    background-color: #10a37f;
}

.content {
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

/* 针对 Markdown 渲染内容的子元素选择排版 */
.content h1,
.content h2,
.content h3,
.content h4 {
    margin-bottom: 0.5rem;
    margin-top: 1rem;
}

.content p {
    margin-bottom: 1rem;
}

.content p:last-child {
    margin-bottom: 0;
}

/* 覆盖 Markdown 表格样式属性 */
.content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.9em;
    border: 1px solid var(--border-color);
}

.content th,
.content td {
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    text-align: left;
}

.content th {
    background-color: var(--bg-hover);
    font-weight: 600;
}

.content tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.02);
}

.code-block-wrapper {
    position: relative;
    display: grid;
    margin: 1rem 0;
}

.content pre {
    grid-area: 1 / 1;
    background: rgba(17, 17, 17, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 1rem;
    padding: 1rem;
    overflow-x: auto;
    margin: 0;
}

.content code {
    font-family: monospace;
    background: #444;
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
}

.content pre code {
    background: none;
    padding: 0;
}

.code-copy-btn-container {
    grid-area: 1 / 1;
    pointer-events: none;
    height: 100%;
}

/* 提取的代码复制动作按钮样式 */
.code-copy-btn {
    position: sticky;
    top: 0.5rem;
    float: right;
    margin: 0.5rem 0.5rem 0 0;
    pointer-events: auto;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-secondary);
    width: 30px;
    height: 30px;
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.875rem;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s, color 0.2s;
    z-index: 2;
}

.code-block-wrapper:hover .code-copy-btn {
    opacity: 1;
}

.code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.code-copy-btn.copied {
    color: #22c55e;
    opacity: 1;
}

.content ul,
.content ol {
    padding-left: 2rem;
    margin-bottom: 1rem;
}

/* 粘流式底部输入栏 */
.input-area {
    padding: 0 1rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(180deg, transparent, var(--bg-main) 60%);
}

.input-container {
    max-width: 800px;
    width: 100%;
    position: relative;
    background-color: rgba(47, 47, 47, 0.5);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: flex-end;
    padding: 0.75rem 1.25rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: border-color 0.3s, box-shadow 0.3s;
}

.input-container:focus-within {
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

textarea {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    max-height: 200px;
    outline: none;
    padding: 0;
    line-height: 1.5;
}

.send-btn {
    background: var(--accent);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.send-btn i {
    font-size: 1.125rem;
}

.send-btn .bx-stop {
    font-size: 1.5rem;
}

.send-btn:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

.send-btn:disabled {
    background: #555;
    cursor: not-allowed;
    opacity: 0.5;
}

.input-footer {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.75rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.copyright {
    opacity: 0.8;
}

/* 模态框通用解耦样式 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: rgba(33, 33, 33, 0.75);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    width: 100%;
    max-width: 450px;
    border-radius: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.close-btn:hover {
    color: white;
}

.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
}

.form-group input {
    background: rgba(47, 47, 47, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    outline: none;
    font-family: inherit;
}

.form-group input:focus {
    border-color: var(--accent);
}

.form-group small {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

.btn {
    padding: 0.75rem 1.25rem;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    font-weight: 500;
    font-family: inherit;
    transition: 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

/* 模拟原生表单的层叠下拉组件 */
.custom-select-wrapper {
    position: relative;
    user-select: none;
    flex: 1;
}

.custom-select-trigger {
    background: rgba(47, 47, 47, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-size: 0.875rem;
}

.custom-select-trigger:hover {
    border-color: var(--text-secondary);
}

.custom-options {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(33, 33, 33, 0.8);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.75rem;
    margin-top: 0.25rem;
    z-index: 10;
    max-height: 200px;
    overflow-y: auto;
    display: none;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.custom-options.open {
    display: block;
}

.custom-option {
    padding: 0.75rem;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
    transition: background-color 0.2s;
}

.custom-option:hover {
    background-color: var(--bg-hover);
}

.custom-option.selected {
    background-color: var(--accent);
    color: white;
}

/* 移动端媒体查询断点 */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100%;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 20px rgba(0, 0, 0, 0.5);
    }

    .menu-btn {
        display: block;
    }
}