/* ============================================================
   蓬湖汇 · AI 助手 样式
   独立 CSS 文件
   ============================================================ */

/* ===== CSS Variables ===== */
:root {
    --bg-body: #f6f8fa;
    --bg-app: #ffffff;
    --bg-sidebar: #fafbfc;
    --bg-input: #f1f3f5;
    --bg-message-user: #e8f0fe;
    --text-user: #1a1a2e;
    --text-ai: #1a1a2e;
    --bg-hover: #e9ecef;
    --bg-active: #e2e8f0;
    --bg-modal: rgba(0, 0, 0, 0.4);
    --bg-modal-content: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --border-color: #e9edf2;
    --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.08);
    --radius-md: 16px;
    --radius-sm: 10px;
    --radius-full: 9999px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    --transition: 0.25s ease;
    --chat-max-width: 720px;
}

[data-theme="dark"] {
    --bg-body: #0d1117;
    --bg-app: #161b22;
    --bg-sidebar: #0d1117;
    --bg-input: #21262d;
    --bg-message-user: #1c2a4a;
    --text-user: #e6edf3;
    --text-ai: #e6edf3;
    --bg-hover: #2d333b;
    --bg-active: #30363d;
    --bg-modal: rgba(0, 0, 0, 0.7);
    --bg-modal-content: #161b22;
    --text-primary: #e6edf3;
    --text-secondary: #b1bac4;
    --text-muted: #6e7681;
    --border-color: #30363d;
    --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.5);
}

/* ===== Reset ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-body);
    color: var(--text-primary);
    transition: background var(--transition), color var(--transition);
}

/* ===== App ===== */
#app {
    display: flex;
    height: 100vh;
    width: 100vw;
    background: var(--bg-app);
    transition: background var(--transition);
}

/* ===== Sidebar ===== */
#sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    padding: 20px 14px;
    transition: background var(--transition), border-color var(--transition);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 18px;
}
.logo-area .logo-icon {
    font-size: 24px;
}
.logo-area .logo-text {
    font-size: 1.05rem;
    font-weight: 650;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}
.logo-area .logo-text span {
    color: #007cba;
}

#new-chat-btn {
    width: 100%;
    padding: 9px 0;
    background: #007cba;
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--font);
}
#new-chat-btn:hover {
    background: #005a8c;
}
#new-chat-btn:active {
    transform: scale(0.97);
}

.history-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin-bottom: 10px;
    font-weight: 600;
}

#history-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    margin-bottom: 12px;
}
#history-list li {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 0.82rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 8px;
}
#history-list li:hover {
    background: var(--bg-hover);
}
#history-list li.active {
    background: var(--bg-active);
    color: #007cba;
    font-weight: 500;
}

#sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
#settings-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.78rem;
    transition: background 0.2s;
    width: 100%;
    font-family: var(--font);
}
#settings-btn:hover {
    background: var(--bg-hover);
}
.footer-links {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 0 4px;
}
.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}
.footer-links a:hover {
    color: #007cba;
}

/* ===== Main ===== */
#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-app);
    transition: background var(--transition);
}

#main-header {
    padding: 12px 28px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
#main-header h2 {
    font-size: 0.95rem;
    font-weight: 550;
    color: var(--text-primary);
}
.header-status {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}
.header-status .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    display: inline-block;
}

/* ===== Messages Container ===== */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px 12px;
    background: var(--bg-body);
    transition: background var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chat-area {
    width: 100%;
    max-width: var(--chat-max-width);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ===== Message ===== */
.message {
    display: flex;
    flex-direction: column;
    width: 100%;
    animation: fadeIn 0.25s ease;
}

.message.user {
    align-items: flex-end;
}
.message.ai {
    align-items: flex-start;
    width: 100%;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== 用户消息 - 气泡 ===== */
.message.user .bubble {
    background: var(--bg-message-user);
    color: var(--text-user);
    padding: 10px 16px;
    border-radius: 16px;
    border-top-right-radius: 4px;
    line-height: 1.7;
    font-size: 0.93rem;
    word-break: break-word;
    max-width: 80%;
    transition: background var(--transition), color var(--transition);
}

/* ===== AI 消息 - 无气泡，占满宽度 ===== */
.message.ai .bubble {
    background: transparent !important;
    color: var(--text-ai);
    padding: 0;
    border-radius: 0;
    line-height: 1.8;
    font-size: 0.95rem;
    word-break: break-word;
    width: 100%;
    transition: color var(--transition);
}

/* ===== Typing cursor ===== */
.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--text-primary);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 0.9s step-end infinite;
}
@keyframes blink {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0;
    }
}

/* ===== Input ===== */
#input-area {
    padding: 12px 28px 20px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--bg-app);
    transition: background var(--transition), border-color var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
}

#input-form {
    width: 100%;
    max-width: var(--chat-max-width);
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--bg-input);
    border-radius: var(--radius-full);
    padding: 4px 4px 4px 20px;
    border: 2px solid transparent;
    transition: border-color 0.2s, background var(--transition);
}
#input-form:focus-within {
    border-color: #007cba;
    background: var(--bg-app);
}
#user-input {
    flex: 1;
    padding: 13px 0;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    outline: none;
    font-family: var(--font);
    color: var(--text-primary);
}
#user-input::placeholder {
    color: var(--text-muted);
}
#send-btn {
    padding: 11px 26px;
    background: #007cba;
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    font-family: var(--font);
    white-space: nowrap;
}
#send-btn:hover {
    background: #005a8c;
}
#send-btn:active {
    transform: scale(0.96);
}
#send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
}

#status {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 8px;
    min-height: 18px;
    transition: color 0.2s;
    max-width: var(--chat-max-width);
    width: 100%;
}
#status.loading {
    color: #007cba;
}
#status.error {
    color: #dc3545;
}

/* ===== Scrollbar ===== */
#chat-messages::-webkit-scrollbar,
#history-list::-webkit-scrollbar {
    width: 4px;
}
#chat-messages::-webkit-scrollbar-thumb,
#history-list::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 10px;
}
#chat-messages::-webkit-scrollbar-track,
#history-list::-webkit-scrollbar-track {
    background: transparent;
}

/* ===== Settings Modal ===== */
#settings-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-modal);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeInOverlay 0.25s ease;
}
#settings-overlay.open {
    display: flex;
}
@keyframes fadeInOverlay {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

#settings-modal {
    background: var(--bg-modal-content);
    border-radius: var(--radius-md);
    padding: 24px 28px;
    max-width: 440px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    transition: background var(--transition);
    animation: slideUp 0.3s ease;
}
@keyframes slideUp {
    from {
        transform: translateY(16px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}
#settings-modal h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}
#settings-modal .subtitle {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 20px;
}

.setting-group {
    margin-bottom: 20px;
}
.setting-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.theme-options {
    display: flex;
    gap: 10px;
}
.theme-btn {
    flex: 1;
    padding: 8px 0;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
    font-family: var(--font);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.theme-btn:hover {
    border-color: #007cba;
}
.theme-btn.active {
    border-color: #007cba;
    background: rgba(0, 124, 186, 0.08);
    color: #007cba;
}

.setting-divider {
    height: 1px;
    background: var(--border-color);
    margin: 16px 0;
}

.about-content {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.8;
}
.about-content p {
    margin-bottom: 6px;
}
.about-content a {
    color: #007cba;
    text-decoration: none;
}
.about-content a:hover {
    text-decoration: underline;
}

#close-settings {
    margin-top: 16px;
    padding: 8px 0;
    width: 100%;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--bg-hover);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
    font-family: var(--font);
}
#close-settings:hover {
    background: var(--border-color);
}

/* ===== Responsive ===== */
@media (max-width: 720px) {
    #sidebar {
        display: none;
    }
    #main-header {
        padding: 10px 16px;
    }
    #chat-messages {
        padding: 14px 16px 8px;
    }
    #input-area {
        padding: 10px 16px 16px;
    }
    #input-form {
        padding-left: 14px;
    }
    #settings-modal {
        padding: 20px 16px;
    }
    :root {
        --chat-max-width: 100%;
    }
    .message.user .bubble {
        max-width: 92%;
    }
}