:root {
    --bg-dark: #07080b;
    --bg-card: rgba(22, 24, 33, 0.6);
    --bg-secondary: #12141c;
    --primary: #818cf8;
    --primary-glow: rgba(129, 140, 248, 0.2);
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --glass-blur: blur(20px);
    --accent: #34d399;
    --error: #f87171;
    --header-height: 72px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(129, 140, 248, 0.4);
    background-clip: content-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for mobile */
    width: 100vw;
}

h1,
h2,
h3,
.logo h1 {
    font-family: 'Outfit', sans-serif;
    letter-spacing: -0.02em;
}

/* --- Layout --- */
#app {
    height: 100%;
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

section {
    display: none;
    height: 100%;
    width: 100%;
    flex-direction: column;
}

section.active {
    display: flex;
}

/* --- Glassmorphism & Cards --- */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-radius: 24px;
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
}

/* --- Login Page --- */
#login-section {
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at 50% 0%, #1e1b4b 0%, #07080b 100%);
    padding: 20px;
}

.auth-card {
    padding: 48px 32px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    animation: slideUpFade 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

.logo {
    margin-bottom: 32px;
}

.logo-img {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    filter: drop-shadow(0 0 15px var(--primary-glow));
}

.logo h1 {
    font-size: 2.4rem;
    font-weight: 700;
}

.logo h1 span {
    color: var(--primary);
}

.subtitle {
    color: var(--text-dim);
    margin-bottom: 40px;
    line-height: 1.6;
    font-size: 1.05rem;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 16px 32px;
    border-radius: 16px;
    border: none;
    font-weight: 600;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    width: 100%;
}

.primary-btn {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 20px var(--primary-glow);
}

.primary-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

/* --- Chat Header --- */
.glass-header {
    height: var(--header-height);
    background: rgba(7, 8, 11, 0.85);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    display: flex;
    align-items: center;
    padding: 0 24px;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    align-items: center;
}

.logo-small {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.logo-small h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.badge {
    background: rgba(255, 255, 255, 0.04);
    padding: 6px 14px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
}

.premium-badge {
    color: var(--accent);
    background: rgba(52, 211, 153, 0.08);
}

.icon-btn {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: var(--text-dim);
    width: 38px;
    height: 38px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* --- Chat Area --- */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
    mask-image: linear-gradient(to bottom, transparent, black 20px, black calc(100% - 20px), transparent);
}

.message {
    max-width: 85%;
    padding: 16px 20px;
    line-height: 1.6;
    font-size: 1.05rem;
    animation: messageIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.message.user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-radius: 24px 24px 4px 24px;
    box-shadow: 0 8px 20px -8px var(--primary-glow);
    margin: 20px;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bg-secondary);
    border-radius: 24px 24px 24px 4px;
}

.message.error {
    background: rgba(248, 113, 113, 0.1);
    color: var(--error);
}

/* --- Footer --- */
.chat-footer {
    padding: 24px;
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
}

.input-container {
    display: flex;
    align-items: flex-end;
    padding: 14px 14px 14px 24px;
    gap: 12px;
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-size: 1.1rem;
    font-family: inherit;
    resize: none;
    max-height: 180px;
    padding: 10px 0;
}

textarea:focus {
    outline: none;
}

#send-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 12px var(--primary-glow);
}

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

#send-btn:disabled {
    background: var(--bg-secondary);
    color: var(--text-dim);
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.5;
}

.disclaimer {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 16px;
    opacity: 0.7;
}

/* --- Mobile Adaptations --- */
@media (max-width: 768px) {
    :root {
        --header-height: 64px;
    }

    #chat-container {
        padding: 16px;
        gap: 16px;
    }

    .message {
        max-width: 92%;
        font-size: 1rem;
        padding: 14px 16px;
    }

    .chat-footer {
        padding: 12px;
    }

    .input-container {
        padding: 10px 10px 10px 20px;
        border-radius: 20px;
    }

    .logo h1 {
        font-size: 2rem;
    }

    .badge {
        display: none;
        /* Hide authorized badge on mobile to save space */
    }
}

/* --- Animations --- */
@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

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

@keyframes messageIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255, 255, 255, 0.05);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 32px auto;
}

.hidden {
    display: none !important;
}

/* Code and Lists */
pre {
    background: #000000;
    padding: 16px;
    border-radius: 12px;
    overflow-x: auto;
    margin: 12px 0;
}

ul,
ol {
    margin-left: 20px;
    margin-bottom: 12px;
}

li {
    margin-bottom: 4px;
}