:root {
    color-scheme: dark;
    --ai-bg-0: var(--theme-bg-page, #0b1220);
    --ai-bg-1: var(--theme-bg-page-2, #0f1729);
    --ai-bg-2: var(--theme-bg-page-3, #111b2f);
    --ai-card: var(--theme-surface, #132237);
    --ai-border: var(--theme-border, #2f4764);
    --ai-text: var(--theme-text, #e9f2ff);
    --ai-muted: var(--theme-muted, #9bb3cd);
    --ai-accent: var(--theme-accent, #5ab6ff);
    --ai-accent-2: var(--theme-accent-2, #2f8bd8);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background:
        radial-gradient(1400px 680px at 82% -20%, color-mix(in srgb, var(--ai-accent) 18%, transparent), transparent 60%),
        radial-gradient(900px 520px at -10% 0%, color-mix(in srgb, var(--ai-accent-2) 16%, transparent), transparent 62%),
        linear-gradient(165deg, color-mix(in srgb, var(--ai-bg-0) 92%, #000000 8%), var(--ai-bg-1) 56%, var(--ai-bg-2));
    color: var(--ai-text);
    font-family: "Segoe UI", Arial, sans-serif;
}

.ai-app {
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: transparent;
}

.ai-topbar {
    height: 52px;
    border-bottom: 1px solid var(--ai-border);
    background: color-mix(in srgb, var(--ai-card) 86%, #000000 14%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
}

.brand strong {
    color: var(--ai-accent);
    margin-right: 10px;
}

.brand span {
    color: var(--ai-muted);
    font-size: 12px;
}

.top-links a {
    text-decoration: none;
    color: var(--ai-text);
    border: 1px solid var(--ai-border);
    border-radius: 8px;
    padding: 5px 10px;
    margin-left: 8px;
    font-size: 12px;
}

.ai-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
}

.ai-footer {
    height: 28px;
    border-top: 1px solid var(--ai-border);
    background: color-mix(in srgb, var(--ai-card) 84%, #000000 16%);
    color: var(--ai-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    font-size: 11px;
}

.ai-sidebar {
    width: 280px;
    min-width: 280px;
    border-right: 1px solid var(--ai-border);
    background: linear-gradient(180deg, rgba(15, 23, 38, 0.96), rgba(12, 19, 31, 0.96));
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    transition: width .18s ease, min-width .18s ease;
}

.ai-sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right: 0;
    overflow: hidden;
}

.ai-sidebar-backdrop {
    display: none;
}

.sidebar-head {
    padding: 10px;
    border-bottom: 1px solid #24303d;
    display: flex;
    gap: 8px;
}

.primary-btn, .send-btn, button, select, textarea, input {
    border: 1px solid #3f5672;
    border-radius: 9px;
    background: #101a2a;
    color: var(--ai-text);
    font-size: 13px;
    transition: border-color .16s ease, background .16s ease, transform .14s ease, box-shadow .16s ease;
}

.primary-btn {
    flex: 1;
    padding: 7px 10px;
    background: linear-gradient(135deg, #163856, #1e4d76);
    border-color: #5aa4dd;
    box-shadow: 0 6px 18px rgba(23, 78, 123, 0.35);
}

.icon-btn {
    padding: 6px 10px;
}

button:hover {
    border-color: #7dc5ff;
}

.session-list {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 10px 8px;
}

.session-item {
    position: relative;
    border: 1px solid #36506e;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(15, 25, 40, 0.88), rgba(11, 20, 31, 0.88));
    padding: 4px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
    transform: translateY(0);
    transition: transform .14s ease, border-color .14s ease, box-shadow .16s ease;
}

.session-open {
    flex: 1 1 auto;
    min-width: 0;
    padding: 4px 5px;
    border: 0;
    border-radius: 7px;
    color: inherit;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.session-open:focus-visible {
    outline: 2px solid #79c8ff;
    outline-offset: 1px;
}

.session-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 3px;
}

.session-actions button {
    padding: 5px 6px;
    font-size: 11px;
}

.session-item.active {
    border-color: #79c8ff;
    box-shadow: 0 0 0 1px rgba(121, 200, 255, 0.35) inset, 0 8px 20px rgba(14, 50, 80, 0.24);
}

.session-item:hover {
    transform: translateY(-1px);
    border-color: #619fce;
}

.session-title {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-meta {
    margin-top: 3px;
    font-size: 11px;
    color: #8196ac;
}

.session-menu-btn {
    position: absolute;
    right: 7px;
    top: 7px;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #94aac0;
    opacity: 0;
}

.session-item:hover .session-menu-btn {
    opacity: 1;
}

.session-menu {
    position: absolute;
    right: 8px;
    top: 30px;
    background: #172231;
    border: 1px solid #354760;
    border-radius: 8px;
    overflow: hidden;
    z-index: 8;
}

.session-menu button {
    width: 100%;
    text-align: left;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 7px 10px;
    font-size: 12px;
}

.session-menu button:hover {
    background: #20314a;
}

.config-status {
    border-top: 1px solid #24303d;
    color: #8da3b9;
    font-size: 12px;
    padding: 8px 10px 10px;
}

.chat-panel {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(16, 25, 38, 0.94), rgba(12, 19, 31, 0.94));
}

.chat-head {
    flex: 0 0 auto;
    height: 58px;
    border-bottom: 1px solid var(--ai-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 12px;
    background: linear-gradient(180deg, rgba(20, 31, 47, 0.96), rgba(18, 28, 43, 0.92));
    backdrop-filter: blur(10px);
}

.chat-title {
    font-size: 15px;
    font-weight: 600;
}

.chat-meta {
    color: #859bb0;
    font-size: 12px;
    margin-top: 2px;
}

.head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tools-panel {
    border: 1px solid var(--ai-border);
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(17, 28, 42, 0.95), rgba(14, 23, 36, 0.95));
    margin-bottom: 8px;
    padding: 10px;
    animation: panelIn .18s ease-out;
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr));
    gap: 8px;
}

.tool-grid label {
    min-width: 0;
    font-size: 12px;
    color: #90a5ba;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.execution-permission-note {
    margin-top: 8px;
    padding: 8px 10px;
    border: 1px solid #344a62;
    border-radius: 8px;
    background: rgba(24, 39, 57, .72);
    color: #a9bfd5;
    font-size: 12px;
    line-height: 1.5;
}

.execution-permission-note.is-full {
    border-color: #3f6d5a;
    background: rgba(22, 55, 45, .52);
    color: #b9dfce;
}

.gateway-card {
    margin-top: 8px;
    padding: 9px 10px;
    border: 1px solid #30465e;
    border-radius: 9px;
    background: linear-gradient(135deg, rgba(18, 34, 51, .9), rgba(13, 25, 39, .9));
}

.gateway-card-head,
.gateway-stats {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gateway-card-head {
    justify-content: space-between;
    color: #d3e3f2;
    font-size: 12px;
}

.gateway-badge {
    flex: 0 0 auto;
    padding: 2px 8px;
    border: 1px solid #4b6075;
    border-radius: 999px;
    color: #b7c8d8;
    background: rgba(75, 96, 117, .18);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .02em;
}

.gateway-badge.is-ready {
    border-color: #427c5e;
    color: #baf0d0;
    background: rgba(49, 112, 78, .2);
}

.gateway-badge.is-blocked,
.gateway-badge.is-error {
    border-color: #8b5555;
    color: #ffc0c0;
    background: rgba(139, 70, 70, .2);
}

.gateway-badge.is-loading {
    border-color: #536f8d;
    color: #bad5ef;
}

.gateway-summary {
    margin-top: 5px;
    color: #9fb5ca;
    font-size: 12px;
    line-height: 1.45;
}

.gateway-stats {
    flex-wrap: wrap;
    margin-top: 7px;
    color: #87a5c0;
    font-size: 11px;
}

.gateway-stats > span {
    min-width: 0;
    padding-right: 8px;
    border-right: 1px solid #34475a;
}

.gateway-stats > span:last-child {
    padding-right: 0;
    border-right: 0;
}

.gateway-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 9px;
}

.gateway-actions.hidden {
    display: none;
}

.gateway-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 5px 9px;
    border: 1px solid #40566d;
    border-radius: 7px;
    color: #b9cce0;
    background: rgba(39, 59, 80, .38);
    font-size: 11px;
    font-weight: 700;
    text-decoration: none;
}

.gateway-action:hover,
.gateway-action:focus-visible {
    border-color: #6d95bd;
    color: #e6f3ff;
    background: rgba(58, 91, 124, .5);
}

.gateway-action-primary {
    border-color: #4f7ea9;
    color: #e5f3ff;
    background: rgba(45, 101, 151, .46);
}

.attach-grid {
    margin-top: 8px;
}

.checkbox-like {
    flex-direction: row !important;
    align-items: center;
    gap: 8px !important;
    padding: 6px 8px;
    border: 1px solid #2c3b4d;
    border-radius: 8px;
    background: #0f1621;
    min-height: 34px;
}

.checkbox-like input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin: 0;
    padding: 0;
}

.checkbox-like span {
    font-size: 12px;
    color: #c5d5e6;
}

select, textarea, input, button {
    padding: 7px 9px;
}

.tools-actions {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chat-log {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overscroll-behavior: contain;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 28px clamp(14px, 3.2vw, 52px) 22px;
    scroll-behavior: smooth;
    scroll-padding-block: 24px;
}

.bubble {
    position: relative;
    align-self: center;
    width: min(100%, 1040px);
    border: 1px solid rgba(65, 91, 119, .62);
    border-radius: 18px;
    background: linear-gradient(145deg, rgba(18, 30, 45, .9), rgba(12, 22, 35, .82));
    padding: 14px 18px 18px;
    box-shadow: 0 18px 46px rgba(3, 10, 20, .22);
    animation: bubbleInLeft .22s ease-out;
}

.bubble.assistant {
    border-left: 3px solid color-mix(in srgb, var(--ai-accent) 76%, #ffffff 24%);
}

.bubble.user {
    align-self: flex-end;
    width: fit-content;
    max-width: min(760px, 78%);
    margin-left: auto;
    border-color: #4a86bb;
    background: linear-gradient(145deg, rgba(33, 73, 108, .96), rgba(22, 52, 82, .96));
    box-shadow: 0 14px 34px rgba(8, 31, 53, .28);
    animation: bubbleInRight .22s ease-out;
}

.bubble.pending {
    min-height: 88px;
    border-color: rgba(71, 112, 151, .72);
}

.message-head {
    min-height: 25px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.bubble .role {
    color: #a8c8e2;
    letter-spacing: .02em;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}

.bubble .role::before {
    content: "AI";
    width: 24px;
    height: 24px;
    display: inline-grid;
    place-items: center;
    border-radius: 8px;
    color: #e9f7ff;
    background: linear-gradient(145deg, #2d82c4, #225782);
    box-shadow: 0 5px 14px rgba(32, 106, 163, .28);
    font-size: 9px;
    letter-spacing: 0;
}

.bubble.user .role {
    color: #c4dcf2;
}

.bubble.user .role::before {
    content: "ME";
    color: #17324b;
    background: #a7d9fa;
    box-shadow: none;
}

.message-actions {
    display: flex;
    align-items: center;
    min-height: 25px;
    opacity: .58;
    transition: opacity .16s ease;
}

.bubble:hover .message-actions,
.bubble:focus-within .message-actions {
    opacity: 1;
}

.message-copy,
.code-copy {
    min-height: 26px;
    padding: 3px 9px;
    border-color: rgba(74, 103, 132, .72);
    border-radius: 7px;
    background: rgba(12, 22, 34, .5);
    color: #a8bfd4;
    font-size: 11px;
    cursor: pointer;
}

.message-copy.is-copied,
.code-copy.is-copied {
    border-color: #4c966e;
    color: #a9e7c4;
}

.message-copy.is-error,
.code-copy.is-error {
    border-color: #a66363;
    color: #ffc2c2;
}

.message-retry {
    border-color: color-mix(in srgb, var(--ai-accent) 58%, var(--ai-border) 42%);
    color: var(--ai-accent-strong, var(--ai-accent));
}

.bubble .content {
    min-width: 0;
    color: #dce9f5;
    line-height: 1.72;
    font-size: 14.5px;
    overflow-wrap: anywhere;
    word-break: normal;
}

.bubble .content > :first-child {
    margin-top: 0;
}

.bubble .content > :last-child {
    margin-bottom: 0;
}

.bubble .content p {
    margin: 0 0 .88em;
}

.bubble .content :is(h1, h2, h3, h4) {
    color: #f2f7fc;
    line-height: 1.3;
    letter-spacing: -.015em;
    margin: 1.35em 0 .6em;
}

.bubble .content h1 {
    padding-bottom: .36em;
    border-bottom: 1px solid rgba(77, 101, 126, .54);
    font-size: 1.55em;
}

.bubble .content h2 {
    font-size: 1.32em;
}

.bubble .content h3 {
    font-size: 1.14em;
}

.bubble .content :is(ul, ol) {
    margin: .55em 0 1em;
    padding-left: 1.65em;
}

.bubble .content li + li {
    margin-top: .32em;
}

.bubble .content li > :is(ul, ol) {
    margin-block: .32em;
}

.bubble .content a {
    color: #77c7ff;
    text-decoration: underline;
    text-decoration-color: rgba(119, 199, 255, .4);
    text-underline-offset: 3px;
}

.bubble .content a:hover {
    text-decoration-color: currentColor;
}

.bubble .content blockquote {
    margin: 1em 0;
    padding: .7em 1em;
    border-left: 3px solid #559bd0;
    border-radius: 0 9px 9px 0;
    background: rgba(34, 66, 94, .28);
    color: #bfd1e1;
}

.bubble .content blockquote > :last-child {
    margin-bottom: 0;
}

.bubble .content hr {
    margin: 1.4em 0;
    border: 0;
    border-top: 1px solid rgba(73, 96, 119, .62);
}

.bubble .content img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
}

.bubble .content code {
    padding: .14em .38em;
    border: 1px solid rgba(68, 91, 114, .68);
    border-radius: 5px;
    background: rgba(6, 14, 23, .72);
    color: #c9e7ff;
    font-family: "Cascadia Code", Consolas, "Courier New", monospace;
    font-size: .88em;
}

.code-block {
    margin: 1em 0 1.15em;
    overflow: hidden;
    border: 1px solid #2b4055;
    border-radius: 11px;
    background: #08111b;
    box-shadow: inset 0 1px rgba(255, 255, 255, .025);
}

.code-block-head {
    min-height: 36px;
    padding: 5px 8px 5px 12px;
    border-bottom: 1px solid #26394c;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #829db7;
    background: #101d2a;
    font: 11px/1.2 "Segoe UI", Arial, sans-serif;
    text-transform: lowercase;
}

.code-block-head > :first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.code-copy {
    flex: 0 0 auto;
}

.bubble .content .code-block pre {
    margin: 0;
    max-height: 560px;
    padding: 14px 16px 16px;
    border: 0;
    border-radius: 0;
    background: transparent;
    overflow: auto;
    white-space: pre;
    tab-size: 4;
}

.bubble .content .code-block pre code {
    padding: 0;
    border: 0;
    background: transparent;
    color: #d7e7f5;
    font-size: 12.5px;
    line-height: 1.62;
}

.table-scroll {
    margin: 1em 0 1.15em;
    overflow-x: auto;
    border: 1px solid #30475e;
    border-radius: 10px;
}

.bubble .content table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
    background: rgba(9, 18, 29, .54);
}

.bubble .content th,
.bubble .content td {
    padding: 9px 11px;
    border-right: 1px solid #2c4054;
    border-bottom: 1px solid #2c4054;
    text-align: left;
    vertical-align: top;
}

.bubble .content th {
    color: #e2effa;
    background: rgba(38, 66, 92, .68);
    font-size: 12px;
    letter-spacing: .015em;
}

.bubble .content tr:last-child td {
    border-bottom: 0;
}

.bubble .content :is(th, td):last-child {
    border-right: 0;
}

.ai-math-inline {
    display: inline-block;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-inline: .08em;
    vertical-align: -.08em;
}

.ai-math-block {
    max-width: 100%;
    margin: 1.1em 0;
    padding: 12px 14px;
    overflow-x: auto;
    overflow-y: hidden;
    border: 1px solid rgba(60, 88, 114, .62);
    border-radius: 10px;
    background: rgba(7, 16, 26, .52);
    text-align: center;
}

.ai-math .katex-display {
    margin: 0;
}

.ai-math-error {
    color: #ffc0c0;
    font-family: "Cascadia Code", Consolas, monospace;
    white-space: pre-wrap;
}

.typing {
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #9db5ca;
    font-size: 13px;
}

.typing-dots,
.typing-dots::before,
.typing-dots::after {
    width: 5px;
    height: 5px;
    border-radius: 999px;
    background: #67b8f0;
    animation: typingPulse 1.15s infinite ease-in-out;
}

.typing-dots {
    position: relative;
    margin-inline: 8px;
}

.typing-dots::before,
.typing-dots::after {
    content: "";
    position: absolute;
    top: 0;
}

.typing-dots::before {
    left: -8px;
    animation-delay: -.18s;
}

.typing-dots::after {
    right: -8px;
    animation-delay: .18s;
}

.chat-empty {
    width: min(100%, 760px);
    margin: auto;
    padding: 32px 18px 52px;
    text-align: center;
    animation: panelIn .24s ease-out;
}

.chat-empty-mark {
    width: 56px;
    height: 56px;
    margin: 0 auto 18px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(111, 191, 247, .72);
    border-radius: 18px;
    color: #effaff;
    background: linear-gradient(145deg, #2e86c7, #1d4b73);
    box-shadow: 0 18px 40px rgba(20, 88, 137, .3), inset 0 1px rgba(255, 255, 255, .16);
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -.03em;
}

.chat-empty h2 {
    margin: 0;
    color: #f0f7fd;
    font-size: clamp(20px, 2.5vw, 27px);
    line-height: 1.25;
    letter-spacing: -.025em;
}

.chat-empty p {
    max-width: 610px;
    margin: 10px auto 20px;
    color: #91aac0;
    font-size: 13px;
    line-height: 1.65;
}

.chat-suggestions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
}

.chat-suggestions button {
    min-height: 58px;
    padding: 10px 12px;
    border-color: rgba(62, 88, 115, .8);
    border-radius: 11px;
    color: #bed2e3;
    background: rgba(18, 32, 48, .72);
    line-height: 1.4;
    cursor: pointer;
}

.chat-suggestions button:hover,
.chat-suggestions button:focus-visible {
    border-color: #62afe6;
    color: #f1f8ff;
    background: rgba(32, 64, 91, .72);
    transform: translateY(-1px);
}

.search-meta {
    margin: 0 18px 10px;
    border: 1px solid #314153;
    border-radius: 9px;
    background: #131d29;
    color: #95aabc;
    font-size: 12px;
    padding: 8px 10px;
}

.composer-wrap {
    position: relative;
    flex: 0 0 auto;
    min-width: 0;
    border-top: 1px solid var(--ai-border);
    background: linear-gradient(180deg, rgba(15, 24, 36, .9), rgba(11, 18, 29, .98));
    backdrop-filter: blur(16px);
    padding: 10px clamp(10px, 2.4vw, 32px) 14px;
}

.composer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    position: relative;
    flex-wrap: nowrap;
    width: min(100%, 1040px);
    margin-inline: auto;
}

.tools-panel {
    width: min(100%, 1040px);
    margin-inline: auto;
}

.quick-field {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #a5c0da;
    font-size: 11px;
    border: 1px solid #2f4158;
    border-radius: 999px;
    padding: 2px 8px 2px 10px;
    background: rgba(14, 24, 37, 0.72);
}

.quick-field span {
    white-space: nowrap;
}

.quick-field select {
    border: 0;
    background: transparent;
    color: #d9e8f6;
    padding: 4px 2px;
    min-height: 24px;
    font-size: 12px;
    outline: none;
}

.quick-field.model select {
    min-width: 0;
    max-width: 100%;
}

.quick-field select option {
    background: #12253a;
    color: #e6f2ff;
}

.composer-toolbar.compact {
    gap: 6px;
    overflow: visible;
    flex-wrap: wrap;
    padding-bottom: 2px;
}

.toolbar-core,
.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex-wrap: wrap;
    flex: 0 1 auto;
}

.toolbar-actions {
    margin-left: auto;
}

.model-mode-hidden {
    display: none !important;
}

.toggle-btn {
    border-color: #3a5978;
    color: #bcd7ef;
    white-space: nowrap;
}

.toggle-btn.active {
    border-color: #77c5ff;
    background: rgba(80, 159, 217, 0.2);
    color: #e5f4ff;
}

.mode-chip {
    border: 1px solid #496685;
    border-radius: 999px;
    font-size: 12px;
    color: #a7c4df;
    padding: 3px 8px;
    white-space: nowrap;
}

.ghost-btn {
    background: transparent;
}

.ghost-btn:hover {
    background: rgba(109, 172, 228, 0.12);
}

/* Anchor the file picker to the full toolbar, not its narrow trigger. */
.attach-wrap {
    position: static;
}

.attach-pop {
    position: absolute;
    right: 0;
    left: auto;
    bottom: calc(100% + 8px);
    width: min(560px, 100%);
    max-height: min(54dvh, 480px);
    overflow: auto;
    overscroll-behavior: contain;
    border: 1px solid #33465c;
    border-radius: 10px;
    background: #111a25;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.38);
    padding: 10px;
    z-index: 40;
}

.attach-pop-head {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 12px;
}

.attach-count {
    color: #9bb4ce;
    font-size: 11px;
}

.attach-pop-section {
    margin-bottom: 8px;
}

.attach-pop-title {
    font-size: 11px;
    color: #88a6c4;
    margin-bottom: 5px;
}

.attach-pop-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 5px;
}

.attach-pop-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ghost-btn.mini {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 7px;
}

.attach-browse-path {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
    margin-bottom: 6px;
}

.attach-browse-path input,
.attach-search {
    width: 100%;
    min-width: 0;
    border: 1px solid #2d3f56;
    background: #0f1722;
    color: #d2e2f4;
    font-size: 12px;
    padding: 6px 8px;
}

.attach-search {
    margin-bottom: 6px;
}

.attach-list {
    max-height: 132px;
    overflow: auto;
    border: 1px solid #2d3c50;
    border-radius: 8px;
    background: #0d141f;
    padding: 4px;
}

.attach-list-lg {
    max-height: 200px;
}

.attach-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 12px;
    color: #c9daec;
}

.attach-item:hover {
    background: #192639;
}

.attach-item input {
    margin: 0;
}

.attach-item .path {
    min-width: 0;
    flex: 1 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attach-item.attach-dir {
    justify-content: space-between;
}

.attach-item .attach-kind {
    font-size: 10px;
    border: 1px solid #3a536f;
    border-radius: 999px;
    color: #9ec5e8;
    padding: 1px 6px;
}

.attach-item .attach-open {
    margin-left: 8px;
    padding: 3px 8px;
    font-size: 11px;
    border-radius: 7px;
}

.attach-empty {
    padding: 8px 6px;
    color: #7d95af;
    font-size: 12px;
}

.attach-pop-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 2px;
}

.composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 10px;
    width: min(100%, 1040px);
    margin: 0 auto;
    padding: 7px 7px 7px 12px;
    border: 1px solid #3d5872;
    border-radius: 15px;
    background: linear-gradient(145deg, rgba(17, 30, 45, .98), rgba(11, 21, 33, .98));
    box-shadow: 0 14px 34px rgba(2, 9, 18, .24), inset 0 1px rgba(255, 255, 255, .025);
    transition: border-color .16s ease, box-shadow .16s ease;
}

.composer:focus-within {
    border-color: #69b8ed;
    box-shadow: 0 14px 36px rgba(2, 9, 18, .3), 0 0 0 3px rgba(74, 163, 224, .12);
}

.composer.is-busy {
    border-color: #47647e;
}

.composer-input-wrap {
    min-width: 0;
}

.composer textarea {
    display: block;
    width: 100%;
    min-height: 52px;
    max-height: 190px;
    padding: 9px 5px 4px;
    overflow-y: auto;
    resize: none;
    border: 0;
    border-radius: 0;
    outline: none;
    background: transparent;
    box-shadow: none;
    color: #ebf4fc;
    font-size: 14px;
    line-height: 1.55;
}

.composer textarea::placeholder {
    color: #708aa1;
}

.composer-foot {
    min-height: 18px;
    padding: 0 5px 1px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: #687f95;
    font-size: 10.5px;
    line-height: 1.2;
}

.input-count {
    flex: 0 0 auto;
    min-width: 18px;
    text-align: right;
}

textarea {
    width: 100%;
    min-height: 66px;
    max-height: 200px;
    resize: vertical;
}

.send-btn {
    min-width: 78px;
    min-height: 48px;
    padding-inline: 16px;
    border-radius: 11px;
    background: linear-gradient(135deg, #23669b, #2f8acb);
    border-color: #70c1ff;
    box-shadow: 0 8px 20px rgba(31, 109, 165, .32);
    color: #f2f9ff;
    font-weight: 700;
    cursor: pointer;
}

.send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #2a75ad, #3a97d7);
    transform: translateY(-1px);
}

.send-btn:disabled {
    cursor: wait;
    opacity: .58;
    transform: none;
}

.hidden {
    display: none !important;
}

.dialog-mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .58);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.dialog-card {
    width: min(460px, 92vw);
    max-height: 90dvh;
    overflow: auto;
    background: #141d29;
    border: 1px solid #33455d;
    border-radius: 10px;
    padding: 14px;
}

.dialog-card h3 {
    margin: 0 0 8px;
    font-size: 16px;
}

.dialog-card p {
    margin: 0 0 12px;
    color: #9cb2c8;
    font-size: 13px;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.dialog-card input {
    width: 100%;
}

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

.plan-card {
    width: min(980px, 95vw);
    max-height: 90vh;
    overflow: auto;
    background: #111a26;
    border: 1px solid #2f4259;
    border-radius: 12px;
    padding: 14px;
}

.plan-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 10px;
}

.plan-head h3 {
    margin: 0 0 6px;
}

.plan-head p {
    margin: 0;
    color: #9cb2c8;
    font-size: 13px;
}

.plan-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.metric-chip {
    border: 1px solid #2f4158;
    border-radius: 8px;
    background: #0f1622;
    padding: 8px;
}

.metric-chip .label {
    font-size: 11px;
    color: #8ea6bc;
}

.metric-chip .value {
    font-size: 16px;
    font-weight: 600;
}

.plan-reads {
    border: 1px solid #2f4158;
    border-radius: 10px;
    background: #0f1520;
    padding: 10px;
    margin-bottom: 12px;
}

.plan-reads h4,
.plan-ops h4 {
    margin: 0 0 8px;
    font-size: 14px;
}

.read-item {
    font-size: 12px;
    color: #b8c8d9;
    padding: 4px 0;
    border-top: 1px dashed #243547;
}

.read-item:first-child {
    border-top: 0;
}

.plan-ops {
    border: 1px solid #2f4158;
    border-radius: 10px;
    background: #0f1520;
    padding: 10px;
}

.op-item {
    border: 1px solid #293a4e;
    border-radius: 8px;
    background: #121e2d;
    padding: 8px;
    margin-bottom: 8px;
}

.op-item:last-child {
    margin-bottom: 0;
}

.op-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.op-main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.op-main input[type="checkbox"] {
    width: 14px;
    height: 14px;
}

.op-title {
    font-size: 13px;
    font-weight: 600;
    color: #d8e4ef;
}

.risk-badge {
    font-size: 11px;
    border-radius: 999px;
    border: 1px solid #45607d;
    padding: 1px 8px;
    color: #c3d8ea;
}

.risk-high {
    border-color: #8c4c4c;
    color: #ffb2b2;
    background: rgba(140, 76, 76, 0.2);
}

.risk-medium {
    border-color: #7d6b3c;
    color: #ffe0a3;
    background: rgba(125, 107, 60, 0.2);
}

.risk-low {
    border-color: #3c7d56;
    color: #b8ffd0;
    background: rgba(60, 125, 86, 0.2);
}

.op-detail {
    font-size: 12px;
    color: #9fb4c8;
    margin-top: 6px;
    padding-left: 22px;
    word-break: break-word;
}

.inline-plan-card {
    margin-top: 12px;
    border: 1px solid #2f4158;
    border-radius: 10px;
    background: #0f1520;
    padding: 10px;
}

.ip-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.ip-title {
    font-size: 14px;
    font-weight: 700;
    color: #d6e6f7;
}

.ip-status {
    font-size: 12px;
    color: #91bde0;
}

.ip-summary {
    color: #a9bfd4;
    font-size: 13px;
    margin-top: 4px;
}

.ip-metrics {
    margin-top: 8px;
    margin-bottom: 8px;
}

.ip-sub-title {
    margin-top: 6px;
    margin-bottom: 4px;
    color: #86bfe8;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.ip-warning {
    color: #ffc98f;
    font-size: 12px;
}

.mt8 {
    margin-top: 8px;
}

.ip-reads,
.ip-ops {
    padding: 8px;
}

.ip-op-item {
    border: 1px solid #293a4e;
    border-radius: 8px;
    background: #121e2d;
    padding: 8px;
    margin-bottom: 8px;
}

.ip-op-item.done {
    opacity: .72;
    background: #162733;
}

.ip-op-item:last-child {
    margin-bottom: 0;
}

.ip-op-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.ip-op-main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.ip-op-check {
    width: 14px;
    height: 14px;
}

.ip-op-title {
    font-size: 13px;
    font-weight: 600;
    color: #d8e4ef;
}

.ip-done-chip {
    font-size: 10px;
    border: 1px solid #38604a;
    color: #98e0b8;
    border-radius: 999px;
    padding: 1px 7px;
}

.ip-op-detail {
    font-size: 12px;
    color: #9fb4c8;
    margin-top: 6px;
    padding-left: 22px;
    word-break: break-word;
}

.ip-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.ip-btn {
    border: 1px solid #3f678a;
    border-radius: 8px;
    background: #12253a;
    color: #d9e9f8;
    font-size: 12px;
    padding: 5px 10px;
}

.ip-btn:hover {
    border-color: #7ac2f6;
}

.ip-backup {
    margin-top: 8px;
    color: #8fb0ca;
    font-size: 12px;
}

.pending-action {
    border-bottom: 1px solid #32506f;
    background: linear-gradient(180deg, rgba(22, 38, 58, 0.96), rgba(15, 29, 46, 0.96));
    padding: 9px 12px 10px;
    animation: panelIn .2s ease-out;
}

.pending-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
}

.pending-head span:first-child {
    font-size: 12px;
    font-weight: 700;
    color: #cfe8ff;
}

.pending-target {
    font-size: 11px;
    color: #8fbbdf;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 56%;
}

.pending-desc {
    color: #9db8d3;
    font-size: 12px;
}

.pending-actions {
    margin-top: 7px;
    display: flex;
    gap: 8px;
}

@keyframes bubbleInLeft {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes bubbleInRight {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes panelIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes typingPulse {
    0%, 70%, 100% { opacity: .35; transform: translateY(0); }
    35% { opacity: 1; transform: translateY(-2px); }
}

.chat-log::-webkit-scrollbar,
.session-list::-webkit-scrollbar,
.attach-list::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.chat-log::-webkit-scrollbar-thumb,
.session-list::-webkit-scrollbar-thumb,
.attach-list::-webkit-scrollbar-thumb {
    background: rgba(110, 156, 199, 0.32);
    border-radius: 8px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}

button:hover {
    border-color: #6db8f1;
}

button:disabled {
    opacity: .6;
    cursor: not-allowed;
}

body.embedded .ai-topbar {
    display: none;
}

/* The Notebook dock already provides navigation, context and close/fullscreen
   controls.  Keep the embedded document as a single Agent surface instead of
   rendering a second global shell inside the iframe. */
body.embedded.ws-shell-enabled {
    padding: 0 !important;
}

body.embedded :is(.ws-shell-topbar, .ws-shell-bottom, .ws-shell-network-banner) {
    display: none !important;
}

body.embedded.ws-shell-enabled.ai-page .ai-app {
    height: 100dvh;
}

@media (max-width: 980px) {
    .tool-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .quick-field.model select {
        min-width: 148px;
    }
    .attach-pop {
        width: min(560px, 100%);
    }
    .bubble {
        max-width: 94%;
    }

    .chat-suggestions {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .ai-main {
        position: relative;
        overflow: hidden;
    }

    .chat-panel {
        width: 100%;
        min-width: 0;
    }

    .ai-sidebar {
        position: absolute;
        z-index: 120;
        inset: 0 auto 0 0;
        width: min(300px, 86vw);
        min-width: min(300px, 86vw);
        max-width: calc(100vw - 36px);
        border-right: 1px solid var(--ai-border);
        transform: translateX(0);
        transition: transform var(--motion-base, 180ms) var(--motion-ease-out, ease), visibility 0s;
        box-shadow: 18px 0 48px rgba(9, 31, 50, .24);
    }

    .ai-sidebar.collapsed {
        width: min(300px, 86vw);
        min-width: min(300px, 86vw);
        border-right: 1px solid var(--ai-border);
        overflow: hidden;
        visibility: hidden;
        pointer-events: none;
        transform: translateX(-105%);
        transition: transform var(--motion-base, 180ms) var(--motion-ease-out, ease), visibility 0s var(--motion-base, 180ms);
    }

    .ai-sidebar-backdrop {
        position: absolute;
        z-index: 110;
        inset: 0;
        border: 0;
        border-radius: 0;
        background: rgba(9, 31, 50, .34);
        backdrop-filter: blur(2px);
    }

    .ai-sidebar:not(.collapsed) + .ai-sidebar-backdrop {
        display: block;
    }

    .chat-head {
        min-width: 0;
        padding-inline: 9px;
    }

    .chat-head > div {
        min-width: 0;
    }

    .chat-title,
    .chat-meta {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .composer-wrap {
        min-width: 0;
        padding-inline: 8px;
    }

    .chat-log {
        gap: 14px;
        padding: 16px 10px 14px;
    }

    .bubble {
        width: 100%;
        max-width: 100%;
        padding: 12px 13px 15px;
        border-radius: 14px;
    }

    .bubble.user {
        width: fit-content;
        max-width: 92%;
    }

    .bubble .content {
        font-size: 14px;
    }

    .message-actions {
        opacity: .85;
    }

    .chat-empty {
        padding: 20px 4px 30px;
    }

    .composer {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 6px;
        padding-left: 8px;
    }

    .composer-foot > :first-child {
        display: none;
    }

    .send-btn {
        min-width: 64px;
        padding-inline: 11px;
    }

    .composer-toolbar.compact {
        max-width: 100%;
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        overflow: visible;
    }

    .composer-toolbar.compact :is(.toolbar-core, .toolbar-actions) {
        width: 100%;
        min-width: 0;
        flex-wrap: wrap;
    }

    .composer-toolbar.compact .toolbar-actions {
        margin-left: 0;
    }

    .composer-toolbar.compact .quick-field.model {
        min-width: 0;
        flex: 1 1 160px;
    }

    .composer-toolbar.compact .quick-field.model select {
        width: 100%;
        min-width: 0;
    }

    .gateway-card-head,
    .gateway-stats {
        align-items: flex-start;
    }

    .gateway-stats {
        display: grid;
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .gateway-stats > span {
        padding-right: 0;
        border-right: 0;
    }
}

/* Keep the Agent surface aligned with the application's light theme palette. */
:root {
    color-scheme: light;
    --ai-surface-main: var(--theme-surface, #fbfdff);
    --ai-surface-raised: var(--theme-surface-2, #f3f8fc);
    --ai-surface-soft: var(--theme-surface-soft, #e9f1f8);
    --ai-ink: var(--theme-text, #102538);
    --ai-ink-soft: var(--theme-text-soft, #263f55);
    --ai-ink-muted: var(--theme-muted, #405a70);
    --ai-shadow: var(--theme-shadow-card, 0 12px 30px rgba(25, 63, 91, .14));
}

.ai-sidebar {
    background: linear-gradient(180deg, var(--ai-surface-main), var(--ai-surface-raised));
    box-shadow: 8px 0 26px rgba(42, 77, 105, .07);
}

.sidebar-head,
.config-status {
    border-color: color-mix(in srgb, var(--ai-border) 72%, transparent);
}

.config-status,
.session-meta,
.chat-meta {
    color: var(--ai-ink-muted);
}

.session-item {
    border-color: color-mix(in srgb, var(--ai-border) 82%, transparent);
    background: rgba(255, 255, 255, .58);
    box-shadow: 0 5px 14px rgba(43, 76, 101, .05);
}

.session-item.active {
    border-color: color-mix(in srgb, var(--ai-accent) 78%, #ffffff 22%);
    background: color-mix(in srgb, var(--ai-accent) 9%, #ffffff 91%);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--ai-accent) 18%, transparent) inset, 0 8px 18px rgba(31, 91, 132, .1);
}

.chat-panel {
    background:
        radial-gradient(900px 400px at 52% -120px, color-mix(in srgb, var(--ai-accent) 8%, transparent), transparent 72%),
        linear-gradient(180deg, color-mix(in srgb, var(--theme-bg-page, #eef5fb) 76%, #ffffff 24%), var(--theme-bg-page-2, #e2edf7));
}

.chat-head {
    background: color-mix(in srgb, var(--ai-surface-main) 92%, transparent);
    box-shadow: 0 6px 20px rgba(38, 72, 99, .06);
}

.tools-panel,
.gateway-card,
.execution-permission-note,
.checkbox-like,
.search-meta,
.attach-pop {
    border-color: color-mix(in srgb, var(--ai-border) 82%, transparent);
    background: var(--ai-surface-main);
    color: var(--ai-ink-soft);
    box-shadow: var(--ai-shadow);
}

.execution-permission-note,
.gateway-summary,
.gateway-stats,
.attach-pop-title,
.attach-count {
    color: var(--ai-ink-muted);
}

.checkbox-like span,
.gateway-card-head {
    color: var(--ai-ink-soft);
}

.bubble {
    border-color: color-mix(in srgb, var(--ai-border) 78%, transparent);
    background: color-mix(in srgb, var(--ai-surface-main) 94%, #ffffff 6%);
    box-shadow: var(--ai-shadow);
}

.bubble.assistant {
    border-left-color: var(--ai-accent);
}

.bubble.user {
    border-color: color-mix(in srgb, var(--ai-accent) 76%, #ffffff 24%);
    background: linear-gradient(145deg, color-mix(in srgb, var(--ai-accent) 88%, #15476c 12%), color-mix(in srgb, var(--ai-accent-2) 82%, #153c5b 18%));
    box-shadow: 0 12px 26px color-mix(in srgb, var(--ai-accent) 20%, transparent);
}

.bubble .content,
.bubble .content :is(h1, h2, h3, h4) {
    color: var(--ai-ink);
}

.bubble.user .content,
.bubble.user .content :is(h1, h2, h3, h4),
.bubble.user .role {
    color: #f5fbff;
}

.bubble .role {
    color: var(--ai-ink-soft);
}

.message-copy {
    border-color: color-mix(in srgb, var(--ai-border) 75%, transparent);
    background: rgba(255, 255, 255, .56);
    color: var(--ai-ink-muted);
}

.bubble.user .message-copy {
    border-color: rgba(255, 255, 255, .35);
    background: rgba(8, 43, 70, .22);
    color: #eef8ff;
}

.bubble .content a {
    color: color-mix(in srgb, var(--ai-accent) 88%, #064776 12%);
}

.bubble .content blockquote {
    border-left-color: var(--ai-accent);
    background: color-mix(in srgb, var(--ai-accent) 8%, #ffffff 92%);
    color: var(--ai-ink-soft);
}

.bubble .content code:not(pre code) {
    border-color: color-mix(in srgb, var(--ai-border) 64%, transparent);
    background: color-mix(in srgb, var(--theme-surface-soft, #e9f1f8) 72%, #ffffff 28%);
    color: color-mix(in srgb, var(--ai-accent) 64%, #173a55 36%);
}

.code-block {
    border-color: color-mix(in srgb, var(--ai-border) 86%, #17293b 14%);
    background: var(--theme-code-bg, #102033);
}

.code-block-head {
    border-color: rgba(137, 173, 204, .24);
    background: color-mix(in srgb, var(--theme-code-bg, #102033) 88%, #28445f 12%);
    color: #b6cadb;
}

.code-copy {
    border-color: rgba(157, 187, 212, .34);
    background: rgba(255, 255, 255, .06);
    color: #d5e4ef;
}

.bubble .content .code-block pre code {
    color: var(--theme-code-text, #e7f2ff);
}

.table-scroll {
    border-color: color-mix(in srgb, var(--ai-border) 86%, transparent);
    background: rgba(255, 255, 255, .7);
}

.bubble .content table {
    background: transparent;
}

.bubble .content th {
    color: var(--ai-ink);
    background: color-mix(in srgb, var(--ai-accent) 10%, #ffffff 90%);
}

.bubble .content :is(th, td) {
    border-color: color-mix(in srgb, var(--ai-border) 52%, transparent);
}

.ai-math-block {
    border-color: color-mix(in srgb, var(--ai-border) 68%, transparent);
    background: rgba(255, 255, 255, .68);
}

.typing,
.chat-empty p,
.composer-foot {
    color: var(--ai-ink-muted);
}

.chat-empty h2 {
    color: var(--ai-ink);
}

.chat-suggestions button {
    border-color: color-mix(in srgb, var(--ai-border) 82%, transparent);
    color: var(--ai-ink-soft);
    background: rgba(255, 255, 255, .58);
    box-shadow: 0 7px 18px rgba(41, 76, 104, .07);
}

.chat-suggestions button:hover,
.chat-suggestions button:focus-visible {
    border-color: var(--ai-accent);
    color: var(--ai-ink);
    background: color-mix(in srgb, var(--ai-accent) 8%, #ffffff 92%);
}

.composer-wrap {
    background: color-mix(in srgb, var(--ai-surface-main) 92%, transparent);
    box-shadow: 0 -8px 28px rgba(38, 72, 99, .06);
}

.composer {
    border-color: color-mix(in srgb, var(--ai-border) 92%, transparent);
    background: rgba(255, 255, 255, .84);
    box-shadow: var(--ai-shadow);
}

.composer:focus-within {
    border-color: var(--ai-accent);
    box-shadow: var(--ai-shadow), 0 0 0 3px color-mix(in srgb, var(--ai-accent) 13%, transparent);
}

.composer textarea {
    color: var(--ai-ink);
}

.composer textarea::placeholder {
    color: color-mix(in srgb, var(--ai-ink-muted) 72%, transparent);
}

.quick-field {
    border-color: color-mix(in srgb, var(--ai-border) 80%, transparent);
    background: rgba(255, 255, 255, .62);
    color: var(--ai-ink-muted);
}

.quick-field select,
select,
textarea,
input,
button {
    border-color: color-mix(in srgb, var(--ai-border) 88%, transparent);
    background: color-mix(in srgb, var(--ai-surface-main) 86%, #ffffff 14%);
    color: var(--ai-ink);
}

.quick-field select option {
    background: #ffffff;
    color: var(--ai-ink);
}

.ghost-btn {
    color: var(--ai-ink-soft);
}

.send-btn {
    border-color: color-mix(in srgb, var(--ai-accent) 72%, #ffffff 28%);
    color: #ffffff;
    background: linear-gradient(135deg, color-mix(in srgb, var(--ai-accent) 92%, #145785 8%), color-mix(in srgb, var(--ai-accent-2) 88%, #165478 12%));
}

/* Conversation workspace. Keep responsive rules in this single section so
   embedded panels and the full page share the same layout constraints. */
body.ai-page {
    --ai-reading-width: 860px;
    --ai-panel-gutter: clamp(12px, 3vw, 40px);
}

.ai-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

body.ai-page :is(button, input, textarea, select):focus-visible {
    outline: 2px solid var(--ai-accent);
    outline-offset: 3px;
}

body.ai-page .ai-sidebar {
    width: 252px;
    min-width: 252px;
    min-height: 0;
    border-right-color: color-mix(in srgb, var(--ai-border) 60%, transparent);
    background: var(--ai-surface-main);
    box-shadow: none;
}

body.ai-page .ai-sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right: 0;
    visibility: hidden;
    pointer-events: none;
}

body.ai-page .sidebar-head {
    flex: 0 0 auto;
    padding: 12px 10px 8px;
    border-bottom: 0;
}

body.ai-page .sidebar-head .primary-btn {
    min-height: 36px;
    border-color: color-mix(in srgb, var(--ai-border) 70%, transparent);
    background: var(--ai-surface-soft);
    color: var(--ai-ink);
    box-shadow: none;
    text-align: left;
    font-weight: 600;
}

.session-search-wrap {
    flex: 0 0 auto;
    padding: 2px 10px 10px;
}

#ai-session-search {
    width: 100%;
    min-width: 0;
    min-height: 34px;
    border-color: color-mix(in srgb, var(--ai-border) 50%, transparent);
    background: transparent;
    font-size: 12px;
}

body.ai-page .session-list {
    padding: 2px 8px 12px;
}

body.ai-page .session-item {
    margin: 2px 0;
    padding: 4px;
    border-color: transparent;
    border-radius: 8px;
    background: transparent;
    box-shadow: none;
}

body.ai-page .session-item:hover,
body.ai-page .session-item.active {
    transform: none;
    border-color: transparent;
    background: var(--ai-surface-soft);
    box-shadow: none;
}

body.ai-page .session-item.active .session-title {
    font-weight: 650;
}
body.ai-page .session-actions button {
    border-color: transparent;
    background: transparent;
}
.session-empty {
    padding: 14px 8px;
    color: var(--ai-ink-muted);
    font-size: 12px;
    line-height: 1.6;
}
body.ai-page .config-status {
    overflow-wrap: anywhere;
    flex: 0 0 auto;
}

body.ai-page .chat-panel {
    background: var(--theme-bg-page, #f7f8fa);
}

body.ai-page .chat-head {
    height: 54px;
    min-height: 54px;
    padding-inline: var(--ai-panel-gutter);
    border-bottom-color: color-mix(in srgb, var(--ai-border) 38%, transparent);
    background: var(--ai-surface-main);
    box-shadow: none;
}

.chat-heading {
    min-width: 0;
    flex: 1;
}
body.ai-page .chat-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 650;
}
body.ai-page .chat-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
}
body.ai-page .head-actions {
    flex: 0 0 auto;
}
body.ai-page .head-actions .ghost-btn {
    min-height: 34px;
    border-color: transparent;
    font-size: 12px;
}

.conversation-stage {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

body.ai-page .chat-log {
    gap: 22px;
    padding: 28px var(--ai-panel-gutter) 56px;
    scroll-padding-block: 24px;
}

body.ai-page .bubble {
    width: min(100%, var(--ai-reading-width));
    min-width: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

body.ai-page .bubble.assistant {
    border-left: 0;
}
body.ai-page .bubble.assistant::after,
body.ai-page .bubble.user::after {
    content: none;
}

body.ai-page .bubble.user {
    width: fit-content;
    max-width: min(680px, 85%);
    margin: 0 max(0px, calc((100% - var(--ai-reading-width)) / 2)) 2px auto;
    padding: 12px 16px;
    border: 0;
    border-radius: 16px;
    color: var(--ai-ink);
    background: var(--ai-surface-soft);
    box-shadow: none;
}

body.ai-page .bubble.user :is(.content, .role),
body.ai-page .bubble.user .content :is(h1, h2, h3, h4) {
    color: var(--ai-ink);
}
body.ai-page .bubble.user .role::before {
    display: none;
}
body.ai-page .bubble.user .message-copy {
    color: var(--ai-ink-muted);
    background: transparent;
    border-color: transparent;
}
body.ai-page .message-head {
    min-height: 24px;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 6px;
}
body.ai-page .bubble.user .message-head {
    min-height: 20px;
    margin-bottom: 4px;
}
body.ai-page .bubble .role {
    gap: 8px;
    font-size: 11px;
    letter-spacing: .01em;
}
body.ai-page .bubble.assistant .role::before {
    content: "S";
    width: 23px;
    height: 23px;
    border-radius: 7px;
    background: var(--ai-ink);
    color: var(--ai-surface-main);
    box-shadow: none;
}
body.ai-page .message-actions {
    min-width: 0;
    gap: 5px;
    flex-wrap: wrap;
    min-height: 24px;
    opacity: .7;
}
body.ai-page .bubble:hover .message-actions,
body.ai-page .bubble:focus-within .message-actions,
body.ai-page .bubble.pending .message-actions {
    opacity: 1;
}
body.ai-page .bubble .content {
    font-size: 15px;
    line-height: 1.76;
}
body.ai-page .bubble.user .content {
    font-size: 14px;
    line-height: 1.65;
}
body.ai-page .bubble.pending {
    min-height: 52px;
}
body.ai-page .bubble :is(.table-scroll, .code-block, .ai-math-block) {
    max-width: 100%;
}
body.ai-page .bubble .content pre {
    max-width: 100%;
    overflow: auto;
}
body.ai-page .bubble .content :is(blockquote, code:not(pre code), th) {
    background: var(--ai-surface-soft);
}
body.ai-page .bubble .content code:not(pre code) {
    color: var(--ai-ink-soft);
}
body.ai-page .table-scroll,
body.ai-page .ai-math-block {
    background: var(--ai-surface-main);
}

.jump-latest {
    position: absolute;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    z-index: 5;
    min-height: 34px;
    max-width: calc(100% - 24px);
    padding: 6px 14px;
    border-radius: 20px;
    background: var(--ai-surface-main);
    color: var(--ai-ink-soft);
    box-shadow: var(--ai-shadow);
    font-size: 12px;
}

.stream-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--ai-ink-muted);
    font-size: 11px;
}
.stream-status-dot,
.agent-activity-dot {
    width: 6px;
    height: 6px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--ai-accent);
    animation: streamPulse 1.35s ease-out infinite;
}
.content.is-streaming::after {
    content: "";
    display: inline-block;
    width: 2px;
    height: 1.05em;
    margin-left: 3px;
    border-radius: 2px;
    vertical-align: -.14em;
    background: var(--ai-accent);
    animation: streamCursor .86s steps(1, end) infinite;
}

body.ai-page .composer-wrap {
    padding: 8px var(--ai-panel-gutter) max(14px, env(safe-area-inset-bottom));
    border-top: 0;
    background: var(--theme-bg-page, #f7f8fa);
    box-shadow: none;
}

body.ai-page :is(.composer-toolbar, .composer, .context-chips) {
    width: min(100%, var(--ai-reading-width));
    margin-inline: auto;
}

body.ai-page .composer-toolbar {
    min-height: 32px;
    margin-bottom: 6px;
    overflow: visible;
    flex-wrap: wrap;
}

body.ai-page .quick-field.model {
    min-width: 0;
    max-width: 100%;
    border: 0;
    padding-left: 2px;
    background: transparent;
}
body.ai-page .quick-field.model span {
    display: none;
}
body.ai-page .quick-field.model select {
    min-width: 0;
    width: 160px;
    max-width: 100%;
    padding-left: 0;
    color: var(--ai-ink-muted);
    background: transparent;
}
body.ai-page .quick-field select option {
    background: var(--ai-surface-main);
    color: var(--ai-ink);
}
body.ai-page .composer-toolbar .ghost-btn {
    min-height: 32px;
    padding: 5px 8px;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    font-size: 12px;
}
body.ai-page .composer-toolbar .ghost-btn:hover,
body.ai-page .composer-toolbar .ghost-btn:focus-visible {
    border-color: var(--ai-border);
    background: var(--ai-surface-soft);
}
body.ai-page .mode-chip {
    min-width: 0;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 26px;
    padding: 3px 8px;
    border-color: color-mix(in srgb, var(--ai-border) 55%, transparent);
    color: var(--ai-ink-muted);
    background: transparent;
    font-size: 11px;
}

body.ai-page .composer {
    padding: 8px 8px 8px 14px;
    border-color: color-mix(in srgb, var(--ai-border) 85%, transparent);
    border-radius: 18px;
    background: var(--ai-surface-main);
    box-shadow: 0 5px 18px rgba(20, 30, 40, .06);
}

body.ai-page .composer:focus-within {
    border-color: var(--ai-accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--ai-accent) 10%, transparent);
}
body.ai-page .composer textarea {
    max-height: min(180px, 25dvh);
    padding-block: 7px 3px;
    font-size: 15px;
    line-height: 1.55;
    background: transparent;
}
body.ai-page .composer-foot {
    min-height: 15px;
    font-size: 10px;
}
body.ai-page .send-btn {
    min-width: 64px;
    min-height: 42px;
    border: 0;
    border-radius: 12px;
    color: var(--ai-surface-main);
    background: var(--ai-ink);
    box-shadow: none;
}
body.ai-page .send-btn:hover:not(:disabled) {
    background: var(--ai-ink-soft);
    transform: none;
}
body.ai-page .send-btn.is-stop {
    border: 1px solid var(--ai-border);
    background: var(--ai-surface-soft);
    color: var(--ai-ink);
}

body.ai-page .tools-panel,
.command-menu {
    position: absolute;
    z-index: 45;
    bottom: calc(100% + 4px);
    left: var(--ai-panel-gutter);
    right: var(--ai-panel-gutter);
    width: auto;
    max-width: var(--ai-reading-width);
    max-height: min(50dvh, 520px);
    margin: 0 auto;
    padding: 12px;
    overflow: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--ai-border);
    border-radius: 12px;
    /* Keep overlays opaque so a long response never shows through controls. */
    background: var(--theme-surface-base, #ffffff);
    box-shadow: var(--ai-shadow);
}

body.ai-page .tools-panel select {
    width: 100%;
    min-width: 0;
}
body.ai-page .tools-panel > label {
    display: grid;
    gap: 5px;
    margin-top: 10px;
    color: var(--ai-ink-muted);
    font-size: 12px;
}
body.ai-page .gateway-card-head {
    flex-wrap: wrap;
}
body.ai-page .tools-panel :is(input, textarea, select, button) {
    background: var(--ai-surface-raised);
}
body.ai-page .attach-pop {
    background: var(--theme-surface-base, #ffffff);
}
body.ai-page .attach-list {
    background: var(--ai-surface-soft);
    border-color: var(--ai-border);
}
body.ai-page .attach-item {
    color: var(--ai-ink-soft);
}
body.ai-page .attach-item:hover {
    background: var(--ai-surface-raised);
}
body.ai-page :is(.attach-search, .attach-browse-path input) {
    background: var(--ai-surface-main);
    color: var(--ai-ink);
    border-color: var(--ai-border);
}

.context-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 78px;
    overflow: auto;
    margin-bottom: 7px;
}
.context-chips:empty {
    display: none;
}
.ai-context-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    padding: 3px 4px 3px 9px;
    border: 1px solid var(--ai-border);
    border-radius: 8px;
    background: var(--ai-surface-main);
    font-size: 11px;
}
.ai-context-chip-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ai-ink-soft);
}
.ai-context-chip-remove {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ai-ink-muted);
}
.command-menu {
    padding: 6px;
}
.ai-command-option {
    display: grid;
    grid-template-columns: minmax(92px, .28fr) minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    width: 100%;
    padding: 11px 10px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    text-align: left;
    cursor: pointer;
}
.ai-command-option:hover,
.ai-command-option.active {
    background: var(--ai-surface-soft);
}
.ai-command-name {
    font: 600 12px/1.5 "Cascadia Code", Consolas, monospace;
    color: var(--ai-ink);
}
.ai-command-description {
    color: var(--ai-ink-muted);
    font-size: 12px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

body.ai-page .chat-empty {
    width: min(100%, 700px);
    padding: 24px 0 36px;
}
body.ai-page .chat-empty-mark {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 13px;
    background: var(--ai-ink);
    color: var(--ai-surface-main);
    box-shadow: none;
}
body.ai-page .chat-suggestions {
    gap: 9px;
}
body.ai-page .chat-suggestions button {
    min-height: 64px;
    border-radius: 10px;
    background: var(--ai-surface-main);
    box-shadow: none;
    text-align: left;
}
body.ai-page .chat-suggestions button:hover {
    background: var(--ai-surface-soft);
    transform: none;
}

html[data-theme="codex"] body.ai-page :is(.tools-panel, .command-menu, .attach-pop),
body[data-theme="codex"] .ai-page :is(.tools-panel, .command-menu, .attach-pop) {
    background: #212121;
}

.agent-activity {
    width: min(calc(100% - 30px), 720px);
    margin: 0 0 14px 30px;
    border: 1px solid color-mix(in srgb, var(--ai-border) 60%, transparent);
    border-radius: 10px;
    background: var(--ai-surface-soft);
    color: var(--ai-ink-muted);
    overflow: hidden;
}
.agent-activity > summary {
    min-height: 35px;
    padding: 7px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    list-style: none;
    font-size: 11.5px;
    user-select: none;
}
.agent-activity > summary::-webkit-details-marker {
    display: none;
}
.agent-activity.is-complete .agent-activity-dot {
    background: var(--theme-success, #4b9c6b);
    animation: none;
}
.agent-activity-label {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.agent-activity-count {
    flex: 0 0 auto;
    color: var(--ai-ink-muted);
    font-size: 10px;
}
.agent-activity-list {
    margin: 0;
    padding: 2px 12px 10px 31px;
    border-top: 1px solid var(--ai-border);
    font-size: 11px;
    line-height: 1.6;
    overflow-wrap: anywhere;
}
.agent-activity-list li {
    padding: 3px 2px;
}
.agent-activity-list .is-complete {
    color: var(--theme-success, #287347);
}
.agent-activity-list .is-warning {
    color: var(--theme-warning, #9a651d);
}

@keyframes streamPulse {
    0% {
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--ai-accent) 30%, transparent);
    }
    72%, 100% {
        box-shadow: 0 0 0 7px transparent;
    }
}
@keyframes streamCursor {
    0%, 52% {
        opacity: 1;
    }
    53%, 100% {
        opacity: .18;
    }
}

@media (max-width: 760px) {
    body.ai-page {
        --ai-panel-gutter: 10px;
    }
    body.ai-page .ai-sidebar,
    body.ai-page .ai-sidebar.collapsed {
        width: min(300px, 86vw);
        min-width: min(300px, 86vw);
    }
    body.ai-page .chat-head {
        height: 48px;
        min-height: 48px;
        gap: 8px;
    }
    body.ai-page .chat-meta {
        display: none;
    }
    body.ai-page .head-actions .ghost-btn {
        max-width: 105px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    body.ai-page .chat-log {
        gap: 20px;
        padding: 20px var(--ai-panel-gutter) 48px;
    }
    body.ai-page .bubble.user {
        max-width: 92%;
        margin-right: 0;
        padding: 10px 12px;
    }
    body.ai-page .bubble .content {
        font-size: 14px;
    }
    body.ai-page .composer-toolbar.compact {
        overflow: visible;
    }
    body.ai-page .composer-toolbar .toolbar-core {
        flex-wrap: nowrap;
    }
    body.ai-page .quick-field.model {
        flex: 1 1 auto;
    }
    body.ai-page .quick-field.model select {
        width: 100%;
        max-width: 100%;
    }
    body.ai-page .toolbar-actions {
        gap: 3px;
    }
    body.ai-page .mode-chip {
        margin-left: auto;
        max-width: min(140px, 42vw);
    }
    body.ai-page .composer {
        padding-left: 10px;
        border-radius: 16px;
    }
    body.ai-page .composer textarea {
        font-size: 16px;
    }
    body.ai-page .send-btn {
        min-width: 56px;
        padding-inline: 10px;
    }
    body.ai-page .message-copy,
    body.ai-page .code-copy,
    body.ai-page .session-actions button {
        min-height: 32px;
    }
    .tool-grid {
        grid-template-columns: minmax(0, 1fr);
    }
    .ai-command-option {
        grid-template-columns: minmax(0, 1fr);
        gap: 2px;
    }
    .attach-pop {
        max-height: min(48dvh, 420px);
    }
}

@media (max-height: 560px) {
    body.ai-page .chat-head {
        height: 42px;
        min-height: 42px;
    }
    body.ai-page .composer-wrap {
        padding-top: 4px;
        padding-bottom: 6px;
    }
    body.ai-page .composer textarea {
        min-height: 38px;
        max-height: 72px;
    }
    body.ai-page .composer-foot {
        display: none;
    }
    body.ai-page .context-chips {
        max-height: 34px;
        margin-bottom: 3px;
    }
    body.ai-page .tools-panel,
    .command-menu,
    .attach-pop {
        max-height: min(42dvh, max(72px, calc(100dvh - 240px)));
    }
    body.ai-page .chat-empty {
        padding-block: 10px;
    }
    body.ai-page .chat-empty-mark {
        display: none;
    }
}
