* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #667eea;
    --primary-dark: #5568d3;
    --primary-light: #8b9eff;
    --secondary: #764ba2;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
}

/* ========== BUBBLE BACKGROUND ========== */

.bubble-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: auto;
}

/* ========== AUTH CONTAINER ========== */

.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    z-index: 1;
    position: relative;
}

.auth-box {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    padding: 48px 40px;
    border-radius: 24px;
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255, 255, 255, 0.1);
    width: 100%;
    max-width: 440px;
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.auth-logo {
    text-align: center;
    margin-bottom: 40px;
}

.logo-icon {
    display: inline-block;
    margin-bottom: 20px;
    animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

.auth-logo h1 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 400;
}

.auth-section {
    margin-bottom: 24px;
}

.input-group {
    position: relative;
    margin-bottom: 16px;
}

.input-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    z-index: 1;
}

.input-group input {
    width: 100%;
    padding: 14px 16px 14px 48px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 15px;
    font-weight: 400;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-primary);
    color: var(--text-primary);
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.input-group input::placeholder {
    color: var(--text-tertiary);
}

button {
    width: 100%;
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

button:hover::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px -2px rgba(102, 126, 234, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--primary);
    border: 2px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary);
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 32px 0;
    color: var(--text-tertiary);
    font-size: 13px;
    font-weight: 500;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border);
}

.divider span {
    padding: 0 16px;
}

.social-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.btn-google, .btn-anonymous {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 2px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.btn-google:hover, .btn-anonymous:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ========== CHAT CONTAINER ========== */

.chat-container {
    width: 100%;
    max-width: 1400px;
    height: 90vh;
    background: var(--bg-primary);
    border-radius: 24px;
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: row;
    overflow: hidden;
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1;
    position: relative;
}

/* ========== SIDEBAR ========== */

.chat-sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease;
    position: relative;
    z-index: 10;
}

.chat-sidebar.collapsed {
    width: 0;
    transform: translateX(-100%);
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 8px;
    align-items: center;
}

.sidebar-toggle-btn {
    display: none;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 2px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    transform: translateY(-1px);
}

.sidebar-toggle-btn svg {
    display: block;
}

.btn-new-chat {
    flex: 1;
    padding: 10px 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
    box-shadow: var(--shadow-sm);
}

.btn-new-chat:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--secondary) 100%);
}

.btn-new-chat svg {
    stroke-width: 2.5;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 3px;
}

.chat-search {
    padding: 8px 16px 16px;
}

.search-input {
    width: 100%;
    padding: 10px 12px 10px 38px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    background: var(--bg-primary);
    transition: all 0.3s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
}

.chat-groups {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-group {
    margin-bottom: 8px;
}

.group-header {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    padding: 8px 12px 4px;
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-item {
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    background: transparent;
}

.chat-item:hover {
    background: var(--bg-primary);
}

.chat-item.active {
    background: var(--primary);
    color: white;
}

.chat-item.pinned {
    border-left: 3px solid var(--warning);
}

.chat-item-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.chat-item-content {
    flex: 1;
    min-width: 0;
}

.chat-item-title {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.chat-item.active .chat-item-title {
    color: white;
}

.chat-item-preview {
    font-size: 12px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item.active .chat-item-preview {
    color: rgba(255, 255, 255, 0.8);
}

.chat-item-actions {
    display: none;
    gap: 4px;
}

.chat-item:hover .chat-item-actions {
    display: flex;
}

.chat-action-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: var(--bg-tertiary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.chat-action-btn:hover {
    background: var(--primary);
    color: white;
}

.chat-item.active .chat-action-btn {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.chat-item.active .chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    color: white;
}

.pin-icon {
    color: var(--warning);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.btn-sidebar-action {
    width: 100%;
    padding: 10px 16px;
    background: var(--bg-primary);
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
    color: var(--text-primary);
}

.btn-sidebar-action:hover {
    border-color: var(--primary);
    background: var(--bg-tertiary);
}

/* ========== MAIN CHAT AREA ========== */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 24px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-small {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-left h2 {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.3px;
}

.status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    opacity: 0.9;
    margin-top: 2px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.9); }
}

.header-actions {
    display: flex;
    gap: 12px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    background: var(--bg-secondary);
    scroll-behavior: smooth;
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    animation: fadeIn 0.8s ease-out;
}

.welcome-icon {
    margin-bottom: 24px;
    animation: bounceIn 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.welcome-message h3 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    letter-spacing: -0.5px;
}

.welcome-message p {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 400;
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    animation: messageSlide 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.message-icon {
    font-size: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    font-weight: 600;
    overflow: hidden;
}

.bot-avatar {
    background: #f3f4f6;
    padding: 0;
}

.bot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-icon {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
}

.user-avatar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
}

.bot-message .message-icon {
    background: var(--bg-primary);
    color: var(--primary);
    border: 2px solid var(--border);
}

.message-content {
    max-width: 65%;
    padding: 14px 18px;
    border-radius: 16px;
    line-height: 1.6;
    font-size: 15px;
    box-shadow: var(--shadow-sm);
    word-wrap: break-word;
    position: relative;
}

.user-message .message-content {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.bot-message .message-content {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

.chat-input-container {
    padding: 24px 32px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--bg-secondary);
    padding: 8px;
    border-radius: 16px;
    border: 2px solid var(--border);
    transition: all 0.3s;
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

#chat-input {
    flex: 1;
    padding: 10px 12px;
    border: none;
    background: transparent;
    font-size: 15px;
    color: var(--text-primary);
    outline: none;
}

#chat-input::placeholder {
    color: var(--text-tertiary);
}

.btn-send {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    box-shadow: var(--shadow-md);
}

.btn-send:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 8px 16px -2px rgba(102, 126, 234, 0.4);
}

.btn-send:active {
    transform: translateY(0) scale(0.95);
}

/* ========== SCROLLBAR STYLING ========== */

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ========== RESPONSIVE DESIGN ========== */

.mobile-menu-btn {
    display: none;
}

@media (max-width: 1024px) {
    .chat-sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        box-shadow: var(--shadow-xl);
    }

    .chat-sidebar.collapsed {
        transform: translateX(-100%);
    }

    .mobile-menu-btn {
        display: flex;
    }

    .sidebar-toggle-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
}

@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .auth-box {
        padding: 32px 24px;
        border-radius: 0;
        max-width: 100%;
        height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .auth-logo h1 {
        font-size: 28px;
    }

    .chat-container {
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
    }

    .chat-sidebar {
        width: 280px;
    }

    .chat-header {
        padding: 16px;
    }

    .header-left {
        gap: 8px;
    }

    .header-left h2 {
        font-size: 16px;
    }

    .logo-small img {
        width: 32px;
        height: 32px;
    }

    .chat-messages {
        padding: 16px;
    }

    .message-content {
        max-width: 75%;
        font-size: 14px;
        padding: 12px 16px;
    }

    .chat-input-container {
        padding: 12px 16px;
    }

    .welcome-message {
        padding: 40px 16px;
    }

    .welcome-message h3 {
        font-size: 20px;
    }

    .welcome-message p {
        font-size: 14px;
    }

    .social-buttons {
        grid-template-columns: 1fr;
    }

    .icon-btn {
        width: 32px;
        height: 32px;
    }

    .icon-btn svg {
        width: 16px;
        height: 16px;
    }
}

@media (max-width: 480px) {
    .message-content {
        max-width: 85%;
    }

    .divider {
        font-size: 12px;
    }

    button {
        font-size: 14px;
        padding: 12px 20px;
    }
}

/* ========== STREAMING MESSAGE ========== */

.streaming-message {
    animation: streamFadeIn 0.3s ease-out;
}

.streaming-message .message-content::after {
    content: '▋';
    animation: cursorBlink 1s infinite;
    margin-left: 2px;
    color: var(--primary);
}

@keyframes cursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

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

/* ========== TYPING INDICATOR ========== */

.typing-indicator-msg {
    opacity: 0.8;
}

.typing-content {
    display: flex;
    align-items: center;
    padding: 12px 16px !important;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.typing-dot {
    width: 10px;
    height: 10px;
    background: var(--primary);
    border-radius: 50%;
    animation: typingBounce 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; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-8px); opacity: 1; }
}

/* ========== MESSAGE FORMATTING ========== */

.message-content p {
    margin: 0;
    line-height: 1.6;
}

.message-content p + p {
    margin-top: 12px;
}

.message-content strong {
    font-weight: 700;
    color: var(--text-primary);
}

.message-content em {
    font-style: italic;
    color: var(--text-secondary);
}

.message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    color: var(--primary);
}

.user-message .message-content code {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message-content .list-item {
    display: flex;
    gap: 8px;
    margin: 6px 0;
    align-items: flex-start;
}

.message-content .list-number {
    font-weight: 700;
    color: var(--primary);
    min-width: 24px;
}

.message-content .bullet {
    color: var(--primary);
    font-weight: 700;
    min-width: 16px;
}

.user-message .message-content .list-number,
.user-message .message-content .bullet {
    color: white;
}

/* ========== SMOOTH TRANSITIONS ========== */

* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button, input, .message, .auth-box, .chat-container {
    will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
