/* 统一聊天页面 */
:root {
    --chat-bg: #0b1220;
    --chat-surface: rgba(15, 23, 42, 0.92);
    --chat-surface-soft: rgba(30, 41, 59, 0.9);
    --chat-surface-muted: rgba(51, 65, 85, 0.72);
    --chat-border: rgba(148, 163, 184, 0.18);
    --chat-text: #e5eefb;
    --chat-text-soft: #a9b7cf;
    --chat-text-muted: #7d8da8;
    --chat-primary: #5b8cff;
    --chat-primary-strong: #3f73ff;
    --chat-primary-soft: rgba(91, 140, 255, 0.16);
    --chat-success: #22c55e;
    --chat-danger: #f87171;
    --chat-warning: #fbbf24;
    --chat-shadow: 0 22px 60px rgba(3, 8, 20, 0.35);
    --chat-radius-lg: 24px;
    --chat-radius-md: 18px;
    --chat-radius-sm: 14px;
    --chat-content-width: 100%;
}

[data-theme="light"] {
    --chat-bg: #eef3fb;
    --chat-surface: rgba(255, 255, 255, 0.96);
    --chat-surface-soft: rgba(255, 255, 255, 0.92);
    --chat-surface-muted: rgba(226, 232, 240, 0.78);
    --chat-border: rgba(148, 163, 184, 0.22);
    --chat-text: #0f172a;
    --chat-text-soft: #334155;
    --chat-text-muted: #64748b;
    --chat-primary: #2563eb;
    --chat-primary-strong: #1d4ed8;
    --chat-primary-soft: rgba(37, 99, 235, 0.1);
    --chat-shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(59, 130, 246, 0.12), transparent 28%),
        radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.08), transparent 22%),
        var(--chat-bg);
    color: var(--chat-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.chat-shell {
    width: min(1500px, calc(100vw - 32px));
    margin: 18px auto 24px;
    display: grid;
    grid-template-columns: 308px minmax(0, 1fr);
    gap: 18px;
    min-height: calc(100vh - 110px);
}

.chat-shell.is-sidebar-collapsed {
    grid-template-columns: minmax(0, 1fr);
}

.chat-shell.is-sidebar-collapsed .chat-sidebar {
    display: none;
}

.chat-sidebar-overlay {
    display: none;
}

.chat-sidebar,
.chat-main {
    min-height: 0;
}

.chat-sidebar {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px;
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius-lg);
    background: var(--chat-surface);
    box-shadow: var(--chat-shadow);
    backdrop-filter: blur(18px);
}

.chat-sidebar-head {
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 2;
    padding-bottom: 12px;
    background: linear-gradient(180deg, var(--chat-surface) 78%, transparent);
}

.chat-sidebar-head-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chat-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-sidebar-brand strong,
.chat-sidebar-brand small {
    display: block;
}

.chat-sidebar-brand strong {
    font-size: 0.96rem;
}

.chat-sidebar-brand small {
    margin-top: 2px;
    color: var(--chat-text-muted);
}

.chat-sidebar-brand-mark,
.chat-sidebar-toggle,
.chat-sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text);
}

.chat-sidebar-toggle,
.chat-sidebar-close {
    appearance: none;
    cursor: pointer;
}

.chat-sidebar-close {
    display: none;
}

.chat-primary-action,
.chat-primary-send,
.chat-secondary-action,
.chat-thinking-toggle {
    appearance: none;
    border: 0;
    cursor: pointer;
    transition: all 0.18s ease;
}

.chat-primary-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    height: 46px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-strong));
    color: #fff;
    font-weight: 700;
    box-shadow: 0 14px 24px rgba(37, 99, 235, 0.28);
}

.chat-primary-action:hover,
.chat-primary-send:hover {
    transform: translateY(-1px);
}

.chat-sidebar-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--chat-text-soft);
}

.chat-sidebar-title {
    font-size: 0.96rem;
    font-weight: 700;
}

.chat-sidebar-meta-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.chat-sidebar-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--chat-primary-soft);
    color: var(--chat-primary);
    font-weight: 700;
}

.chat-sidebar-clear {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid rgba(248, 113, 113, 0.22);
    background: rgba(248, 113, 113, 0.08);
    color: #f87171;
    font-size: 0.76rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.18s ease;
}

.chat-sidebar-clear:hover:not(:disabled) {
    background: rgba(248, 113, 113, 0.14);
    border-color: rgba(248, 113, 113, 0.34);
}

.chat-sidebar-clear:disabled {
    opacity: 0.52;
    cursor: not-allowed;
}

.chat-session-list {
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-right: 4px;
}

.chat-session-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-session-group-title {
    padding: 0 4px;
    color: var(--chat-text-muted);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.chat-session-group-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-session-item {
    width: 100%;
    padding: 12px 14px;
    border-radius: 18px;
    border: 1px solid transparent;
    background: var(--chat-surface-soft);
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: all 0.18s ease;
}

.chat-session-item:hover {
    border-color: var(--chat-border);
    background: var(--chat-surface-muted);
}

.chat-session-item:focus-visible {
    outline: none;
    border-color: rgba(91, 140, 255, 0.36);
    box-shadow: 0 0 0 4px rgba(91, 140, 255, 0.12);
}

.chat-session-item.is-active {
    border-color: rgba(91, 140, 255, 0.36);
    background: linear-gradient(135deg, var(--chat-primary-soft), rgba(34, 197, 94, 0.08));
    box-shadow: inset 0 0 0 1px rgba(91, 140, 255, 0.18);
}

.chat-session-item-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
}

.chat-session-title {
    flex: 1 1 auto;
    min-width: 0;
    display: block;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--chat-text);
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-session-delete {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: transparent;
    color: var(--chat-text-muted);
    border: 1px solid transparent;
}

.chat-session-delete:hover {
    color: var(--chat-danger);
    border-color: rgba(248, 113, 113, 0.2);
    background: rgba(248, 113, 113, 0.08);
}

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

.chat-topbar,
.chat-messages-panel,
.chat-composer-panel {
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius-lg);
    background: var(--chat-surface);
    box-shadow: var(--chat-shadow);
    backdrop-filter: blur(18px);
}

.chat-topbar {
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 12px;
    z-index: 4;
}

.chat-model-panel-head {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chat-sidebar-toggle {
    display: inline-flex;
    flex-shrink: 0;
}

.chat-session-badge {
    flex: 1 1 auto;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    min-height: 30px;
    width: 100%;
    padding: 0 2px;
    color: var(--chat-text);
    font-size: 0.96rem;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-field > span {
    font-size: 0.84rem;
    color: var(--chat-text-muted);
    font-weight: 700;
}

.chat-select {
    width: 100%;
    min-height: 46px;
    padding: 0 14px;
    border-radius: 16px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text);
    font-size: 0.95rem;
    outline: none;
}

.chat-select:focus {
    border-color: rgba(91, 140, 255, 0.4);
    box-shadow: 0 0 0 4px rgba(91, 140, 255, 0.12);
}

.chat-model-hint {
    min-height: 0;
    color: var(--chat-text-soft);
    font-size: 0.78rem;
    line-height: 1.42;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
}

.chat-model-hint a {
    color: var(--chat-primary);
    font-weight: 700;
    text-decoration: none;
}

.chat-model-hint-main {
    color: var(--chat-text);
    font-weight: 700;
}

.chat-model-hint-note {
    color: var(--chat-text-muted);
}

.chat-model-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chat-model-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text-soft);
    font-size: 0.76rem;
    font-weight: 700;
}

.chat-model-badge.is-local {
    color: #60a5fa;
}

.chat-model-badge.is-online {
    color: #22c55e;
}

.chat-model-badge.is-thinking {
    color: var(--chat-success);
}

.chat-controls-panel {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

.chat-model-select-inline {
    flex: 0 1 168px;
}

.chat-model-select-inline .chat-select {
    min-height: 34px;
    border-radius: 12px;
    padding: 0 34px 0 10px;
    font-size: 0.84rem;
}

.chat-composer-inline-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 10px;
    min-width: 0;
    flex: 1 1 auto;
}

.chat-switch-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
}

.chat-switch-stack-inline {
    flex: 0 1 auto;
}

.chat-switch-control {
    min-width: 0;
    flex: 0 0 auto;
}

.chat-switch-button {
    appearance: none;
    min-height: 32px;
    min-width: 82px;
    width: auto;
    padding: 0 9px;
    border-radius: 12px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--chat-text);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.18s ease;
}

.chat-switch-name {
    font-size: 0.76rem;
    font-weight: 800;
    color: var(--chat-text-soft);
}

.chat-switch-button:hover:not(:disabled) {
    border-color: rgba(91, 140, 255, 0.32);
}

.chat-switch-button:disabled {
    opacity: 0.58;
    cursor: not-allowed;
}

.chat-switch-button[aria-checked="true"] {
    border-color: rgba(91, 140, 255, 0.36);
    background: linear-gradient(135deg, rgba(91, 140, 255, 0.18), rgba(34, 197, 94, 0.1));
}

.chat-switch-track {
    width: 38px;
    height: 22px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.34);
    position: relative;
    flex-shrink: 0;
    transition: background 0.18s ease;
}

.chat-switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.18);
    transition: transform 0.18s ease;
}

.chat-switch-button[aria-checked="true"] .chat-switch-track {
    background: rgba(34, 197, 94, 0.56);
}

.chat-switch-button[aria-checked="true"] .chat-switch-thumb {
    transform: translateX(16px);
}

.chat-switch-value {
    flex: 1 1 auto;
    text-align: left;
    font-size: 0.78rem;
    color: var(--chat-text-muted);
}

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

.chat-controls-summary {
    margin-top: 6px;
}

.chat-inline-metrics {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 14px;
}

.chat-inline-metric {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    min-width: 0;
}

.chat-inline-metric span {
    color: var(--chat-text-muted);
    font-size: 0.76rem;
    font-weight: 700;
}

.chat-inline-metric strong {
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--chat-text);
}

.chat-inline-metrics-inline {
    flex: 0 1 auto;
    min-width: 0;
    margin-left: auto;
}

.chat-prompt-action {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 12px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text-soft);
    font-size: 0.78rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.18s ease;
}

.chat-prompt-action:hover:not(:disabled) {
    border-color: rgba(91, 140, 255, 0.3);
    color: var(--chat-text);
}

.chat-prompt-action.is-active {
    border-color: rgba(91, 140, 255, 0.34);
    background: rgba(91, 140, 255, 0.12);
    color: var(--chat-primary);
}

.chat-prompt-action:disabled {
    opacity: 0.58;
    cursor: not-allowed;
}

.chat-resource-modal-dialog {
    width: min(860px, calc(100vw - 32px));
}

.chat-resource-modal-body {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.chat-resource-section {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--chat-border);
    border-radius: 18px;
    background: var(--chat-surface-soft);
}

.chat-resource-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.chat-resource-section-head strong {
    font-size: 0.92rem;
}

.chat-resource-count,
.chat-resource-pager-text {
    color: var(--chat-text-muted);
    font-size: 0.76rem;
    font-weight: 700;
}

.chat-resource-list {
    min-height: 300px;
    max-height: 420px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-resource-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--chat-border);
    border-radius: 14px;
    background: var(--chat-surface);
    cursor: pointer;
}

.chat-resource-item:hover {
    border-color: rgba(91, 140, 255, 0.26);
}

.chat-resource-checkbox {
    margin-top: 2px;
}

.chat-resource-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-resource-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--chat-text);
    line-height: 1.35;
}

.chat-resource-meta {
    font-size: 0.76rem;
    color: var(--chat-text-muted);
    line-height: 1.4;
}

.chat-resource-empty {
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 18px;
    border: 1px dashed var(--chat-border);
    border-radius: 14px;
    color: var(--chat-text-muted);
    text-align: center;
    font-size: 0.82rem;
}

.chat-resource-pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.chat-messages-panel {
    min-height: 0;
    overflow: hidden;
}

.chat-messages {
    height: 100%;
    min-height: 420px;
    max-height: calc(100vh - 340px);
    overflow: auto;
    padding: 18px 10px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-session-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 10px;
}

.chat-session-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.28);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.chat-empty-state {
    margin: auto;
    width: min(640px, 100%);
    padding: 28px;
    border-radius: 26px;
    border: 1px dashed var(--chat-border);
    background: linear-gradient(135deg, var(--chat-primary-soft), rgba(15, 23, 42, 0.06));
    text-align: center;
}

.chat-empty-state i {
    font-size: 2rem;
    color: var(--chat-primary);
}

.chat-empty-state h3 {
    margin: 14px 0 10px;
    font-size: 1.1rem;
}

.chat-empty-state p {
    margin: 0;
    color: var(--chat-text-soft);
    line-height: 1.7;
}

.chat-quick-actions {
    margin-top: 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.chat-quick-action {
    appearance: none;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text);
    min-height: 40px;
    padding: 0 14px;
    border-radius: 999px;
    font: inherit;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.18s ease;
}

.chat-quick-action:hover {
    border-color: rgba(91, 140, 255, 0.3);
    background: var(--chat-primary-soft);
    color: var(--chat-primary);
}

.chat-empty-state a {
    color: var(--chat-primary);
    font-weight: 700;
}

.chat-message {
    width: 100%;
    margin: 0;
    display: grid;
    gap: 6px;
}

.chat-message-shell {
    display: grid;
    gap: 10px;
}

.chat-message.is-user {
    justify-items: end;
}

.chat-message-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    color: var(--chat-text-muted);
    font-size: 0.75rem;
    font-weight: 700;
}

.chat-message-role,
.chat-message-tools {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.chat-message-role {
    min-width: 0;
}

.chat-message-identity {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.chat-message-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-message-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 10px;
    background: rgba(148, 163, 184, 0.14);
    color: var(--chat-primary);
}

.chat-message-copy {
    appearance: none;
    border: 1px solid transparent;
    background: transparent;
    color: var(--chat-text-muted);
    width: 28px;
    height: 28px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.18s ease;
}

.chat-message-delete {
    appearance: none;
    border: 1px solid transparent;
    background: transparent;
    color: var(--chat-text-muted);
    width: 28px;
    height: 28px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.18s ease;
}

.chat-message-copy:hover,
.chat-message-delete:hover {
    border-color: var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text);
}

.chat-message-delete:hover {
    color: var(--chat-danger);
    border-color: rgba(248, 113, 113, 0.22);
    background: rgba(248, 113, 113, 0.08);
}

.chat-message-body {
    max-width: 100%;
    padding: 14px 16px;
    border-radius: 18px;
    background: var(--chat-surface-soft);
    border: 1px solid var(--chat-border);
    line-height: 1.68;
    white-space: normal;
    word-break: break-word;
}

.chat-message-body > :first-child,
.chat-inline-block-content > :first-child {
    margin-top: 0;
}

.chat-message-body > :last-child,
.chat-inline-block-content > :last-child {
    margin-bottom: 0;
}

.chat-message-body p,
.chat-inline-block-content p {
    margin: 0 0 0.62em;
}

.chat-message-body p:last-child,
.chat-inline-block-content p:last-child {
    margin-bottom: 0;
}

.chat-message-body ul,
.chat-message-body ol,
.chat-inline-block-content ul,
.chat-inline-block-content ol {
    margin: 0.28em 0 0.62em 1.15em;
    padding: 0;
}

.chat-message-body li,
.chat-inline-block-content li {
    margin: 0.18em 0;
}

.chat-message-body pre,
.chat-inline-block-content pre {
    margin: 0.62em 0;
    padding: 12px 14px;
    overflow: auto;
    border-radius: 14px;
    background: rgba(2, 6, 23, 0.78);
    border: 1px solid rgba(148, 163, 184, 0.18);
}

.chat-message-body code,
.chat-inline-block-content code {
    font-family: "Consolas", "SFMono-Regular", "Courier New", monospace;
    font-size: 0.92em;
}

.chat-message-body :not(pre) > code,
.chat-inline-block-content :not(pre) > code {
    padding: 0.16em 0.42em;
    border-radius: 8px;
    background: rgba(148, 163, 184, 0.16);
}

.chat-message-body blockquote,
.chat-inline-block-content blockquote {
    margin: 0.64em 0;
    padding: 0.2em 0 0.2em 1em;
    border-left: 3px solid rgba(91, 140, 255, 0.36);
    color: var(--chat-text-soft);
}

.chat-message-body table,
.chat-inline-block-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.62em 0;
    overflow: hidden;
    border-radius: 14px;
    border: 1px solid var(--chat-border);
}

.chat-message-body th,
.chat-message-body td,
.chat-inline-block-content th,
.chat-inline-block-content td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--chat-border);
    text-align: left;
}

.chat-message-body a,
.chat-inline-block-content a {
    color: var(--chat-primary);
}

.chat-message-body .katex,
.chat-inline-block-content .katex {
    color: inherit;
    font-size: 1em;
}

.chat-message-body .katex-display,
.chat-inline-block-content .katex-display {
    margin: 0.72em 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.08em 0.02em;
}

.chat-message.is-user .chat-message-body {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-strong));
    color: #fff;
    border-color: transparent;
}

.chat-message.is-assistant .chat-message-body {
    background: rgba(15, 23, 42, 0.22);
}

[data-theme="light"] .chat-message.is-assistant .chat-message-body {
    background: rgba(248, 250, 252, 0.92);
}

.chat-message.is-error .chat-message-body {
    border-color: rgba(248, 113, 113, 0.26);
    background: rgba(248, 113, 113, 0.08);
    color: #fecaca;
}

[data-theme="light"] .chat-message.is-error .chat-message-body {
    color: #b91c1c;
}

.chat-message-model {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: min(320px, 42vw);
    height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text-soft);
    font-size: 0.72rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-message.is-assistant .chat-message-shell {
    padding: 14px 16px;
    border-radius: 20px;
    border: 1px solid var(--chat-border);
    background: rgba(15, 23, 42, 0.22);
}

[data-theme="light"] .chat-message.is-assistant .chat-message-shell {
    background: rgba(248, 250, 252, 0.92);
}

.chat-message-inline-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: -4px;
}

.chat-inline-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

.chat-inline-toolbar::-webkit-scrollbar {
    display: none;
}

.chat-inline-panels {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-inline-panel.collapsed {
    display: none;
}

.chat-message.is-assistant .chat-message-body {
    padding: 0;
    border: 0;
    background: transparent;
}

.chat-inline-block {
    width: 100%;
    margin: 0;
    padding-left: 0;
    border-left: 0;
}

.chat-inline-block-shell {
    width: 100%;
    margin-left: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--chat-text-soft);
}

.chat-inline-block-header {
    appearance: none;
    position: relative;
    cursor: pointer;
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
    max-width: none;
    white-space: nowrap;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid rgba(91, 140, 255, 0.22);
    background: rgba(91, 140, 255, 0.12);
    color: var(--chat-text-soft);
    font-size: 0.74rem;
    font-weight: 700;
}

.chat-inline-block.is-search .chat-inline-block-shell {
    background: transparent;
}

.chat-inline-block.is-search {
    border-left-color: rgba(245, 158, 11, 0.26);
}

.chat-inline-block.is-search .chat-inline-block-header {
    border-color: rgba(245, 158, 11, 0.28);
    background: rgba(245, 158, 11, 0.12);
}

.chat-inline-block.is-knowledge {
    border-left-color: rgba(16, 185, 129, 0.24);
}

.chat-inline-block.is-embedded .chat-inline-block-shell {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
}

.chat-inline-block.is-embedded .chat-inline-block-header {
    max-width: 100%;
}

.chat-inline-block.is-knowledge .chat-inline-block-shell {
    background: transparent;
}

.chat-inline-block.is-knowledge .chat-inline-block-header {
    border-color: rgba(16, 185, 129, 0.26);
    background: rgba(16, 185, 129, 0.12);
}

.chat-inline-block-header:hover {
    background: rgba(91, 140, 255, 0.18);
    border-color: rgba(91, 140, 255, 0.34);
}

.chat-inline-block.is-search .chat-inline-block-header:hover {
    background: rgba(245, 158, 11, 0.2);
    border-color: rgba(245, 158, 11, 0.34);
}

.chat-inline-block.is-knowledge .chat-inline-block-header:hover {
    background: rgba(16, 185, 129, 0.18);
    border-color: rgba(16, 185, 129, 0.32);
}

.chat-inline-block-header.is-loading .chat-inline-block-toggle {
    animation: chat-spin 1s linear infinite;
}

.chat-inline-block-title,
.chat-inline-block-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chat-inline-block-title {
    color: var(--chat-primary);
    min-width: 0;
}

.chat-inline-block-title span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-inline-block.is-search .chat-inline-block-title {
    color: #f59e0b;
}

.chat-inline-block.is-knowledge .chat-inline-block-title {
    color: #10b981;
}

.chat-inline-block-toggle {
    color: inherit;
    transition: transform 0.18s ease;
}

.chat-inline-block-toggle.collapsed {
    transform: rotate(-90deg);
}

.chat-inline-block-content {
    margin-top: 0;
    padding: 10px 12px 12px;
    border-radius: 14px;
    background: rgba(91, 140, 255, 0.12);
    color: var(--chat-text-soft);
    line-height: 1.6;
    white-space: normal;
    word-break: break-word;
    min-width: 0;
}

.chat-inline-block.is-search .chat-inline-block-content {
    background: rgba(245, 158, 11, 0.12);
}

.chat-inline-block.is-knowledge .chat-inline-block-content {
    background: rgba(16, 185, 129, 0.12);
}

.chat-inline-block-content.collapsed {
    display: none;
}

[data-theme="light"] .chat-inline-block-shell {
    background: transparent;
}

[data-theme="light"] .chat-inline-block.is-search .chat-inline-block-shell {
    background: transparent;
}

[data-theme="light"] .chat-inline-block.is-knowledge .chat-inline-block-shell {
    background: transparent;
}

[data-theme="light"] .chat-inline-block-content {
    background: rgba(219, 234, 254, 0.6);
}

[data-theme="light"] .chat-inline-block.is-search .chat-inline-block-content {
    background: rgba(255, 237, 213, 0.72);
}

[data-theme="light"] .chat-inline-block.is-knowledge .chat-inline-block-content {
    background: rgba(209, 250, 229, 0.72);
}

.chat-composer-panel {
    padding: 14px 16px 14px;
    position: sticky;
    bottom: 10px;
    z-index: 4;
}

.chat-composer-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 10px;
    margin-bottom: 4px;
}

.chat-composer {
    display: block;
}

.chat-input-shell {
    position: relative;
}

.chat-input {
    width: 100%;
    min-height: 108px;
    max-height: 220px;
    resize: none;
    padding: 16px 172px 18px 16px;
    border-radius: 20px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text);
    font: inherit;
    line-height: 1.55;
    outline: none;
}

.chat-input:focus {
    border-color: rgba(91, 140, 255, 0.4);
    box-shadow: 0 0 0 4px rgba(91, 140, 255, 0.12);
}

.chat-composer-actions {
    position: absolute;
    right: 12px;
    bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-secondary-action,
.chat-primary-send {
    min-width: 74px;
    height: 40px;
    padding: 0 12px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-weight: 700;
    font-size: 0.84rem;
}

.chat-secondary-action {
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text);
}

.chat-primary-send {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-strong));
    color: #fff;
    box-shadow: 0 14px 24px rgba(37, 99, 235, 0.2);
}

.chat-secondary-action:disabled,
.chat-primary-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.chat-footer-hint {
    margin-top: 6px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    color: var(--chat-text-muted);
    font-size: 0.74rem;
    line-height: 1.4;
}

.chat-footer-hint a {
    color: var(--chat-primary);
    font-weight: 700;
    text-decoration: none;
}

.chat-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2400;
}

.chat-modal.is-open {
    display: flex;
}

.chat-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.58);
    backdrop-filter: blur(6px);
}

.chat-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(720px, calc(100vw - 32px));
    border: 1px solid var(--chat-border);
    border-radius: 22px;
    background: var(--chat-surface);
    box-shadow: var(--chat-shadow);
    overflow: hidden;
}

.chat-modal-head,
.chat-modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
}

.chat-modal-head {
    border-bottom: 1px solid var(--chat-border);
}

.chat-modal-head strong {
    font-size: 0.98rem;
}

.chat-modal-close {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 12px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text);
    cursor: pointer;
}

.chat-modal-body {
    padding: 16px;
}

.chat-prompt-textarea {
    width: 100%;
    min-height: 220px;
    resize: vertical;
    padding: 14px 16px;
    border-radius: 18px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text);
    font: inherit;
    line-height: 1.6;
    outline: none;
}

.chat-prompt-textarea:focus {
    border-color: rgba(91, 140, 255, 0.4);
    box-shadow: 0 0 0 4px rgba(91, 140, 255, 0.12);
}

.chat-modal-actions {
    justify-content: flex-end;
    border-top: 1px solid var(--chat-border);
}

.chat-modal-save {
    width: auto;
    min-width: 92px;
    padding: 0 16px;
}

.chat-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.chat-history-loader {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    align-self: center;
    min-height: 34px;
    margin-bottom: 2px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface-soft);
    color: var(--chat-text-soft);
    font-size: 0.78rem;
    font-weight: 700;
}

.chat-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(148, 163, 184, 0.24);
    border-top-color: var(--chat-primary);
    border-radius: 50%;
    animation: chat-spin 0.85s linear infinite;
}

.chat-toast-stack {
    position: fixed;
    right: 18px;
    bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2200;
}

.chat-toast {
    min-width: 260px;
    max-width: 360px;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--chat-border);
    background: var(--chat-surface);
    color: var(--chat-text);
    box-shadow: var(--chat-shadow);
}

.chat-toast.is-success {
    border-color: rgba(34, 197, 94, 0.3);
}

.chat-toast.is-error {
    border-color: rgba(248, 113, 113, 0.28);
}

.chat-toast.is-warning {
    border-color: rgba(251, 191, 36, 0.32);
}

@keyframes chat-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 1180px) {
    .chat-shell {
        grid-template-columns: 280px minmax(0, 1fr);
    }

    .chat-messages {
        max-height: none;
    }
}

@media (max-width: 920px) {
    .chat-shell {
        width: min(100vw - 20px, 100%);
        grid-template-columns: 1fr;
        margin-top: 12px;
    }

    .chat-sidebar {
        order: 2;
        position: fixed;
        top: 72px;
        left: 10px;
        bottom: 10px;
        width: min(360px, calc(100vw - 20px));
        transform: translateX(calc(-100% - 20px));
        transition: transform 0.22s ease;
        z-index: 40;
    }

    .chat-main {
        order: 1;
    }

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

    .chat-sidebar-overlay.is-visible {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(2, 6, 23, 0.45);
        backdrop-filter: blur(4px);
        z-index: 35;
    }

    .chat-sidebar-close {
        display: inline-flex;
    }

    .chat-composer-inline-controls {
        width: 100%;
    }

    .chat-model-select-inline {
        flex-basis: 100%;
    }

    .chat-model-select-inline .chat-select {
        width: 100%;
    }

    .chat-resource-modal-body {
        grid-template-columns: 1fr;
    }

    .chat-input {
        min-height: 120px;
        padding-right: 16px;
        padding-bottom: 64px;
    }

    .chat-composer-actions {
        left: 12px;
        right: 12px;
        justify-content: flex-end;
    }

    .chat-inline-metrics {
        gap: 6px 12px;
    }

    .chat-footer-hint {
        justify-content: flex-start;
    }
}
