:root {
    --bg: #f3efe5;
    --panel: rgba(255, 252, 246, 0.84);
    --panel-strong: rgba(255, 252, 246, 0.94);
    --line: rgba(27, 31, 35, 0.12);
    --line-strong: rgba(27, 31, 35, 0.24);
    --text: #181714;
    --muted: #6d675c;
    --accent: #b55d2c;
    --accent-soft: rgba(181, 93, 44, 0.12);
    --ok: #2a7a5a;
    --warn: #b55d2c;
    --danger: #9f2e2e;
    --locked: #8a6c28;
    --shadow: 0 20px 50px rgba(34, 26, 16, 0.08);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

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

body {
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(181, 93, 44, 0.14), transparent 28rem),
        radial-gradient(circle at bottom right, rgba(42, 122, 90, 0.12), transparent 32rem),
        var(--bg);
    overflow-x: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

body.rail-open {
    overflow: hidden;
}

.app-shell {
    min-height: 100svh;
    display: grid;
    grid-template-columns: 22rem minmax(0, 1fr);
    backdrop-filter: blur(18px);
}

.rail-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(20, 18, 15, 0.36);
    backdrop-filter: blur(6px);
}

.rail {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 2rem 1.5rem;
    border-right: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(255, 250, 242, 0.92), rgba(255, 251, 246, 0.8));
}

.rail-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand-block,
.rail-section,
.workspace-header,
.composer,
.auth-panel {
    animation: rise-in 420ms ease both;
}

.brand-block {
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--line);
}

.eyebrow,
.section-kicker,
.empty-kicker,
.status-label {
    margin: 0;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.brand-block h1,
.workspace-header h2,
.empty-state h3,
.auth-panel h3 {
    margin: 0.35rem 0 0;
    font-family: "Space Grotesk", "Segoe UI", sans-serif;
    line-height: 0.95;
    letter-spacing: -0.04em;
}

.brand-block h1 {
    font-size: clamp(2.5rem, 6vw, 4rem);
    max-width: 9ch;
}

.lead,
.status-text,
.empty-copy,
.composer-meta,
.auth-copy {
    margin: 0;
    line-height: 1.5;
    color: var(--muted);
}

.rail-section {
    display: grid;
    gap: 1rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--line);
}

.status-line {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.status-dot {
    width: 0.8rem;
    height: 0.8rem;
    border-radius: 999px;
    background: var(--warn);
    box-shadow: 0 0 0 0.4rem rgba(181, 93, 44, 0.1);
    flex: none;
}

.status-dot.is-online {
    background: var(--ok);
    box-shadow: 0 0 0 0.4rem rgba(42, 122, 90, 0.14);
}

.status-dot.is-offline {
    background: var(--danger);
    box-shadow: 0 0 0 0.4rem rgba(159, 46, 46, 0.14);
}

.status-dot.is-locked {
    background: var(--locked);
    box-shadow: 0 0 0 0.4rem rgba(138, 108, 40, 0.14);
}

.field {
    display: grid;
    gap: 0.45rem;
}

.field-label {
    font-size: 0.85rem;
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 1px solid var(--line);
    border-radius: 1rem;
    background: var(--panel);
    transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--panel-strong);
    transform: translateY(-1px);
}

textarea {
    resize: vertical;
    min-height: 3rem;
}

.split-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.8rem;
}

.toggle-row {
    display: flex;
    align-items: start;
    gap: 0.75rem;
    font-size: 0.92rem;
    color: var(--muted);
}

.toggle-row input {
    width: 1rem;
    height: 1rem;
    margin-top: 0.2rem;
    padding: 0;
}

.ghost-button,
.prompt-chip,
.send-button {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    padding: 0.7rem 1rem;
    min-height: 2.85rem;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.ghost-button:hover,
.prompt-chip:hover,
.send-button:hover {
    transform: translateY(-1px);
    border-color: var(--line-strong);
}

.ghost-button {
    justify-self: start;
}

.advanced-settings {
    display: grid;
    gap: 1rem;
    padding-top: 0.2rem;
}

.security-list {
    margin: 0;
    padding-left: 1.1rem;
    color: var(--muted);
    line-height: 1.5;
}

.security-list li + li {
    margin-top: 0.45rem;
}

.prompt-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.prompt-chip {
    background: var(--panel);
}

.workspace {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 100svh;
    padding: 1.6rem 2rem;
}

.workspace-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 1.2rem;
    border-bottom: 1px solid var(--line);
}

.workspace-header h2 {
    font-size: clamp(2rem, 4vw, 3.2rem);
    max-width: 14ch;
}

.header-actions {
    display: flex;
    gap: 0.8rem;
}

.mobile-only {
    display: none;
}

.empty-state {
    padding: 3rem 0 2rem;
    border-bottom: 1px solid var(--line);
}

.empty-state h3 {
    font-size: clamp(2rem, 4vw, 3rem);
    max-width: 15ch;
}

.empty-copy {
    max-width: 34rem;
    margin-top: 1rem;
}

.messages {
    flex: 1;
    overflow: auto;
    padding: 1rem 0 8rem;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.messages.is-empty {
    display: none;
}

.message {
    padding: 1.35rem 0;
    border-bottom: 1px solid var(--line);
    animation: rise-in 260ms ease both;
}

.message-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.message-role {
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.message-role.user {
    color: var(--accent);
}

.message-role.assistant {
    color: var(--ok);
}

.message-time,
.message-meta {
    font-size: 0.88rem;
    color: var(--muted);
}

.message-body {
    max-width: 52rem;
    white-space: pre-wrap;
    line-height: 1.65;
}

.message-body.is-empty {
    color: var(--muted);
    font-style: italic;
}

.message-footer {
    display: grid;
    gap: 0.8rem;
    margin-top: 1rem;
}

.reasoning {
    max-width: 52rem;
    padding-left: 1rem;
    border-left: 2px solid var(--accent-soft);
    color: var(--muted);
}

.reasoning summary {
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}

.reasoning pre {
    margin: 0.8rem 0 0;
    white-space: pre-wrap;
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    line-height: 1.55;
}

.message.pending .message-body::after {
    content: "";
    display: inline-block;
    width: 0.65rem;
    height: 0.65rem;
    margin-left: 0.55rem;
    border-radius: 999px;
    background: var(--accent);
    animation: pulse 900ms ease-in-out infinite;
}

.composer {
    position: sticky;
    bottom: 0;
    margin-top: auto;
    padding-top: 1rem;
    background: linear-gradient(180deg, rgba(243, 239, 229, 0), rgba(243, 239, 229, 0.86) 1.5rem, rgba(243, 239, 229, 0.98) 100%);
}

.composer-label {
    display: inline-block;
    margin-bottom: 0.55rem;
    font-size: 0.84rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

#promptInput {
    min-height: 4rem;
    max-height: 14rem;
    padding: 1rem 1.1rem;
    border-radius: 1.2rem;
    border-color: var(--line-strong);
    background: rgba(255, 252, 246, 0.92);
    box-shadow: var(--shadow);
    resize: none;
}

.composer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 0.85rem;
}

.send-button {
    padding-inline: 1.35rem;
    background: var(--accent);
    color: #fffaf5;
    border-color: transparent;
}

.send-button:disabled,
.ghost-button:disabled,
.prompt-chip:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.auth-gate {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: rgba(243, 239, 229, 0.9);
    backdrop-filter: blur(14px);
}

.auth-panel {
    width: min(100%, 28rem);
    display: grid;
    gap: 1rem;
    padding: 2rem;
    border: 1px solid var(--line);
    border-radius: 1.6rem;
    background: rgba(255, 250, 242, 0.985);
    box-shadow: 0 28px 70px rgba(34, 26, 16, 0.16);
    position: relative;
    z-index: 1;
}

.login-form {
    display: grid;
    gap: 1rem;
}

.auth-error {
    margin: 0;
    color: var(--danger);
    line-height: 1.45;
}

.auth-button {
    justify-self: start;
}

code {
    padding: 0.14rem 0.35rem;
    border-radius: 0.45rem;
    background: rgba(0, 0, 0, 0.05);
    font-size: 0.95em;
}

@keyframes rise-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

@keyframes pulse {
    0%,
    100% {
        opacity: 0.3;
        transform: scale(0.8);
    }

    50% {
        opacity: 1;
        transform: scale(1);
    }
}

@media (max-width: 980px) {
    .app-shell {
        display: block;
    }

    .rail {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 30;
        max-height: min(82svh, 44rem);
        overflow: auto;
        border-right: none;
        border-top: 1px solid var(--line);
        border-radius: 1.6rem 1.6rem 0 0;
        padding: 1rem 1rem calc(1.1rem + env(safe-area-inset-bottom));
        gap: 1rem;
        box-shadow: 0 -22px 50px rgba(34, 26, 16, 0.16);
        transform: translateY(calc(100% + 1rem));
        transition: transform 220ms ease;
    }

    .rail.is-open {
        transform: translateY(0);
    }

    .rail-topbar {
        display: flex;
        position: sticky;
        top: -1rem;
        padding: 0.1rem 0 0.85rem;
        background: linear-gradient(180deg, rgba(255, 251, 246, 0.98), rgba(255, 251, 246, 0.92));
        border-bottom: 1px solid var(--line);
        z-index: 1;
    }

    .workspace {
        min-height: 100svh;
        padding: max(1rem, env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom));
    }

    .workspace-header,
    .composer-actions,
    .header-actions {
        align-items: start;
        flex-direction: column;
    }

    .workspace-header {
        gap: 0.85rem;
    }

    .header-actions {
        width: 100%;
    }

    .mobile-only {
        display: inline-flex;
    }

    .header-actions .ghost-button {
        width: 100%;
        justify-content: center;
    }

    .brand-block h1 {
        font-size: clamp(2.15rem, 11vw, 3rem);
        max-width: none;
    }

    .workspace-header h2,
    .empty-state h3,
    .auth-panel h3 {
        max-width: none;
    }

    .empty-state {
        padding: 1.75rem 0 1.35rem;
    }

    .messages {
        padding: 0.6rem 0 7.6rem;
    }

    .message-head {
        flex-direction: column;
        align-items: start;
        gap: 0.35rem;
    }

    .composer {
        padding-top: 0.85rem;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .composer-actions {
        align-items: stretch;
    }

    .send-button {
        width: 100%;
        justify-content: center;
    }

    .auth-gate {
        position: fixed;
        inset: 0;
        padding:
            max(1rem, env(safe-area-inset-top))
            1rem
            max(1rem, env(safe-area-inset-bottom));
        align-items: start;
        overflow: auto;
        background: rgba(243, 239, 229, 0.97);
    }

    .auth-panel {
        margin: auto 0;
    }
}

@media (max-width: 640px) {
    .rail,
    .workspace {
        padding-left: 0.9rem;
        padding-right: 0.9rem;
    }

    .brand-block {
        padding-bottom: 1rem;
    }

    .rail-section {
        gap: 0.85rem;
        padding-bottom: 1rem;
    }

    .workspace-header h2,
    .empty-state h3,
    .auth-panel h3 {
        font-size: clamp(1.75rem, 8.8vw, 2.35rem);
    }

    .split-fields {
        grid-template-columns: 1fr;
    }

    .prompt-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.55rem;
    }

    .prompt-chip,
    .ghost-button,
    .send-button {
        width: 100%;
        justify-content: center;
    }

    .security-list {
        padding-left: 1rem;
        font-size: 0.94rem;
    }

    .message {
        padding: 1rem 0;
    }

    .message-body,
    .reasoning,
    .empty-copy {
        max-width: none;
    }

    .composer-label {
        margin-bottom: 0.4rem;
    }

    #promptInput {
        min-height: 3.5rem;
        max-height: 11rem;
        padding: 0.9rem 1rem;
    }

    .composer-actions {
        gap: 0.75rem;
    }

    .auth-panel {
        padding: 1.25rem;
        border-radius: 1.35rem;
    }
}

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