:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2330;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #2557d6;
  --accent-ink: #ffffff;
  --user-bubble: #e8efff;
  --bot-bubble: #ffffff;
  --ok: #1a7f4b;
  --warn: #9a6200;
  --warn-bg: #fff6e0;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --panel: #1b2029;
    --text: #e6e9ef;
    --muted: #98a1b0;
    --line: #2c3340;
    --accent: #6d93ff;
    --accent-ink: #0d1220;
    --user-bubble: #23345e;
    --bot-bubble: #1f2531;
    --ok: #4cc38a;
    --warn: #f0b44c;
    --warn-bg: #3a2e14;
    --bad: #ff7b6e;
    --bad-bg: #3d1d1a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; margin: 0 0 12px; color: var(--muted); font-size: 13px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); font-size: 15px; }
button {
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  padding: 8px 16px;
  background: var(--accent);
  color: var(--accent-ink);
}
button:disabled { opacity: .5; cursor: not-allowed; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 0 0 12px; }
.notice { padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 24px; }
.login-card h1 { margin: 0 0 20px; font-size: 22px; }
.login-card button { width: 100%; padding: 10px; }

.app {
  --canvas: #fff;
  --rail: #f6f5f2;
  --ink: #2c2c28;
  --subtle: #686963;
  --edge: #e7e6e1;
  --selected: #e9e8e2;
  --mark: #f4e7c2;
  --mark-ink: #705316;
  --measure: 720px;
  height: 100%;
  height: 100dvh;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  .app {
    --canvas: #20211f; --rail: #191a18; --ink: #eeeee8; --subtle: #b1b2a9;
    --edge: #363732; --selected: #30312b; --mark: #493e23; --mark-ink: #f2d582;
  }
}
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.layout { display: flex; height: 100%; }
.sidebar {
  width: 252px; flex: none; display: flex; flex-direction: column; min-height: 0;
  padding: 18px 12px 10px; background: var(--rail); border-right: 1px solid var(--edge);
}
.assistant-picker { position: relative; display: flex; align-items: center; margin: 0 2px; }
.assistant-picker select {
  appearance: none; width: 100%; padding: 9px 30px 9px 45px; border: 0; background: transparent;
  font-weight: 600; font-size: 15px; cursor: pointer; text-overflow: ellipsis;
}
.assistant-picker select:hover { background: var(--selected); }
.assistant-mark, .picker-chevron { position: absolute; pointer-events: none; }
.assistant-mark { left: 5px; z-index: 1; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--mark); color: var(--mark-ink); }
.picker-chevron { right: 7px; width: 14px; color: var(--subtle); }
.conv-head, .sidebar-foot { display: flex; align-items: center; justify-content: space-between; }
.conv-head { padding: 0 3px 4px 10px; margin-top: 32px; }
.conv-head h2 { margin: 0; color: var(--subtle); font-size: 12px; font-weight: 550; }
.icon-btn, .quiet-btn {
  display: inline-flex; justify-content: center; align-items: center; gap: 7px;
  padding: 6px 9px; background: transparent; color: var(--subtle); font-size: 13px; border-radius: 7px;
}
.icon-btn { width: 34px; height: 34px; padding: 0; }
.icon-btn:hover, .quiet-btn:hover { background: var(--selected); color: var(--ink); }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv-item { display: flex; align-items: center; border-radius: 8px; margin-bottom: 2px; }
.conv-item:hover, .conv-item:focus-within { background: color-mix(in srgb, var(--rail), var(--selected) 65%); }
.conv-item:has(.active) { background: var(--selected); }
.conv-open { text-align: left; min-width: 0; flex: 1; display: flex; flex-direction: column; padding: 8px 10px; background: none; color: var(--ink); }
.conv-list .t { font-size: 14px; width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-list .d { color: var(--subtle); font-size: 11px; line-height: 1.5; }
.conv-del { background: none; color: var(--subtle); font-size: 12px; padding: 6px; margin-right: 4px; }
@media (min-width: 761px) and (hover: hover) {
  .conv-item:not(:hover):not(:focus-within) .conv-del { opacity: 0; }
}
.conv-del:hover { color: var(--bad); }
.sidebar-foot { padding: 10px 4px 0 10px; border-top: 1px solid var(--edge); font-size: 13px; color: var(--subtle); }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--canvas); }
.page-head { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 26px; border-bottom: 1px solid var(--edge); }
.page-head h1 { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-head button { flex: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--edge); padding: 0 16px; overflow-x: auto; }
.tab { background: none; color: var(--subtle); border-radius: 0; padding: 10px 12px; border-bottom: 2px solid transparent; }
.tab.active { color: var(--ink); border-bottom-color: currentColor; }
.panel { flex: 1; min-height: 0; overflow-y: auto; padding: 20px; }
.chat-panel {
  display: flex; flex-direction: column; overflow: hidden; padding: 0 clamp(14px, 4vw, 54px);
}
.chat-panel.is-empty { justify-content: center; }
.chat-panel.is-empty .messages { display: none; }
.messages, .composer-wrap { width: min(100%, var(--measure)); margin-inline: auto; }
.messages { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 26px; padding: 30px 4px 20px; }
.msg { max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.75; }
.msg.user { align-self: flex-end; max-width: 85%; background: var(--rail); padding: 10px 16px; border-radius: 17px 17px 5px 17px; }
.msg.assistant { align-self: flex-start; padding: 0 3px; }
.msg .meta { display: block; color: var(--subtle); font-size: 11px; margin-top: 5px; }
.receipt-query { margin-top: 5px; padding-inline: 0; text-decoration: underline; text-underline-offset: 3px; }
.msg.error .meta { color: var(--bad); }
.msg.streaming .meta::after { content: " …"; }
.composer-wrap { flex: none; padding: 12px 2px max(24px, env(safe-area-inset-bottom)); }
.is-empty .composer-wrap { padding-block: 0; }
.composer {
  display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; padding: 13px;
  border: 1px solid color-mix(in srgb, var(--ink) 23%, var(--canvas)); border-radius: 16px;
  box-shadow: 0 3px 10px rgb(0 0 0 / .04); background: var(--canvas);
}
.composer:focus-within { border-color: var(--subtle); }
.composer textarea { grid-column: 1 / -1; min-width: 0; resize: none; outline: 0; border: 0; background: transparent; padding: 4px 3px; line-height: 1.55; }
.composer textarea::placeholder { color: var(--subtle); }
.composer > button { flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 3px; white-space: nowrap; padding: 6px 10px; border-radius: 8px; color: var(--canvas); background: var(--ink); font-size: 13px; }
.composer .icon { width: 15px; height: 15px; }
.quick { position: relative; justify-self: start; }
#quick-toggle { display: flex; align-items: center; gap: 4px; padding: 5px 7px; font-size: 13px; color: var(--subtle); background: transparent; }
#quick-toggle span { font-size: 17px; line-height: 1; }
#quick-toggle:hover, #quick-toggle[aria-expanded="true"] { background: var(--rail); color: var(--ink); }
#quick-menu {
  position: absolute; bottom: calc(100% + 5px); left: 0; z-index: 1;
  width: 172px; padding: 5px; background: var(--canvas); border: 1px solid var(--edge);
  border-radius: 10px; box-shadow: 0 6px 22px rgb(0 0 0 / .12); overflow-y: auto;
  max-height: min(250px, 42dvh);
}
#quick-menu button { display: block; width: 100%; text-align: left; background: transparent; color: var(--ink); padding: 7px 10px; border-radius: 6px; font-size: 14px; }
#quick-menu button:is(:hover, :focus-visible) { outline: none; background: var(--selected); }
#command-dialog {
  width: min(380px, calc(100% - 32px)); padding: 22px; color: var(--ink); background: var(--canvas);
  border: 1px solid var(--edge); border-radius: 14px; box-shadow: 0 16px 60px rgb(0 0 0 / .14);
}
#command-dialog::backdrop { background: rgb(0 0 0 / .26); }
#command-title { margin: 0; font-size: 18px; }
#command-recipient { margin: 6px 0 18px; font-size: 14px; color: var(--subtle); overflow-wrap: anywhere; }
#order-input { background: var(--canvas); resize: vertical; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
#command-submit { background: var(--ink); color: var(--canvas); font-size: 14px; }
#chat-banner button { background: transparent; color: inherit; text-decoration: underline; padding: 2px 6px; }
.small-btn { padding: 4px 10px; font-size: 13px; }
.danger-btn { background: var(--bad-bg); color: var(--bad); }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; max-width: 720px; }
.card h3 { margin: 0 0 12px; font-size: 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.progress { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin: 4px 0 12px; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.steps { margin: 0; padding-left: 20px; font-size: 14px; }
.steps li { margin: 2px 0; color: var(--muted); }
.steps li.running { color: var(--accent); font-weight: 600; }
.steps li.done { color: var(--ok); }
.steps li.failed { color: var(--bad); }
.steps li.skipped { color: var(--muted); opacity: 0.7; }
.steps li.done::after { content: " ✓"; }
.steps li.failed::after { content: " ✗"; }
.steps li.skipped::after { content: " （未执行）"; }
.steps li.pending::after { content: " （待执行）"; }
.confirm { margin-top: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.confirm h4 { margin: 0 0 8px; }
.confirm ul { margin: 4px 0 10px; padding-left: 20px; font-size: 13px; word-break: break-all; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
.check input { width: auto; margin: 0; }
.card.wide { max-width: 980px; }
.table-wrap { overflow-x: auto; margin-top: 12px; }
.records { width: 100%; border-collapse: collapse; font-size: 14px; }
.records th, .records td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.records th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.records td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }
.records .sub { display: block; font-size: 12px; color: var(--muted); }
.records .err { display: block; font-size: 12px; color: var(--bad); margin-top: 2px; }
.st-success { color: var(--ok); }
.st-failed, .st-closed, .st-expired { color: var(--bad); }
.st-pending, .st-unpaid, .st-partial { color: var(--warn); }
.only-mobile, #sidebar-shade { display: none; }
@media (max-width: 760px) {
  .only-mobile { display: inline-flex; }
  .sidebar { position: fixed; z-index: 3; inset: 0 auto 0 0; width: min(280px, 82vw); visibility: hidden; }
  .sidebar.open { visibility: visible; box-shadow: 6px 0 32px rgb(0 0 0 / .1); }
  #sidebar-shade { display: block; position: fixed; inset: 0; width: 100%; z-index: 2; border-radius: 0; background: rgb(0 0 0 / .22); }
  .page-head { min-height: 56px; padding: 6px 10px; gap: 7px; }
  .page-head h1 { font-size: 15px; }
  .icon-btn, .quiet-btn, .conv-del { min-height: 44px; }
  .composer-wrap { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .composer { padding: 10px; }
  .composer textarea, #order-input { font-size: 16px; }
  #quick-menu button, #quick-toggle, .composer > button { min-height: 44px; }
}
