:root {
    --primary-color: #6a11cb;
    --secondary-color: #2575fc;
    --text-color: #333;
    --bg-color: #f5f5f5;
    --chat-bg: #fff;
    --user-bubble: #e6e6fa;
    --ai-bubble: #f0f8ff;
    --shadow: rgba(0, 0, 0, 0.1);
    --input-bg: #fff;
    --border-color: #ddd;
    --success-color: #4CAF50;
    --error-color: #f44336;
}

.dark-mode {
    --primary-color: #2575fc;
    --secondary-color: #6a11cb;
    --text-color: #f0f0f0;
    --bg-color: #1a1a2e;
    --chat-bg: #16213e;
    --user-bubble: #6a11cb;
    --ai-bubble: #1a2a6c;
    --shadow: rgba(0, 0, 0, 0.3);
    --input-bg: #0f3460;
    --border-color: #2a2a4a;
    --success-color: #2E7D32;
    --error-color: #C62828;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: background-color 0.3s, color 0.3s;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-image: var(--custom-bg, none);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 2px 10px var(--shadow);
    position: relative;
}

.theme-toggle {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
}

.setup-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    max-width: 600px;
    margin: 2rem auto;
    background-color: var(--chat-bg);
    border-radius: 15px;
    box-shadow: 0 5px 15px var(--shadow);
    text-align: center;
    animation: fadeIn 0.5s ease-in-out;
}

.setup-screen h2 {
    margin-bottom: 1.5rem;
    color: var(--primary-color);
}

.setup-screen input {
    width: 100%;
    padding: 0.8rem;
    margin: 1rem 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 1rem;
}

.btn {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: 0.8rem 2rem;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 1rem;
    transition: all 0.3s;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow);
}

.btn:disabled {
    background: #cccccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.chat-container {
    display: none;
    flex-direction: column;
    max-width: 800px;
    margin: 2rem auto;
    width: 90%;
    height: 70vh;
    background-color: rgba(var(--chat-bg-rgb), 0.9);
    border-radius: 15px;
    box-shadow: 0 5px 15px var(--shadow);
    overflow: hidden;
    animation: fadeIn 0.5s ease-in-out;
    position: relative;
}

.chat-header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    position: relative;
}

.chat-header img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid white;
}

.chat-messages {
    flex-grow: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 80%;
    padding: 0.8rem 1.2rem;
    border-radius: 15px;
    animation: fadeIn 0.3s ease-in-out;
    line-height: 1.5;
}

.user-message {
    align-self: flex-end;
    background-color: var(--user-bubble);
    border-bottom-right-radius: 5px;
}

.ai-message {
    align-self: flex-start;
    background-color: var(--ai-bubble);
    border-bottom-left-radius: 5px;
}

.chat-input {
    display: flex;
    padding: 1rem;
    background-color: rgba(var(--chat-bg-rgb), 0.9);
    border-top: 1px solid var(--border-color);
}

.chat-input input {
    flex-grow: 1;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 1rem;
}

.chat-input button {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: 0 1.5rem;
    margin-left: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.chat-input button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow);
}

.typing-indicator {
    display: none;
    align-self: flex-start;
    background-color: var(--ai-bubble);
    padding: 0.8rem 1.2rem;
    border-radius: 15px;
    margin-bottom: 1rem;
    border-bottom-left-radius: 5px;
}

.typing-dots {
    display: flex;
    gap: 5px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: var(--text-color);
    border-radius: 50%;
    animation: typingAnimation 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;
}

.chat-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 10px;
    z-index: 10;
}

.chat-controls button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
}

.chat-controls button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.settings-panel {
    position: absolute;
    top: 50px;
    right: 10px;
    background-color: var(--chat-bg);
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 5px 15px var(--shadow);
    z-index: 10;
    display: none;
    width: 250px;
}

.settings-panel h3 {
    margin-bottom: 10px;
    color: var(--primary-color);
}

.bg-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.bg-option {
    width: 100%;
    height: 50px;
    border-radius: 5px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.3s;
}

.bg-option:hover {
    transform: scale(1.05);
}

.bg-option.selected {
    border-color: var(--primary-color);
}

.upload-btn {
    position: relative;
    overflow: hidden;
    width: 100%;
    margin-bottom: 10px;
}

.upload-btn input {
    position: absolute;
    font-size: 100px;
    opacity: 0;
    right: 0;
    top: 0;
    cursor: pointer;
}

.message-image {
    max-width: 100%;
    max-height: 200px;
    border-radius: 10px;
    margin-top: 5px;
}

.input-container {
    display: flex;
    align-items: center;
    width: 100%;
}

@keyframes typingAnimation {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-5px);
    }
}

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

@media (max-width: 600px) {
    .chat-container {
        width: 95%;
        height: 80vh;
    }
    
    .message {
        max-width: 90%;
    }
}