/* IMPORTS & VARIABLES */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Light Theme */
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --accent-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    
    --bg-primary: #ffffff;
    --bg-secondary: #f8faff;
    --bg-tertiary: #e8f0fe;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --text-muted: #a0aec0;
    
    --border-color: #e2e8f0;
    --shadow-light: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-heavy: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    
    --border-radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dark-mode {
    --primary-gradient: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    --secondary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --accent-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #4a5568;
    --text-primary: #f7fafc;
    --text-secondary: #e2e8f0;
    --text-muted: #a0aec0;
    
    --border-color: #4a5568;
    --shadow-light: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-medium: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    --shadow-heavy: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* RESET & BASE */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    transition: var(--transition);
    overflow-x: hidden;
}

/* SCROLLBAR STYLING */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--secondary-gradient);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-gradient);
}

/* SIDEBAR OVERLAY */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* SIDEBAR */
.sidebar {
    width: 320px;
    background: var(--bg-secondary);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    z-index: 999;
    box-shadow: var(--shadow-medium);
    overflow: hidden;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 24px;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo i {
    font-size: 28px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.close-sidebar-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: var(--transition);
    display: none;
}

.close-sidebar-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.new-chat-btn {
    width: 100%;
    padding: 16px 20px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--transition);
    box-shadow: var(--shadow-light);
    margin-bottom: 24px;
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.search-section {
    margin-bottom: 32px;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-wrapper i {
    position: absolute;
    left: 16px;
    color: var(--text-muted);
    z-index: 1;
}

#search-bar {
    width: 100%;
    padding: 14px 16px 14px 48px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 14px;
    color: var(--text-primary);
    transition: var(--transition);
}

#search-bar:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.library-section h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-list li {
    padding: 12px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
    color: var(--text-primary);
    position: relative;
    overflow: hidden;
}

.chat-list li:hover {
    background: var(--bg-tertiary);
    transform: translateX(4px);
}

.chat-list li.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
}

.sidebar-footer {
    padding: 24px;
    border-top: 1px solid var(--border-color);
}

.settings-btn {
    width: 100%;
    padding: 14px 20px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--transition);
}

.settings-btn:hover {
    background: var(--bg-tertiary);
}

/* MAIN CONTENT */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.chat-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(20px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.menu-btn {
    background: var(--primary-gradient);
    border: none;
    color: white;
    font-size: 18px;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
    display: none;
}

.menu-btn:hover {
    transform: scale(1.1);
}

.chat-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#chat-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-indicator .online {
    color: #48bb78;
}

.header-actions {
    display: flex;
    gap: 12px;
}

.theme-toggle {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
}

/* CHAT CONTAINER */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 1000px;
    margin: 0 auto;
    padding: 24px;
    width: 100%;
}

.chat-box {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 24px;
    overflow-y: auto;
    min-height: 60vh;
    margin-bottom: 24px;
    box-shadow: var(--shadow-light);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    height: 100%;
    color: var(--text-secondary);
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 24px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-message h2 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.welcome-message p {
    font-size: 16px;
    max-width: 400px;
}

/* CHAT MESSAGES */
.chat-message {
    max-width: 70%;
    padding: 16px 20px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    animation: messageSlideIn 0.3s ease-out;
    word-wrap: break-word;
    position: relative;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    background: var(--primary-gradient);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 6px;
    box-shadow: var(--shadow-light);
}

.bot-message {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-light);
}

/* FILE AND AUDIO MESSAGES */
.file-message {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    text-decoration: none;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.file-message:hover {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
}

.audio-message {
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.audio-message audio {
    width: 100%;
    max-width: 300px;
}

/* CHAT INPUT */
.chat-input-container {
    position: relative;
}

.chat-input {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 12px 16px;
    box-shadow: var(--shadow-light);
    transition: var(--transition);
}

.chat-input:focus-within {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.input-btn {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
}

.input-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.record-btn.recording {
    background: var(--secondary-gradient);
    color: white;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(245, 87, 108, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(245, 87, 108, 0); }
    100% { box-shadow: 0 0 0 0 rgba(245, 87, 108, 0); }
}

.message-input-wrapper {
    flex: 1;
    position: relative;
}

#user-input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    font-size: 15px;
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 8px;
}

#user-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    background: var(--primary-gradient);
    border: none;
    color: white;
    padding: 12px 16px;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    height: 48px;
}

.send-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* TYPING INDICATOR */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-light);
    border: 1px solid var(--border-color);
}

.typing-indicator.show {
    display: flex;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-heavy);
    border: 1px solid var(--border-color);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: var(--transition);
}

.modal-overlay.show .modal {
    transform: scale(1);
}

.modal-header {
    padding: 24px 24px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 24px;
    padding-bottom: 16px;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-content {
    padding: 0 24px 24px;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.theme-options {
    display: flex;
    gap: 12px;
}

.theme-option {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.theme-option:hover,
.theme-option.active {
    background: var(--primary-gradient);
    color: white;
    border-color: transparent;
}

.font-size-controls {
    display: flex;
    gap: 8px;
}

.font-size-controls button {
    flex: 1;
    padding: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.font-size-controls button:hover,
.font-size-controls button.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
}

/* TOGGLE SWITCH */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--border-color);
    transition: var(--transition);
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background: white;
    transition: var(--transition);
    border-radius: 50%;
}

input:checked + .slider {
    background: var(--primary-gradient);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

/* LOADING OVERLAY */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    text-align: center;
    color: white;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-spinner p {
    font-size: 16px;
    font-weight: 500;
}

/* RESPONSIVE DESIGN */
@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
    }
    
    .chat-container {
        padding: 16px;
    }
    
    .chat-message {
        max-width: 85%;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -320px;
        z-index: 999;
        transition: left 0.3s ease;
    }
    
    .sidebar.show {
        left: 0;
    }
    
    .sidebar-overlay.show {
        display: block;
    }
    
    .menu-btn {
        display: flex;
    }
    
    .close-sidebar-btn {
        display: block;
    }
    
    .chat-header {
        padding: 16px 20px;
    }
    
    .chat-container {
        padding: 16px 12px;
    }
    
    .chat-box {
        padding: 16px;
        margin-bottom: 16px;
        min-height: 50vh;
    }
    
    .chat-input {
        padding: 8px 12px;
    }
    
    .chat-message {
        max-width: 90%;
        padding: 12px 16px;
    }
    
    .welcome-message h2 {
        font-size: 24px;
    }
    
    .welcome-icon {
        font-size: 48px;
        margin-bottom: 16px;
    }
    
    #chat-title {
        font-size: 18px;
    }
    
    .modal {
        margin: 20px;
        width: calc(100% - 40px);
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 100%;
        left: -100%;
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .chat-container {
        padding: 12px 8px;
    }
    
    .chat-input {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .message-input-wrapper {
        order: 3;
        flex-basis: 100%;
        margin-top: 8px;
    }
    
    .chat-message {
        max-width: 95%;
        padding: 10px 14px;
        font-size: 14px;
    }
    
    .input-btn {
        min-width: 36px;
        height: 36px;
        padding: 8px;
    }
    
    .send-btn {
        min-width: 44px;
        height: 44px;
    }
}

/* ANIMATIONS & TRANSITIONS */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.user-message {
    animation: slideInRight 0.3s ease-out;
}

.bot-message {
    animation: slideInLeft 0.3s ease-out;
}

/* UTILITY CLASSES */
.font-small { font-size: 14px !important; }
.font-medium { font-size: 16px !important; }
.font-large { font-size: 18px !important; }

.fade-in {
    animation: fadeInUp 0.5s ease-out;
}

/* HIGH CONTRAST MODE */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000;
        --shadow-light: 0 2px 4px rgba(0, 0, 0, 0.8);
    }
    
    .dark-mode {
        --border-color: #fff;
    }
}

/* REDUCED MOTION */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}