:root {
    --bg-color: #ffffff;
    --sidebar-bg: #f9f9f9;
    --border-color: #e5e5e5;
    --primary-color: #5D5FEF;
    --text-color: #333333;
    --text-secondary: #666666;
    --user-msg-bg: #f4f4f4;
    --ai-msg-bg: transparent;
    --input-bg: #ffffff;
    --card-bg: #ffffff;
    --hover-bg: #eee;
    --font-primary: 'DM Sans', sans-serif;
    --font-heading: 'Red Rose', serif;
}

[data-theme="dark"] {
    --bg-color: #1e1e1e;
    --sidebar-bg: #252526;
    --border-color: #3e3e3e;
    --primary-color: #7072f5;
    --text-color: #e0e0e0;
    --text-secondary: #a0a0a0;
    --user-msg-bg: #2d2d2d;
    --ai-msg-bg: transparent;
    --input-bg: #2d2d2d;
    --card-bg: #2d2d2d;
    --hover-bg: #333333;
}

[data-theme="dark"] .logo,
[data-theme="dark"] .mobile-logo {
    background-color: rgba(255, 255, 255, 0.9);
    padding: 4px 8px;
    border-radius: 6px;
}

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

body {
    font-family: var(--font-primary);
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px;
    transition: transform 0.3s ease;
}

.logo-area {
    margin-bottom: 30px;
}

.logo {
    height: 32px;
    margin-bottom: 20px;
    display: block;
}

/* New Chat Button */
.new-chat-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-color);
    transition: all 0.2s;
}

.new-chat-btn:hover {
    background: var(--hover-bg);
}

[data-theme="dark"] .new-chat-btn {
    border-color: #3e3e3e;
    color: #e0e0e0;
}

[data-theme="dark"] .new-chat-btn:hover {
    background: #333;
    color: #fff;
    border-color: #555;
}

.history-list {
    flex: 1;
    overflow-y: auto;
}

.history-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    display: block;
    padding: 0 5px;
}

.history-item {
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-color);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.history-item:hover {
    background: #eee;
}

.history-delete-btn {
    opacity: 0;
    background: none;
    border: none;
    color: #999;
    font-size: 16px;
    line-height: 1;
    padding: 0 5px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.history-item:hover .history-delete-btn {
    opacity: 1;
}

.history-delete-btn:hover {
    color: #ff4d4f;
}

.sidebar-footer {
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.avatar {
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-info {
    display: flex;
    flex-direction: column;
}

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

.user-info .status {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Main Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-color);
}

.mobile-header {
    display: none;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    justify-content: space-between;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 40px 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.message {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
    animation: fadeIn 0.3s ease;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    border: 1px solid #eee;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    flex: 1;
    line-height: 1.6;
    font-size: 16px;
}

.message-content h1 {
    font-family: var(--font-heading);
    font-size: 24px;
    margin-bottom: 10px;
}

.message-content p {
    margin-bottom: 15px;
}

/* User Message Style */
.user-message {
    flex-direction: row-reverse;
}

.user-message .message-content {
    background: var(--user-msg-bg);
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 80%;
    flex: unset;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

/* Theme Settings Button */
.theme-settings-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.theme-settings-btn:hover {
    background: var(--hover-bg);
    color: var(--text-color);
}

/* Theme Modal */
.theme-options {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
}

.theme-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.theme-option input {
    display: none;
}

.theme-preview {
    width: 80px;
    height: 80px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    transition: all 0.2s;
    background: var(--bg-color);
}

.theme-option input:checked + .theme-preview {
    border-color: var(--primary-color);
    background: rgba(93, 95, 239, 0.1);
}

.theme-option span {
    font-size: 14px;
    color: var(--text-color);
}

.action-btn {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-color);
    transition: all 0.2s;
}

.action-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: #f8f8ff;
}

/* Input Area */
.input-area {
    padding: 20px;
    background: var(--bg-color);
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.input-wrapper {
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--input-bg);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    padding: 10px 16px;
    display: flex;
    align-items: flex-end;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 2px 15px rgba(93, 95, 239, 0.1);
}

textarea {
    flex: 1;
    border: none;
    resize: none;
    padding: 8px 0;
    font-family: inherit;
    font-size: 16px;
    outline: none;
    max-height: 200px;
    background: transparent;
}

.send-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 10px;
    margin-bottom: 2px;
    transition: background 0.2s;
}

.send-btn:hover {
    background: #4a4cdb;
}

.disclaimer {
    text-align: center;
    font-size: 12px;
    color: #999;
    margin-top: 10px;
}

/* Widget Cards (Price, etc.) */
.widget-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-top: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.widget-title {
    font-weight: bold;
    margin-bottom: 15px;
    font-size: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.price-table {
    width: 100%;
    border-collapse: collapse;
}

.price-table th, .price-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.price-table th {
    color: #999;
    font-weight: 500;
    font-size: 12px;
}

.price-val {
    color: var(--primary-color);
    font-weight: bold;
}

/* Login Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.modal-container {
    background: var(--card-bg);
    border-radius: 16px;
    width: 400px;
    max-width: 90%;
    padding: 30px;
    position: relative;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    text-align: center;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
}

.login-content h2 {
    margin-bottom: 10px;
}

.qr-placeholder {
    margin: 0 auto;
    width: 180px;
    height: 180px;
    border: 1px solid #eee;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--sidebar-bg);
}

.wechat-login-btn {
    background: #07c160;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    cursor: pointer;
    font-weight: bold;
}

/* WeChat Login Container */
.wx-login-container {
    text-align: center;
    background: var(--card-bg);
    padding: 20px;
}

/* Ensure text inputs inherit text color */
input, textarea {
    color: var(--text-color);
}

textarea::placeholder {
    color: var(--text-secondary);
}

/* Scrollbar styling for dark mode */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.wx-iframe-mock {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 20px;
    display: inline-block;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.wx-iframe-mock h3 {
    font-size: 18px;
    margin-bottom: 20px;
    font-weight: 500;
}

/* Profile Edit & Logout */
.avatar-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    opacity: 0;
    transition: opacity 0.2s;
    cursor: pointer;
    border-radius: 50%;
}

.profile-avatar-large {
    position: relative; /* Ensure overlay positions correctly */
}

.profile-avatar-large:hover .avatar-overlay {
    opacity: 1;
}

.edit-icon-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
}

.edit-icon-btn:hover {
    color: #fff;
}

#userName[contenteditable="true"] {
    border-bottom: 1px solid #fff;
    outline: none;
    padding-right: 5px;
}

.logout-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background 0.2s;
    z-index: 10;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.3);
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 900;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 260px;
        transform: translateX(-100%);
        height: 100%;
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-header {
        display: flex;
    }
    
    .chat-container {
        padding: 20px 15px;
    }
    
    .mobile-logo {
        height: 24px;
    }
    
    .menu-btn {
        background: none;
        border: none;
        font-size: 24px;
        cursor: pointer;
        color: var(--text-color);
        padding: 0; /* Remove default padding */
    }

    [data-theme="dark"] .menu-btn {
        color: #fff; /* Explicitly white in dark mode */
    }

    /* Mobile Login Logic */
    .pc-login-view {
        display: none;
    }
    .mobile-login-view {
        display: block;
    }
}

/* History Item Styles (Global) */
.history-item.active {
    background: #eee;
    color: #333;
}

[data-theme="dark"] .history-item {
    color: #e0e0e0;
    border: 1px solid transparent;
}

[data-theme="dark"] .history-item:hover {
    background: #333;
    color: #fff;
    border-color: #555;
}

[data-theme="dark"] .history-item.active {
    background: #333;
    color: #fff;
    border-color: #555;
}
