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

:root {
    --pink: #e91e8c;
    --purple: #9333ea;
    --violet: #7c3aed;
    --deep-purple: #581c87;
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-elevated: #1a1a28;
    --bg-glass: rgba(22, 22, 35, 0.7);
    --border: rgba(147, 51, 234, 0.15);
    --border-glow: rgba(233, 30, 140, 0.3);
    --text-primary: #f0eef5;
    --text-secondary: #9a95ad;
    --text-muted: #5a5571;
    --gradient-main: linear-gradient(135deg, var(--pink), var(--purple));
    --gradient-soft: linear-gradient(135deg, rgba(233, 30, 140, 0.15), rgba(147, 51, 234, 0.15));
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

/* Animated background glows */
.bg-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.4;
    pointer-events: none;
    z-index: 0;
    animation: glowDrift 12s ease-in-out infinite alternate;
}

.bg-glow-1 {
    width: 500px;
    height: 500px;
    background: var(--pink);
    top: -15%;
    right: -10%;
    opacity: 0.12;
}

.bg-glow-2 {
    width: 600px;
    height: 600px;
    background: var(--purple);
    bottom: -20%;
    left: -15%;
    opacity: 0.1;
    animation-delay: -4s;
}

.bg-glow-3 {
    width: 300px;
    height: 300px;
    background: var(--violet);
    top: 40%;
    left: 50%;
    opacity: 0.08;
    animation-delay: -8s;
}

@keyframes glowDrift {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(30px, -20px) scale(1.1); }
}

/* App Layout */
.app-layout {
    position: relative;
    z-index: 1;
    display: flex;
    width: 100%;
    height: 100vh;
    height: 100dvh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    min-height: 73px;
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 700;
    background: var(--gradient-main);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    flex: 1;
}

.new-chat-btn {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.new-chat-btn:hover {
    background: var(--gradient-soft);
    border-color: var(--border-glow);
    color: var(--text-primary);
}

/* Chat List */
.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-list::-webkit-scrollbar {
    width: 4px;
}

.chat-list::-webkit-scrollbar-thumb {
    background: rgba(147, 51, 234, 0.2);
    border-radius: 10px;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 2px;
}

.chat-list-item:hover {
    background: rgba(147, 51, 234, 0.1);
}

.chat-list-item.active {
    background: rgba(147, 51, 234, 0.15);
    border: 1px solid var(--border);
}

.chat-list-title {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-item.active .chat-list-title {
    color: var(--text-primary);
}

.chat-delete-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.15s;
    flex-shrink: 0;
}

.chat-list-item:hover .chat-delete-btn {
    opacity: 1;
}

.chat-delete-btn:hover {
    background: rgba(251, 113, 133, 0.15);
    color: #fb7185;
}

/* Chat Container */
.chat-container {
    flex: 1;
    min-width: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: rgba(10, 10, 15, 0.6);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

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

.header-avatar {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--gradient-main);
    padding: 2px;
    flex-shrink: 0;
}

.header-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.header-avatar .fallback-letter {
    display: none;
}

.header-avatar.fallback img {
    display: none;
}

.header-avatar.fallback .fallback-letter {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    background: var(--bg-elevated);
    border-radius: 50%;
}

.status-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 12px;
    height: 12px;
    background: #22c55e;
    border-radius: 50%;
    border: 2.5px solid var(--bg-secondary);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.header-info h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.header-info .status-text {
    font-size: 12px;
    color: #22c55e;
    font-weight: 500;
}

.status-bio {
    font-size: 16px;
    color: var(--text-secondary);
    font-style: italic;
    display: block;
    line-height: 1.4;
}

.clear-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.clear-btn:hover {
    background: var(--gradient-soft);
    border-color: var(--border-glow);
    color: var(--text-primary);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(147, 51, 234, 0.3);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(147, 51, 234, 0.5);
}

/* Welcome Message */
.welcome-message {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.welcome-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--gradient-main);
    padding: 3px;
    box-shadow: 0 0 40px rgba(233, 30, 140, 0.25), 0 0 80px rgba(147, 51, 234, 0.15);
}

.welcome-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.welcome-avatar .fallback-letter {
    display: none;
}

.welcome-avatar.fallback img {
    display: none;
}

.welcome-avatar.fallback .fallback-letter {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 32px;
    color: #fff;
    background: var(--bg-elevated);
    border-radius: 50%;
}

.welcome-message h2 {
    font-size: 20px;
    font-weight: 600;
    background: var(--gradient-main);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-message p {
    color: var(--text-muted);
    font-size: 14px;
}

/* Message Rows */
.message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 80%;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.message.visible {
    opacity: 1;
    transform: translateY(0);
}

.message.user {
    align-self: flex-end;
    flex-direction: row;
}

.message.assistant {
    align-self: flex-start;
    flex-direction: row;
}

/* Message Avatars */
.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.msg-avatar .fallback-letter {
    display: none;
}

.msg-avatar.fallback img {
    display: none;
}

.msg-avatar.fallback .fallback-letter {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    color: #fff;
}

.assistant-avatar {
    background: var(--gradient-main);
}

.assistant-avatar.fallback .fallback-letter {
    background: var(--bg-elevated);
    border-radius: 50%;
}

.user-avatar {
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
}

.user-avatar.fallback .fallback-letter {
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    border-radius: 50%;
}

/* Bubble Wrap & Name Labels */
.bubble-wrap {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.msg-name {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0 4px;
}

.message.assistant .msg-name {
    color: #c084fc;
}

.message.user .msg-name {
    color: #38bdf8;
    text-align: right;
}

/* Bubbles */
.bubble {
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 15.5px;
    line-height: 1.55;
    word-wrap: break-word;
}

.message.user .bubble {
    white-space: pre-wrap;
}

.message.user .bubble {
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    color: #fff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 20px rgba(14, 165, 233, 0.2);
}

.message.assistant .bubble {
    background: linear-gradient(135deg, #b5179e, #7c3aed);
    color: #fff;
    border-bottom-left-radius: 6px;
    box-shadow: 0 4px 20px rgba(181, 23, 158, 0.15);
}

/* Markdown inside bubbles */
.bubble p {
    margin: 0 0 0.4em 0;
}

.bubble p:last-child {
    margin-bottom: 0;
}

.bubble strong {
    font-weight: 700;
}

.bubble em {
    font-style: italic;
}

.bubble code {
    background: rgba(0, 0, 0, 0.25);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.bubble pre {
    background: rgba(0, 0, 0, 0.25);
    padding: 8px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
}

.bubble pre code {
    background: none;
    padding: 0;
}

.bubble ul, .bubble ol {
    padding-left: 1.4em;
    margin: 4px 0;
}

.bubble a {
    color: #c4b5fd;
    text-decoration: underline;
}

.bubble.error {
    color: #fb7185;
    border-color: rgba(251, 113, 133, 0.3);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 20px;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--pink);
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    background: var(--purple);
    animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
    background: var(--violet);
    animation-delay: 0.3s;
}

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

/* Emoji Panel */
.emoji-panel {
    display: none;
    position: absolute;
    bottom: 70px;
    left: 20px;
    right: 20px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px;
    z-index: 10;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.emoji-panel.open {
    display: block;
}

.emoji-panel::-webkit-scrollbar {
    width: 5px;
}

.emoji-panel::-webkit-scrollbar-thumb {
    background: rgba(147, 51, 234, 0.3);
    border-radius: 10px;
}

.emoji-section {
    margin-bottom: 10px;
}

.emoji-section-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 4px 6px;
}

.emoji-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
}

.emoji-grid span {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.12s;
}

.emoji-grid span:hover {
    background: rgba(147, 51, 234, 0.2);
}

.emoji-toggle-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s;
}

.emoji-toggle-btn:hover {
    color: var(--text-primary);
}

/* Input Area */
.chat-input-area {
    position: relative;
    padding: 12px 20px 16px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    overflow: hidden;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 6px 6px 6px 20px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.input-wrapper:focus-within {
    border-color: rgba(233, 30, 140, 0.4);
    box-shadow: 0 0 20px rgba(233, 30, 140, 0.08), 0 0 40px rgba(147, 51, 234, 0.05);
}

textarea {
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    resize: none;
    padding: 8px 0;
    max-height: 120px;
    line-height: 1.45;
}

textarea::placeholder {
    color: var(--text-muted);
}

#sendBtn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--gradient-main);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.25s;
    box-shadow: 0 4px 15px rgba(233, 30, 140, 0.25);
}

#sendBtn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(233, 30, 140, 0.35);
}

#sendBtn:active {
    transform: scale(0.95);
}

#sendBtn:disabled {
    background: var(--bg-secondary);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* Auth Gate */
.auth-gate {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
}

.auth-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 36px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
    width: 340px;
    max-width: 90vw;
}

.auth-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--gradient-main);
    padding: 3px;
    box-shadow: 0 0 40px rgba(233, 30, 140, 0.25), 0 0 80px rgba(147, 51, 234, 0.15);
}

.auth-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.auth-avatar .fallback-letter {
    display: none;
}

.auth-avatar.fallback img {
    display: none;
}

.auth-avatar.fallback .fallback-letter {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 32px;
    color: #fff;
    background: var(--bg-elevated);
    border-radius: 50%;
}

.auth-title {
    font-size: 22px;
    font-weight: 700;
    background: var(--gradient-main);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
}

.auth-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.auth-input:focus {
    border-color: rgba(233, 30, 140, 0.4);
    box-shadow: 0 0 20px rgba(233, 30, 140, 0.08);
}

.auth-input::placeholder {
    color: var(--text-muted);
}

.auth-error {
    color: #fb7185;
    font-size: 13px;
    min-height: 18px;
}

.auth-submit {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 12px;
    background: var(--gradient-main);
    color: #fff;
    font-family: 'Inter', sans-serif;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
    box-shadow: 0 4px 15px rgba(233, 30, 140, 0.25);
}

.auth-submit:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 25px rgba(233, 30, 140, 0.35);
}

.auth-submit:active {
    transform: scale(0.98);
}

.auth-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .message {
        max-width: 88%;
    }

    .bg-glow {
        opacity: 0.06;
    }
}
