/* ===== CSS Variables & Theme System ===== */
:root {
    --bg-primary: #FFFFFF;
    --bg-secondary: #F7F7F8;
    --bg-tertiary: #EFEFF1;
    --text-primary: #1F1F1F;
    --text-secondary: #6B6B6B;
    --text-tertiary: #9E9EA1;
    --border-color: #E5E5E7;
    --accent-color: #4D5BFF;
    --accent-hover: #3D4AE6;
    --user-bubble: #4D5BFF;
    --user-text: #FFFFFF;
    --assistant-bubble: #F7F7F8;
    --assistant-text: #1F1F1F;
    --sidebar-bg: #FFFFFF;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --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;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-primary: #0F0F0F;
    --bg-secondary: #1A1A1B;
    --bg-tertiary: #27272A;
    --text-primary: #F4F4F5;
    --text-secondary: #A1A1AA;
    --text-tertiary: #71717A;
    --border-color: #27272A;
    --accent-color: #6366F1;
    --accent-hover: #818CF8;
    --user-bubble: #6366F1;
    --user-text: #FFFFFF;
    --assistant-bubble: #1A1A1B;
    --assistant-text: #F4F4F5;
    --sidebar-bg: #1A1A1B;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.5;
    transition: background-color var(--transition-normal), color var(--transition-normal);
    overflow: hidden;
}

body {
    position: relative;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ===== SVIP Gold Shimmer Effect ===== */
.svip-shimmer {
    background: linear-gradient(
        90deg,
        #FFD700 0%,
        #FFF8DC 25%,
        #FFD700 50%,
        #FFF8DC 75%,
        #FFD700 100%
    );
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 3s linear infinite;
    font-weight: 600;
}

.svip-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #1a1a1a;
    position: relative;
    overflow: hidden;
}

.svip-badge::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.6),
        transparent
    );
    animation: badgeShine 2s ease-in-out infinite;
}

@keyframes shimmer {
    0% { background-position: 0% center; }
    100% { background-position: 200% center; }
}

@keyframes badgeShine {
    0% { left: -100%; }
    50% { left: 100%; }
    100% { left: 100%; }
}

/* ===== Sidebar ===== */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background-color: var(--sidebar-bg);
    z-index: 999;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

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

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: background-color var(--transition-fast);
}

.sidebar-user:hover {
    background-color: var(--bg-secondary);
}

.sidebar-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-color), #8B5CF6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-username {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.sidebar-new-chat {
    padding: 12px 16px;
}

.new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition-fast);
}

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

.new-chat-btn:active {
    transform: scale(0.98);
}

.sidebar-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px 8px;
}

.history-section-title {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background-color var(--transition-fast);
    position: relative;
    margin-bottom: 2px;
}

.history-item:hover {
    background-color: var(--bg-secondary);
}

.history-item.active {
    background-color: var(--bg-tertiary);
    font-weight: 500;
}

.history-item .delete-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 16px;
    transition: opacity var(--transition-fast);
}

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

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-footer-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    transition: background-color var(--transition-fast);
}

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

.sidebar-footer-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ===== Header ===== */
.header {
    height: 56px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    position: relative;
    z-index: 100;
    transition: background-color var(--transition-normal);
}

.menu-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    transition: background-color var(--transition-fast);
}

.menu-btn:hover {
    background-color: var(--bg-secondary);
}

.menu-btn svg {
    width: 22px;
    height: 22px;
}

.header-title {
    flex: 1;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-right {
    width: 40px;
    display: flex;
    justify-content: flex-end;
}

/* ===== Chat Container ===== */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar {
    width: 4px;
}

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

.chat-container::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 2px;
}

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px 20px;
}

.welcome-logo {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--accent-color), #8B5CF6);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    box-shadow: var(--shadow-lg);
}

.welcome-logo svg {
    width: 32px;
    height: 32px;
    color: white;
}

.welcome-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.welcome-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.suggestion-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
    max-width: 400px;
}

.suggestion-card {
    padding: 16px;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
    border: 1px solid transparent;
}

.suggestion-card:hover {
    background-color: var(--bg-tertiary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.suggestion-card:active {
    transform: translateY(0);
}

.suggestion-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.suggestion-desc {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ===== Messages ===== */
.message-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 768px;
    margin: 0 auto;
}

.message {
    display: flex;
    gap: 12px;
    animation: messageIn 0.3s ease;
}

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

.message.user {
    flex-direction: row-reverse;
}

.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;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--accent-color), #8B5CF6);
    color: white;
}

.message.assistant .message-avatar {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.message-content {
    max-width: calc(100% - 44px);
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

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

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

.message-bubble code {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: "SF Mono", Monaco, Menlo, monospace;
    font-size: 13px;
}

.message.user .message-bubble code {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-tertiary);
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ===== Input Area ===== */
.input-area {
    padding: 12px 16px 20px;
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    transition: background-color var(--transition-normal);
}

.input-wrapper {
    max-width: 768px;
    margin: 0 auto;
    position: relative;
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-xl);
    padding: 8px 8px 8px 16px;
    border: 1px solid var(--border-color);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-container:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(77, 91, 255, 0.1);
}

textarea {
    flex: 1;
    border: none;
    background: none;
    resize: none;
    font-size: 15px;
    font-family: inherit;
    color: var(--text-primary);
    outline: none;
    max-height: 120px;
    min-height: 24px;
    line-height: 1.5;
    padding: 4px 0;
}

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

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

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

.send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

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

/* ===== Auth Pages ===== */
.auth-container {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background-color: var(--bg-primary);
    border-radius: var(--radius-xl);
    padding: 32px 24px;
    box-shadow: var(--shadow-lg);
}

.auth-logo {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent-color), #8B5CF6);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.auth-logo svg {
    width: 28px;
    height: 28px;
    color: white;
}

.auth-title {
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.auth-subtitle {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 28px;
}

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

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

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 15px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(77, 91, 255, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-md);
    background-color: var(--accent-color);
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-top: 8px;
}

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

.btn-primary:active {
    transform: scale(0.98);
}

.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-secondary);
}

.auth-switch a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
}

.auth-error {
    padding: 12px;
    background-color: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: var(--radius-md);
    color: #DC2626;
    font-size: 14px;
    margin-bottom: 16px;
    text-align: center;
}

[data-theme="dark"] .auth-error {
    background-color: rgba(220, 38, 38, 0.1);
    border-color: rgba(220, 38, 38, 0.3);
    color: #FCA5A5;
}

/* ===== Profile Page ===== */
.profile-page {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
}

.profile-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 0;
    text-align: center;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-color), #8B5CF6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 32px;
    font-weight: 600;
    margin-bottom: 16px;
    box-shadow: var(--shadow-md);
}

.profile-name {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
}

.profile-role-badge {
    margin-top: 8px;
}

.profile-stats {
    display: flex;
    justify-content: center;
    gap: 32px;
    padding: 20px 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    margin: 20px 0;
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.settings-section {
    margin-bottom: 24px;
}

.settings-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    padding: 0 4px;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.settings-item:hover {
    background-color: var(--bg-tertiary);
}

.settings-label {
    font-size: 15px;
    color: var(--text-primary);
}

.settings-value {
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Theme toggle switch */
.theme-toggle {
    display: flex;
    gap: 4px;
    padding: 4px;
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.theme-option {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-secondary);
}

.theme-option.active {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* ===== Utility Classes ===== */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.slide-up {
    animation: slideUp 0.3s ease;
}

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

/* ===== Responsive ===== */
@media (min-width: 768px) {
    .sidebar {
        width: 320px;
    }
    
    .suggestion-cards {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 480px) {
    .chat-container {
        padding: 16px 12px;
    }
    
    .message-bubble {
        padding: 10px 14px;
        font-size: 14px;
    }
    
    .input-area {
        padding: 10px 12px 16px;
    }
}

/* ===== Additional Optimizations ===== */

/* Better sidebar transition */
.sidebar {
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .sidebar {
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
}

/* Smooth message appearance */
.message {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Input focus enhancement */
.input-container {
    transition: all 0.2s ease;
}

/* Button press effect */
button:active {
    transform: scale(0.97);
}

/* History item hover smooth */
.history-item {
    transition: all 0.15s ease;
}

/* Settings item hover */
.settings-item {
    transition: background-color 0.15s ease;
}

/* Theme option smooth */
.theme-option {
    transition: all 0.15s ease;
    user-select: none;
}

/* Auth card entrance animation */
.slide-up {
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* Fade in animation */
.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* SVIP badge enhanced glow */
.svip-badge {
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

/* Scrollbar styling */
.chat-container::-webkit-scrollbar {
    width: 4px;
}

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

.chat-container::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 2px;
    opacity: 0.5;
}

.sidebar-history::-webkit-scrollbar {
    width: 4px;
}

.sidebar-history::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-history::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 2px;
}

/* Profile page stats animation */
.stat-value {
    transition: transform 0.2s ease;
}

/* Welcome screen elements */
.welcome-logo {
    animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Send button disabled state */
.send-btn:disabled {
    cursor: not-allowed;
    transform: none !important;
}

/* Textarea smooth resize */
textarea {
    transition: height 0.1s ease;
}

/* Mobile optimizations */
@media (max-width: 380px) {
    .welcome-title {
        font-size: 20px;
    }
    
    .message-bubble {
        font-size: 14px;
        padding: 10px 12px;
    }
    
    .sidebar {
        width: 260px;
    }
}

/* Ensure proper height */
html, body, #app, #mainApp {
    height: 100%;
    overflow: hidden;
}

#chatPage, #profilePage {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Fix hidden class specificity */
.hidden {
    display: none !important;
}


/* ===== Admin Blue V Badge ===== */
.admin-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 6px;
    vertical-align: middle;
}

.admin-badge svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    filter: drop-shadow(0 1px 2px rgba(83, 150, 255, 0.3));
}

.admin-badge-text {
    font-size: 11px;
    color: #5396FF;
    font-weight: 600;
    white-space: nowrap;
}

/* Sidebar username with admin badge */
.sidebar-username {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

/* Profile name with badges */
.profile-name {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.profile-role-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

/* Dark mode admin badge */
[data-theme="dark"] .admin-badge-text {
    color: #6BA8FF;
}

[data-theme="dark"] .admin-badge svg {
    filter: drop-shadow(0 1px 2px rgba(83, 150, 255, 0.4));
}


/* ===== Voice Input ===== */

/* Input actions container */
.input-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* Mic button */
.mic-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
    padding: 0;
    flex-shrink: 0;
}

.mic-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

.mic-icon {
    width: 18px;
    height: 18px;
}

/* Recording state */
.mic-btn.recording {
    background: #EF4444;
    color: white;
    animation: micPulse 1.5s ease-in-out infinite;
}

.mic-btn.recording:hover {
    background: #DC2626;
    color: white;
}

@keyframes micPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }
}

/* Mic wave (inside button, hidden by default) */
.mic-wave {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    gap: 2px;
}

.mic-btn.recording .mic-icon {
    display: none;
}

.mic-btn.recording .mic-wave {
    display: flex;
}

.mic-wave span {
    display: block;
    width: 2px;
    height: 10px;
    background: white;
    border-radius: 1px;
    animation: micWaveBar 0.8s ease-in-out infinite;
}

.mic-wave span:nth-child(1) { animation-delay: 0s; }
.mic-wave span:nth-child(2) { animation-delay: 0.2s; }
.mic-wave span:nth-child(3) { animation-delay: 0.4s; }

@keyframes micWaveBar {
    0%, 100% { height: 6px; }
    50% { height: 12px; }
}

/* Voice indicator bar */
.voice-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-radius: 12px;
    margin-top: 8px;
    border: 1px solid var(--border-color);
    animation: slideDown 0.3s ease;
}

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

.voice-wave {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 24px;
}

.voice-wave span {
    display: block;
    width: 3px;
    background: #EF4444;
    border-radius: 2px;
    animation: voiceWave 1s ease-in-out infinite;
}

.voice-wave span:nth-child(1) { animation-delay: 0s; height: 8px; }
.voice-wave span:nth-child(2) { animation-delay: 0.1s; height: 14px; }
.voice-wave span:nth-child(3) { animation-delay: 0.2s; height: 20px; }
.voice-wave span:nth-child(4) { animation-delay: 0.3s; height: 14px; }
.voice-wave span:nth-child(5) { animation-delay: 0.4s; height: 8px; }

@keyframes voiceWave {
    0%, 100% { transform: scaleY(0.6); }
    50% { transform: scaleY(1); }
}

.voice-text {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}

.voice-stop-btn {
    padding: 6px 14px;
    background: #EF4444;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.voice-stop-btn:hover {
    background: #DC2626;
}

.voice-stop-btn:active {
    transform: scale(0.97);
}

/* Dark mode adjustments */
[data-theme="dark"] .voice-indicator {
    background: var(--bg-tertiary);
}

/* Send button adjust for new layout */
.send-btn {
    width: 32px;
    height: 32px;
}

/* Mobile optimizations */
@media (max-width: 480px) {
    .voice-text {
        font-size: 13px;
    }
    
    .voice-stop-btn {
        padding: 5px 12px;
        font-size: 12px;
    }
}


/* ===== Logo Images ===== */
.auth-logo img {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 14px;
}

.welcome-logo img {
    width: 64px;
    height: 64px;
    object-fit: contain;
    border-radius: 16px;
}

/* Sidebar brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 8px;
}

.sidebar-brand img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 8px;
}

.sidebar-brand span {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
}


/* ===== Image Cropper Modal ===== */
.cropper-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.cropper-container {
    background: var(--bg-primary);
    border-radius: 16px;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: scaleIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

.cropper-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.cropper-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.15s;
}

.cropper-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.cropper-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cropper-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    touch-action: none;
    user-select: none;
}

#cropperCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.cropper-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.cropper-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70%;
    aspect-ratio: 1;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.cropper-preview {
    display: flex;
    align-items: center;
    gap: 16px;
}

.preview-label {
    font-size: 13px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.preview-circle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

#previewCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.cropper-controls {
    padding: 16px 20px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cropper-zoom {
    display: flex;
    align-items: center;
    gap: 12px;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.zoom-btn:hover {
    background: var(--bg-tertiary);
}

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

#zoomSlider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 2px;
    outline: none;
}

#zoomSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-color, #4F46E5);
    cursor: pointer;
}

.cropper-actions {
    display: flex;
    gap: 12px;
}

.cropper-actions button {
    flex: 1;
    padding: 12px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

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

.btn-primary {
    background: var(--accent-color, #4F46E5);
    color: white;
}

.btn-primary:hover {
    filter: brightness(1.1);
}

/* Register avatar */
.register-avatar {
    display: flex;
    justify-content: center;
}

.register-avatar-preview {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 2px dashed var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s;
    font-size: 12px;
    color: var(--text-secondary);
}

.register-avatar-preview:hover {
    border-color: var(--accent-color, #4F46E5);
    color: var(--accent-color, #4F46E5);
}

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

/* Profile avatar clickable */
.profile-avatar {
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
    overflow: hidden;
}

.profile-avatar:hover {
    transform: scale(1.05);
}

.profile-avatar::after {
    content: '更换';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 11px;
    text-align: center;
    padding: 4px 0;
    opacity: 0;
    transition: opacity 0.2s;
}

.profile-avatar:hover::after {
    opacity: 1;
}

/* Avatar images in messages */
.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.sidebar-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}


/* ===== Redesigned Voice Input ===== */

/* Input mode container */
.input-mode {
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.input-mode.hidden {
    display: none;
}

/* Mic toggle button (text mode) */
.mic-toggle-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #B5B5B5;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    flex-shrink: 0;
}

.mic-toggle-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

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

[data-theme="dark"] .mic-toggle-btn {
    color: #6B7280;
}

[data-theme="dark"] .mic-toggle-btn:hover {
    color: #9CA3AF;
}

/* Voice Mode Panel */
.voice-mode {
    width: 100%;
}

.voice-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px 20px;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.voice-mic-area {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
}

.voice-mic-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #B5B5B5;
    transition: all 0.2s ease;
    z-index: 2;
}

[data-theme="dark"] .voice-mic-icon {
    color: #6B7280;
    background: var(--bg-tertiary);
}

/* Recording state */
.voice-panel.recording .voice-mic-icon {
    background: #EF4444;
    color: white;
    transform: scale(1.1);
}

/* Cancel state (slide up) */
.voice-panel.canceling .voice-mic-icon {
    background: #6B7280;
    color: white;
    transform: scale(0.95);
}

/* Voice waves */
.voice-waves {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 3px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.voice-panel.recording .voice-waves {
    opacity: 1;
}

.voice-waves span {
    display: block;
    width: 4px;
    height: 16px;
    background: rgba(239, 68, 68, 0.6);
    border-radius: 2px;
    animation: voiceWaveAnim 1s ease-in-out infinite;
}

.voice-waves span:nth-child(1) { animation-delay: 0s; height: 10px; }
.voice-waves span:nth-child(2) { animation-delay: 0.1s; height: 16px; }
.voice-waves span:nth-child(3) { animation-delay: 0.2s; height: 24px; }
.voice-waves span:nth-child(4) { animation-delay: 0.3s; height: 30px; }
.voice-waves span:nth-child(5) { animation-delay: 0.4s; height: 24px; }
.voice-waves span:nth-child(6) { animation-delay: 0.5s; height: 16px; }
.voice-waves span:nth-child(7) { animation-delay: 0.6s; height: 10px; }

@keyframes voiceWaveAnim {
    0%, 100% { transform: scaleY(0.5); opacity: 0.4; }
    50% { transform: scaleY(1.2); opacity: 1; }
}

/* Pulse ring effect when recording */
.voice-panel.recording .voice-mic-icon::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.3);
    animation: micPulseRing 1.5s ease-out infinite;
    z-index: -1;
}

@keyframes micPulseRing {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.6;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.8);
        opacity: 0;
    }
}

/* Voice hint text */
.voice-hint {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    transition: all 0.2s ease;
}

.voice-panel.recording .voice-hint {
    color: #EF4444;
}

.voice-panel.canceling .voice-hint {
    display: none;
}

/* Cancel hint */
.voice-cancel-hint {
    font-size: 14px;
    color: #6B7280;
    font-weight: 500;
    display: none;
    transition: all 0.2s ease;
}

.voice-panel.canceling .voice-cancel-hint {
    display: block;
}

/* Keyboard button (switch back to text) */
.keyboard-btn {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
}

.keyboard-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

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

/* Voice mode positioning */
.voice-mode {
    position: relative;
}

/* Smooth mode transition */
.text-mode {
    animation: fadeSlideUp 0.25s ease;
}

.voice-mode {
    animation: fadeSlideUp 0.25s ease;
}

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

/* Adjust input container for new layout */
.input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

/* Send button adjust */
.send-btn {
    margin-bottom: 4px;
}

/* Mobile optimizations */
@media (max-width: 480px) {
    .voice-mic-area {
        width: 70px;
        height: 70px;
    }
    
    .voice-mic-icon {
        width: 56px;
        height: 56px;
    }
    
    .voice-mic-icon svg {
        width: 40px;
        height: 40px;
    }
    
    .voice-hint, .voice-cancel-hint {
        font-size: 13px;
    }
}


/* ===== Profile Stats (4-column grid) ===== */
.profile-stats {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 12px !important;
    padding: 16px 20px !important;
    background: var(--bg-secondary) !important;
    border-radius: 12px !important;
    margin: 0 20px 16px !important;
    border: none !important;
    border-top: none !important;
    border-bottom: none !important;
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 18px !important;
    font-weight: 700 !important;
    color: var(--text-primary) !important;
    margin-bottom: 4px !important;
}

.stat-label {
    font-size: 12px !important;
    color: var(--text-secondary) !important;
    margin-top: 4px !important;
}

@media (max-width: 480px) {
    .profile-stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px !important;
    }
    
    .stat-value {
        font-size: 16px !important;
    }
}


/* ===== Copyright Footer ===== */
.auth-copyright {
    margin-top: 24px;
    text-align: center;
    font-size: 11px;
    line-height: 1.8;
    color: #999;
    pointer-events: none;
}

.auth-copyright p {
    margin: 0;
    padding: 0;
}

[data-theme="dark"] .auth-copyright {
    color: #666;
}

.profile-copyright {
    margin-top: auto;
    padding: 20px;
    text-align: center;
    font-size: 11px;
    line-height: 1.8;
    color: #999;
    border-top: 1px solid var(--border-color);
}

.profile-copyright p {
    margin: 0;
    padding: 0;
}

[data-theme="dark"] .profile-copyright {
    color: #666;
}


/* ===== Global Image Fix ===== */
img {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

/* Ensure logo images have fixed sizes */
.auth-logo {
    width: 64px !important;
    height: 64px !important;
    overflow: hidden;
}

.auth-logo img {
    width: 64px !important;
    height: 64px !important;
    object-fit: contain;
}

.welcome-logo {
    width: 72px !important;
    height: 72px !important;
    overflow: hidden;
}

.welcome-logo img {
    width: 72px !important;
    height: 72px !important;
    object-fit: contain;
}

.sidebar-brand img {
    width: 32px !important;
    height: 32px !important;
    flex-shrink: 0;
}

/* Message avatar images */
.message-avatar {
    overflow: hidden;
}

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


/* Ensure mic button is clickable */
.mic-toggle-btn {
    position: relative;
    z-index: 10;
    cursor: pointer;
    pointer-events: auto;
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    z-index: 5;
}

.input-container {
    position: relative;
    z-index: 1;
}

/* Make sure textarea doesn't overflow and cover buttons */
#messageInput {
    min-height: auto;
    max-height: 120px;
}

/* Voice mode panel visibility fix */
.voice-mode:not(.hidden) {
    display: block !important;
    width: 100%;
}

.text-mode:not(.hidden) {
    display: block !important;
    width: 100%;
}
