.chat-workspace {
    position: relative;
    display: none;
    width: 100%;
    min-width: 0;
    height: 100%;
    min-height: 0;
    grid-column: 2 / -1;
    overflow: hidden;
    background: var(--color-surface);
}

.main-content[data-workspace-view="chat"] {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.main-content[data-workspace-view="chat"] .left-panel,
.main-content[data-workspace-view="chat"] .right-panel,
.main-content[data-workspace-view="chat"] .history-workspace {
    display: none;
}

.main-content.sidebar-collapsed[data-workspace-view="chat"] {
    grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr);
}

.main-content[data-workspace-view="chat"] .chat-workspace {
    display: block;
    grid-column: 2 / -1;
}

.chat-header { display: none; }

.chat-heading {
    display: none;
}

.chat-header-actions {
    display: flex;
    pointer-events: auto;
}

.chat-secondary-button {
    display: inline-flex;
    min-height: 38px;
    padding: 0 12px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: color-mix(in srgb, var(--color-surface) 92%, transparent);
    color: var(--color-text-secondary);
    font-size: 12px;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(12px);
}

.chat-panel {
    position: relative;
    display: grid;
    width: 100%;
    height: 100%;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) auto auto;
    overflow: hidden;
    background: var(--color-surface);
}

.chat-messages {
    min-height: 0;
    padding: 42px clamp(20px, 7vw, 110px) 28px;
    overflow: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    scroll-padding-block: 84px 190px;
}

.chat-welcome {
    display: grid;
    min-height: 100%;
    place-content: center;
    justify-items: center;
    padding-bottom: 80px;
    text-align: center;
}

.chat-welcome-icon {
    display: grid;
    width: 58px;
    height: 58px;
    margin-bottom: 15px;
    place-items: center;
    border: 1px solid color-mix(in srgb, var(--color-primary) 22%, var(--color-border));
    border-radius: 18px;
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

.chat-welcome-icon .ui-icon {
    width: 27px;
    height: 27px;
}

.chat-welcome h2 {
    margin: 0 0 8px;
    color: var(--color-text);
    font-size: 22px;
}

.chat-welcome p {
    max-width: 520px;
    margin: 0;
    color: var(--color-text-secondary);
    line-height: 1.7;
}

.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    margin-top: 22px;
    justify-content: center;
    gap: 8px;
}

.chat-suggestion {
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-size: 11px;
}

.chat-message {
    display: flex;
    width: min(860px, 100%);
    margin: 0 auto 32px;
}

.chat-message.is-user {
    justify-content: flex-end;
    margin-bottom: 46px;
}

.chat-message-content {
    width: min(780px, 100%);
    min-width: 0;
}

.chat-message.is-user .chat-message-content {
    width: fit-content;
    max-width: min(620px, 78%);
}

.chat-message.is-user .chat-message-text {
    padding: 11px 15px;
    border: 1px solid var(--color-border);
    border-radius: 18px;
    background: var(--color-surface-soft);
    white-space: pre-wrap;
    box-shadow: 0 2px 8px rgb(16 24 40 / 4%);
}

.chat-message.is-error .chat-message-text {
    padding: 12px 14px;
    border: 1px solid color-mix(in srgb, var(--color-error) 38%, var(--color-border));
    border-radius: 12px;
    background: color-mix(in srgb, var(--color-error) 5%, var(--color-surface));
}

.chat-message.is-pending .chat-message-text {
    display: none;
}

.chat-message-text {
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.78;
    overflow-wrap: anywhere;
}

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

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

.chat-message-text p,
.chat-message-text ul,
.chat-message-text ol,
.chat-message-text blockquote,
.chat-message-text pre,
.chat-markdown-table {
    margin: 0 0 12px;
}

.chat-message-text ul,
.chat-message-text ol {
    padding-left: 22px;
}

.chat-message-text li + li {
    margin-top: 4px;
}

.chat-message-text h1,
.chat-message-text h2,
.chat-message-text h3,
.chat-message-text h4,
.chat-message-text h5,
.chat-message-text h6 {
    margin: 18px 0 8px;
    color: var(--color-text);
    line-height: 1.35;
}

.chat-message-text h1 { font-size: 20px; }
.chat-message-text h2 { font-size: 18px; }
.chat-message-text h3 { font-size: 16px; }
.chat-message-text h4,
.chat-message-text h5,
.chat-message-text h6 { font-size: 14px; }

.chat-message-text code {
    padding: 2px 5px;
    border-radius: 5px;
    background: var(--color-surface-soft);
    color: var(--color-primary);
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 0.9em;
}

.chat-message-text pre,
.chat-source-view {
    max-width: 100%;
    padding: 13px;
    overflow: auto;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-canvas);
    white-space: pre;
}

.chat-message-text pre code {
    padding: 0;
    background: transparent;
    color: var(--color-text);
}

.chat-message-text blockquote {
    padding: 7px 12px;
    border-left: 3px solid var(--color-primary);
    background: var(--color-primary-soft);
    color: var(--color-text-secondary);
}

.chat-message-text hr {
    margin: 14px 0;
    border: 0;
    border-top: 1px solid var(--color-border);
}

.chat-message-text a {
    color: var(--color-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-markdown-table {
    max-width: 100%;
    overflow-x: auto;
}

.chat-markdown-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.chat-markdown-table th,
.chat-markdown-table td {
    padding: 7px 9px;
    border: 1px solid var(--color-border);
    text-align: left;
}

.chat-markdown-table th {
    background: var(--color-surface-soft);
}

.chat-message-meta {
    margin-top: 7px;
    color: var(--color-text-muted);
    font-size: 10px;
}

.chat-message.is-user .chat-message-meta {
    text-align: right;
}

.chat-reasoning {
    margin: 0 0 13px;
    color: var(--color-text-secondary);
    font-size: 12px;
}

.chat-reasoning summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.chat-reasoning summary::-webkit-details-marker {
    display: none;
}

.chat-reasoning summary::after {
    content: "⌄";
    color: var(--color-text-muted);
    transition: transform var(--duration-fast) ease;
}

.chat-reasoning[open] summary::after {
    transform: rotate(180deg);
}

.chat-reasoning summary .ui-icon {
    width: 15px;
    height: 15px;
}

.chat-reasoning-content {
    max-height: 240px;
    margin-top: 9px;
    padding: 10px 12px;
    overflow: auto;
    border-left: 2px solid var(--color-border-strong);
    color: var(--color-text-secondary);
    line-height: 1.65;
}

.chat-message.is-pending .chat-reasoning summary {
    animation: chatPulse 1.1s ease-in-out infinite alternate;
}

.chat-message-files,
.chat-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.chat-message-files {
    margin-top: 9px;
}

.chat-message-files span,
.chat-attachment-chip {
    display: inline-flex;
    min-height: 28px;
    padding: 0 9px;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface-soft);
    color: var(--color-text-secondary);
    font-size: 10px;
}

.chat-citations {
    display: grid;
    margin-top: 13px;
    padding-top: 10px;
    gap: 5px;
    border-top: 1px solid var(--color-border);
}

.chat-citations strong,
.chat-citations a {
    font-size: 11px;
}

.chat-citations strong {
    color: var(--color-text-secondary);
}

.chat-citations a {
    color: var(--color-primary);
    overflow-wrap: anywhere;
}

.chat-message-actions {
    display: flex;
    margin-top: 7px;
    align-items: center;
    gap: 2px;
}

.chat-message.is-user .chat-message-actions {
    justify-content: flex-end;
}

.chat-message-action {
    display: grid;
    width: 30px;
    height: 30px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text-muted);
}

.chat-message-action:hover,
.chat-message-action.is-active {
    background: var(--color-surface-soft);
    color: var(--color-text);
}

.chat-message-action.is-image-prompt {
    margin-left: 4px;
    color: var(--color-primary);
}

.chat-message-action .ui-icon,
.chat-secondary-button .ui-icon {
    width: 16px;
    height: 16px;
}

.chat-message-editor {
    width: min(620px, 76vw);
    min-height: 110px;
    padding: 12px;
    resize: vertical;
    border: 1px solid var(--color-primary);
    border-radius: 12px;
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    line-height: 1.6;
    outline: 0;
}

.chat-message-editor-actions {
    display: flex;
    margin-top: 8px;
    justify-content: flex-end;
    gap: 7px;
}

.chat-editor-button {
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    color: var(--color-text-secondary);
}

.chat-editor-button.is-primary {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: #fff;
}

.chat-composer {
    position: relative;
    z-index: 5;
    display: grid;
    width: min(850px, calc(100% - 40px));
    margin: 0 auto 22px;
    padding: 12px 13px 10px;
    gap: 8px;
    border: 1px solid var(--color-border-strong);
    border-radius: 20px;
    background: color-mix(in srgb, var(--color-surface) 96%, transparent);
    box-shadow: 0 14px 44px rgb(16 24 40 / 12%);
    backdrop-filter: blur(16px);
}

.chat-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.chat-composer textarea {
    width: 100%;
    min-height: 54px;
    max-height: 180px;
    padding: 5px 4px;
    resize: none;
    border: 0;
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: 14px;
    line-height: 1.6;
    outline: 0;
}

.chat-composer-tools,
.chat-composer-left,
.chat-composer-right {
    display: flex;
    min-width: 0;
    align-items: center;
}

.chat-composer-tools {
    justify-content: space-between;
    gap: 12px;
}

.chat-composer-left,
.chat-composer-right {
    gap: 6px;
}

.chat-attach-button,
.chat-parameter-button,
.chat-api-status,
.chat-composer-left .chat-secondary-button,
.chat-model-refresh,
.chat-send-button {
    display: inline-flex;
    min-height: 36px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-surface);
    color: var(--color-text-secondary);
}

.chat-attach-button,
.chat-parameter-button,
.chat-composer-left .chat-secondary-button,
.chat-model-refresh {
    width: 36px;
    padding: 0;
    font-size: 0;
}

.chat-api-status {
    padding: 0 9px;
    border-color: color-mix(in srgb, var(--color-warning) 35%, var(--color-border));
    color: var(--color-warning);
    font-size: 10px;
    font-weight: 700;
}

.chat-api-status.is-ready {
    border-color: color-mix(in srgb, var(--color-success) 35%, var(--color-border));
    color: var(--color-success);
}

.chat-search-toggle {
    display: inline-flex;
    min-height: 36px;
    padding: 0 9px;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-surface);
    color: var(--color-text-secondary);
    cursor: pointer;
}

.chat-search-toggle:has(input:checked) {
    border-color: color-mix(in srgb, var(--color-primary) 45%, var(--color-border));
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

.chat-search-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.chat-search-toggle span {
    font-size: 10px;
    font-weight: 700;
}

.chat-search-toggle small,
.chat-search-toggle .ui-icon {
    display: none;
}

.chat-model-field {
    display: block;
    min-width: 0;
}

.chat-model-field > span {
    display: none;
}

.chat-model-control {
    display: grid;
    width: min(250px, 30vw);
    grid-template-columns: minmax(0, 1fr) 36px;
    gap: 6px;
}

.chat-model-field select,
.chat-model-field input {
    width: 100%;
    min-height: 36px;
    padding: 0 10px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 11px;
}

.chat-model-field select {
    grid-column: 1;
    grid-row: 1;
}

.chat-custom-model {
    grid-column: 1 / -1;
    grid-row: 2;
}

.chat-custom-model[hidden] {
    display: none;
}

.chat-model-refresh {
    grid-column: 2;
    grid-row: 1;
}

.chat-model-refresh.is-loading .ui-icon {
    animation: chatSpin 0.8s linear infinite;
}

.chat-parameter-button {
    position: relative;
}

.chat-parameter-button.has-active-parameters::after {
    content: attr(data-count);
    position: absolute;
    top: -5px;
    right: -5px;
    display: grid;
    width: 17px;
    height: 17px;
    place-items: center;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    font-size: 9px;
}

.chat-send-button {
    padding: 0 13px;
    gap: 6px;
    border: 0;
    background: var(--brand-gradient);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}

.chat-attach-button .ui-icon,
.chat-parameter-button .ui-icon,
.chat-model-refresh .ui-icon,
.chat-send-button .ui-icon {
    width: 16px;
    height: 16px;
}

.chat-attachments {
    max-width: 100%;
    padding: 0 2px 2px;
    overflow-x: auto;
}

.chat-attachments[hidden] {
    display: none;
}

.chat-attachment-chip {
    flex: 0 0 auto;
}

.chat-attachment-remove {
    width: 20px;
    height: 20px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--color-text-muted);
}

.chat-parameter-panel {
    position: absolute;
    z-index: 12;
    bottom: calc(100% + 10px);
    left: 0;
    display: grid;
    width: min(350px, 90vw);
    max-height: min(620px, 70dvh);
    padding: 14px;
    gap: 10px;
    overflow: auto;
    border: 1px solid var(--color-border);
    border-radius: 16px;
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
}

.chat-parameter-panel[hidden] {
    display: none;
}

.chat-parameter-panel > header {
    display: grid;
    gap: 3px;
}

.chat-parameter-panel > header strong {
    color: var(--color-text);
    font-size: 14px;
}

.chat-parameter-panel > header span,
.chat-parameter-row small {
    color: var(--color-text-muted);
    font-size: 10px;
}

.chat-parameter-row {
    display: grid;
    padding: 11px;
    gap: 6px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-surface-soft);
    opacity: 0.66;
}

.chat-parameter-row.is-enabled {
    border-color: color-mix(in srgb, var(--color-primary) 32%, var(--color-border));
    opacity: 1;
}

.chat-parameter-row-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 7px;
}

.chat-parameter-row-header strong {
    color: var(--color-text);
    font-size: 12px;
}

.chat-parameter-row-header output {
    width: fit-content;
    padding: 2px 6px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-size: 9px;
}

.chat-parameter-row-header input {
    width: 18px;
    height: 18px;
}

.chat-parameter-row input[type="range"] {
    width: 100%;
    accent-color: var(--color-primary);
}

.chat-composer-hint {
    display: none;
}

@keyframes chatPulse {
    from { opacity: 0.45; }
    to { opacity: 1; }
}

@keyframes chatSpin {
    to { transform: rotate(360deg); }
}

@media (max-width: 767px) {
    .chat-workspace,
    .main-content[data-mobile-pane="chat"] .chat-workspace {
        display: block !important;
        width: 100%;
        height: calc(100dvh - var(--header-height) - 64px);
        min-height: 0;
        padding: 0;
        overflow: hidden;
    }

    .chat-secondary-button {
        width: 38px;
        min-height: 38px;
        padding: 0;
        font-size: 0;
    }

    .chat-panel {
        height: 100%;
    }

    .chat-messages {
        padding: 22px 12px 18px;
        scroll-padding-bottom: 180px;
    }

    .chat-welcome {
        min-height: 340px;
        padding: 12px 8px 50px;
    }

    .chat-welcome-icon {
        width: 52px;
        height: 52px;
        margin-bottom: 12px;
    }

    .chat-welcome h2 {
        font-size: 18px;
    }

    .chat-welcome p {
        max-width: 290px;
        font-size: 12px;
    }

    .chat-suggestions {
        display: grid;
        width: min(100%, 310px);
        margin-top: 16px;
    }

    .chat-suggestion {
        min-height: 40px;
        text-align: left;
    }

    .chat-message {
        width: 100%;
        margin-bottom: 24px;
    }

    .chat-message.is-user {
        margin-bottom: 34px;
    }

    .chat-message.is-user .chat-message-content {
        max-width: 86%;
    }

    .chat-message-text {
        font-size: 13px;
        line-height: 1.7;
    }

    .chat-message.is-user .chat-message-text {
        padding: 10px 13px;
        border-radius: 16px;
    }

    .chat-message-meta {
        font-size: 9px;
    }

    .chat-message-actions {
        max-width: 100%;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .chat-message-action {
        flex: 0 0 32px;
        width: 32px;
        height: 32px;
    }

    .chat-markdown-table,
    .chat-message-text pre {
        max-width: calc(100vw - 24px);
    }

    .chat-reasoning-content {
        max-height: 180px;
    }

    .chat-message-editor {
        width: 82vw;
    }

    .chat-composer {
        width: calc(100% - 16px);
        margin: 0 8px max(8px, env(safe-area-inset-bottom));
        padding: 9px 9px 8px;
        gap: 6px;
        border-radius: 17px;
    }

    .chat-composer textarea {
        min-height: 42px;
        max-height: 120px;
        padding: 4px 3px;
        font-size: 14px;
    }

    .chat-composer-tools {
        gap: 7px;
    }

    .chat-composer-left,
    .chat-composer-right {
        gap: 4px;
    }

    .chat-attach-button,
    .chat-parameter-button,
    .chat-composer-left .chat-secondary-button,
    .chat-model-refresh {
        width: 34px;
        min-height: 34px;
    }

    .chat-search-toggle {
        width: 34px;
        min-height: 34px;
        padding: 0;
        justify-content: center;
    }

    .chat-search-toggle span {
        display: none;
    }

    .chat-search-toggle .ui-icon {
        display: block;
        width: 16px;
        height: 16px;
    }

    .chat-api-status {
        display: none;
    }

    .chat-model-control {
        width: min(185px, 47vw);
        grid-template-columns: minmax(0, 1fr);
    }

    .chat-model-refresh {
        display: none;
    }

    .chat-model-field select,
    .chat-model-field input {
        min-height: 34px;
        font-size: 10px;
    }

    .chat-send-button {
        width: 38px;
        min-height: 34px;
        padding: 0;
        font-size: 0;
    }

    .chat-send-button .ui-icon {
        width: 17px;
        height: 17px;
    }

    .chat-attachments {
        flex-wrap: nowrap;
        padding: 0;
        scrollbar-width: none;
    }

    .chat-attachment-chip {
        max-width: 78vw;
    }

    .chat-parameter-panel {
        position: fixed;
        inset: auto 8px calc(72px + env(safe-area-inset-bottom));
        width: auto;
        max-height: min(68dvh, 560px);
        padding: 12px;
    }
}

@media (max-width: 390px) {
    .chat-messages {
        padding-inline: 8px;
    }

    .chat-composer-left .chat-secondary-button {
        display: none;
    }

    .chat-model-control {
        width: min(165px, 45vw);
    }
}
