:root {
    --bg-color: #050505;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --glass-bg: rgba(15, 23, 42, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
    --accent-color: #0ea5e9;
    --accent-hover: #0284c7;
    --user-msg-bg: linear-gradient(135deg, #0ea5e9, #6366f1);
    --ai-msg-bg: rgba(30, 41, 59, 0.7);
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

/* Stunning Animated Background */
.background {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 0; overflow: hidden;
    background: radial-gradient(circle at 50% 50%, #1e1b4b 0%, #050505 100%);
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.6;
    animation: float 25s infinite ease-in-out alternate;
}

.blob-1 {
    top: -20%; left: -10%;
    width: 60vw; height: 60vw;
    background: radial-gradient(circle, rgba(14,165,233,0.3) 0%, rgba(14,165,233,0) 70%);
}

.blob-2 {
    bottom: -20%; right: -10%;
    width: 70vw; height: 70vw;
    background: radial-gradient(circle, rgba(99,102,241,0.3) 0%, rgba(99,102,241,0) 70%);
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1) rotate(0deg); }
    100% { transform: translate(15%, 15%) scale(1.2) rotate(10deg); }
}

/* Glassmorphism Panel */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

.app-container {
    width: 100%;
    max-width: 1000px;
    height: 92vh;
    display: flex;
    flex-direction: column;
    z-index: 1;
    border-radius: 28px;
    overflow: hidden;
    margin: 0 20px;
    position: relative;
    border: 1px solid rgba(255,255,255,0.1);
}

.app-container::before {
    content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    z-index: 10;
}

/* Header */
.header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 24px 35px;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(15, 23, 42, 0.8);
}

.logo { display: flex; align-items: center; gap: 14px; }
.logo i { font-size: 32px; color: #38bdf8; filter: drop-shadow(0 0 10px rgba(56,189,248,0.5)); }
.logo h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; background: linear-gradient(to right, #fff, #94a3b8); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.status { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-secondary); font-weight: 500; }
.status-indicator {
    width: 10px; height: 10px; border-radius: 50%; background-color: #10b981;
    box-shadow: 0 0 12px #10b981, 0 0 4px #10b981;
}

/* Chat Area */
.chat-container {
    flex: 1; overflow-y: auto; padding: 40px 35px; display: flex; flex-direction: column; gap: 32px;
    scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar { width: 8px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 10px; }
.chat-container::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.25); }

/* Messages */
.message {
    display: flex; gap: 20px; max-width: 88%;
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    opacity: 0; transform: translateY(20px);
}

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

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

.avatar {
    width: 42px; height: 42px; border-radius: 50%;
    display: flex; justify-content: center; align-items: center;
    flex-shrink: 0; font-size: 22px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.user .avatar { background: var(--user-msg-bg); color: white; }
.ai .avatar { background: #1e293b; border: 1px solid rgba(255, 255, 255, 0.15); color: #38bdf8; }

.message-body {
    display: flex; flex-direction: column; gap: 8px;
    max-width: 100%; min-width: 0;
}

.content {
    padding: 18px 24px; border-radius: 22px;
    font-size: 15.5px; line-height: 1.65; word-wrap: break-word;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.user .content {
    background: var(--user-msg-bg);
    border-top-right-radius: 6px;
    color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.ai .content {
    background: var(--ai-msg-bg);
    border-top-left-radius: 6px;
    border: 1px solid var(--glass-border);
}

/* Action Bar for AI Messages */
.action-bar {
    display: flex; gap: 10px; margin-left: 5px; opacity: 0; transition: opacity 0.3s;
}
.message.ai:hover .action-bar { opacity: 1; }

.msg-action-btn {
    background: transparent; border: none; color: var(--text-secondary);
    font-size: 13px; font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 6px;
    padding: 4px 8px; border-radius: 6px; transition: all 0.2s;
    font-family: var(--font-family);
}
.msg-action-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }

/* Markdown Styles */
.content p { margin-bottom: 1em; }
.content p:last-child { margin-bottom: 0; }
.content a { color: #38bdf8; text-decoration: none; border-bottom: 1px solid transparent; transition: border-color 0.2s; }
.content a:hover { border-color: #38bdf8; }
.content ul, .content ol { margin-left: 24px; margin-bottom: 1em; }
.content li { margin-bottom: 4px; }
.content strong { color: #fff; font-weight: 600; }

/* Enhanced Code Blocks */
.code-wrapper {
    margin: 16px 0; border-radius: 12px; overflow: hidden;
    border: 1px solid rgba(255,255,255,0.15);
    background: #0f172a;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.code-header {
    display: flex; justify-content: space-between; align-items: center;
    background: #1e293b; padding: 10px 16px; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.code-lang { font-size: 12px; color: #94a3b8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.copy-code-btn {
    background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
    color: #cbd5e1; padding: 6px 12px; border-radius: 6px;
    font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 6px;
    transition: all 0.2s; font-family: var(--font-family); font-weight: 500;
}
.copy-code-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.content pre {
    padding: 16px; margin: 0; overflow-x: auto; font-size: 14px;
}
.content pre::-webkit-scrollbar { height: 6px; }
.content pre::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }
.content code {
    font-family: 'Fira Code', 'Courier New', Courier, monospace;
    background: rgba(255,255,255,0.1); padding: 3px 6px; border-radius: 4px; font-size: 0.9em;
}
.content pre code { background: transparent; padding: 0; color: #e2e8f0; line-height: 1.5; }

/* Tables */
.content table {
    width: 100%; border-collapse: separate; border-spacing: 0; margin: 16px 0;
    border-radius: 12px; overflow: hidden; border: 1px solid rgba(255,255,255,0.1);
}
.content th, .content td { padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.05); text-align: left; }
.content th { background: rgba(255,255,255,0.08); font-weight: 600; color: #fff; }
.content tr:last-child td { border-bottom: none; }
.content tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

/* Input Area */
.input-area {
    padding: 24px 35px; border-top: 1px solid var(--glass-border);
    background: rgba(15, 23, 42, 0.8);
}
.input-form {
    display: flex; gap: 16px; align-items: flex-end;
    background: rgba(0, 0, 0, 0.3); border-radius: 24px; padding: 10px 10px 10px 20px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.2);
}
.input-form:focus-within {
    border-color: #38bdf8; background: rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15), inset 0 2px 10px rgba(0,0,0,0.2);
}
textarea {
    flex: 1; background: transparent; border: none; color: var(--text-primary);
    font-family: var(--font-family); font-size: 16px; padding: 12px 0;
    resize: none; outline: none; max-height: 150px; line-height: 1.5;
}
textarea::placeholder { color: var(--text-secondary); }
#send-btn {
    background: var(--user-msg-bg); color: white; border: none;
    width: 48px; height: 48px; border-radius: 50%;
    display: flex; justify-content: center; align-items: center; cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); flex-shrink: 0;
    box-shadow: 0 4px 15px rgba(14, 165, 233, 0.4);
}
#send-btn i { font-size: 22px; }
#send-btn:hover { transform: scale(1.08) translateY(-2px); box-shadow: 0 6px 20px rgba(14, 165, 233, 0.6); }
#send-btn:active { transform: scale(0.95); }

/* Typing indicator */
.typing-indicator { display: flex; gap: 5px; padding: 8px 4px; }
.typing-dot {
    width: 8px; height: 8px; background: #38bdf8; border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both; opacity: 0.7;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* Responsive Design */

@media (max-width: 1024px) {
    .app-container { margin: 0 15px; width: auto; }
}

@media (max-width: 768px) {
    .app-container { height: 100vh; height: 100dvh; margin: 0; border-radius: 0; border: none; width: 100%; }
    .header { padding: 15px 20px; }
    .logo i { font-size: 26px; }
    .logo h1 { font-size: 18px; }
    .chat-container { padding: 20px; gap: 24px; }
    .message { max-width: 95%; gap: 12px; }
    .avatar { width: 36px; height: 36px; font-size: 18px; }
    .content { padding: 14px 18px; font-size: 15px; }
    .input-area { padding: 15px 20px; }
    .input-form { padding: 8px 8px 8px 16px; border-radius: 20px; gap: 12px; }
    #send-btn { width: 44px; height: 44px; }
    #send-btn i { font-size: 20px; }
}

@media (max-width: 480px) {
    .header { padding: 12px 15px; }
    .logo h1 { font-size: 16px; }
    .logo i { font-size: 22px; }
    .status-text { display: none; }
    .chat-container { padding: 15px 10px; gap: 16px; }
    .message { max-width: 100%; gap: 8px; }
    .avatar { width: 30px; height: 30px; font-size: 15px; }
    .content { padding: 12px 16px; font-size: 14px; border-radius: 18px; }
    .user .content { border-top-right-radius: 6px; }
    .ai .content { border-top-left-radius: 6px; }
    .input-area { padding: 12px 10px; }
    .input-form { padding: 6px 6px 6px 14px; border-radius: 22px; }
    textarea { font-size: 15px; padding: 10px 0; }
    #send-btn { width: 40px; height: 40px; }
    #send-btn i { font-size: 18px; }
    .content pre { padding: 12px; font-size: 12px; }
    .content th, .content td { padding: 8px 10px; font-size: 13px; }
}
