:root {
    --bg: #ececf1;
    --panel: #ffffff;
    --panel-border: #e5e7eb;
    --text: #111827;
    --text-soft: #6b7280;
    --text-inverse: #f9fafb;
    --accent: #10a37f;
    --accent-strong: #0d8b6c;
    --shadow: 0 18px 50px rgba(17, 24, 39, 0.08);
}

* {
    box-sizing: border-box;
}

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

body {
    overflow: hidden;
    min-height: 100vh;
    font-family: "IBM Plex Sans", "Aptos", "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
}

body.sidebar-open {
    overflow: hidden;
}

.sidebar,
.messages-scroller,
.session-history {
    scrollbar-width: thin;
}

.sidebar {
    scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

.messages-scroller,
.session-history {
    scrollbar-color: rgba(148, 163, 184, 0.42) transparent;
}

.sidebar::-webkit-scrollbar,
.messages-scroller::-webkit-scrollbar,
.session-history::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.sidebar::-webkit-scrollbar-track,
.messages-scroller::-webkit-scrollbar-track,
.session-history::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb,
.messages-scroller::-webkit-scrollbar-thumb,
.session-history::-webkit-scrollbar-thumb {
    border: 3px solid transparent;
    border-radius: 999px;
    background-clip: padding-box;
    transition: background-color 120ms ease;
}

.sidebar::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.18);
}

.messages-scroller::-webkit-scrollbar-thumb,
.session-history::-webkit-scrollbar-thumb {
    background-color: rgba(148, 163, 184, 0.34);
}

.sidebar:hover::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
}

.messages-scroller:hover::-webkit-scrollbar-thumb,
.session-history:hover::-webkit-scrollbar-thumb {
    background-color: rgba(100, 116, 139, 0.48);
}

button,
textarea {
    font: inherit;
}

.app-shell {
    height: 100vh;
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
    display: grid;
    grid-template-rows: auto auto auto 1fr;
    gap: 18px;
    padding: 20px 16px;
    background:
        radial-gradient(circle at top left, rgba(16, 163, 127, 0.18), transparent 36%),
        linear-gradient(180deg, #1b1b1b, #111111);
    color: var(--text-inverse);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    min-height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
}

.sidebar__brand {
    padding: 12px 10px 0;
}

.sidebar__eyebrow {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(249, 250, 251, 0.62);
}

.sidebar__title {
    margin-top: 8px;
    font-size: 1.45rem;
    font-weight: 700;
}

.sidebar__card-note,
.sidebar__brand,
.session-history__preview,
.read-only-banner,
.empty-state__text,
.composer-note,
.captcha-modal__text {
    line-height: 1.45;
}

.sidebar__card-note {
    color: rgba(249, 250, 251, 0.68);
}

.sidebar__new-chat {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-inverse);
    text-align: left;
    cursor: pointer;
    transition: background-color 120ms ease, transform 120ms ease, border-color 120ms ease;
}

.sidebar__new-chat:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
}

.sidebar__card {
    padding: 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar__card-button {
    width: 100%;
    text-align: left;
    color: var(--text-inverse);
    cursor: pointer;
    transition: background-color 120ms ease, transform 120ms ease, border-color 120ms ease;
}

.sidebar__card-button:hover {
    background: rgba(255, 255, 255, 0.09);
    border-color: rgba(255, 255, 255, 0.14);
    transform: translateY(-1px);
}

.sidebar__card-button:disabled {
    cursor: default;
    opacity: 1;
    transform: none;
}

.sidebar__card-button.is-viewing-history {
    background: rgba(16, 163, 127, 0.15);
    border-color: rgba(16, 163, 127, 0.28);
}

.sidebar__card-label {
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(249, 250, 251, 0.54);
}

.sidebar__card-value {
    margin-top: 10px;
    font-size: 1rem;
    font-weight: 600;
}

.sidebar__card-note {
    margin-top: 10px;
    font-size: 0.92rem;
}

.sidebar__history {
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 10px;
}

.sidebar__history[hidden] {
    display: none;
}

.sidebar__section-title {
    padding: 0 10px;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(249, 250, 251, 0.54);
}

.session-history {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

.session-history:empty {
    display: none;
}

.session-history__item {
    border: 0;
    width: 100%;
    text-align: left;
    border-radius: 14px;
    padding: 12px 12px 11px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-inverse);
    cursor: pointer;
    transition: background-color 120ms ease, transform 120ms ease;
}

.session-history__item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.session-history__item.is-current {
    background: rgba(16, 163, 127, 0.18);
    box-shadow: inset 0 0 0 1px rgba(16, 163, 127, 0.38);
}

.session-history__item.is-viewed:not(.is-current) {
    background: rgba(255, 255, 255, 0.12);
}

.session-history__title {
    display: block;
    font-size: 0.96rem;
    font-weight: 600;
}

.session-history__meta {
    display: block;
    margin-top: 5px;
    font-size: 0.82rem;
    color: rgba(249, 250, 251, 0.56);
}

.session-history__preview {
    display: block;
    margin-top: 7px;
    color: rgba(249, 250, 251, 0.72);
    font-size: 0.9rem;
}

.chat-panel {
    min-width: 0;
    min-height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background:
        radial-gradient(circle at top center, rgba(16, 163, 127, 0.07), transparent 26%),
        var(--bg);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 28px;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(17, 24, 39, 0.06);
}

.chat-header__meta {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
}

.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    padding: 0;
    border: 1px solid rgba(17, 24, 39, 0.08);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    color: #111827;
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.06);
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.sidebar-toggle:hover {
    background: #ffffff;
    border-color: rgba(17, 24, 39, 0.14);
    transform: translateY(-1px);
}

.sidebar-toggle__icon {
    display: block;
}

.chat-header__title {
    font-size: 1.15rem;
    font-weight: 700;
    min-width: 0;
    white-space: nowrap;
}

.health-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--panel-border);
    color: #374151;
    font-size: 0.92rem;
    white-space: nowrap;
    margin-left: auto;
}

.status-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #c4c9d3;
    box-shadow: 0 0 0 4px rgba(196, 201, 211, 0.2);
    transition: background-color 140ms ease, box-shadow 140ms ease;
}

.status-dot.is-healthy {
    background: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.16);
}

.status-dot.is-unhealthy {
    background: #9ca3af;
    box-shadow: 0 0 0 4px rgba(156, 163, 175, 0.16);
}

.messages-scroller {
    overflow-y: auto;
    min-height: 0;
    padding: 24px 24px 32px;
}

.read-only-banner {
    max-width: 880px;
    margin: 0 auto 16px;
    padding: 12px 14px;
    border-radius: 14px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #9a3412;
}

.read-only-banner[hidden] {
    display: none;
}

#messages {
    max-width: 880px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.empty-state {
    max-width: 860px;
    margin: min(10vh, 88px) auto 0;
    padding: 12px 0 32px;
}

.empty-state[hidden] {
    display: none;
}

.empty-state__eyebrow {
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.empty-state__title {
    margin: 12px 0 0;
    font-size: clamp(2rem, 4vw, 3.2rem);
    line-height: 1.02;
    letter-spacing: -0.03em;
}

.empty-state__text {
    max-width: 720px;
    margin: 18px 0 0;
    color: var(--text-soft);
    font-size: 1.02rem;
    line-height: 1.6;
}

.message-row {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

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

.message-row.error,
.message-row.assistant {
    justify-content: flex-start;
}

.message-avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-inverse);
    background: #111827;
    box-shadow: 0 6px 18px rgba(17, 24, 39, 0.16);
}

.message-row.error .message-avatar {
    background: #b91c1c;
}

.message {
    width: fit-content;
    max-width: min(78ch, 100%);
    padding: 16px 18px;
    border-radius: 20px;
    line-height: 1.6;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    box-shadow: 0 8px 28px rgba(17, 24, 39, 0.05);
}

.message.user {
    background: #dff5ee;
    border-color: #bfe8dc;
}

.message.assistant {
    background: rgba(255, 255, 255, 0.92);
}

.message.error {
    background: #fff1f2;
    border-color: #fecdd3;
    color: #9f1239;
}

.message p {
    margin: 0 0 0.8em;
}

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

.message h1,
.message h2,
.message h3 {
    margin: 0 0 0.65em;
    line-height: 1.2;
}

.message h1:last-child,
.message h2:last-child,
.message h3:last-child {
    margin-bottom: 0;
}

.message h1 {
    font-size: 1.45rem;
}

.message h2 {
    font-size: 1.25rem;
}

.message h3 {
    font-size: 1.1rem;
}

.message hr {
    margin: 1em 0;
    border: 0;
    border-top: 1px solid rgba(17, 24, 39, 0.12);
}

.message strong {
    font-weight: 700;
}

.message em {
    font-style: italic;
}

.message code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.94em;
    background: rgba(17, 24, 39, 0.06);
    border-radius: 6px;
    padding: 0.1em 0.35em;
}

.message pre {
    margin: 0.8em 0 0;
    overflow-x: auto;
    background: rgba(17, 24, 39, 0.05);
    border-radius: 12px;
    padding: 12px;
}

.message pre code {
    background: transparent;
    padding: 0;
}

.message ul {
    margin: 0.8em 0;
    padding-left: 1.3em;
}

.message li + li {
    margin-top: 0.25em;
}

.composer-panel {
    padding: 16px 24px 24px;
    background:
        linear-gradient(180deg, rgba(236, 236, 241, 0), rgba(236, 236, 241, 0.96) 28%),
        transparent;
}

.composer-shell {
    max-width: 880px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
    padding: 14px;
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(17, 24, 39, 0.08);
    box-shadow: var(--shadow);
}

textarea {
    min-height: 52px;
    max-height: 88px;
    resize: none;
    overflow-y: hidden;
    width: 100%;
    padding: 12px 14px;
    border: 0;
    border-radius: 18px;
    line-height: 1.5;
    background: transparent;
    color: var(--text);
}

textarea:focus {
    outline: none;
}

textarea::placeholder {
    color: #9ca3af;
}

.submit-button,
.button-muted,
#captcha-retry {
    border: 0;
    cursor: pointer;
    transition: transform 120ms ease, opacity 120ms ease, background-color 120ms ease;
}

.submit-button:hover,
.button-muted:hover,
#captcha-retry:hover {
    transform: translateY(-1px);
}

.submit-button:disabled,
.button-muted:disabled,
#captcha-retry:disabled,
.sidebar__new-chat:disabled {
    opacity: 0.62;
    cursor: wait;
    transform: none;
}

.submit-button {
    width: 48px;
    height: 48px;
    min-width: 48px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #ffffff;
}

.submit-button:hover {
    background: var(--accent-strong);
}

.composer-note {
    max-width: 880px;
    margin: 10px auto 0;
    padding: 0 8px;
    font-size: 0.9rem;
    color: var(--text-soft);
}

.button-muted,
#captcha-retry {
    border-radius: 999px;
    padding: 10px 16px;
}

.button-muted {
    background: #eef2f7;
    color: #334155;
}

#captcha-retry {
    background: #111827;
    color: #f9fafb;
}

.captcha-modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(17, 24, 39, 0.36);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
}

.captcha-modal.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-overlay {
    display: none;
}

.captcha-modal__dialog {
    width: min(100%, 460px);
    background: #ffffff;
    border: 1px solid rgba(17, 24, 39, 0.08);
    border-radius: 24px;
    box-shadow: 0 24px 60px rgba(17, 24, 39, 0.18);
    padding: 24px;
}

.captcha-modal__title {
    margin: 0;
    font-size: 1.2rem;
}

.captcha-modal__text {
    margin: 10px 0 0;
    color: var(--text-soft);
    line-height: 1.5;
}

.captcha-modal__widget {
    margin-top: 18px;
    min-height: 72px;
}

.captcha-modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.typing {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(17, 24, 39, 0.56);
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.18s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.36s;
}

@keyframes typing-bounce {
    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: 0.35;
    }
    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

@media (max-width: 1024px) {
    body {
        overflow: hidden;
    }

    .app-shell {
        height: 100dvh;
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 40;
        width: min(84vw, 320px);
        height: 100vh;
        grid-template-rows: auto auto auto minmax(0, 1fr);
        gap: 14px;
        padding: 16px;
        border-right: 1px solid rgba(255, 255, 255, 0.08);
        min-height: 100vh;
        max-height: 100vh;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 180ms ease;
        box-shadow: 0 18px 48px rgba(17, 24, 39, 0.28);
    }

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

    .chat-panel {
        min-height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 30;
        display: block;
        background: rgba(17, 24, 39, 0.32);
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease;
    }

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

@media (max-width: 720px) {
    .chat-header {
        padding: 14px 16px;
        gap: 10px;
    }

    .chat-header__title {
        font-size: 1rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .messages-scroller {
        padding: 16px 12px 24px;
    }

    #messages {
        gap: 10px;
    }

    .empty-state {
        margin-top: 28px;
        padding-bottom: 20px;
    }

    .message-row {
        gap: 0;
    }

    .message {
        max-width: 100%;
        font-size: 0.95rem;
        line-height: 1.52;
        padding: 12px 13px;
    }

    .composer-panel {
        padding: 8px 10px 12px;
    }

    .composer-shell {
        gap: 8px;
        padding: 8px 9px;
        border-radius: 18px;
        grid-template-columns: minmax(0, 1fr) auto;
    }

    textarea {
        min-height: 40px;
        max-height: 64px;
        padding: 9px 10px;
        font-size: 0.94rem;
        line-height: 1.4;
    }

    .submit-button {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }

    .submit-button svg {
        width: 18px;
        height: 18px;
    }

    .composer-note {
        margin-top: 6px;
        padding: 0 6px;
        font-size: 0.76rem;
    }

    .captcha-modal__actions {
        flex-direction: column-reverse;
    }

    .health-pill {
        margin-left: auto;
        padding: 8px 11px;
        font-size: 0.84rem;
    }

    .sidebar-toggle {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
        border-radius: 11px;
    }

    .message-avatar {
        display: none;
    }

    .message h1 {
        font-size: 1.25rem;
    }

    .message h2 {
        font-size: 1.12rem;
    }

    .message h3 {
        font-size: 1rem;
    }
}
