* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --success-color: #48bb78;
    --danger-color: #f56565;
    --warning-color: #ed8936;
    --info-color: #4299e1;
    --bg-light: #f7fafc;
    --bg-dark: #1a202c;
    --text-dark: #2d3748;
    --text-light: #718096;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
}

html, body, .app-container {
    height: 100%;
    width: 100%;
}

/* ═══════════════════════════════════════
   APP LAYOUT
   ═══════════════════════════════════════ */

.app-container {
    display: flex;
    flex-direction: column;
    background: white;
}

.app-header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.header-content h1 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

.header-content p {
    font-size: 0.9rem;
    opacity: 0.9;
}

.btn-clear-history {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.btn-clear-history:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.app-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ═══════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════ */

.sidebar {
    width: 220px;
    background: var(--bg-light);
    padding: 1.5rem;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
}

.sidebar h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-dark);
}

.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.mode-btn {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-dark);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    text-align: left;
}

.mode-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateX(5px);
}

.mode-btn.active {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-color: var(--secondary-color);
    font-weight: 600;
}

/* ═══════════════════════════════════════
   CHAT CONTAINER
   ═══════════════════════════════════════ */

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    margin-bottom: 0.5rem;
    animation: slideIn 0.3s ease;
    word-wrap: break-word;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    justify-content: flex-end;
}

.user-message p {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 18px 18px 4px 18px;
    max-width: 85%;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    line-height: 1.6;
}

.bot-message {
    justify-content: flex-start;
}

.bot-message p {
    background: var(--bg-light);
    color: var(--text-dark);
    padding: 1rem 1.5rem;
    border-radius: 18px 18px 18px 4px;
    max-width: 85%;
    border: 1px solid var(--border-color);
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    line-height: 1.6;
}

.bot-message strong {
    color: var(--primary-color);
    font-weight: 600;
}

.bot-message em {
    font-style: italic;
    color: var(--text-dark);
}

.bot-message code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

/* ═══════════════════════════════════════
   INPUT AREA
   ═══════════════════════════════════════ */

.input-area {
    background: white;
    border-top: 1px solid var(--border-color);
    padding: 1.5rem;
}

.chat-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-wrapper {
    display: flex;
    gap: 0.8rem;
}

#messageInput {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    max-height: 120px;
    transition: border-color 0.3s ease;
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.btn-send {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 100px;
}

.btn-send:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.loader {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader.hidden {
    display: none;
}

.input-hint {
    color: var(--text-light);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* ═══════════════════════════════════════
   LOADING MODAL
   ═══════════════════════════════════════ */

.loading-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999;
}

.loading-modal.hidden {
    display: none;
}

.loading-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

/* ═══════════════════════════════════════
   SCROLLBAR
   ═══════════════════════════════════════ */

.messages::-webkit-scrollbar {
    width: 8px;
}

.messages::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

/* ═══════════════════════════════════════
   RESPONSIVE DESIGN
   ═══════════════════════════════════════ */

@media (max-width: 768px) {
    .app-main {
        flex-direction: column-reverse;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-top: 1px solid var(--border-color);
        max-height: 150px;
        overflow-x: auto;
    }

    .mode-buttons {
        flex-direction: row;
        overflow-x: auto;
        gap: 0.5rem;
    }

    .mode-btn {
        white-space: nowrap;
        flex-shrink: 0;
    }

    .user-message p,
    .bot-message p {
        max-width: 95%;
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
    }

    .header-content p {
        display: none;
    }

    .btn-clear-history {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .app-header {
        padding: 1rem;
    }

    .header-content h1 {
        font-size: 1.4rem;
    }

    .messages {
        padding: 1rem;
        gap: 1rem;
    }

    .message p {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .user-message p,
    .bot-message p {
        max-width: 100%;
    }

    .input-area {
        padding: 1rem;
    }
}
