:root {
  color-scheme: light;
  font-family: Inter, "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  color: #111827;
  background: #f4f5f7;
  font-synthesis: none;
  --canvas: #f4f5f7;
  --sidebar: #111827;
  --surface: #fff;
  --subtle: #f8fafc;
  --text: #111827;
  --secondary: #475569;
  --muted: #94a3b8;
  --border: #e2e8f0;
  --strong-border: #cbd5e1;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --success: #16a34a;
  --warning: #d97706;
  --error: #dc2626;
  --sidebar-width: 288px;
  --message-width: 920px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button, select, label { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(79, 70, 229, .25);
  outline-offset: 2px;
}
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); height: 100dvh; }

.loading-page, .access-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--secondary);
  background: var(--canvas);
}
.spinner { width: 18px; height: 18px; border: 2px solid #cbd5e1; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.small { width: 14px; height: 14px; flex: 0 0 14px; }
.connection-error { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 32px; text-align: center; }
.connection-error strong { color: var(--text); font-size: 18px; }
.connection-error span { max-width: 480px; font-size: 13px; }
.connection-error button, .access-card button { border: 0; border-radius: 8px; padding: 10px 16px; color: #fff; background: var(--accent); cursor: pointer; }
.access-card { width: min(420px, calc(100% - 32px)); padding: 36px 32px; border: 1px solid var(--border); border-radius: 16px; background: #fff; text-align: center; box-shadow: 0 12px 32px rgba(15, 23, 42, .1); }
.access-mark, .empty-mark { display: grid; place-items: center; margin: 0 auto; background: var(--sidebar); color: #fff; font-weight: 700; }
.access-mark { width: 48px; height: 48px; border-radius: 14px; }
.access-card h1 { margin: 20px 0 8px; font-size: 20px; }
.access-card p { margin: 0 0 24px; color: var(--secondary); font-size: 14px; line-height: 1.7; }

.sidebar { min-width: 0; display: flex; flex-direction: column; padding: 16px 12px 14px; overflow: hidden; background: var(--sidebar); color: #f9fafb; }
.brand-row { height: 44px; display: flex; align-items: center; gap: 11px; padding: 0 8px; }
.brand-mark { width: 32px; height: 32px; display: grid; place-items: center; flex: 0 0 32px; border-radius: 10px; background: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: -1px; }
.brand-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.brand-copy strong { font-size: 14px; letter-spacing: .01em; }
.brand-copy span { color: #9ca3af; font-size: 11px; }
.connection-dot { width: 8px; height: 8px; margin-left: auto; flex: 0 0 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 3px rgba(52, 211, 153, .11); }
.connection-dot.offline { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, .11); }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; cursor: pointer; }
.icon-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.sidebar-close { display: none; color: #94a3b8; font-size: 24px; }
.new-chat { height: 40px; display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 16px; border: 0; border-radius: 10px; background: #fff; color: #111827; font-size: 13px; font-weight: 650; cursor: pointer; box-shadow: 0 1px 2px rgba(15,23,42,.06); }
.new-chat:hover { background: #f8fafc; }
.new-chat span:first-child { color: var(--accent); font-size: 19px; font-weight: 400; line-height: 1; }
.search-box { position: relative; display: block; margin-top: 12px; }
.search-box svg { position: absolute; left: 11px; top: 10px; width: 15px; fill: none; stroke: #64748b; stroke-width: 1.8; stroke-linecap: round; }
.search-box input { width: 100%; height: 36px; border: 1px solid rgba(255,255,255,.09); border-radius: 8px; padding: 0 10px 0 34px; outline: 0; background: rgba(255,255,255,.045); color: #f8fafc; font-size: 12px; }
.search-box input::placeholder { color: #64748b; }
.search-box input:focus { border-color: rgba(129,140,248,.65); background: rgba(255,255,255,.07); }
.section-label { margin: 20px 8px 7px; color: #64748b; font-size: 10px; font-weight: 700; letter-spacing: .15em; }
.chat-list { min-height: 0; flex: 1; overflow: auto; padding-right: 2px; scrollbar-color: rgba(255,255,255,.14) transparent; scrollbar-width: thin; }
.chat-row { width: 100%; min-height: 58px; display: flex; align-items: flex-start; gap: 9px; margin: 2px 0; padding: 10px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: #cbd5e1; text-align: left; cursor: pointer; }
.chat-row:hover { background: rgba(255,255,255,.055); }
.chat-row.active { border-color: rgba(255,255,255,.055); background: rgba(255,255,255,.1); color: #fff; }
.task-dot { width: 7px; height: 7px; margin-top: 5px; flex: 0 0 7px; border-radius: 50%; background: #64748b; }
.task-dot.warning { background: #fbbf24; }
.task-dot.success { background: #34d399; }
.task-dot.error { background: #fb7185; }
.chat-copy { min-width: 0; display: flex; flex: 1; flex-direction: column; gap: 5px; }
.chat-copy strong { overflow: hidden; color: inherit; font-size: 12.5px; font-weight: 550; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.chat-copy small { overflow: hidden; color: #64748b; font-size: 10.5px; text-overflow: ellipsis; white-space: nowrap; }
.chat-row.active .chat-copy small { color: #94a3b8; }
.no-history { padding: 24px 8px; color: #64748b; font-size: 12px; text-align: center; }
.quota-card { margin-top: 10px; padding: 12px; border: 1px solid rgba(255,255,255,.09); border-radius: 11px; background: rgba(255,255,255,.04); }
.quota-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #94a3b8; font-size: 10.5px; }
.quota-heading strong { color: #e2e8f0; font-size: 10.5px; font-weight: 600; }
.quota-track { height: 5px; margin-top: 9px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.09); }
.quota-track span { width: 0; height: 100%; display: block; border-radius: inherit; background: #818cf8; transition: width .3s ease; }
.quota-reset { margin-top: 8px; color: #64748b; font-size: 10px; }
.identity-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 9px 7px 0; border-top: 1px solid rgba(255,255,255,.07); }
.avatar { width: 28px; height: 28px; display: grid; place-items: center; flex: 0 0 28px; border-radius: 8px; background: #334155; color: #cbd5e1; font-size: 11px; font-weight: 700; }
.identity-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.identity-copy strong { color: #cbd5e1; font-size: 11px; font-weight: 550; }
.identity-copy span { overflow: hidden; color: #64748b; font-size: 9.5px; text-overflow: ellipsis; white-space: nowrap; }

.main { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.topbar { height: 64px; display: flex; align-items: center; flex: 0 0 64px; padding: 0 24px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.97); }
.mobile-menu { display: none; margin-right: 8px; color: var(--secondary); }
.title-block { min-width: 0; }
.title-line { display: flex; align-items: center; gap: 9px; min-width: 0; }
.title-line h1 { max-width: min(56vw, 620px); overflow: hidden; margin: 0; color: var(--text); font-size: 14px; font-weight: 650; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.status-badge { flex: 0 0 auto; border-radius: 999px; padding: 3px 8px; font-size: 9.5px; font-weight: 650; }
.status-badge.warning { background: #fffbeb; color: #b45309; }
.status-badge.success { background: #f0fdf4; color: #15803d; }
.status-badge.error { background: #fef2f2; color: #b91c1c; }
.status-badge.neutral { background: #f1f5f9; color: #475569; }
.conversation-meta { max-width: 65vw; overflow: hidden; margin-top: 3px; color: #94a3b8; font-size: 10.5px; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; margin-left: auto; }
.stop-button { height: 34px; display: flex; align-items: center; gap: 7px; border: 1px solid var(--border); border-radius: 8px; padding: 0 11px; background: #fff; color: var(--secondary); font-size: 11.5px; cursor: pointer; }
.stop-button:hover { border-color: #fecaca; background: #fef2f2; color: #b91c1c; }
.stop-button:disabled { opacity: .5; cursor: wait; }
.stop-square { width: 9px; height: 9px; border-radius: 2px; background: currentColor; }
.workspace-shell { min-height: 0; display: flex; flex: 1; flex-direction: column; overflow: hidden; }
.messages { min-height: 0; flex: 1; overflow-x: hidden; overflow-y: auto; padding: 28px max(24px, calc((100% - var(--message-width)) / 2)); scroll-behavior: smooth; scrollbar-color: #cbd5e1 transparent; scrollbar-width: thin; }
.message-row { width: 100%; margin: 0 0 26px; }
.message-row.user { display: flex; justify-content: flex-end; }
.user-bubble { max-width: 78%; padding: 11px 15px; border: 1px solid #e0e7ff; border-radius: 15px 15px 4px 15px; background: var(--accent-soft); color: #27324a; font-size: 13.5px; line-height: 1.7; overflow-wrap: anywhere; }
.user-bubble p, .user-bubble h3, .user-bubble h4 { margin: 0; }
.user-bubble br + br { display: none; }
.message-row.assistant { display: flex; align-items: flex-start; gap: 12px; }
.assistant-mark { width: 30px; height: 30px; display: grid; place-items: center; flex: 0 0 30px; border-radius: 9px; background: var(--sidebar); color: #fff; font-size: 9px; font-weight: 750; letter-spacing: -1px; }
.assistant-body { min-width: 0; flex: 1; padding-top: 1px; }
.assistant-label { margin-bottom: 7px; color: #64748b; font-size: 10.5px; font-weight: 650; }
.markdown-body, .live-output { color: #334155; font-size: 13.5px; line-height: 1.75; overflow-wrap: anywhere; }
.markdown-body p, .live-output p { margin: 0 0 9px; }
.markdown-body p:last-child, .live-output p:last-child { margin-bottom: 0; }
.markdown-body h3, .markdown-body h4, .live-output h3, .live-output h4 { margin: 20px 0 8px; color: var(--text); line-height: 1.4; }
.markdown-body h3, .live-output h3 { font-size: 15px; }
.markdown-body h4, .live-output h4 { font-size: 14px; }
.markdown-body ul, .markdown-body ol, .live-output ul, .live-output ol { margin: 6px 0 10px; padding-left: 22px; }
.markdown-body li, .live-output li { margin: 3px 0; }
.markdown-body code, .user-bubble code, .live-output code { border-radius: 4px; padding: 1px 5px; background: #eef2f6; color: #9f1239; font-family: "Cascadia Code", Consolas, monospace; font-size: .9em; }
.markdown-body pre, .live-output pre { margin: 12px 0; overflow: auto; border: 1px solid #1e293b; border-radius: 9px; background: #0f172a; }
.markdown-body pre div, .live-output pre div { padding: 6px 12px; border-bottom: 1px solid #1e293b; color: #94a3b8; font-size: 10px; }
.markdown-body pre code, .live-output pre code { display: block; padding: 13px; background: transparent; color: #e2e8f0; font-size: 11.5px; line-height: 1.65; white-space: pre; }
.markdown-body a, .live-output a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover, .live-output a:hover { text-decoration: underline; }
.message-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.message-files span { display: inline-flex; align-items: center; gap: 5px; max-width: 280px; overflow: hidden; border: 1px solid var(--border); border-radius: 7px; padding: 4px 7px; background: rgba(255,255,255,.6); color: #64748b; font-size: 10.5px; text-overflow: ellipsis; white-space: nowrap; }
.job-row { margin: -8px 0 26px 42px; }
.progress-card, .result-card { overflow: hidden; border: 1px solid var(--border); border-radius: 11px; background: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.06); }
.progress-head { min-height: 39px; display: flex; align-items: center; gap: 8px; padding: 9px 13px; border-bottom: 1px solid #f1f5f9; color: #334155; font-size: 11.5px; }
.progress-head strong { font-weight: 650; }
.pulse-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: #f59e0b; animation: pulse 1.5s ease-in-out infinite; }
.elapsed { margin-left: auto; color: #94a3b8; font-size: 10px; font-variant-numeric: tabular-nums; }
.event-list { margin: 0; padding: 10px 13px 10px 38px; list-style: none; }
.event-list li { position: relative; min-height: 26px; color: #64748b; font-size: 11.5px; line-height: 1.45; }
.event-list li::before { position: absolute; top: 14px; bottom: -4px; left: -20px; width: 1px; background: #e2e8f0; content: ""; }
.event-list li:last-child::before { display: none; }
.event-list li > span { position: absolute; left: -27px; top: 0; width: 15px; height: 15px; display: grid; place-items: center; border: 1px solid #cbd5e1; border-radius: 50%; background: #fff; color: #fff; font-size: 8px; }
.event-list li.done > span { border-color: #22c55e; background: #22c55e; }
.event-list li.current > span { border: 3px solid #c7d2fe; background: var(--accent); }
.event-list li.current { color: #334155; font-weight: 550; }
.progress-placeholder { display: flex; align-items: center; gap: 8px; padding: 13px; color: #64748b; font-size: 11.5px; }
.live-output { max-height: 260px; overflow: auto; padding: 0 13px 13px; border-top: 1px solid #f1f5f9; font-size: 12px; }
.live-output > :first-child { margin-top: 12px; }
.result-card { padding: 13px 15px; font-size: 12px; }
.result-card strong { color: var(--text); }
.result-card p { margin: 5px 0 0; color: var(--secondary); line-height: 1.6; }
.error-card { border-color: #fecaca; background: #fffafa; }
.error-card strong { color: #b91c1c; }
.canceled-card { background: #f8fafc; }

.empty-state { max-width: 720px; margin: clamp(70px, 14vh, 150px) auto 0; text-align: center; }
.empty-mark { width: 44px; height: 44px; border-radius: 13px; font-size: 11px; }
.empty-state h2 { margin: 19px 0 7px; font-size: 18px; font-weight: 650; }
.empty-state > p { margin: 0; color: #64748b; font-size: 12.5px; }
.capability-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 29px; text-align: left; }
.capability-grid div { padding: 14px; border: 1px solid var(--border); border-radius: 11px; background: rgba(255,255,255,.74); }
.capability-grid div > span { width: 25px; height: 25px; display: grid; place-items: center; margin-bottom: 9px; border-radius: 7px; background: #f1f5f9; color: #64748b; font-size: 12px; }
.capability-grid strong, .capability-grid small { display: block; }
.capability-grid strong { margin-bottom: 4px; font-size: 11.5px; }
.capability-grid small { color: #94a3b8; font-size: 9.5px; line-height: 1.5; }

.composer-dock { position: relative; flex: 0 0 auto; padding: 6px 24px calc(13px + env(safe-area-inset-bottom)); background: var(--canvas); }
.composer { width: min(var(--message-width), 100%); margin: 0 auto; overflow: hidden; border: 1px solid var(--strong-border); border-radius: 15px; background: #fff; box-shadow: 0 12px 32px rgba(15,23,42,.1); transition: border-color .15s ease, box-shadow .15s ease; }
.composer:focus-within { border-color: #818cf8; box-shadow: 0 0 0 3px rgba(79,70,229,.08), 0 12px 32px rgba(15,23,42,.1); }
#prompt { width: 100%; min-height: 66px; max-height: 180px; display: block; resize: none; overflow-y: auto; border: 0; padding: 14px 15px 8px; outline: 0; background: transparent; color: var(--text); font-size: 13.5px; line-height: 1.55; }
#prompt::placeholder { color: #94a3b8; }
.file-previews { display: flex; gap: 7px; overflow-x: auto; padding: 10px 12px 0; }
.file-chip { height: 34px; max-width: 220px; display: flex; align-items: center; gap: 7px; flex: 0 0 auto; border: 1px solid var(--border); border-radius: 8px; padding: 3px 5px 3px 4px; background: #f8fafc; color: #475569; font-size: 10.5px; }
.file-chip img, .file-icon { width: 26px; height: 26px; object-fit: cover; border-radius: 5px; background: #e2e8f0; }
.file-icon { display: grid; place-items: center; }
.file-chip > span:not(.file-icon) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { width: 20px; height: 20px; display: grid; place-items: center; flex: 0 0 20px; border: 0; border-radius: 5px; background: transparent; color: #94a3b8; cursor: pointer; }
.file-chip button:hover { background: #e2e8f0; color: #475569; }
.composer-toolbar { min-height: 43px; display: flex; align-items: center; gap: 7px; padding: 5px 9px 7px; border-top: 1px solid #f1f5f9; }
.attach-button { width: 32px; height: 32px; display: grid; place-items: center; flex: 0 0 32px; border-radius: 8px; color: #64748b; cursor: pointer; }
.attach-button:hover { background: #f1f5f9; color: #334155; }
.attach-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.attach-button input { display: none; }
.select-wrap { position: relative; max-width: 180px; }
.select-wrap::after { position: absolute; right: 8px; top: 10px; color: #94a3b8; font-size: 8px; pointer-events: none; content: "▼"; }
select { width: 100%; height: 30px; appearance: none; overflow: hidden; border: 1px solid var(--border); border-radius: 7px; padding: 0 23px 0 8px; outline: 0; background: #fff; color: #475569; font-size: 10.5px; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
select:hover { border-color: var(--strong-border); }
.keyboard-hint { margin-left: auto; color: #94a3b8; font-size: 9.5px; white-space: nowrap; }
.send-button { width: 32px; height: 32px; display: grid; place-items: center; flex: 0 0 32px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; }
.send-button:hover { background: var(--accent-hover); }
.send-button:disabled { opacity: .45; cursor: wait; }
.send-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.composer-note { width: min(var(--message-width), 100%); margin: 7px auto 0; color: #94a3b8; font-size: 9px; text-align: center; }
.toast-region { position: fixed; z-index: 100; right: 18px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { max-width: min(360px, calc(100vw - 36px)); padding: 11px 14px; border: 1px solid #fecaca; border-radius: 9px; background: #fff; color: #991b1b; font-size: 12px; box-shadow: 0 12px 32px rgba(15,23,42,.14); animation: toast-in .16s ease both; }
.toast.success { border-color: #bbf7d0; color: #166534; }
.drawer-overlay { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; transform: scale(.85); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1100px) {
  :root { --sidebar-width: 258px; }
  .messages { padding-left: 28px; padding-right: 28px; }
  .composer-dock { padding-left: 28px; padding-right: 28px; }
}

@media (max-width: 760px) {
  body.drawer-open { overflow: hidden; }
  .app { display: block; }
  .sidebar { position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: min(88vw, 310px); transform: translateX(-102%); box-shadow: 0 12px 32px rgba(15,23,42,.3); transition: transform .18s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: grid; margin-left: 0; }
  .connection-dot { margin-left: auto; }
  .drawer-overlay { position: fixed; z-index: 40; inset: 0; display: block; visibility: hidden; opacity: 0; background: rgba(15,23,42,.42); transition: opacity .18s ease, visibility .18s; }
  .drawer-overlay.visible { visibility: visible; opacity: 1; }
  .main { height: 100dvh; }
  .topbar { height: 58px; flex-basis: 58px; padding: 0 12px 0 8px; }
  .mobile-menu { display: grid; }
  .title-line h1 { max-width: 49vw; font-size: 13px; }
  .conversation-meta { max-width: 58vw; }
  .stop-button { width: 34px; justify-content: center; padding: 0; }
  .stop-button span:last-child { display: none; }
  .messages { padding: 20px 14px; }
  .message-row { margin-bottom: 22px; }
  .user-bubble { max-width: 88%; padding: 10px 13px; font-size: 13px; }
  .message-row.assistant { gap: 9px; }
  .assistant-mark { width: 27px; height: 27px; flex-basis: 27px; border-radius: 8px; font-size: 8px; }
  .markdown-body, .live-output { font-size: 13px; }
  .job-row { margin-left: 36px; }
  .capability-grid { grid-template-columns: 1fr; margin-top: 22px; }
  .capability-grid div { display: grid; grid-template-columns: 28px 1fr; column-gap: 9px; padding: 11px 13px; }
  .capability-grid div > span { grid-row: 1 / 3; margin: 0; }
  .empty-state { margin-top: 54px; }
  .empty-state h2 { font-size: 16px; }
  .composer-dock { padding: 5px 10px calc(8px + env(safe-area-inset-bottom)); }
  .composer { border-radius: 13px; }
  #prompt { min-height: 58px; padding: 12px 12px 6px; font-size: 13px; }
  .keyboard-hint { display: none; }
  .select-wrap { min-width: 0; max-width: 125px; }
  .select-wrap:nth-of-type(2) { max-width: 105px; }
  .composer-note { margin-top: 5px; font-size: 8.5px; }
}

@media (max-width: 390px) {
  .select-wrap { max-width: 105px; }
  .select-wrap:nth-of-type(2) { max-width: 88px; }
  select { padding-left: 6px; font-size: 9.5px; }
  .composer-toolbar { gap: 5px; padding-left: 6px; padding-right: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
