:root {
    color-scheme: light;
    --bg: #f4f1ef;
    --bg-soft: #f7f4f2;
    --panel: #f1ece9;
    --surface: #ffffff;
    --surface-soft: #faf7f5;
    --line: #e3ddd9;
    --line-strong: #d6cfcb;
    --text: #151515;
    --text-soft: #5d5855;
    --text-muted: #8a837e;
    --shadow: 0 8px 24px rgba(31, 24, 20, 0.06);
    --shadow-strong: 0 16px 36px rgba(31, 24, 20, 0.08);
    --radius: 8px;
    --chat-width: 760px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', sans-serif;
}

body {
    min-height: 100vh;
}

button,
input,
textarea {
    font: inherit;
}

button {
    border: 0;
    background: none;
    color: inherit;
    cursor: pointer;
}

a {
    color: inherit;
    text-decoration: none;
}

.shell {
    display: grid;
    grid-template-columns: 52px 0 minmax(0, 1fr);
    min-height: 100vh;
    transition: grid-template-columns 0.24s ease;
}

.shell.has-history {
    grid-template-columns: 52px 260px minmax(0, 1fr);
}

.rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 10px 8px;
    background: linear-gradient(180deg, #f7f3f1 0%, #f2edeb 100%);
    border-right: 1px solid var(--line);
}

.rail__group {
    display: grid;
    gap: 8px;
}

.rail__group--bottom {
    padding-bottom: 2px;
}

.rail__brand,
.rail__button,
.topbar__menu,
.history-panel__close,
.canvas-panel__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.7);
    color: var(--text-soft);
}

.rail__button--primary {
    background: #161616;
    border-color: #161616;
    color: #ffffff;
}

.brand-mark {
    position: relative;
    width: 14px;
    height: 14px;
}

.brand-mark::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 5px;
    transform: rotate(45deg);
    background: linear-gradient(135deg, #4e8eff 0%, #65b5ff 44%, #31b29d 78%, #f2a052 100%);
}

.history-panel {
    min-width: 0;
    overflow: hidden;
    border-right: 1px solid var(--line);
    background: linear-gradient(180deg, #f7f3f1 0%, #f4efec 100%);
}

.history-panel__header,
.history-panel__section-head,
.canvas-panel__header,
.canvas-panel__footer,
.settings-form__header,
.settings-form__footer,
.message__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.history-panel__header {
    padding: 16px 16px 12px;
}

.history-panel__eyebrow,
.topbar__eyebrow,
.welcome-state__eyebrow,
.history-panel__section-head,
.composer__hint,
.settings-form__eyebrow,
.canvas-panel__eyebrow,
.message__time,
.attachment-chip__meta,
.legal-note,
.notice-card span {
    margin: 0;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.45;
}

.history-panel__header h1,
.canvas-panel__header h3,
.settings-form h3 {
    margin: 4px 0 0;
    font-size: 18px;
    line-height: 1.25;
    font-weight: 600;
}

.history-panel__new {
    width: calc(100% - 32px);
    margin: 0 16px 14px;
    min-height: 40px;
    border-radius: 10px;
    background: #161616;
    color: #fff;
    font-weight: 600;
}

.history-panel__section {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: calc(100vh - 108px);
    padding: 0 16px 16px;
}

.history-panel__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
}

.conversation-list {
    display: grid;
    align-content: start;
    gap: 8px;
    overflow-y: auto;
    padding-right: 2px;
}

.conversation-item {
    width: 100%;
    display: grid;
    gap: 4px;
    text-align: left;
    padding: 11px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.66);
    border: 1px solid transparent;
}

.conversation-item.is-active {
    background: var(--surface);
    border-color: var(--line);
    box-shadow: var(--shadow);
}

.conversation-item__title {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 500;
}

.main-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 14px 18px 0;
}

.topbar__left,
.topbar__right,
.composer__footer,
.composer__modes,
.canvas-panel__toolbar,
.topbar__account {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar__menu,
.history-panel__close {
    display: none;
}

.topbar__title {
    margin: 2px 0 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
}

.topbar__pill,
.topbar__model,
.topbar__link,
.composer__chip,
.canvas-panel__toolbar-button,
.message__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.78);
    color: var(--text-soft);
    font-size: 13px;
}

.topbar__account {
    margin-left: 6px;
}

.topbar__avatar {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: linear-gradient(180deg, #d0cfcd 0%, #8e8b89 100%);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.topbar__pro {
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    background: #121212;
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
}

.main-panel.is-empty .topbar__left {
    opacity: 0;
    pointer-events: none;
}

.main-panel.is-empty .topbar__pill,
.main-panel.is-empty .topbar__model,
.main-panel.is-empty .topbar__link {
    display: none;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 0;
    min-height: 0;
    flex: 1;
    transition: grid-template-columns 0.24s ease;
}

.workspace.has-canvas {
    grid-template-columns: minmax(0, 1fr) 360px;
}

.chat-area {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: 0 18px 18px;
}

.welcome-state {
    width: min(var(--chat-width), 100%);
    margin: auto auto 18px;
    text-align: center;
}

.welcome-state h1 {
    margin: 0;
    font-size: 30px;
    line-height: 1.15;
    font-weight: 700;
}

.chat-thread {
    width: min(var(--chat-width), 100%);
    margin: 0 auto;
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.main-panel.is-empty .chat-thread {
    display: none;
}

.main-panel.has-messages .welcome-state,
.main-panel.has-messages .quick-actions,
.main-panel.has-messages .notice-card,
.main-panel.has-messages .legal-note {
    display: none;
}

.quick-actions {
    display: none;
}

.message {
    width: min(var(--chat-width), 100%);
    margin: 0 auto 16px;
}

.message__identity {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.message__avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: #151515;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
}

.message--assistant .message__avatar {
    background: linear-gradient(135deg, #4e8eff 0%, #31b29d 100%);
}

.message__name {
    font-size: 13px;
    font-weight: 600;
}

.message__surface {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.message--user .message__surface {
    background: #fbfbfb;
}

.message__attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 14px 16px 0;
}

.message__content {
    padding: 16px;
    font-size: 14px;
    line-height: 1.8;
}

.message__content h1,
.message__content h2,
.message__content h3 {
    margin: 0 0 12px;
    line-height: 1.3;
}

.message__content h1 { font-size: 22px; }
.message__content h2 { font-size: 19px; }
.message__content h3 { font-size: 16px; }

.message__content p,
.message__content ul,
.message__content ol,
.message__content pre,
.message__content blockquote {
    margin: 0 0 14px;
}

.message__content p:last-child,
.message__content ul:last-child,
.message__content ol:last-child,
.message__content pre:last-child,
.message__content blockquote:last-child {
    margin-bottom: 0;
}

.message__content ul,
.message__content ol {
    padding-left: 18px;
}

.message__content code {
    padding: 2px 6px;
    border-radius: 6px;
    background: #f3f0ed;
    border: 1px solid var(--line);
    font-size: 0.92em;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.message__content pre {
    overflow-x: auto;
    padding: 14px 16px;
    border-radius: 10px;
    background: #141414;
    color: #ffffff;
}

.message__content pre code {
    padding: 0;
    background: transparent;
    border: 0;
    color: inherit;
}

.message__content blockquote {
    padding: 12px 14px;
    border-left: 3px solid #c7bdb7;
    background: #f8f4f1;
    color: var(--text-soft);
}

.message__actions {
    display: flex;
    justify-content: flex-end;
    padding: 0 16px 16px;
}

.message--pending .message__content::after {
    content: '';
    display: inline-block;
    width: 8px;
    height: 1.1em;
    margin-left: 4px;
    vertical-align: -2px;
    background: #66605d;
    animation: blink 1s steps(1, end) infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

.composer-attachments {
    width: min(var(--chat-width), 100%);
    margin: 0 auto 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 4px 12px rgba(31, 24, 20, 0.04);
}

.attachment-chip__preview {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: #f0ece9;
    background-size: cover;
    background-position: center;
    flex: none;
}

.attachment-chip__preview.is-image {
    background-color: transparent;
}

.attachment-chip__body {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.attachment-chip__name {
    display: block;
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 600;
}

.attachment-chip__remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    color: var(--text-muted);
}

.attachment-chip__remove[hidden] {
    display: none;
}

.attachment-chip--error {
    border-color: #ebd0d0;
    background: #fff7f7;
}

.attachment-chip--message {
    box-shadow: none;
    background: var(--surface-soft);
}

.composer {
    width: min(var(--chat-width), 100%);
    margin: 0 auto;
}

.main-panel.has-messages .composer {
    position: sticky;
    bottom: 0;
    padding-top: 12px;
    background: linear-gradient(180deg, rgba(244, 241, 239, 0) 0%, rgba(244, 241, 239, 0.95) 28%, rgba(244, 241, 239, 1) 100%);
}

.composer__box {
    padding: 14px 16px 12px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(227, 221, 217, 0.35), var(--shadow-strong);
}

.composer__input {
    width: 100%;
    min-height: 78px;
    max-height: 240px;
    resize: none;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
}

.composer__input::placeholder {
    color: var(--text-muted);
}

.composer__footer {
    justify-content: space-between;
}

.composer__chip {
    min-height: 28px;
    padding: 0 10px;
    font-size: 11px;
    background: #ffffff;
}

.composer__chip--soft {
    color: var(--text-muted);
}

.composer__send {
    width: 32px;
    min-width: 32px;
    height: 32px;
    min-height: 32px;
    padding: 0;
    border-radius: 10px;
    background: #171717;
    color: #ffffff;
    font-weight: 700;
    font-size: 14px;
}

.composer__send:disabled {
    opacity: 0.65;
    cursor: default;
}

.composer__hint {
    padding: 8px 4px 0;
}

.quick-action {
    min-height: 36px;
    padding: 0 13px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.84);
    color: var(--text-soft);
    font-size: 12px;
}

.notice-card {
    width: min(400px, calc(100% - 24px));
    margin: 140px auto 10px;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(219, 215, 211, 0.46);
    text-align: center;
}

.notice-card p {
    margin: 0 0 3px;
    font-size: 11px;
    line-height: 1.45;
    color: var(--text-soft);
}

.legal-note {
    text-align: center;
    margin-top: 0;
    margin-bottom: 0;
}

.canvas-panel {
    min-width: 0;
    border-left: 1px solid var(--line);
    background: linear-gradient(180deg, #faf7f5 0%, #f5efeb 100%);
    padding: 16px;
    display: none;
    flex-direction: column;
    gap: 14px;
}

.workspace.has-canvas .canvas-panel {
    display: flex;
}

.canvas-panel__toolbar {
    justify-content: space-between;
    flex-wrap: wrap;
}

.canvas-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-soft);
    font-size: 13px;
}

.canvas-panel__editor {
    width: 100%;
    min-height: 0;
    flex: 1;
    resize: none;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    padding: 14px;
    outline: 0;
    line-height: 1.7;
    color: var(--text);
    box-shadow: var(--shadow);
}

.settings-modal {
    width: min(560px, calc(100vw - 24px));
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 24px 56px rgba(31, 24, 20, 0.16);
}

.settings-modal::backdrop {
    background: rgba(21, 21, 21, 0.14);
    backdrop-filter: blur(6px);
}

.settings-form {
    display: grid;
    gap: 18px;
    padding: 24px;
}

.field {
    display: grid;
    gap: 8px;
}

.field span {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-soft);
}

.field input,
.field textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-soft);
    outline: 0;
}

.field input:focus,
.field textarea:focus,
.canvas-panel__editor:focus {
    border-color: var(--line-strong);
}

.settings-form__save {
    min-width: 140px;
}

.backdrop {
    display: none;
}

@media (max-width: 1180px) {
    .workspace.has-canvas {
        grid-template-columns: minmax(0, 1fr);
    }

    .canvas-panel {
        position: fixed;
        inset: 0 0 0 auto;
        width: min(400px, 92vw);
        z-index: 40;
        box-shadow: -14px 0 34px rgba(31, 24, 20, 0.12);
    }
}

@media (max-width: 980px) {
    .shell,
    .shell.has-history {
        grid-template-columns: 52px minmax(0, 1fr);
    }

    .history-panel {
        position: fixed;
        inset: 0 auto 0 52px;
        width: min(260px, calc(100vw - 52px));
        transform: translateX(-100%);
        transition: transform 0.24s ease;
        z-index: 35;
    }

    .shell.has-history .history-panel {
        transform: translateX(0);
    }

    .backdrop {
        position: fixed;
        inset: 0;
        background: rgba(21, 21, 21, 0.18);
        z-index: 30;
    }

    .backdrop.is-visible {
        display: block;
    }

    .topbar__menu,
    .history-panel__close {
        display: inline-flex;
    }
}

@media (max-width: 760px) {
    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .topbar__right,
    .composer__footer,
    .composer__modes,
    .settings-form__header,
    .settings-form__footer {
        width: 100%;
    }

    .topbar__right,
    .composer__footer {
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .chat-area {
        padding-left: 14px;
        padding-right: 14px;
    }

    .welcome-state h1 {
        font-size: 34px;
    }

    .composer__chip,
    .topbar__pill,
    .topbar__link,
    .topbar__model {
        flex: 1;
    }
}
