:root {
  --void: #f6f8fc;
  --stage: #eef2f8;
  --panel: #ffffff;
  --sidebar: #f1f5f9;
  --sidebar-hover: #e8edf4;
  --ink: #243044;
  --mute: #64748b;
  --line: #dbe3ef;
  --line-soft: rgba(36, 48, 68, 0.06);
  --accent: #e11d48;
  --accent-strong: #be123c;
  --accent-soft: rgba(225, 29, 72, 0.12);
  --user-bg: #fff1f2;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --diff-before: #fff1f2;
  --diff-after: #ecfdf5;
  --shadow: 0 8px 30px rgba(36, 48, 68, 0.08);
  --sidebar-w: 260px;
  --top-h: 52px;
  --font: "Segoe UI", ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--void);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
textarea, input, select { outline: none; }
[hidden] { display: none !important; }

.logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(145deg, #fb7185, var(--accent));
  color: #fff; font-weight: 800; font-size: 11px; letter-spacing: -0.04em;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(225, 29, 72, 0.25);
}
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.brand strong { display: block; font-size: 14px; }
.brand p { margin: 0; color: var(--mute); font-size: 11px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--line-soft);
  background: rgba(255,255,255,.85); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.mode-switch { display: inline-flex; padding: 2px; gap: 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
.mode-switch button { border-radius: 999px; padding: 5px 10px; font-size: 11px; color: var(--mute); }
.mode-switch button.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 11px; color: var(--mute); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #cbd5e1; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.err { background: var(--danger); }
.ghost, .mini { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; min-height: 30px; padding: 0 10px; font-size: 12px; color: var(--mute); }
.mini { min-height: 26px; font-size: 11px; }
.primary, .send { border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; min-height: 34px; padding: 0 14px; }
.primary:hover, .send:hover { background: var(--accent-strong); }
.primary:disabled, .send:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); }
.icon-btn.tiny { width: 24px; height: 24px; font-size: 11px; }
.lang-pair { display: inline-flex; align-items: center; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; }
.lang-pair select, .keys-input { border: 0; background: transparent; font-size: 11px; padding: 4px; max-width: 130px; }
.keys-input { border: 1px solid var(--line); border-radius: 8px; min-width: 140px; padding: 6px 8px; font-size: 12px; }

/* ===== Tool layout (Auto / Basic) ===== */
body.layout-tool {
  background:
    radial-gradient(ellipse 90% 55% at 50% -15%, rgba(225, 29, 72, 0.08), transparent 55%),
    linear-gradient(180deg, #fff 0%, var(--void) 40%, #eef3f9 100%);
}
.tool-app { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; }
.tool-main { width: min(1180px, 100%); margin: 0 auto; padding: 16px; display: grid; gap: 12px; align-content: start; }
.tool-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tool-lang-pair select { max-width: 150px; font-size: 13px; }
.file-btn { display: inline-flex; align-items: center; cursor: pointer; }
.translate-btn { min-width: 96px; font-size: 14px; }
.tool-attach-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; background: var(--accent-soft); border: 1px solid rgba(225,29,72,.18); font-size: 12px; }
.chip-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-size { color: var(--mute); font-size: 11px; }
.tool-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; min-height: min(58vh, 520px); }
.tool-panel { display: grid; grid-template-rows: auto 1fr; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); overflow: hidden; min-height: 320px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f8fafc; font-size: 12px; font-weight: 600; }
.panel-meta { color: var(--mute); font-weight: 400; font-size: 11px; }
.panel-actions { display: flex; gap: 6px; }
.tool-textarea { width: 100%; height: 100%; min-height: 280px; border: 0; resize: none; padding: 12px 14px; font-size: 14px; line-height: 1.6; background: transparent; font-family: var(--font); }
.tool-textarea.readonly { background: #fafbfd; color: var(--ink); font-family: var(--mono); font-size: 13px; }
.tool-progress { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 10px 12px; }
.progress-bar { height: 6px; border-radius: 999px; background: #e2e8f0; overflow: hidden; margin-bottom: 6px; }
.progress-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #fb7185, var(--accent)); transition: width .25s ease; }
.tool-progress p { margin: 0; font-size: 12px; color: var(--mute); }
.tool-steps { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 8px 10px; font-size: 12px; color: var(--mute); }
.tool-diff-host .card { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.tool-diff-host .card-h { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #f8fafc; font-size: 12px; }
.tool-diff-host .card-actions { display: flex; gap: 6px; }
.tool-diff-host .diff-grid { display: grid; grid-template-columns: 1fr 1fr; }
.tool-diff-host .diff-pane.before { background: var(--diff-before); }
.tool-diff-host .diff-pane.after { background: var(--diff-after); }
.tool-diff-host .diff-pane + .diff-pane { border-left: 1px solid var(--line); }
.tool-diff-host .diff-label { padding: 6px 8px; font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--mute); border-bottom: 1px solid var(--line); }
.tool-diff-host .diff-body { margin: 0; padding: 10px; font-family: var(--mono); font-size: 11px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; }
.tool-error { background: var(--danger-soft); border: 1px solid #fecaca; color: #991b1b; border-radius: 10px; padding: 12px; font-size: 13px; }

.site-footer { border-top: 1px solid var(--line); background: rgba(255,255,255,.7); padding: 24px 16px 32px; }
.footer-inner { width: min(880px, 100%); margin: 0 auto; }
.footer-inner h1 { margin: 0 0 8px; font-size: 20px; font-weight: 800; }
.footer-inner h2 { margin: 0 0 8px; font-size: 16px; font-weight: 700; }
.footer-inner h3 { margin: 12px 0 4px; font-size: 14px; font-weight: 600; }
.footer-inner p { margin: 0 0 8px; color: var(--ink); line-height: 1.6; }
.footer-inner a { color: var(--accent); text-decoration: none; }
.footer-inner a:hover { text-decoration: underline; }
.footer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0; }
.footer-note { color: var(--mute); font-size: 12px; margin: 0; }
.footer-links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; font-size: 12px; }
.footer-links a { color: var(--mute); text-decoration: none; }
.footer-links a:hover { color: var(--accent); text-decoration: underline; }

/* ===== Agent layout ===== */
body.layout-agent { background: var(--void); overflow: hidden; }
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; overflow: hidden; }
.sidebar { background: var(--sidebar); border-right: 1px solid var(--line); display: grid; grid-template-rows: auto 1fr auto; min-height: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 12px; border-bottom: 1px solid var(--line); }
.new-chat { width: 32px; height: 32px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); font-size: 18px; line-height: 1; }
.new-chat:hover { background: var(--accent-soft); border-color: rgba(225,29,72,.25); }
.session-list { overflow: auto; padding: 8px; display: grid; gap: 4px; align-content: start; }
.sidebar-empty { color: var(--mute); font-size: 12px; padding: 8px; margin: 0; }
.sess-item { width: 100%; text-align: left; border: 0; border-radius: 10px; padding: 10px; background: transparent; display: grid; gap: 2px; }
.sess-item:hover { background: var(--sidebar-hover); }
.sess-item.active { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.sess-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-time { font-size: 11px; color: var(--mute); }
.sidebar-foot { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.foot-btn { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--panel); font-size: 12px; }

/* Agent LLM provider — fixed in sidebar, not buried in Settings */
.provider-panel {
  margin: 0 8px 8px; padding: 10px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); display: grid; gap: 8px; align-content: start;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.6);
}
.provider-panel.highlight { border-color: rgba(225,29,72,.45); box-shadow: 0 0 0 3px var(--accent-soft); }
.provider-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.provider-head strong { font-size: 12px; }
.provider-dot { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; flex-shrink: 0; }
.provider-dot.ok { background: var(--ok); }
.provider-dot.warn { background: var(--warn); }
.provider-dot.err { background: var(--danger); }
.provider-hint { margin: 0; font-size: 11px; color: var(--mute); line-height: 1.4; }
.field.compact { gap: 3px; }
.field.compact > span { font-size: 10px; }
.field.compact input, .field.compact select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; font-size: 12px; width: 100%;
}
.provider-actions { display: flex; gap: 6px; }
.primary.compact { min-height: 30px; padding: 0 12px; font-size: 12px; flex: 1; }
.provider-out { margin: 0; padding: 6px 8px; border-radius: 8px; background: #f8fafc; border: 1px solid var(--line); font-family: var(--mono); font-size: 10px; max-height: 72px; overflow: auto; white-space: pre-wrap; }
.drawer-lead { margin: 0; font-size: 12px; color: var(--mute); line-height: 1.45; }
.main { display: grid; grid-template-rows: var(--top-h) 1fr auto; min-width: 0; min-height: 0; background: var(--void); }
.agent-topbar { position: static; padding: 0 16px; }
.top-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.model-badge { font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; padding: 4px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); }
.session-title { font-size: 13px; color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-view { overflow: hidden; min-height: 0; }
.timeline { height: 100%; overflow: auto; padding: 20px 16px; }
.timeline-inner { max-width: 780px; margin: 0 auto; display: grid; gap: 20px; }
.welcome { text-align: center; padding: 8vh 12px 24px; max-width: 520px; margin: 0 auto; }
.welcome h1 { margin: 0 0 8px; font-size: 26px; }
.welcome p { margin: 0 0 16px; color: var(--mute); }
.welcome-cards { display: grid; gap: 8px; text-align: left; }
.welcome-card { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); text-align: left; }
.welcome-card strong { display: block; margin-bottom: 2px; }
.welcome-card span { color: var(--mute); font-size: 12px; }
.msg { display: grid; gap: 8px; }
.msg.user { justify-items: end; }
.msg-bubble { max-width: min(680px, 92%); background: var(--user-bg); border: 1px solid rgba(225,29,72,.12); border-radius: 16px 16px 4px 16px; padding: 10px 14px; }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-file { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); margin-bottom: 6px; }
.msg-file strong { display: block; font-size: 13px; }
.msg-file span { font-size: 11px; color: var(--mute); }
.msg-head { display: flex; align-items: center; gap: 8px; }
.avatar { width: 24px; height: 24px; border-radius: 6px; background: linear-gradient(145deg,#fb7185,var(--accent)); color:#fff; font-size:9px; font-weight:800; display:grid; place-items:center; }
.who { font-size: 12px; font-weight: 600; }
.engine-tag { font-size: 10px; color: var(--accent-strong); background: var(--accent-soft); padding: 2px 6px; border-radius: 999px; font-weight: 700; }
.msg-body { display: grid; gap: 10px; padding-left: 32px; }
.prose { white-space: pre-wrap; word-break: break-word; }
.live-line { display: flex; gap: 8px; align-items: center; color: var(--mute); font-size: 13px; }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(225,29,72,.35)} 70%{box-shadow:0 0 0 8px rgba(225,29,72,0)} 100%{box-shadow:0 0 0 0 rgba(225,29,72,0)} }
.steps { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; overflow: hidden; }
.steps > summary { padding: 8px 10px; font-size: 12px; color: var(--mute); cursor: pointer; list-style: none; }
.steps > summary::-webkit-details-marker { display: none; }
.step-list { border-top: 1px solid var(--line); }
.step { padding: 8px 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--mute); }
.step-text { color: var(--ink); }
.pill { display: inline-block; font-size: 9px; font-weight: 700; text-transform: uppercase; border-radius: 999px; padding: 2px 6px; margin-right: 4px; border: 1px solid var(--line); }
.pill.run { color: #1d4ed8; background: #eff6ff; }
.pill.ok { color: #166534; background: #f0fdf4; }
.pill.err { color: #991b1b; background: var(--danger-soft); }
.pill.warn { color: #92400e; background: #fef3c7; }
.error-box { background: var(--danger-soft); border: 1px solid #fecaca; color: #991b1b; border-radius: 10px; padding: 12px; }
.degraded-bar { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px dashed #f59e0b; background: #fffbeb; border-radius: 8px; }
.card { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.card-h { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #f8fafc; font-size: 12px; }
.card-actions { display: flex; gap: 6px; }
.diff-grid { display: grid; grid-template-columns: 1fr 1fr; }
.diff-pane.before { background: var(--diff-before); } .diff-pane.after { background: var(--diff-after); }
.diff-pane + .diff-pane { border-left: 1px solid var(--line); }
.diff-label { padding: 6px 8px; font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--mute); border-bottom: 1px solid var(--line); }
.diff-body, .file-body { margin: 0; padding: 10px; font-family: var(--mono); font-size: 11px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow: auto; }
.composer-wrap { padding: 0 16px 14px; background: linear-gradient(180deg, transparent, var(--void) 30%); }
.composer { max-width: 780px; margin: 0 auto; border: 1px solid var(--line); background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); padding: 10px 12px; }
.composer:focus-within { border-color: rgba(225,29,72,.35); }
.composer.drag { border-color: var(--accent); background: #fff1f2; }
.attach-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
#input { width: 100%; border: 0; resize: none; background: transparent; min-height: 24px; max-height: 160px; padding: 2px 0 8px; }
.composer-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.bar-left, .bar-right { display: flex; gap: 6px; align-items: center; }
.hint { color: var(--mute); font-size: 11px; }
.fineprint { text-align: center; color: var(--mute); font-size: 11px; margin: 6px 0 0; }

.mask { position: fixed; inset: 0; background: rgba(36,48,68,.25); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(400px,100vw); background: var(--panel); border-left: 1px solid var(--line); z-index: 50; display: grid; grid-template-rows: auto 1fr auto; box-shadow: var(--shadow); }
.drawer-h, .drawer-f { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.drawer-f { border-bottom: 0; border-top: 1px solid var(--line); justify-content: flex-end; }
.drawer-h h2 { margin: 0; font-size: 15px; }
.drawer-b { overflow: auto; padding: 14px; display: grid; gap: 10px; align-content: start; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 11px; color: var(--mute); font-weight: 600; }
.field input, .field select { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.cfg-out { margin: 0; padding: 8px; border-radius: 8px; background: #f8fafc; border: 1px solid var(--line); font-family: var(--mono); font-size: 11px; max-height: 120px; overflow: auto; white-space: pre-wrap; }
.toasts { position: fixed; right: 14px; bottom: 14px; z-index: 80; display: grid; gap: 6px; }
.toast { min-width: 140px; padding: 10px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 13px; }
.toast.err { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.drop-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(255,241,245,.9); display: none; place-items: center; font-size: 20px; font-weight: 650; color: var(--accent-strong); pointer-events: none; }
body.layout-agent .composer.drag ~ .fineprint, body.layout-agent .drop-overlay { display: none; }
.mobile-only { display: none; }

@media (max-width: 900px) {
  .tool-panels { grid-template-columns: 1fr; min-height: auto; }
  .tool-panel { min-height: 240px; }
  .footer-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); z-index: 30; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .mobile-only { display: grid; }
  .session-title { display: none; }
  .msg-body { padding-left: 0; }
  .diff-grid, .tool-diff-host .diff-grid { grid-template-columns: 1fr; }
  .diff-pane + .diff-pane, .tool-diff-host .diff-pane + .diff-pane { border-left: 0; border-top: 1px solid var(--line); }
}
