:root {
            --bg: #eef6ff;
            --bg-accent: #dfeefe;
            --panel: rgba(250, 253, 255, 0.86);
            --panel-solid: #fafdff;
            --text: #162033;
            --muted: #64748b;
            --border: rgba(125, 164, 214, 0.26);
            --primary: #2563eb;
            --primary-strong: #1d4ed8;
            --primary-soft: rgba(37, 99, 235, 0.10);
            --assistant: #f3f8fe;
            --assistant-border: #dce8f6;
    --user: linear-gradient(135deg, #5b8def, #7dd3fc);
            --success: #15803d;
            --warning: #b45309;
            --danger: #dc2626;
            --shadow: 0 24px 60px rgba(37, 99, 235, 0.12);
            --radius-xl: 28px;
            --radius-lg: 22px;
            --radius-md: 16px;
            --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
        }

        [data-theme="dark"] {
            --bg: #10151c;
            --bg-accent: #1b2430;
            --panel: rgba(18, 24, 32, 0.84);
            --panel-solid: #141b24;
            --text: #e5e7eb;
            --muted: #94a3b8;
            --border: rgba(148, 163, 184, 0.18);
            --primary: #60a5fa;
            --primary-strong: #93c5fd;
            --primary-soft: rgba(96, 165, 250, 0.12);
            --assistant: #18212c;
            --assistant-border: #243243;
    --user: linear-gradient(135deg, #4f7fe0, #60a5fa);
            --shadow: 0 28px 70px rgba(0, 0, 0, 0.34);
        }

        * {
            box-sizing: border-box;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        body {
            margin: 0;
            min-height: 100vh;
            font-family: "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
            color: var(--text);
            background:
                radial-gradient(circle at top left, rgba(59, 130, 246, 0.18), transparent 28%),
                radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.15), transparent 26%),
                linear-gradient(160deg, var(--bg) 0%, var(--bg-accent) 100%);
            padding: 18px;
        }

        button,
        select,
        textarea {
            font: inherit;
        }

        .app {
            width: min(1080px, 100%);
            height: calc(100vh - 36px);
            margin: 0 auto;
            display: flex;
        }

        .chat-shell {
            flex: 1;
            min-height: 100%;
            background: var(--panel);
            border: 1px solid var(--border);
            backdrop-filter: blur(16px);
            box-shadow: var(--shadow);
            border-radius: var(--radius-xl);
            display: grid;
            grid-template-rows: auto minmax(0, 1fr) auto;
            overflow: hidden;
        }

        .topbar {
            padding: 18px;
            border-bottom: 1px solid var(--border);
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 14px;
            flex-wrap: wrap;
        }

        .brand {
            display: flex;
            align-items: center;
            gap: 14px;
            min-width: 0;
        }

        .logo {
            width: 48px;
            height: 48px;
            border-radius: 16px;
            background: linear-gradient(135deg, #2563eb, #38bdf8);
            color: #fff;
            display: grid;
            place-items: center;
            font-weight: 800;
            letter-spacing: -0.04em;
            box-shadow: 0 12px 28px rgba(37, 99, 235, 0.24);
            flex: 0 0 auto;
        }

        .brand-copy {
            min-width: 0;
        }

        .brand-copy h1 {
            margin: 0;
            font-size: 20px;
            line-height: 1.15;
        }

        .brand-copy p {
            margin: 4px 0 0;
            color: var(--muted);
            font-size: 13px;
        }

        .toolbar {
            position: relative;
            display: flex;
            align-items: center;
            gap: 10px;
            flex-wrap: wrap;
        }

        .mode-switch {
            min-height: 46px;
            padding: 0 8px 0 14px;
            border-radius: 999px;
            border: 1px solid var(--border);
            background: linear-gradient(135deg, rgba(255, 255, 255, 0.82), rgba(242, 248, 255, 0.98));
            color: var(--text);
            cursor: pointer;
            transition: 0.18s ease;
            display: inline-flex;
            align-items: center;
            gap: 10px;
            font-weight: 700;
            white-space: nowrap;
        }

        .mode-switch:hover {
            transform: translateY(-1px);
            border-color: rgba(37, 99, 235, 0.32);
            background: var(--primary-soft);
        }

        [data-theme="dark"] .mode-switch {
            background: linear-gradient(135deg, rgba(30, 41, 59, 0.82), rgba(20, 27, 36, 0.96));
        }

        .mode-switch-label {
            font-size: 14px;
        }

        .mode-switch-track {
            width: 44px;
            height: 26px;
            border-radius: 999px;
            background: rgba(148, 163, 184, 0.35);
            position: relative;
            transition: 0.18s ease;
            flex: 0 0 auto;
        }

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

        .mode-switch.active {
            border-color: rgba(37, 99, 235, 0.4);
            color: var(--primary-strong);
        }

        .mode-switch.active .mode-switch-track {
            background: linear-gradient(135deg, #2563eb, #38bdf8);
        }

        .mode-switch.active .mode-switch-thumb {
            transform: translateX(18px);
        }

        [data-theme="dark"] .mode-switch.active {
            color: #bfdbfe;
            border-color: rgba(96, 165, 250, 0.4);
        }

        .toolbar-btn {
            min-height: 46px;
            border-radius: 999px;
            border: 1px solid var(--border);
            background: var(--panel-solid);
            color: var(--text);
            padding: 0 16px;
            cursor: pointer;
            transition: 0.16s ease;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            font-weight: 700;
        }

        .toolbar-btn:hover {
            transform: translateY(-1px);
            border-color: rgba(37, 99, 235, 0.32);
            background: var(--primary-soft);
        }

        .toolbar-btn.subtle {
            background: linear-gradient(135deg, rgba(255, 255, 255, 0.82), rgba(242, 248, 255, 0.98));
        }

        [data-theme="dark"] .toolbar-btn.subtle {
            background: linear-gradient(135deg, rgba(30, 41, 59, 0.82), rgba(20, 27, 36, 0.96));
        }

.messages {
    min-height: 0;
    overflow-y: auto;
    padding: 20px 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
    scrollbar-gutter: stable both-edges;
}

        .empty {
            margin: auto;
            max-width: 580px;
            text-align: center;
            color: var(--muted);
            padding: 32px 18px;
        }

        .empty h2 {
            margin: 0;
            color: var(--text);
            font-size: clamp(28px, 5vw, 42px);
            line-height: 1.08;
        }

        .empty p {
            margin: 12px 0 0;
            line-height: 1.7;
        }

.message {
    max-width: min(56%, 470px);
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: rise 0.18s ease;
}

.message.assistant.has-trace {
    max-width: min(88%, 900px);
    display: grid;
    grid-template-columns: minmax(220px, max-content) minmax(240px, 300px);
    align-items: start;
    gap: 12px;
}

.message-main {
    width: fit-content;
    max-width: 100%;
    display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .message.user .message-main {
            align-self: flex-end;
        }

        .message.assistant .message-main {
            align-self: flex-start;
        }

        .message.user {
            align-self: flex-end;
        }

        .message.assistant {
            align-self: flex-start;
        }

        @keyframes rise {
            from {
                opacity: 0;
                transform: translateY(6px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

.bubble {
    border-radius: 24px;
    padding: 8px 10px;
    min-width: 80px;
    font-size: 14px;
    line-height: 1.62;
    word-break: break-word;
    white-space: pre-wrap;
}

.message.user .bubble {
    background: var(--user);
    color: #fff;
    border-bottom-right-radius: 8px;
}

.message.assistant .bubble {
    background: var(--assistant);
    border: 1px solid var(--assistant-border);
    border-bottom-left-radius: 8px;
}

.message[data-loading="true"] .bubble {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.loading-bubble {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    font-size: inherit;
    line-height: 1.62;
    gap: 8px;
    min-height: 1.62em;
    margin: 1em 0;
}

.loading-bubble > span:first-child {
    display: inline-block;
    line-height: 1.62;
}

.message-meta {
    color: var(--muted);
    font-size: 12.5px;
    display: flex;
    align-items: center;
    gap: 10px;
            flex-wrap: wrap;
            padding: 0 4px;
        }

        .copy-btn {
            border: none;
            background: transparent;
            color: var(--muted);
            cursor: pointer;
            padding: 0;
            font-size: 12px;
        }

        .copy-btn:hover {
            color: var(--primary);
        }

.trace-stack {
    display: grid;
    gap: 10px;
    width: 100%;
}

        .trace-card {
            background: var(--panel-solid);
            border: 1px solid var(--border);
            border-radius: 18px;
            overflow: hidden;
        }

.trace-card summary {
            list-style: none;
            cursor: pointer;
            display: block;
            position: relative;
            padding: 12px 14px;
    font-size: 13px;
    font-weight: 700;
}

        .trace-card summary::-webkit-details-marker {
            display: none;
        }

        .trace-card[open] summary {
            border-bottom: 1px solid var(--border);
            background: var(--primary-soft);
        }

        .trace-labels {
             display: flex;
             align-items: center;
             justify-content: flex-start;
             gap: 8px;
             min-width: 0;
             width: 100%;
        }

        .trace-labels > .trace-tag {
            flex: 0 0 auto;
        }

        .trace-labels > span:last-child:not(.trace-tag) {
            visibility: hidden;
            width: 0;
            overflow: hidden;
            white-space: nowrap;
        }

        .planner-card summary::after,
        .tool-trace-card summary::after {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            pointer-events: none;
            color: var(--text-main);
        }

        .planner-card summary::after {
            content: "规划决策";
        }

        .tool-trace-card summary::after {
            content: "工具轨迹";
        }

        .trace-tag {
            border-radius: 999px;
            padding: 4px 9px;
            font-size: 11px;
            font-weight: 800;
            letter-spacing: 0.02em;
            text-transform: uppercase;
        }

        .trace-tag.route-research,
        .trace-tag.trace {
            background: rgba(37, 99, 235, 0.10);
            color: #1d4ed8;
        }

        .trace-tag.route-agent {
            background: rgba(14, 165, 233, 0.10);
            color: #0369a1;
        }

        .trace-tag.action {
            background: rgba(96, 165, 250, 0.12);
            color: var(--primary-strong);
        }

        [data-theme="dark"] .trace-tag.route-research,
        [data-theme="dark"] .trace-tag.trace {
            color: #7dd3fc;
        }

        [data-theme="dark"] .trace-tag.route-agent {
            color: #7dd3fc;
        }

        [data-theme="dark"] .trace-tag.action {
            color: #bfdbfe;
        }

        .trace-content {
            padding: 14px;
            display: grid;
            gap: 12px;
        }

        .kv-grid {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 10px;
        }

.kv {
    background: rgba(148, 163, 184, 0.06);
    border-radius: 14px;
    padding: 10px 12px;
}

.kv strong {
    display: block;
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.kv div {
    font-size: 12.5px;
    line-height: 1.58;
}

.trace-summary {
    font-size: 11px;
    line-height: 1.45;
    color: var(--muted);
    margin-top: 4px;
}

.trace-pre {
    margin: 0;
    font-family: var(--mono);
    font-size: 11.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

        .composer {
            padding: 14px;
            border-top: 1px solid var(--border);
        }

        .input-box {
            display: flex;
            align-items: flex-end;
            gap: 10px;
            padding: 10px 12px;
            background: var(--panel-solid);
            border: 1px solid var(--border);
            border-radius: 24px;
        }

        textarea {
            flex: 1;
            min-width: 0;
            min-height: 44px;
            max-height: 180px;
            resize: none;
            border: none;
            background: transparent;
            outline: none;
            color: var(--text);
            line-height: 1.55;
            padding: 10px 2px;
        }

        textarea::placeholder {
            color: var(--muted);
        }

        .send-btn {
            width: 46px;
            height: 46px;
            min-width: 46px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border: none;
            border-radius: 50%;
            background: var(--user);
            color: #fff;
            cursor: pointer;
            box-shadow: 0 12px 22px rgba(37, 99, 235, 0.24);
        }

        .send-btn svg {
            width: 18px;
            height: 18px;
            stroke: currentColor;
            stroke-width: 2.2;
            stroke-linecap: round;
            stroke-linejoin: round;
            fill: none;
        }

        .send-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            box-shadow: none;
        }

        .composer-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 10px;
            padding: 10px 4px 2px;
            color: var(--muted);
            font-size: 12px;
            flex-wrap: wrap;
        }

        .status-line {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .status-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: var(--success);
        }

        .dots {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            min-height: 1.62em;
        }

        .dot {
            display: block;
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background: var(--muted);
            animation: pulse 1s infinite ease-in-out;
        }

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

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

        .loading-bubble {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

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

        .loading-progress {
            display: flex;
            flex-direction: column;
            gap: 6px;
            max-height: 180px;
            overflow: auto;
            padding-left: 2px;
        }

        .loading-progress-item {
            font-size: 12px;
            color: var(--muted);
            line-height: 1.5;
        }

        .interactive-panel {
            margin-top: 10px;
            padding: 12px 14px;
            border-radius: 16px;
            border: 1px solid var(--border);
            background: rgba(255, 255, 255, 0.55);
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        [data-theme="dark"] .interactive-panel {
            background: rgba(20, 27, 36, 0.78);
        }

        .interactive-title {
            font-size: 13px;
            font-weight: 700;
            color: var(--primary-strong);
        }

        .interactive-copy,
        .interactive-sub {
            font-size: 13px;
            line-height: 1.6;
        }

        .interactive-sub {
            color: var(--muted);
        }

        .interactive-input {
            width: 100%;
            min-height: 70px;
            resize: vertical;
            border-radius: 14px;
            border: 1px solid var(--border);
            background: rgba(255, 255, 255, 0.8);
            padding: 10px 12px;
            color: var(--text);
        }

        [data-theme="dark"] .interactive-input {
            background: rgba(15, 23, 42, 0.72);
        }

        .interactive-actions {
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
        }

        .interactive-log {
            display: flex;
            flex-direction: column;
            gap: 6px;
            max-height: 180px;
            overflow: auto;
        }

        @keyframes pulse {
            0%, 80%, 100% {
                opacity: 0.36;
                transform: scale(0.7);
            }
            40% {
                opacity: 1;
                transform: scale(1);
            }
        }

        pre code,
        code {
            font-family: var(--mono);
        }

        .bubble pre {
            margin: 10px 0;
            padding: 12px;
            border-radius: 16px;
            overflow-x: auto;
            background: rgba(15, 23, 42, 0.92);
            color: #e5e7eb;
            white-space: pre;
        }

        .messages {
            scrollbar-width: thin;
            scrollbar-color: rgba(148, 163, 184, 0.45) transparent;
        }

        @media (max-width: 1080px) {
            body {
                padding: 12px;
            }

            .app {
                width: 100%;
                height: calc(100vh - 24px);
                min-height: calc(100vh - 24px);
            }

            .chat-shell {
                min-height: 100%;
            }
        }

        @media (max-width: 720px) {
            body {
                padding: 0;
            }

            .app {
                height: 100vh;
                min-height: 100vh;
            }

            .chat-shell {
                border-radius: 0;
            }

            .topbar {
                padding: 14px;
            }

            .toolbar {
                width: 100%;
                display: grid;
                grid-template-columns: 1fr 1fr;
            }

            .toolbar-btn {
                width: 100%;
                justify-content: center;
            }

            .mode-switch {
                width: 100%;
                justify-content: space-between;
            }

            .messages {
                padding: 14px 12px 8px;
            }

    .message {
        max-width: 78%;
    }

    .message.assistant.has-trace {
        max-width: 88%;
        grid-template-columns: 1fr;
    }

    .message-main {
        gap: 7px;
    }

    .bubble {
        min-width: 72px;
        font-size: 13px;
        padding: 7px 9px;
    }

            .trace-stack {
                width: 100%;
            }

            .kv-grid {
                grid-template-columns: 1fr;
            }

            .composer {
                padding-bottom: max(14px, env(safe-area-inset-bottom));
            }
        }
