/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --ai-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --user-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.8);
    --text-muted: rgba(255, 255, 255, 0.6);
    --bg-primary: #0a0a14;
    --bg-secondary: #1a1a2e;
    --accent-blue: #3b82f6;
    --accent-purple: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --sidebar-width: 280px;
    --border-radius: 16px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* Glass Effect */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    box-shadow: var(--glass-shadow);
}

.glass-bottom {
    background: linear-gradient(to bottom, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255,255,255,0.1);
    border-radius: 0;
    border-bottom-left-radius: var(--border-radius);
    border-bottom-right-radius: var(--border-radius);
}

.glass-top {
    background: linear-gradient(to top, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    border-radius: 0;
    border-top-left-radius: var(--border-radius);
    border-top-right-radius: var(--border-radius);
}

/* Login Overlay */
#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #0a0a14 0%, #1a1a2e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#login-overlay.hidden {
    display: none;
}

.login-box {
    width: 90%;
    max-width: 400px;
    padding: var(--spacing-xl);
    text-align: center;
    animation: slideUp 0.5s ease-out;
}

.login-box h2 {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    font-size: 2.5rem;
    margin-bottom: var(--spacing-lg);
    font-weight: 800;
    letter-spacing: -0.5px;
}

.login-box input {
    width: 100%;
    padding: 14px 18px;
    margin: var(--spacing-md) 0;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 16px;
    transition: all 0.3s ease;
}

.login-box input:focus {
    outline: none;
    border-color: var(--accent-blue);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.login-box input::placeholder {
    color: var(--text-muted);
}

.login-box button {
    width: 100%;
    padding: 15px;
    background: var(--primary-gradient);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: var(--spacing-md);
}

.login-box button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
}

.login-box button:active {
    transform: translateY(0);
}

#login-error {
    color: var(--danger);
    margin-top: var(--spacing-md);
    font-size: 14px;
    min-height: 20px;
}

/* App Container */
#app-container {
    display: flex;
    height: 100vh;
    background: linear-gradient(135deg, #0a0a14 0%, #1a1a2e 100%);
    position: relative;
}

#app-container.hidden {
    display: none;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: var(--spacing-lg);
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
}

.new-chat-btn {
    background: var(--primary-gradient);
    color: white;
    padding: 14px 18px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.3s ease;
    margin-bottom: var(--spacing-lg);
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    margin: var(--spacing-md) 0;
    padding-right: var(--spacing-sm);
}

/* Scrollbar */
.chat-list::-webkit-scrollbar,
.messages-container::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-track,
.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-list::-webkit-scrollbar-thumb,
.messages-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.chat-list::-webkit-scrollbar-thumb:hover,
.messages-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-item {
    padding: 14px 16px;
    margin: 6px 0;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.1);
}

.chat-item.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
}

.chat-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
    color: var(--text-secondary);
}

.chat-item.active .chat-title {
    color: var(--text-primary);
    font-weight: 500;
}

.chat-item .ph-chat-circle-text {
    color: var(--accent-blue);
    font-size: 18px;
}

.chat-item .delete-chat {
    color: var(--text-muted);
    opacity: 0;
    transition: all 0.3s ease;
    padding: 4px;
    border-radius: 6px;
}

.chat-item:hover .delete-chat {
    opacity: 1;
}

.chat-item .delete-chat:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.user-profile {
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.user-profile .ph-user-circle {
    font-size: 24px;
    color: var(--accent-purple);
}

.user-profile .logout-btn {
    margin-left: auto;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.user-profile .logout-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* Chat Area */
.chat-area {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
}

.chat-header {
    padding: var(--spacing-lg) var(--spacing-xl);
    font-size: 24px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-align: center;
    letter-spacing: -0.5px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-xl);
    padding-bottom: calc(var(--spacing-xl) * 2);
}

.welcome-screen {
    text-align: center;
    padding: var(--spacing-xl) 0;
    margin-top: 20vh;
    animation: fadeIn 1s ease-out;
}

.welcome-screen h1 {
    font-size: 4rem;
    background: linear-gradient(135deg, #667eea, #764ba2, #f093fb, #f5576c);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: var(--spacing-md);
    font-weight: 800;
    letter-spacing: -1px;
    animation: gradientShift 8s ease infinite;
    background-size: 400% 400%;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.welcome-screen p {
    font-size: 1.5rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
}

/* Messages */
.message {
    display: flex;
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
    animation: messageAppear 0.4s ease-out;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 4px;
}

.message.user .message-avatar {
    background: var(--user-gradient);
}

.message.assistant .message-avatar {
    background: var(--ai-gradient);
}

.message-avatar .ph {
    font-size: 20px;
    color: white;
}

.message-content {
    flex: 1;
    padding: var(--spacing-lg);
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.6;
    position: relative;
    min-width: 200px;
}

.message.user .message-content {
    background: rgba(245, 87, 108, 0.15);
    border: 1px solid rgba(245, 87, 108, 0.2);
    border-top-right-radius: 4px;
    margin-left: 60px;
}

.message.assistant .message-content {
    background: rgba(79, 172, 254, 0.15);
    border: 1px solid rgba(79, 172, 254, 0.2);
    border-top-left-radius: 4px;
    margin-right: 60px;
}

/* Markdown Styles */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 1.5em 0 0.8em 0;
    color: var(--text-primary);
    font-weight: 600;
}

.message-content h1 { font-size: 1.8em; }
.message-content h2 { font-size: 1.6em; }
.message-content h3 { font-size: 1.4em; }
.message-content h4 { font-size: 1.2em; }
.message-content h5 { font-size: 1.1em; }
.message-content h6 { font-size: 1em; }

.message-content p {
    margin: 1em 0;
    color: var(--text-secondary);
}

.message-content strong {
    color: var(--text-primary);
    font-weight: 600;
}

.message-content em {
    color: var(--text-secondary);
    font-style: italic;
}

.message-content a {
    color: var(--accent-blue);
    text-decoration: none;
    border-bottom: 1px solid rgba(59, 130, 246, 0.3);
    transition: all 0.3s ease;
}

.message-content a:hover {
    color: var(--accent-purple);
    border-bottom-color: var(--accent-purple);
}

.message-content ul,
.message-content ol {
    margin: 1em 0;
    padding-left: 2em;
    color: var(--text-secondary);
}

.message-content li {
    margin: 0.5em 0;
}

.message-content blockquote {
    border-left: 4px solid var(--accent-purple);
    margin: 1.5em 0;
    padding: 0.5em 1em;
    background: rgba(139, 92, 246, 0.1);
    border-radius: 0 8px 8px 0;
    color: var(--text-secondary);
}

.message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 0.9em;
    color: #e6e6e6;
}

.message-content pre {
    background: #1e1e2e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: var(--spacing-md);
    margin: 1.5em 0;
    overflow-x: auto;
    position: relative;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    font-size: 14px;
    line-height: 1.5;
}

.message-content pre::before {
    content: '📋';
    position: absolute;
    top: 12px;
    right: 12px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    opacity: 0.7;
    transition: opacity 0.3s ease;
}

.message-content pre:hover::before {
    opacity: 1;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    overflow: hidden;
}

.message-content th,
.message-content td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.message-content th {
    background: rgba(255, 255, 255, 0.1);
    font-weight: 600;
    color: var(--text-primary);
}

.message-content tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.message-image {
    margin-top: 12px;
    border-radius: 12px;
    overflow: hidden;
    max-width: 400px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.message-image img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
}

.message-image:hover img {
    transform: scale(1.02);
}

/* Input Area */
.input-area-wrapper {
    padding: var(--spacing-md) var(--spacing-xl);
    position: relative;
}

.attachment-preview {
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-sm);
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    border: 1px dashed rgba(255, 255, 255, 0.1);
}

.attachment-preview.hidden {
    display: none;
}

.attachment-item {
    position: relative;
    display: inline-block;
    margin: var(--spacing-sm);
}

.attachment-item img {
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.attachment-item button {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    background: var(--danger);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.3s ease;
}

.attachment-item button:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.input-box {
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-md);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    padding: 8px 8px 8px 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.input-box:focus-within {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.attach-btn {
    padding: 10px;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 10px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.attach-btn:hover {
    color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.1);
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    padding: 10px 0;
    min-height: 24px;
}

#message-input:focus {
    outline: none;
}

#message-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 44px;
    height: 44px;
    background: var(--primary-gradient);
    border: none;
    border-radius: 12px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.send-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
}

.send-btn:active {
    transform: translateY(0);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--accent-blue);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.6; }
    40% { transform: scale(1); opacity: 1; }
}

/* Error Message */
.error-message {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid rgba(239, 68, 68, 0.2);
    font-size: 14px;
}

/* Snowflakes */
.snowflakes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

.snowflake {
    position: absolute;
    color: rgba(255, 255, 255, 0.3);
    font-size: 1.2em;
    animation: fall linear infinite;
    top: -10%;
}

.snowflake:nth-child(1) { left: 10%; animation-duration: 10s; animation-delay: 0s; }
.snowflake:nth-child(2) { left: 20%; animation-duration: 12s; animation-delay: 1s; }
.snowflake:nth-child(3) { left: 30%; animation-duration: 14s; animation-delay: 2s; }
.snowflake:nth-child(4) { left: 40%; animation-duration: 16s; animation-delay: 3s; }
.snowflake:nth-child(5) { left: 50%; animation-duration: 18s; animation-delay: 4s; }
.snowflake:nth-child(6) { left: 60%; animation-duration: 20s; animation-delay: 5s; }
.snowflake:nth-child(7) { left: 70%; animation-duration: 22s; animation-delay: 6s; }
.snowflake:nth-child(8) { left: 80%; animation-duration: 24s; animation-delay: 7s; }
.snowflake:nth-child(9) { left: 90%; animation-duration: 26s; animation-delay: 8s; }
.snowflake:nth-child(10) { left: 95%; animation-duration: 28s; animation-delay: 9s; }
.snowflake:nth-child(11) { left: 5%; animation-duration: 30s; animation-delay: 10s; }
.snowflake:nth-child(12) { left: 15%; animation-duration: 32s; animation-delay: 11s; }

@keyframes fall {
    to {
        transform: translateY(110vh) rotate(360deg);
        opacity: 0;
    }
}

/* Animations */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        transition: left 0.3s ease;
        z-index: 1000;
    }
    
    .sidebar.active {
        left: 0;
    }
    
    .chat-area {
        margin-left: 0;
    }
    
    .chat-header {
        font-size: 20px;
        padding: var(--spacing-md);
    }
    
    .messages-container {
        padding: var(--spacing-md);
    }
    
    .message {
        gap: var(--spacing-md);
        margin-bottom: var(--spacing-lg);
    }
    
    .message-content {
        padding: var(--spacing-md);
        font-size: 14px;
    }
    
    .input-area-wrapper {
        padding: var(--spacing-md);
    }
    
    .welcome-screen h1 {
        font-size: 2.5rem;
    }
    
    .welcome-screen p {
        font-size: 1.2rem;
    }
}