* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f8;
    --bg-tertiary: #ececf1;
    --text-primary: #2e2e2e;
    --text-secondary: #6e6e80;
    --text-tertiary: #8e8ea0;
    --border-color: #e5e5e5;
    --accent-color: #10a37f;
    --accent-hover: #0e8c6f;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --gradient-primary: linear-gradient(135deg, #10a37f 0%, #0e8c6f 100%);
    --gradient-secondary: linear-gradient(135deg, #f7f7f8 0%, #ececf1 100%);
    --gradient-welcome: linear-gradient(135deg, #10a37f 0%, #0e8c6f 100%);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2a2a2a;
    --bg-tertiary: #3a3a3a;
    --text-primary: #ffffff;
    --text-secondary: #b4b4b4;
    --text-tertiary: #8a8a8a;
    --border-color: #404040;
    --accent-color: #10a37f;
    --accent-hover: #0e8c6f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
    --gradient-primary: linear-gradient(135deg, #10a37f 0%, #0e8c6f 100%);
    --gradient-secondary: linear-gradient(135deg, #2a2a2a 0%, #3a3a3a 100%);
    --gradient-welcome: linear-gradient(135deg, #10a37f 0%, #0e8c6f 100%);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: var(--transition);
}

.app-container {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    position: relative;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.new-chat-btn {
    width: 100%;
    padding: 14px 16px;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.chat-list::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-tertiary);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 14px;
}

.chat-item {
    padding: 14px 16px;
    margin-bottom: 8px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid transparent;
    position: relative;
}

.chat-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
    transform: translateX(4px);
}

.chat-item.active {
    background: var(--bg-tertiary);
    border-color: var(--accent-color);
}

.chat-item-icon {
    flex-shrink: 0;
    color: var(--text-tertiary);
}

.chat-item-content {
    flex: 1;
    min-width: 0;
}

.chat-item-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 4px;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
}

.sidebar-btn {
    flex: 1;
    padding: 12px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

.sidebar-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    position: relative;
}

.chat-header {
    height: 70px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 20px;
    background: var(--bg-primary);
    backdrop-filter: blur(10px);
}

.icon-btn {
    width: 40px;
    height: 40px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    transform: rotate(15deg);
}

.header-title {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-title h1 {
    font-size: 20px;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.status-badge {
    padding: 6px 12px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    transition: var(--transition);
}

.status-badge.connected {
    background: #d1fae5;
    color: #065f46;
}

[data-theme="dark"] .status-badge.connected {
    background: rgba(16, 163, 127, 0.2);
    color: #10a37f;
}

.status-badge.error {
    background: #fee2e2;
    color: #991b1b;
}

[data-theme="dark"] .status-badge.error {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-primary);
}

.chat-area::-webkit-scrollbar {
    width: 8px;
}

.chat-area::-webkit-scrollbar-track {
    background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 60px;
}

.welcome-icon {
    width: 100px;
    height: 100px;
    background: var(--gradient-welcome);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 32px;
    color: white;
    box-shadow: var(--shadow-lg);
}

.welcome-message h2 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 12px;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-message p {
    font-size: 18px;
    color: var(--text-secondary);
    max-width: 500px;
    line-height: 1.6;
}

.message {
    margin-bottom: 32px;
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    box-shadow: var(--shadow-sm);
}

.message.user .message-avatar {
    color: white;
}

.message.ai .message-avatar {
   
    color: var(--text-primary);
}

.message-author {
    font-size: 15px;
    font-weight: 600;
}

.message-time {
    font-size: 12px;
    color: var(--text-tertiary);
}

.message-content {
    padding-left: 48px;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
    position: relative;
}

.message.user .message-content {
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    margin-left: 20px;
    border-top-left-radius: 4px;
    position: relative;
}

.message.user .message-content::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 0;
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 8px solid var(--bg-tertiary);
}

.message.ai .message-content {
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    margin-right: 20px;
    border-top-right-radius: 4px;
    position: relative;
}

.message.ai .message-content::before {
    content: '';
    position: absolute;
    right: -8px;
    top: 0;
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 8px solid var(--bg-secondary);
}

.message-actions {
    padding-left: 48px;
    margin-top: 16px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: var(--transition);
}

.message:hover .message-actions {
    opacity: 1;
}

.action-btn {
    padding: 8px 16px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
}

.action-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.action-btn.copied {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.typing-indicator {
    padding-left: 48px;
    display: flex;
    gap: 6px;
}

.typing-dot {
    width: 10px;
    height: 10px;
    background: var(--text-tertiary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.input-area {
    padding: 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border: 0.01px solid var(--border-color);
    border-radius: var(--radius-lg);
    transition: var(--transition);
    position: relative;
}

.input-wrapper:focus-within {
    border-color: var(--accent-color);
  
    transform: translateY(-2px);
}

.upload-btn-wrapper {
    position: relative;
}

.upload-btn {
    width: 44px;
    height: 44px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.upload-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: scale(1.1);
}

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 20px;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    overflow-y: auto;
    line-height: 2.5;
}

#messageInput::placeholder {
    color: var(--text-tertiary);
}

#messageInput::-webkit-scrollbar {
    width: 4px;
}

#messageInput::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.send-btn {
    width: 44px;
    height: 44px;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.05) translateY(-2px);
    box-shadow: var(--shadow-md);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal.active {
    display: flex;
}

.modal-content {
    width: 90%;
    max-width: 480px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: modalSlide 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--gradient-secondary);
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 700;
}

.close-btn {
    width: 36px;
    height: 36px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: rotate(90deg);
}

.modal-body {
    padding: 24px;
}

.modal-body p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 24px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.btn-secondary {
    padding: 12px 24px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.btn-danger {
    padding: 12px 24px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-danger:hover {
    background: var(--danger-hover);
    transform: translateY(-1px);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.setting-info label {
    display: block;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
}

.setting-info p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
}

.theme-selector {
    display: flex;
    gap: 12px;
}

.theme-btn {
    padding: 12px 20px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
}

.theme-btn:hover {
    background: var(--bg-tertiary);
    transform: translateY(-2px);
}

.theme-btn.active {
    background: var(--bg-tertiary);
    border-color: var(--accent-color);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.uploaded-image {
    max-width: 300px;
    max-height: 200px;
    border-radius: var(--radius-md);
    margin-top: 12px;
    box-shadow: var(--shadow-sm);
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        transform: translateX(-100%);
        z-index: 100;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .icon-btn {
        display: flex;
    }

    .message-content {
        padding-left: 0;
    }

    .message-actions {
        padding-left: 0;
    }

    .typing-indicator {
        padding-left: 0;
    }

    .chat-area {
        padding: 16px;
    }

    .input-area {
        padding: 16px;
    }

    .welcome-message {
        padding: 40px 20px;
    }

    .welcome-icon {
        width: 80px;
        height: 80px;
    }

    .welcome-message h2 {
        font-size: 24px;
    }

    .welcome-message p {
        font-size: 16px;
    }
}

@media (min-width: 769px) {
    .sidebar-toggle-visible {
        display: none !important;
    }
}