:root {
    color-scheme: light;
    --font-display: "Bricolage Grotesque", sans-serif;
    --font-body: "Manrope", sans-serif;
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 0.75rem;
    --space-lg: 1rem;
    --space-xl: 1.5rem;
    --space-2xl: 2rem;
    --space-3xl: 3rem;
    --radius-sm: 0.85rem;
    --radius-md: 1.25rem;
    --radius-lg: 1.75rem;
    --radius-pill: 999px;
    --surface-0: oklch(0.985 0.006 252);
    --surface-1: oklch(0.962 0.012 252);
    --surface-2: oklch(0.915 0.02 252);
    --surface-3: oklch(0.84 0.03 248);
    --ink-strong: oklch(0.24 0.035 255);
    --ink-soft: oklch(0.44 0.028 252);
    --ink-muted: oklch(0.58 0.018 252);
    --accent: oklch(0.34 0.085 255);
    --accent-strong: oklch(0.27 0.07 255);
    --accent-soft: oklch(0.9 0.02 252);
    --assistant-bubble: oklch(0.955 0.012 248);
    --assistant-meta: oklch(0.47 0.03 248);
    --user-bubble: oklch(0.33 0.08 255);
    --user-ink: oklch(0.97 0.008 252);
    --user-meta: oklch(0.86 0.02 250);
    --danger: oklch(0.6 0.18 26);
    --shadow-soft: 0 20px 60px color-mix(in srgb, var(--ink-strong) 12%, transparent);
    --shadow-card: 0 8px 24px color-mix(in srgb, var(--ink-strong) 8%, transparent);
    --page-width: 96rem;
    --transition-base: 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    font-size: 15px;
}

body {
    min-height: 100svh;
    margin: 0;
    font-family: var(--font-body);
    color: var(--ink-strong);
    overflow: hidden;
    overscroll-behavior-y: none;
    background:
        radial-gradient(circle at top left, color-mix(in srgb, var(--accent) 14%, transparent), transparent 28%),
        radial-gradient(circle at top right, color-mix(in srgb, var(--surface-3) 40%, transparent), transparent 30%),
        linear-gradient(180deg, var(--surface-0), var(--surface-1));
}

body::before {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(color-mix(in srgb, var(--surface-3) 10%, transparent) 1px, transparent 1px),
        linear-gradient(90deg, color-mix(in srgb, var(--surface-3) 10%, transparent) 1px, transparent 1px);
    background-size: 2.5rem 2.5rem;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.32), transparent 50%);
    content: "";
}

textarea,
button,
a {
    font: inherit;
}

button {
    cursor: pointer;
}

textarea {
    resize: none;
}

.page-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 0.75rem;
    width: min(calc(100% - 1.5rem), var(--page-width));
    height: 100svh;
    margin: 0 auto;
    padding: clamp(0.5rem, 1.2vw, 1rem) 0;
}

.app-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    min-height: 3.5rem;
    padding: 0.55rem 0.75rem;
    border-radius: 1.2rem;
    background: color-mix(in srgb, var(--surface-0) 90%, white);
    border: 1px solid color-mix(in srgb, var(--surface-3) 58%, white);
    box-shadow: var(--shadow-card);
}

.app-topbar__brand {
    display: grid;
    gap: 0.1rem;
}

.app-topbar__brand strong {
    font-family: var(--font-display);
    font-size: 1.02rem;
    line-height: 1;
}

.app-topbar__eyebrow {
    margin: 0;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 2.7rem;
    height: 2.7rem;
    border-radius: 0.95rem;
    color: var(--accent-strong);
    background: color-mix(in srgb, var(--accent-soft) 62%, white);
    border: 1px solid color-mix(in srgb, var(--surface-3) 58%, white);
    text-decoration: none;
    transition:
        transform var(--transition-base),
        background-color var(--transition-base),
        color var(--transition-base);
}

.icon-button:hover {
    transform: translateY(-1px);
    background: color-mix(in srgb, var(--accent-soft) 80%, white);
}

.icon-button svg {
    width: 1.1rem;
    height: 1.1rem;
    fill: currentColor;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(17rem, 20rem) minmax(0, 1fr);
    gap: var(--space-md);
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.history-sidebar,
.chat-panel {
    min-height: 0;
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--surface-0) 95%, white);
    box-shadow: var(--shadow-soft);
    border: 1px solid color-mix(in srgb, var(--surface-3) 65%, white);
}

.history-sidebar {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 0.7rem;
    overflow: hidden;
    background: color-mix(in srgb, var(--surface-1) 94%, white);
}

.history-sidebar__header,
.history-sidebar__topbar {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: var(--space-sm);
}

.history-sidebar__header {
    padding: 0.3rem 0.25rem 0.75rem;
}

.history-sidebar__eyebrow,
.chat-panel__eyebrow {
    margin: 0 0 var(--space-xs);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.history-sidebar__header h2,
.chat-panel__header h1,
.empty-state h3 {
    margin: 0;
    font-family: var(--font-display);
}

.history-sidebar__header h2 {
    font-size: 1.15rem;
    line-height: 1.05;
}

.history-sidebar__panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: var(--space-sm);
    min-height: 0;
    padding-top: 0.1rem;
}

.history-sidebar__copy,
.history-status,
.chat-panel__note,
.empty-state p {
    margin: 0;
    color: var(--ink-soft);
    line-height: 1.55;
}

.history-sidebar__toggle {
    display: none;
}

.history-sidebar__new-chat {
    width: 100%;
}

.history-list-wrapper {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: 0;
    overflow: hidden;
}

.history-list {
    display: grid;
    align-content: start;
    gap: 0.2rem;
    min-height: 0;
    overflow: auto;
    padding-right: 0.05rem;
}

.history-list::-webkit-scrollbar,
.conversation::-webkit-scrollbar {
    width: 0.55rem;
}

.history-list::-webkit-scrollbar-thumb,
.conversation::-webkit-scrollbar-thumb {
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--surface-3) 72%, transparent);
}

.history-item {
    display: grid;
    gap: 0.2rem;
    width: 100%;
    padding: 0.75rem 0.8rem;
    border: 1px solid transparent;
    border-radius: 0.95rem;
    background: transparent;
    text-align: left;
    transition:
        transform var(--transition-base),
        border-color var(--transition-base),
        background-color var(--transition-base);
}

.history-item:hover,
.history-item:focus-visible {
    transform: none;
    border-color: color-mix(in srgb, var(--surface-3) 62%, white);
    background: color-mix(in srgb, var(--surface-0) 86%, white);
}

.history-item.is-active {
    border-color: color-mix(in srgb, var(--accent) 70%, white);
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--accent-soft) 88%, white), color-mix(in srgb, var(--surface-0) 86%, white)),
        color-mix(in srgb, var(--accent-soft) 62%, white);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 22%, white);
}

.history-item__title,
.history-item__meta,
.history-item__description {
    margin: 0;
}

.history-item__title {
    font-weight: 800;
    color: var(--ink-strong);
    font-size: 0.93rem;
}

.history-item__description,
.history-item__meta {
    color: var(--ink-soft);
    font-size: 0.82rem;
    line-height: 1.5;
}

.history-item.is-active .history-item__title {
    color: var(--accent-strong);
}

.history-item.is-active .history-item__description,
.history-item.is-active .history-item__meta {
    color: color-mix(in srgb, var(--accent-strong) 72%, var(--ink-soft));
}

.history-item__meta {
    color: var(--ink-muted);
}

.history-empty {
    display: grid;
    place-items: center;
    min-height: 100%;
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--accent-soft) 45%, transparent), transparent),
        var(--surface-1);
    color: var(--ink-soft);
    text-align: center;
}

.history-sidebar__footer {
    display: grid;
    gap: var(--space-sm);
    padding-top: 0.75rem;
}

.history-status {
    min-height: 1.2rem;
    font-size: 0.9rem;
}

.history-status[data-tone="danger"] {
    color: var(--danger);
}

.history-status[data-tone="success"] {
    color: var(--accent-strong);
}

.history-sidebar__load-more {
    width: 100%;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.9rem;
    padding: 0.8rem 1.1rem;
    border: none;
    border-radius: var(--radius-pill);
    font-weight: 700;
    transition:
        transform var(--transition-base),
        background-color var(--transition-base),
        color var(--transition-base),
        opacity var(--transition-base);
}

.button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.button:disabled {
    cursor: progress;
    opacity: 0.62;
}

.button--primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: var(--surface-0);
}

.button--secondary {
    background: color-mix(in srgb, var(--surface-2) 84%, var(--accent-soft));
    color: var(--accent-strong);
}

.button--ghost {
    background: var(--surface-2);
    color: var(--ink-strong);
}

.chat-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
    padding: clamp(0.9rem, 2vw, 1.25rem);
    container-type: inline-size;
    overflow: hidden;
}

.chat-panel__header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-md) var(--space-lg);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid color-mix(in srgb, var(--surface-3) 70%, white);
}

.chat-panel__intro {
    min-width: 0;
}

.chat-panel__header h1 {
    margin: var(--space-xs) 0;
    font-size: clamp(1.35rem, 2.4vw, 1.7rem);
    line-height: 1.05;
}

.chat-panel__header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
    justify-content: flex-end;
}

.chat-panel__history-trigger {
    display: none;
}

.chat-panel__note {
    max-width: 60ch;
    font-size: 0.92rem;
    line-height: 1.45;
}

.chat-panel__note[data-tone="danger"] {
    color: var(--danger);
}

.chat-panel__note[data-tone="success"] {
    color: var(--accent-strong);
}

.chat-panel__badge {
    display: inline-flex;
    align-items: center;
    min-height: 2.4rem;
    padding: 0.35rem 0.8rem;
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--accent-soft) 72%, white);
    color: var(--accent-strong);
    font-size: 0.9rem;
    font-weight: 700;
    white-space: nowrap;
}

.conversation {
    display: grid;
    align-content: start;
    gap: var(--space-md);
    min-height: 0;
    height: 100%;
    padding: 0.35rem 0.35rem 0 0;
    overflow: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

.empty-state {
    display: grid;
    place-items: center;
    min-height: 100%;
    padding: var(--space-3xl) var(--space-xl);
    border-radius: var(--radius-md);
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--accent-soft) 45%, transparent), transparent),
        var(--surface-1);
    text-align: center;
}

.empty-state__box {
    max-width: 34rem;
    width: min(100%, 30rem);
}

.empty-state h3 {
    margin: 0 0 var(--space-sm);
    font-size: 2rem;
    line-height: 1;
}

.empty-state p {
    max-width: 42ch;
    line-height: 1.7;
}

.message {
    display: grid;
    gap: var(--space-sm);
    max-width: min(75ch, 88%);
    padding: 1rem 1rem 0.95rem;
    border-radius: 1.35rem;
    background: var(--surface-0);
    animation: message-enter 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

.message[data-role="assistant"] {
    justify-self: start;
    background: var(--assistant-bubble);
}

.message[data-role="user"] {
    justify-self: end;
    background: var(--user-bubble);
    color: var(--user-ink);
}

.message__meta {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: color-mix(in srgb, var(--ink-soft) 88%, white);
}

.message[data-role="assistant"] .message__meta {
    color: var(--assistant-meta);
}

.message[data-role="user"] .message__meta {
    color: var(--user-meta);
}

.message[data-role="user"] .message__content {
    color: var(--user-ink);
}

.message__content {
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

.message__content--typing {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 1.75rem;
}

.typing-dot {
    width: 0.52rem;
    height: 0.52rem;
    border-radius: 50%;
    background: color-mix(in srgb, var(--ink-soft) 78%, white);
    animation: typing-bounce 900ms ease-in-out infinite;
}

.message[data-role="user"] .typing-dot {
    background: color-mix(in srgb, var(--user-ink) 88%, transparent);
}

.message--pending {
    opacity: 0.82;
}

.composer {
    display: grid;
    gap: var(--space-md);
    padding-top: var(--space-lg);
    margin-top: var(--space-md);
    border: none;
    border-top: 1px solid color-mix(in srgb, var(--surface-3) 70%, white);
    background: color-mix(in srgb, var(--surface-0) 98%, white);
}

.composer textarea {
    min-height: 3.5rem;
    padding: 1rem 1rem 0.95rem;
    border: none;
    border-radius: var(--radius-md);
    background: var(--surface-1);
    color: var(--ink-strong);
    line-height: 1.55;
    outline: 1px solid transparent;
    transition: outline-color var(--transition-base), background-color var(--transition-base);
}

.composer textarea:focus {
    outline-color: color-mix(in srgb, var(--accent) 55%, white);
    background: color-mix(in srgb, var(--surface-0) 88%, white);
}

.composer__row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-sm);
    align-items: end;
}

.composer__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    flex-wrap: wrap;
}

#send-message-button {
    width: 3.5rem;
    min-width: 3.5rem;
    min-height: 3.5rem;
    padding: 0;
    border-radius: 1.1rem;
    align-self: stretch;
}

.send-icon {
    width: 1.15rem;
    height: 1.15rem;
    fill: currentColor;
}

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

:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 65%, white);
    outline-offset: 3px;
}

@keyframes message-enter {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

@keyframes typing-bounce {
    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.48;
    }

    30% {
        transform: translateY(-0.24rem);
        opacity: 1;
    }
}

@container (max-width: 44rem) {
    .chat-panel__header {
        grid-template-columns: 1fr;
    }

    .chat-panel__header-actions {
        justify-content: flex-start;
    }

    .message {
        max-width: 100%;
    }
}

@media (max-width: 72rem) {
    .page-shell {
        width: 100%;
        padding: 0;
    }

    .workspace {
        grid-template-columns: minmax(15rem, 18rem) minmax(0, 1fr);
        gap: 0.75rem;
        height: 100svh;
    }

    .history-sidebar,
    .chat-panel {
        border-radius: 0;
        box-shadow: none;
        border-top: none;
        border-bottom: none;
    }

    .app-topbar {
        border-radius: 0;
        border-left: none;
        border-right: none;
        box-shadow: none;
    }
}

@media (max-width: 48rem) {
    body {
        overflow: hidden;
    }

    .workspace {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .page-shell {
        gap: 0;
        padding: 0;
    }

    .app-topbar {
        min-height: 3.25rem;
        padding: 0.45rem 0.85rem;
        border-radius: 0;
        border-left: none;
        border-right: none;
        box-shadow: none;
    }

    .history-sidebar {
        position: absolute;
        inset: 3.25rem auto 0 0;
        z-index: 3;
        width: min(100%, 22rem);
        transform: translateX(-100%);
        transition: transform var(--transition-base);
        border-right: 1px solid color-mix(in srgb, var(--surface-3) 65%, white);
    }

    .workspace.is-history-open .history-sidebar {
        transform: translateX(0);
    }

    .history-sidebar__toggle {
        display: inline-flex;
        color: var(--ink-muted);
        font-size: 0.82rem;
        font-weight: 700;
    }

    .history-list-wrapper {
        position: relative;
        z-index: 1;
        background: color-mix(in srgb, var(--surface-0) 97%, white);
    }

    .chat-panel {
        min-height: calc(100svh - 3.25rem);
        height: calc(100svh - 3.25rem);
        padding: 0.85rem 0.85rem calc(0.75rem + env(safe-area-inset-bottom, 0rem));
        border: none;
    }

    .composer {
        position: relative;
        z-index: 1;
        padding-bottom: 0;
    }

    .composer textarea {
        font-size: 16px;
    }

    .chat-panel__header {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: start;
        gap: 0.75rem;
        padding-bottom: 0.85rem;
    }

    .chat-panel__history-trigger {
        display: inline-flex;
    }

    .composer__actions,
    .history-sidebar__topbar {
        align-items: stretch;
    }

    .chat-panel__badge,
    .composer__hint {
        display: none;
    }

    .chat-panel__header-actions {
        justify-content: flex-end;
        align-items: flex-start;
    }

    .conversation {
        padding-right: 0.1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
