@import url("https://fonts.googleapis.com/css2?family=Sora:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap");

:root {
    --bg: #f4f6f8;
    --bg-soft: #edf0f4;
    --surface: rgba(255, 255, 255, 0.88);
    --surface-strong: #ffffff;
    --surface-dark: #122030;
    --primary: #df2a39;
    --primary-dark: #b71428;
    --primary-soft: rgba(223, 42, 57, 0.14);
    --text: #0f172a;
    --text-soft: #475569;
    --border: rgba(148, 163, 184, 0.32);
    --assistant-bg: #ffffff;
    --user-bg: linear-gradient(140deg, #e11d48 0%, #b91c1c 100%);
    --shadow-lg: 0 22px 65px rgba(8, 20, 34, 0.14);
    --shadow-md: 0 10px 35px rgba(8, 20, 34, 0.1);
    --radius-xl: 24px;
    --radius-lg: 18px;
    --radius-md: 14px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Sora", sans-serif;
    color: var(--text);
    background: radial-gradient(circle at 15% 20%, #ffe0c8 0%, transparent 34%),
        radial-gradient(circle at 88% 12%, #ffdbe1 0%, transparent 30%),
        linear-gradient(155deg, var(--bg) 0%, var(--bg-soft) 100%);
    overflow: hidden;
}

.bg-grid {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: linear-gradient(rgba(15, 23, 42, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(15, 23, 42, 0.035) 1px, transparent 1px);
    background-size: 30px 30px;
    mask-image: radial-gradient(circle at center, black 45%, transparent 90%);
    z-index: 0;
}

.bg-glow {
    position: fixed;
    width: 40vw;
    height: 40vw;
    min-width: 320px;
    min-height: 320px;
    border-radius: 50%;
    filter: blur(60px);
    opacity: 0.3;
    pointer-events: none;
    z-index: 0;
    animation: floatGlow 12s ease-in-out infinite;
}

.glow-left {
    left: -12vw;
    top: -10vw;
    background: #ff9966;
}

.glow-right {
    right: -8vw;
    bottom: -12vw;
    background: #ff4d6d;
    animation-delay: -5s;
}

.app-shell {
    position: relative;
    z-index: 1;
    width: min(1420px, 96vw);
    margin: 2.2vh auto;
    height: 95.6vh;
    display: grid;
    grid-template-columns: 330px 1fr;
    grid-template-rows: 78px 1fr;
    gap: 14px;
}

.app-header,
.sidebar,
.chat-panel {
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
}

.app-header {
    grid-column: 1 / -1;
    background: var(--surface);
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.4rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.app-logo {
    width: 54px;
    height: 54px;
    border-radius: 14px;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.65);
    padding: 0.25rem;
}

.brand {
    display: block;
    font-family: "Space Grotesk", sans-serif;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0.02em;
}

.brand-subtitle {
    display: block;
    margin-top: 0.1rem;
    color: var(--text-soft);
    font-size: 0.8rem;
}

.icon-button {
    border: 1px solid rgba(148, 163, 184, 0.3);
    background: rgba(255, 255, 255, 0.75);
    color: var(--text);
    font-family: "Space Grotesk", sans-serif;
    font-weight: 600;
    font-size: 0.92rem;
    padding: 0.5rem 0.9rem;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.icon-button:hover,
.icon-button:focus-visible {
    transform: translateY(-1px);
    background: #fff;
    border-color: rgba(223, 42, 57, 0.44);
    outline: none;
}

.sidebar {
    grid-column: 1 / 2;
    grid-row: 2 / 3;
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}

.sidebar h2 {
    margin: 0;
    font-family: "Space Grotesk", sans-serif;
    font-size: 0.94rem;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-soft);
}

.primary-button {
    border: none;
    background: linear-gradient(145deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    font-family: "Space Grotesk", sans-serif;
    font-weight: 700;
    font-size: 0.86rem;
    border-radius: 12px;
    padding: 0.56rem 0.86rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.25s ease;
}

.primary-button:hover,
.primary-button:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 12px 26px rgba(183, 20, 40, 0.32);
    outline: none;
}

.primary-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.chat-list {
    overflow-y: auto;
    padding-right: 0.3rem;
    display: flex;
    flex-direction: column;
    gap: 0.62rem;
}

.chat-list-item {
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.72);
    border-radius: var(--radius-md);
    padding: 0.78rem 0.86rem;
    text-align: left;
    cursor: pointer;
    display: grid;
    gap: 0.23rem;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.chat-list-item:hover,
.chat-list-item:focus-visible {
    transform: translateY(-2px);
    border-color: rgba(223, 42, 57, 0.42);
    background: #fff;
    outline: none;
}

.chat-list-item.active {
    border-color: rgba(223, 42, 57, 0.62);
    background: var(--primary-soft);
}

.chat-title {
    font-weight: 600;
    color: var(--text);
}

.chat-date {
    color: var(--text-soft);
    font-size: 0.8rem;
}

.empty-state {
    margin: 1rem 0;
    color: var(--text-soft);
}

.chat-panel {
    grid-column: 2 / 3;
    grid-row: 2 / 3;
    background: var(--surface);
    border-radius: var(--radius-xl);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto 1fr auto;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.15rem 1.35rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.78);
}

.chat-header h1 {
    margin: 0;
    font-family: "Space Grotesk", sans-serif;
    font-size: 1.32rem;
}

.chat-header p {
    margin: 0.22rem 0 0;
    font-size: 0.88rem;
    color: var(--text-soft);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.42rem;
    padding: 0.46rem 0.66rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-soft);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
    animation: pulse 2s infinite;
}

.chat-messages {
    overflow-y: auto;
    padding: 1.2rem clamp(0.9rem, 2vw, 1.6rem) 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    background: linear-gradient(180deg, #f8fafc 0%, #eff2f6 100%);
}

.chat-messages.empty::before {
    content: attr(data-empty-text);
    text-align: center;
    color: var(--text-soft);
    margin: 2rem auto;
}

.message-bubble {
    display: flex;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.message-bubble.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.message-bubble.user {
    justify-content: flex-end;
}

.bubble-content {
    width: fit-content;
    max-width: min(78%, 720px);
    border-radius: var(--radius-lg);
    background: var(--assistant-bg);
    border: 1px solid rgba(148, 163, 184, 0.22);
    box-shadow: 0 6px 20px rgba(10, 22, 40, 0.09);
    padding: 0.78rem 0.95rem 0.58rem;
}

.message-bubble.user .bubble-content {
    background: var(--user-bg);
    border: none;
    color: #fff;
}

.message-markdown {
    font-size: 0.92rem;
    line-height: 1.5;
    word-break: break-word;
}

.message-markdown > :first-child {
    margin-top: 0;
}

.message-markdown > :last-child {
    margin-bottom: 0;
}

.message-markdown p,
.message-markdown ul,
.message-markdown ol,
.message-markdown blockquote,
.message-markdown pre {
    margin: 0.5rem 0;
}

.message-markdown ul,
.message-markdown ol {
    padding-left: 1.2rem;
}

.message-markdown h1,
.message-markdown h2,
.message-markdown h3,
.message-markdown h4 {
    margin: 0.5rem 0;
    font-family: "Space Grotesk", sans-serif;
    font-weight: 700;
    line-height: 1.3;
}

.message-markdown code {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    background: rgba(15, 23, 42, 0.08);
    border-radius: 8px;
    padding: 0.1rem 0.38rem;
    font-size: 0.82rem;
}

.message-markdown pre {
    padding: 0.7rem;
    border-radius: 12px;
    overflow-x: auto;
    background: rgba(15, 23, 42, 0.86);
    color: #ecfeff;
}

.message-markdown pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.message-markdown a {
    color: #be123c;
    font-weight: 600;
}

.message-bubble.user .message-markdown a {
    color: #fff5f5;
}

.message-bubble time {
    display: block;
    margin-top: 0.48rem;
    text-align: right;
    font-size: 0.72rem;
    opacity: 0.68;
}

.typing-bubble .bubble-content {
    min-width: 72px;
}

.typing-dots {
    display: inline-flex;
    gap: 0.32rem;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: bounce 1.15s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

.message-form {
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.85);
    padding: 0.95rem 1.2rem 1.05rem;
    display: grid;
    gap: 0.65rem;
}

.message-form textarea {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(255, 255, 255, 0.92);
    border-radius: 14px;
    padding: 0.78rem 0.92rem;
    font-family: "Sora", sans-serif;
    font-size: 0.94rem;
    line-height: 1.45;
    resize: none;
    min-height: 52px;
    max-height: 220px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.message-form textarea:focus-visible {
    outline: none;
    border-color: rgba(223, 42, 57, 0.7);
    box-shadow: 0 0 0 3px rgba(223, 42, 57, 0.15);
}

.composer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
}

.composer-hint {
    font-size: 0.76rem;
    color: var(--text-soft);
}

.send-button {
    min-width: 112px;
    padding-inline: 1rem;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.34);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 29;
}

.sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}

@keyframes bounce {
    0%,
    80%,
    100% {
        transform: scale(0.7);
        opacity: 0.45;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes floatGlow {
    0%,
    100% {
        transform: translateY(0) translateX(0);
    }
    50% {
        transform: translateY(-12px) translateX(8px);
    }
}

@media (max-width: 980px) {
    body {
        overflow: auto;
    }

    .app-shell {
        width: 100%;
        height: 100vh;
        margin: 0;
        border-radius: 0;
        gap: 0;
        grid-template-columns: 1fr;
        grid-template-rows: 74px 1fr;
    }

    .app-header,
    .chat-panel {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 74px;
        bottom: 0;
        width: min(84vw, 360px);
        border-radius: 0;
        transform: translateX(-104%);
        transition: transform 0.28s ease;
        z-index: 30;
        border-top: none;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .chat-panel {
        grid-column: 1 / -1;
        grid-row: 2 / 3;
    }

    .message-form {
        padding-bottom: calc(0.95rem + env(safe-area-inset-bottom, 0));
    }

    .bubble-content {
        max-width: 90%;
    }
}
