/* ================================
   CSS Variables / Theme
   ================================ */
:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --accent-color: #10b981;
    --warm-orange: #f59e0b;
    --earth-brown: #8b6f47;
    --sky-blue: #0ea5e9;
    --sage-green: #10b981;
    --message-user: #f1f5f9;
    --message-bot: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-light: #e2e8f0;
    --border-subtle: rgba(226, 232, 240, 0.6);
    --shadow-soft: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-large: 0 20px 25px rgba(0, 0, 0, 0.1);
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
}

/* ================================
   Base Styles & Reset
   ================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-weight: 400;
    line-height: 1.5;
    color: var(--text-primary);
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ================================
   Animations & Transitions
   ================================ */
@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scale-in {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes slide-in-right {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slide-in-left {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes typing-dots {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

@keyframes bounce-in {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Animation Classes */
.animate-fade-in {
    animation: fade-in 0.6s ease-out forwards;
}

.animate-scale-in {
    animation: scale-in 0.3s ease-out forwards;
}

.animate-slide-in-right {
    animation: slide-in-right 0.3s ease-out forwards;
}

.animate-slide-in-left {
    animation: slide-in-left 0.3s ease-out forwards;
}

.animate-bounce-in {
    animation: bounce-in 0.5s ease-out forwards;
}

/* ================================
   Message Styles
   ================================ */
.message-container {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    animation: slide-in-left 0.3s ease-out;
}

.message-container.user {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.message-avatar:hover {
    transform: scale(1.05);
}

.avatar-bot {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.avatar-user {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.message-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    transition: all 0.2s ease;
}

.message-bubble:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-medium);
}

.bubble-bot {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-soft);
}

.bubble-user {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.message-bubble p {
    margin: 0;
}

/* ================================
   Typing Indicator
   ================================ */
#typing {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    animation: fade-in 0.3s ease-out;
}

#typing .message-bubble {
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    padding: 16px 20px;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing-dots 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* ================================
   Scrollbar Styling
   ================================ */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
    transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ================================
   History Sidebar Improvements
   ================================ */
#historyDrawer {
    backdrop-filter: blur(8px);
}

#historyDrawer aside {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--border-subtle);
}

#sessionList {
    padding: 16px;
}

.session-item {
    width: 100%;
    text-align: left;
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: var(--bg-primary);
    transition: all 0.2s ease;
    cursor: pointer;
}

.session-item:hover {
    background: var(--bg-secondary);
    border-color: var(--border-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-soft);
}

.session-item:active {
    transform: translateY(0);
}

.session-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
    line-height: 1.3;
}

.session-time {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.2;
}

.session-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.session-empty-state i {
    font-size: 32px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.session-empty-state p {
    font-size: 14px;
    line-height: 1.4;
}

/* ================================
   Button Improvements
   ================================ */
button {
    cursor: pointer;
    border: none;
    outline: none;
    font-family: inherit;
    transition: all 0.2s ease;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), #1e40af);
    color: white;
    border-radius: 12px;
    padding: 12px 24px;
    font-weight: 500;
    box-shadow: var(--shadow-soft);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 12px 24px;
    font-weight: 500;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-secondary);
    border-color: var(--text-secondary);
    transform: translateY(-1px);
}

/* ================================
   Input Improvements
   ================================ */
input[type="text"], textarea {
    font-family: inherit;
    transition: all 0.2s ease;
}

input[type="text"]:focus, textarea:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ================================
   Modal Improvements
   ================================ */
.modal-backdrop {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-large);
}

/* ================================
   Quick Action Buttons
   ================================ */
.quick-action {
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.quick-action:hover {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-soft);
}

/* ================================
   Accessibility & Focus States
   ================================ */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ================================
   Responsive Design
   ================================ */
@media (max-width: 768px) {
    .message-bubble {
        max-width: 85%;
        font-size: 14px;
    }
    
    #historyDrawer aside {
        width: 100%;
        max-width: 320px;
    }
    
    .session-item {
        padding: 10px 12px;
    }
}

@media (max-width: 640px) {
    .message-container {
        gap: 8px;
        margin-bottom: 20px;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .message-bubble {
        padding: 10px 14px;
        font-size: 14px;
        border-radius: 16px;
    }
}

/* ================================
   New Layout Styles
   ================================ */

/* Sidebar Styles */
#sidebar {
    transition: transform 0.3s ease-in-out, width 0.3s ease-in-out;
}

#sidebar.collapsed {
    transform: translateX(-100%);
}

#collapsedSidebar {
    transition: all 0.3s ease-in-out;
}

/* Profile Dropdown */
#profileDropdown {
    animation: slideDown 0.2s ease-out;
    transform-origin: top right;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chat Layout */
#chatMessages {
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) transparent;
}

/* Input Area Improvements */
#messageInput {
    transition: height 0.2s ease;
    min-height: 48px;
    line-height: 1.5;
}

/* Improved button heights matching */
#sendBtn {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

/* Chat Session Items */
.session-item-container {
    transition: all 0.2s ease;
}

.session-item-container:hover {
    background-color: var(--bg-secondary);
    transform: translateX(2px);
}

/* User Message Styles (simplified) */
.user-message {
    text-align: right;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 1.5rem;
}

/* Bot Message Improvements */
.bot-message-container {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.bot-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.2);
}

.bot-message-bubble {
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 1rem;
    padding: 0.75rem 1rem;
    max-width: 48rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Welcome message improvements */
#welcomeMessage {
    transition: opacity 0.3s ease;
}

/* Quick actions improvements */
#quickActions {
    transition: opacity 0.3s ease;
}

/* Responsive sidebar */
@media (max-width: 1024px) {
    #sidebar {
        position: absolute;
        z-index: 40;
        height: 100%;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    #sidebar.collapsed {
        transform: translateX(-100%);
    }
}

@media (max-width: 768px) {
    #sidebar {
        width: 100%;
        max-width: 320px;
    }
}

/* ================================
   Reduced Motion Support
   ================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ================================
   Dark Mode Support (Optional)
   ================================ */
@media (prefers-color-scheme: dark) {
    :root {
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
        --bg-primary: #1e293b;
        --bg-secondary: #334155;
        --bg-tertiary: #475569;
        --border-light: #334155;
        --border-subtle: rgba(51, 65, 85, 0.6);
    }
    
    body {
        background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    }
    
    .bubble-bot {
        background: var(--bg-secondary);
        border-color: var(--border-light);
    }
}