/* ===== DESIGN TOKENS ===== */
:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-user-msg: #1d2951;
    --bg-bot-msg: rgba(30, 41, 59, 0.6);
    --bg-input: rgba(15, 23, 42, 0.8);
    --border-color: rgba(99, 102, 241, 0.15);
    --border-focus: rgba(99, 102, 241, 0.5);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.25);
    --red-accent: #dc2626;
    --green-accent: #22c55e;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-pill: 24px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
    --shadow-glow: 0 0 30px var(--accent-glow);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0; padding: 0; box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ===== ANIMATED BACKGROUND ===== */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 600px 400px at 20% 20%, rgba(99, 102, 241, 0.08), transparent),
        radial-gradient(ellipse 500px 500px at 80% 80%, rgba(139, 92, 246, 0.06), transparent),
        radial-gradient(ellipse 400px 300px at 50% 50%, rgba(59, 130, 246, 0.04), transparent);
    pointer-events: none;
    z-index: 0;
    animation: bgPulse 8s ease-in-out infinite alternate;
}

@keyframes bgPulse {
    0% { opacity: 0.7; }
    100% { opacity: 1; }
}

/* ===== APP LAYOUT ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 860px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

/* ===== HEADER ===== */
header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 24px;
    backdrop-filter: blur(20px);
    background: rgba(10, 14, 26, 0.85);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.logo {
    width: 42px; height: 42px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px; color: #fff;
    box-shadow: var(--shadow-glow);
    flex-shrink: 0;
}

.header-text h1 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.header-text p {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 1px;
}

.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--green-accent);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
    margin-left: auto;
    flex-shrink: 0;
    animation: pulse 2s ease-in-out infinite;
}

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

/* ===== CHAT MESSAGES ===== */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 5px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.2);
    border-radius: 10px;
}

.msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    line-height: 1.65;
    font-size: 14.5px;
    animation: msgIn 0.3s ease-out both;
    word-wrap: break-word;
}

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

.msg.user {
    align-self: flex-end;
    background: var(--bg-user-msg);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-bottom-right-radius: 4px;
    color: #c7d2fe;
}

.msg.bot {
    align-self: flex-start;
    background: var(--bg-bot-msg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.msg.bot .label {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-light);
    margin-bottom: 6px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

/* Markdown rendering inside bot messages */
.msg.bot h1, .msg.bot h2, .msg.bot h3 {
    margin: 14px 0 6px;
    font-weight: 600;
    color: #e2e8f0;
}
.msg.bot h1 { font-size: 16px; }
.msg.bot h2 { font-size: 15px; }
.msg.bot h3 { font-size: 14px; }

.msg.bot p { margin: 4px 0; }

.msg.bot ul, .msg.bot ol {
    margin: 6px 0 6px 20px;
}

.msg.bot li {
    margin-bottom: 3px;
}

.msg.bot strong {
    color: #c7d2fe;
    font-weight: 600;
}

.msg.bot code {
    background: rgba(99, 102, 241, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.msg.bot pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.msg.bot pre code {
    background: none;
    padding: 0;
}

.msg.bot table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
}

.msg.bot th, .msg.bot td {
    padding: 6px 10px;
    border: 1px solid rgba(99, 102, 241, 0.15);
    text-align: left;
}

.msg.bot th {
    background: rgba(99, 102, 241, 0.1);
    font-weight: 600;
    color: #c7d2fe;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 4px 0;
}

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

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0%, 100% { opacity: 0.3; transform: scale(0.85); }
    50% { opacity: 1; transform: scale(1); }
}

/* ===== WELCOME SCREEN ===== */
#welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
}

#welcome .icon {
    width: 72px; height: 72px;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex; align-items: center; justify-content: center;
    font-size: 32px;
    box-shadow: var(--shadow-glow);
    margin-bottom: 20px;
}

#welcome h2 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: -0.3px;
}

#welcome p {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 380px;
    line-height: 1.6;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 28px;
    justify-content: center;
    max-width: 520px;
}

.suggestions button {
    background: var(--bg-bot-msg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 13px;
    padding: 9px 16px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.suggestions button:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    background: rgba(99, 102, 241, 0.08);
    transform: translateY(-1px);
}

/* ===== INPUT AREA ===== */
#input-area {
    padding: 16px 24px 20px;
    backdrop-filter: blur(20px);
    background: rgba(10, 14, 26, 0.85);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 16px;
    transition: var(--transition);
}

.input-row:focus-within {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-glow);
}

#input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14.5px;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 8px 0;
}

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

#send-btn {
    width: 40px; height: 40px;
    border-radius: var(--radius);
    border: none;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
}

#send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: var(--shadow-glow);
}

#send-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

#send-btn svg {
    width: 18px; height: 18px;
}

.hint {
    font-size: 11px;
    text-align: center;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
    header { padding: 12px 16px; }
    #messages { padding: 14px 16px; }
    #input-area { padding: 12px 16px 16px; }
    .msg { max-width: 92%; font-size: 14px; }
    #welcome h2 { font-size: 19px; }
    .suggestions { flex-direction: column; align-items: center; }
}
