* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #07111f;
    --bg-secondary: #0f172a;

    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;

    --border: rgba(148, 163, 184, 0.22);

    --blue: #2563eb;
    --purple: #7c3aed;

    --user-message: linear-gradient(
        135deg,
        #2563eb,
        #7c3aed
    );

    --assistant-message: rgba(
        15,
        23,
        42,
        0.88
    );

    --safe-bottom: env(
        safe-area-inset-bottom,
        0px
    );
}

/* =========================================================
   PAGE
   ========================================================= */

html {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    overflow: hidden !important;
}

body {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    margin: 0;
    font-family:
        Inter,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden !important;
}

/* =========================================================
   GLOBAL
   ========================================================= */

button,
textarea {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

img {
    display: block;
    max-width: 100%;
}

/* =========================================================
   BACKGROUND
   ========================================================= */

.page-bg {
    position: fixed;

    inset: 0;

    z-index: -1;

    overflow: hidden;

    background:
        radial-gradient(
            circle at top left,
            rgba(56, 189, 248, 0.18),
            transparent 32%
        ),
        radial-gradient(
            circle at top right,
            rgba(168, 85, 247, 0.18),
            transparent 28%
        ),
        linear-gradient(
            135deg,
            #07111f 0%,
            #0f172a 45%,
            #111827 100%
        );
}

.gradient-circle {
    position: absolute;

    border-radius: 999px;

    filter: blur(80px);

    opacity: 0.35;

    pointer-events: none;
}

.circle-1 {
    width: 320px;
    height: 320px;

    top: 5%;
    left: 3%;

    background: #2563eb;
}

.circle-2 {
    width: 300px;
    height: 300px;

    top: 20%;
    right: 5%;

    background: #9333ea;
}

.circle-3 {
    width: 250px;
    height: 250px;

    bottom: 5%;
    left: 40%;

    background: #14b8a6;
}

/* =========================================================
   APP CONTAINER
   ========================================================= */

.app-container {
    width: min(1080px, calc(100% - 32px));
    height: 100dvh;
    margin: 0 auto;
    padding: 28px 0 12px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 18px;
    min-height: 0;
    overflow: hidden !important;
}

/* =========================================================
   HERO
   ========================================================= */

.hero-section {
    width: 100%;
    min-width: 0;

    text-align: center;
}

.badge {
    display: inline-flex;

    align-items: center;

    gap: 8px;

    padding:
        7px
        13px;

    border:
        1px solid
        rgba(148, 163, 184, 0.3);

    border-radius: 999px;

    background:
        rgba(15, 23, 42, 0.68);

    backdrop-filter: blur(15px);

    color: #c4b5fd;

    font-size: 0.76rem;

    font-weight: 700;

    margin-bottom: 14px;
}

.badge-logo {
    width: 26px;
    height: 26px;

    flex-shrink: 0;

    display: flex;

    align-items: center;

    justify-content: center;
}

.badge-logo img {
    width: 26px;
    height: 26px;

    border-radius: 8px;

    object-fit: cover;
}

.status-dot,
.online-dot {
    width: 8px;
    height: 8px;

    flex-shrink: 0;

    border-radius: 50%;

    background: #22c55e;

    box-shadow:
        0 0 15px
        rgba(34, 197, 94, 0.8);
}

.hero-section h1 {
    font-size:
        clamp(
            2.15rem,
            6vw,
            4.25rem
        );

    line-height: 0.98;

    letter-spacing: -0.055em;

    margin-bottom: 11px;

    background:
        linear-gradient(
            135deg,
            #ffffff,
            #93c5fd,
            #c084fc
        );

    background-clip: text;

    -webkit-background-clip: text;

    color: transparent;

    -webkit-text-fill-color: transparent;
}

.hero-section p {
    max-width: 650px;

    margin: 0 auto;

    color: var(--text-secondary);

    font-size: 0.95rem;

    line-height: 1.55;
}

/* =========================================================
   CHAT CARD
   ========================================================= */

.chat-card {
    width: 100%;
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    overflow: hidden !important;
    background: rgba(15, 23, 42, 0.76);

    border:
        1px solid
        var(--border);

    border-radius: 26px;

    box-shadow:
        0 30px 90px
        rgba(0, 0, 0, 0.38);

    backdrop-filter: blur(22px);
}

/* =========================================================
   CHAT HEADER
   ========================================================= */

.chat-header {
    width: 100%;
    min-width: 0;

    display: flex;

    align-items: center;

    justify-content: space-between;

    gap: 16px;

    padding:
        17px
        21px;

    border-bottom:
        1px solid
        var(--border);

    background:
        rgba(2, 6, 23, 0.25);

    overflow: hidden;
}

.assistant-info {
    display: flex;

    align-items: center;

    gap: 11px;

    min-width: 0;
}

.assistant-avatar {
    width: 40px;
    height: 40px;

    flex-shrink: 0;

    display: flex;

    align-items: center;

    justify-content: center;

    border-radius: 12px;

    overflow: hidden;

    background:
        linear-gradient(
            135deg,
            #2563eb,
            #7c3aed
        );

    box-shadow:
        0 8px 25px
        rgba(37, 99, 235, 0.28);
}

.assistant-avatar img {
    width: 100%;
    height: 100%;

    max-width: 100%;
    max-height: 100%;

    object-fit: cover;

    border-radius: 8px;
}

.assistant-details {
    min-width: 0;
}

.assistant-info h2 {
    font-size: 0.96rem;

    font-weight: 700;

    margin-bottom: 3px;

    white-space: nowrap;

    overflow: hidden;

    text-overflow: ellipsis;
}

.online-status {
    display: flex;

    align-items: center;

    gap: 6px;

    color: #86efac;

    font-size: 0.7rem;
}

.online-dot {
    width: 6px;
    height: 6px;

    box-shadow: none;
}

.new-chat-btn {
    display: inline-flex;

    align-items: center;

    gap: 5px;

    flex-shrink: 0;

    border:
        1px solid
        rgba(148, 163, 184, 0.25);

    background:
        rgba(30, 41, 59, 0.65);

    color: var(--text-secondary);

    border-radius: 11px;

    padding:
        8px
        11px;

    font-size: 0.76rem;

    font-weight: 600;

    cursor: pointer;

    transition:
        0.2s
        ease;
}

.new-chat-icon {
    font-size: 1rem;

    line-height: 1;
}

.new-chat-btn:hover {
    background:
        rgba(59, 130, 246, 0.18);

    border-color:
        rgba(96, 165, 250, 0.45);

    color: white;
}

/* =========================================================
   CHAT MESSAGES
   ========================================================= */

#chatMessages {
    width: 100%;
    min-width: 0;
    min-height: 0;
    flex: 1 1 auto;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding: 24px 23px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.45) transparent;
}

#chatMessages::-webkit-scrollbar {
    width: 7px;
}

#chatMessages::-webkit-scrollbar-track {
    background: transparent;
}

#chatMessages::-webkit-scrollbar-thumb {
    background:
        rgba(148, 163, 184, 0.45);

    border-radius: 999px;
}

#chatMessages::-webkit-scrollbar-thumb:hover {
    background:
        rgba(148, 163, 184, 0.65);
}

/* =========================================================
   EMPTY STATE
   ========================================================= */

.empty-state {
    min-height: 100%;

    display: flex;

    flex-direction: column;

    align-items: center;

    justify-content: center;

    text-align: center;

    padding:
        28px
        16px;
}

.empty-icon {
    width: 68px;
    height: 68px;

    display: flex;

    align-items: center;

    justify-content: center;

    border-radius: 20px;

    margin-bottom: 16px;

    background:
        rgba(59, 130, 246, 0.12);

    border:
        1px solid
        rgba(96, 165, 250, 0.2);

    overflow: hidden;
}

.empty-icon img {
    width: 42px;
    height: 42px;

    max-width: 42px;
    max-height: 42px;

    border-radius: 12px;

    object-fit: cover;
}

.empty-state h2 {
    font-size: 1.28rem;

    margin-bottom: 7px;
}

.empty-state > p {
    color: var(--text-muted);

    font-size: 0.88rem;

    margin-bottom: 21px;
}

.quick-prompts {
    display: flex;

    flex-wrap: wrap;

    justify-content: center;

    gap: 8px;

    max-width: 720px;
}

.quick-prompts button {
    border:
        1px solid
        rgba(148, 163, 184, 0.22);

    background:
        rgba(30, 41, 59, 0.58);

    color: #dbeafe;

    border-radius: 999px;

    padding:
        9px
        13px;

    font-size: 0.75rem;

    cursor: pointer;

    transition:
        0.2s
        ease;
}

.quick-prompts button:hover {
    background:
        rgba(59, 130, 246, 0.18);

    border-color:
        rgba(96, 165, 250, 0.45);

    transform:
        translateY(-1px);
}

/* =========================================================
   MESSAGES
   ========================================================= */

.message {
    display: flex;

    gap: 10px;

    margin-bottom: 21px;

    animation:
        messageIn
        0.25s
        ease;
}

.message:last-child {
    margin-bottom: 0;
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 800;
    overflow: hidden;
}

.message-avatar-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    border-radius: 8px;
}

.user-avatar {
    background:
        rgba(99, 102, 241, 0.18);

    border:
        1px solid
        rgba(129, 140, 248, 0.25);

    color: #c7d2fe;
}

.message-content-wrapper {
    max-width:
        min(
            78%,
            720px
        );

    min-width: 0;
}

.message.user .message-content-wrapper {
    display: flex;

    flex-direction: column;

    align-items: flex-end;
}

.message-content {
    max-width: 100%;

    padding:
        13px
        16px;

    border-radius: 17px;

    line-height: 1.62;

    font-size: 0.88rem;

    word-wrap: break-word;

    overflow-wrap: anywhere;
}

.message.user .message-content {
    background:
        var(--user-message);

    color: white;

    border-bottom-right-radius: 5px;

    box-shadow:
        0 12px 30px
        rgba(37, 99, 235, 0.2);
}

.message.assistant .message-content {
    background:
        var(--assistant-message);

    border:
        1px solid
        rgba(148, 163, 184, 0.17);

    color: #e2e8f0;

    border-bottom-left-radius: 5px;
}

/* =========================================================
   MARKDOWN
   ========================================================= */

.message-content h1,
.message-content h2,
.message-content h3 {
    color: white;

    margin:
        16px
        0
        8px;
}

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child {
    margin-top: 0;
}

.message-content p {
    margin-bottom: 9px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul,
.message-content ol {
    padding-left: 20px;

    margin:
        8px
        0
        11px;
}

.message-content li {
    margin-bottom: 4px;
}

.message-content strong {
    color: white;
}

.message-content code {
    padding:
        2px
        6px;

    border-radius: 6px;

    background:
        rgba(2, 6, 23, 0.65);

    font-family:
        "SFMono-Regular",
        Consolas,
        monospace;

    font-size: 0.82em;
}

.message-content pre {
    max-width: 100%;

    overflow-x: auto;

    padding: 12px;

    margin:
        11px
        0;

    border-radius: 10px;

    background:
        rgba(2, 6, 23, 0.75);
}

.message-content pre code {
    background: none;

    padding: 0;
}

.message-content blockquote {
    margin: 10px 0;

    padding-left: 12px;

    border-left:
        3px solid
        #6366f1;

    color: #cbd5e1;
}

/* =========================================================
   MESSAGE ACTIONS
   ========================================================= */

.message-actions {
    display: flex;

    gap: 6px;

    margin-top: 6px;
}

.action-btn {
    border: none;

    background: transparent;

    color: #64748b;

    font-size: 0.7rem;

    cursor: pointer;

    padding:
        3px
        5px;

    transition:
        0.2s
        ease;
}

.action-btn:hover {
    color: #cbd5e1;
}

/* =========================================================
   TYPING INDICATOR
   ========================================================= */

.typing-indicator {
    min-width: 0;

    display: flex;

    align-items: center;

    gap: 10px;

    padding:
        8px
        23px
        10px;

    overflow: hidden;
}

.typing-content {
    display: flex;

    align-items: center;

    gap: 9px;

    color: #64748b;

    font-size: 0.74rem;
}

.typing-dots {
    display: flex;

    gap: 4px;
}

.typing-dots span {
    width: 5px;
    height: 5px;

    border-radius: 50%;

    background: #64748b;

    animation:
        typing
        1.2s
        infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

/* =========================================================
   COMPOSER
   ========================================================= */

.composer-wrapper {
    min-width: 0;

    padding:
        13px
        18px
        calc(
            14px +
            var(--safe-bottom)
        );

    border-top:
        1px solid
        var(--border);

    background:
        rgba(2, 6, 23, 0.28);

    overflow: hidden;
}

.composer {
    width: 100%;
    min-width: 0;

    display: flex;

    align-items: flex-end;

    gap: 9px;

    padding:
        6px
        6px
        6px
        14px;

    border:
        1px solid
        rgba(148, 163, 184, 0.24);

    border-radius: 16px;

    background:
        rgba(2, 6, 23, 0.58);

    transition:
        0.2s
        ease;
}

.composer:focus-within {
    border-color:
        rgba(96, 165, 250, 0.65);

    box-shadow:
        0 0 0 3px
        rgba(59, 130, 246, 0.1);
}

#messageInput {
    flex: 1;

    width: 100%;
    min-width: 0;

    min-height: 42px;

    max-height: 140px;

    resize: none;

    border: none;

    outline: none;

    background: transparent;

    color: white;

    font-family: inherit;

    font-size: 0.88rem;

    line-height: 1.5;

    padding:
        8px
        0;

    overflow-y: auto;
}

#messageInput::placeholder {
    color: #64748b;
}

.send-btn {
    width: 42px;
    height: 42px;

    flex-shrink: 0;

    border: none;

    border-radius: 12px;

    display: flex;

    align-items: center;

    justify-content: center;

    background:
        linear-gradient(
            135deg,
            #2563eb,
            #7c3aed
        );

    color: white;

    cursor: pointer;

    font-size: 0.98rem;

    transition:
        0.2s
        ease;
}

.send-btn:hover:not(:disabled) {
    transform:
        translateY(-1px);

    box-shadow:
        0 9px 25px
        rgba(37, 99, 235, 0.32);
}

.send-btn:disabled {
    opacity: 0.55;

    cursor: not-allowed;
}

.composer-footer {
    display: flex;

    align-items: center;

    justify-content: space-between;

    gap: 10px;

    padding:
        7px
        2px
        0;

    color: #475569;

    font-size: 0.64rem;
}

#threadInfo {
    white-space: nowrap;
}

/* =========================================================
   LOADER
   ========================================================= */

.loader {
    width: 16px;
    height: 16px;

    border:
        2px solid
        rgba(255, 255, 255, 0.35);

    border-top-color: white;

    border-radius: 50%;

    animation:
        spin
        0.8s
        linear
        infinite;
}

.hidden {
    display: none !important;
}

/* =========================================================
   FOOTER
   ========================================================= */

footer {
    text-align: center;

    color: #475569;

    padding:
        0
        10px
        2px;

    font-size: 0.68rem;

    min-width: 0;
}

/* =========================================================
   ANIMATIONS
   ========================================================= */

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes typing {
    0%,
    60%,
    100% {
        opacity: 0.25;
        transform: translateY(0);
    }

    30% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 760px) {
    html,
    body {
        width: 100%;
        height: 100dvh;

        overflow: hidden !important;
    }

    .app-container {
        width: 100%;
        height: 100dvh;

        padding:
            10px
            10px
            0;

        grid-template-rows:
            auto
            minmax(0, 1fr);

        gap: 10px;

        overflow: hidden !important;
    }

    .hero-section {
        min-width: 0;

        padding:
            0
            4px;
    }

    .badge {
        padding:
            6px
            10px;

        margin-bottom: 10px;

        font-size: 0.67rem;
    }

    .badge-logo,
    .badge-logo img {
        width: 20px;
        height: 20px;
    }

    .hero-section h1 {
        font-size:
            clamp(
                1.85rem,
                9vw,
                2.5rem
            );

        margin-bottom: 7px;
    }

    .hero-section p {
        max-width: 360px;

        font-size: 0.75rem;

        line-height: 1.45;
    }

    .chat-card {
        width: 100%;
        height: auto;

        min-width: 0;
        min-height: 0;

        border-radius: 20px;
    }

    .chat-header {
        padding:
            12px
            13px;
    }

    .assistant-avatar {
        width: 34px;
        height: 34px;

        border-radius: 8px;
    }

    .assistant-avatar img {
        border-radius: 8px;
    }

    .assistant-info h2 {
        font-size: 0.82rem;
    }

    .online-status {
        font-size: 0.64rem;
    }

    .new-chat-btn {
        padding:
            7px
            9px;

        font-size: 0.68rem;
    }

    #chatMessages {
        padding:
            17px
            12px;
    }

    .empty-state {
        padding:
            20px
            8px;
    }

    .empty-icon {
        width: 58px;
        height: 58px;

        border-radius: 17px;

        margin-bottom: 14px;
    }

    .empty-icon img {
        width: 36px;
        height: 36px;

        max-width: 36px;
        max-height: 36px;
    }

    .empty-state h2 {
        font-size: 1.08rem;
    }

    .empty-state > p {
        font-size: 0.76rem;

        margin-bottom: 17px;
    }

    .quick-prompts {
        gap: 6px;
    }

    .quick-prompts button {
        padding:
            8px
            10px;

        font-size: 0.67rem;
    }

    .message {
        gap: 8px;

        margin-bottom: 17px;
    }

    .message-avatar {
        width: 34px;
        height: 34px;

        border-radius: 8px;

        font-size: 0.64rem;
    }

    .message-content-wrapper {
        max-width: 87%;
    }

    .message-content {
        padding:
            11px
            13px;

        font-size: 0.82rem;

        line-height: 1.58;
    }

    .typing-indicator {
        padding:
            7px
            12px
            8px;
    }

    .composer-wrapper {
        padding:
            9px
            9px
            calc(
                10px +
                var(--safe-bottom)
            );
    }

    .composer {
        padding-left: 12px;

        border-radius: 15px;
    }

    #messageInput {
        min-height: 39px;

        max-height: 120px;

        font-size: 0.84rem;
    }

    .send-btn {
        width: 39px;
        height: 39px;

        border-radius: 11px;
    }

    .composer-footer {
        padding-top: 6px;

        font-size: 0.56rem;
    }

    footer {
        display: none;
    }
}

/* =========================================================
   SMALL PHONES
   ========================================================= */

@media (max-width: 430px) {
    .app-container {
        padding-left: 7px;
        padding-right: 7px;
    }

    .hero-section p {
        max-width: 320px;
    }

    .new-chat-btn {
        width: 34px;
        height: 34px;

        justify-content: center;

        padding: 0;
    }

    .new-chat-btn span:last-child {
        display: none;
    }

    .new-chat-icon {
        font-size: 1.15rem;
    }

    .message-content-wrapper {
        max-width: 89%;
    }

    .quick-prompts button {
        width: 100%;

        max-width: 290px;
    }

    .footer-hint {
        max-width: 65%;
    }
}

/* =========================================================
   SHORT DESKTOP SCREENS
   ========================================================= */

@media (
    min-width: 761px
) and (
    max-height: 800px
) {
    .app-container {
        padding-top: 16px;

        gap: 10px;
    }

    .hero-section h1 {
        font-size:
            clamp(
                2rem,
                5vw,
                3.4rem
            );
    }

    .hero-section p {
        font-size: 0.84rem;
    }
}

/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}