/* CSS Reset & Variables */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #1e90ff;
    --primary-dark: #187bcd;
    --secondary-color: #ff4d4d;
    --success-color: #00c9a7;
    --bg-light: #f4f4f9;
    --bg-white: #ffffff;
    --bg-message-user: #1e90ff;
    --bg-message-ai: #e0e0e0;
    --text-primary: #333;
    --text-secondary: #666;
    --text-light: #888;
    --border-color: #e0e0e0;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
    --border-radius: 12px;
    --transition: all 0.3s ease;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    transition: var(--transition);
}

/* Dark Mode Variables */
body.dark-mode {
    --bg-light: #121212;
    --bg-white: #1e1e1e;
    --bg-message-ai: #333;
    --text-primary: #e0e0e0;
    --text-secondary: #bbb;
    --text-light: #999;
    --border-color: #333;
    background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
}

/* Login Container */
.login-container {
    width: 100%;
    max-width: 450px;
    padding: 20px;
    animation: fadeIn 0.5s ease;
}

.login-card {
    background: var(--bg-white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.login-header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 40px 30px;
    text-align: center;
}

.login-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 15px;
    animation: bounce 2s infinite;
}

.login-header h1 {
    font-size: 2rem;
    margin: 0 0 10px;
    font-weight: 800;
}

.login-header p {
    margin: 0;
    opacity: 0.95;
    font-size: 1rem;
}

.login-form {
    padding: 35px 30px;
}

.input-group {
    margin-bottom: 25px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.95rem;
}

.input-group input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: var(--transition);
    background-color: var(--bg-white);
    color: var(--text-primary);
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 144, 255, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.error-message {
    margin-top: 15px;
    padding: 12px;
    background-color: #ffe6e6;
    color: var(--secondary-color);
    border-radius: 6px;
    font-size: 0.9rem;
    text-align: center;
}

.error-message.hidden {
    display: none;
}

.login-footer {
    padding: 20px;
    text-align: center;
    background-color: var(--bg-light);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Chat Container */
.chat-container {
    display: none; /* Hidden by default until login */
    width: 100%;
    max-width: 900px;
    height: 90vh;
    background: var(--bg-white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    margin: 20px;
    flex-direction: column;
}

.chat-container.active {
    display: flex; /* Show as flex when active */
}


/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 20px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.chat-icon {
    font-size: 2.5rem;
    animation: pulse 2s infinite;
}

.header-info h2 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    opacity: 0.95;
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: var(--success-color);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.moon-icon {
    display: none;
}

body.dark-mode .sun-icon {
    display: none;
}

body.dark-mode .moon-icon {
    display: inline;
}

/* Search Container */
.search-container {
    padding: 15px 20px;
    background-color: var(--bg-light);
    border-bottom: 1px solid var(--border-color);
}

.search-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    font-size: 0.95rem;
    transition: var(--transition);
    background-color: var(--bg-white);
    color: var(--text-primary);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 144, 255, 0.1);
}

/* Chat Body */
.chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: var(--bg-light);
    scroll-behavior: smooth;
}

/* Custom Scrollbar */
.chat-body::-webkit-scrollbar {
    width: 8px;
}

.chat-body::-webkit-scrollbar-track {
    background: var(--bg-light);
}

.chat-body::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Messages */
.message {
    margin-bottom: 20px;
    animation: slideIn 0.3s ease;
    position: relative;
    display: flex;
    gap: 10px;
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
}

.message.ai .message-avatar {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.message-content {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message.user .message-content {
    align-items: flex-end;
}

.message-text {
    padding: 14px 18px;
    border-radius: 16px;
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.5;
    position: relative;
}

.message.user .message-text {
    background: linear-gradient(135deg, var(--bg-message-user), var(--primary-dark));
    color: white;
    border-bottom-right-radius: 4px;
}

.message.ai .message-text {
    background: var(--bg-message-ai);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
    color: var(--text-light);
}

.timestamp {
    font-size: 0.8rem;
    color: var(--text-light);
}

.message-actions {
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: var(--transition);
}

.message:hover .message-actions {
    opacity: 1;
}

.message-actions button {
    background: rgba(0, 0, 0, 0.05);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

.message-actions button:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: scale(1.1);
}

.message-actions button.delete:hover {
    background: var(--secondary-color);
    color: white;
}

.message-actions button.quote:hover {
    background: var(--primary-color);
    color: white;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.typing-indicator.hidden {
    display: none;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background-color: var(--primary-color);
    border-radius: 50%;
    animation: typingDot 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

.typing-text {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.9rem;
}

/* Chat Input Container */
.chat-input-container {
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    padding: 15px 20px;
}

.chat-actions-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.btn-secondary {
    padding: 8px 16px;
    background-color: var(--bg-light);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-secondary:hover {
    background-color: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
}

.message-count {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.message-count span {
    color: var(--primary-color);
    font-weight: 700;
}

.chat-input {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-input textarea {
    flex: 1;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    min-height: 50px;
    max-height: 150px;
    transition: var(--transition);
    background-color: var(--bg-white);
    color: var(--text-primary);
    line-height: 1.5;
}

.chat-input textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 144, 255, 0.1);
}

.send-btn {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.send-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.send-btn:active {
    transform: translateY(0);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--primary-color);
    color: white;
    padding: 14px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    animation: slideInRight 0.3s ease;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 250px;
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--secondary-color);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

@keyframes typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        align-items: flex-start;
    }

    .chat-container {
        height: 100vh;
        max-width: 100%;
        margin: 0;
        border-radius: 0;
    }

    .login-container {
        max-width: 100%;
        padding: 15px;
    }

    .chat-header {
        padding: 15px 20px;
    }

    .header-info h2 {
        font-size: 1.2rem;
    }

    .chat-icon {
        font-size: 2rem;
    }

    .message-content {
        max-width: 85%;
    }

    .chat-body {
        padding: 15px;
    }

    .toast-container {
        bottom: 20px;
        right: 20px;
        left: 20px;
    }

    .toast {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    .login-card {
        border-radius: 0;
    }

    .login-form {
        padding: 25px 20px;
    }

    .chat-input-container {
        padding: 12px 15px;
    }

    .chat-actions-top {
        flex-wrap: wrap;
        gap: 10px;
    }

    .message-text {
        padding: 12px 14px;
    }
}
