/* Agent 管理台。颜色、圆角、间距、动效时长都是变量；深色模式跟随系统。 */
:root {
  color-scheme: light dark;
  --bg: #fafafa; --surface: #ffffff; --surface-2: #f4f4f5; --overlay: #ffffff;
  --border: #e4e4e7; --border-strong: #d4d4d8;
  --text: #18181b; --text-2: #52525b; --text-3: #8b8b94;
  --accent: #4f46e5; --accent-hover: #4338ca; --accent-soft: #eef2ff; --accent-text: #4338ca; --on-accent: #ffffff;
  --ok: #15803d; --ok-soft: #f0fdf4; --warn: #b45309; --warn-soft: #fffbeb;
  --danger: #b91c1c; --danger-soft: #fef2f2; --info: #0369a1; --info-soft: #f0f9ff;
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .12), 0 2px 6px rgba(0, 0, 0, .06);
  --fast: .12s; --mid: .2s;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --side: 216px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c0e; --surface: #151518; --surface-2: #1d1d21; --overlay: #202025;
    --border: #2a2a30; --border-strong: #3a3a42;
    --text: #ececef; --text-2: #a4a4ae; --text-3: #7c7c86;
    --accent: #818cf8; --accent-hover: #939df9; --accent-soft: #1e1f3a; --accent-text: #a5b4fc; --on-accent: #0c0c0e;
    --ok: #4ade80; --ok-soft: #10261a; --warn: #fbbf24; --warn-soft: #2a2110;
    --danger: #f87171; --danger-soft: #2c1414; --info: #38bdf8; --info-soft: #0f2533;
    --shadow: 0 0 0 1px var(--border-strong);
  }
}

/* ---- reset ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; font-variant-numeric: tabular-nums; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 18px; font-weight: 600; } h2 { font-size: 15px; font-weight: 600; } h3 { font-size: 13px; font-weight: 600; }
a { color: var(--accent-text); text-decoration: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
input:-webkit-autofill { -webkit-box-shadow: 0 0 0 100px var(--surface) inset; -webkit-text-fill-color: var(--text); }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-2); } .dim { color: var(--text-3); } .right { text-align: right; } .nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: var(--s2); min-width: 0; } .wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.hide { display: none !important; }

/* ---- 布局 ---- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; height: 100dvh; }
.side { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: var(--s4) var(--s3); gap: var(--s1); overflow-y: auto; }
.brand { font-weight: 600; font-size: 15px; padding: var(--s2) var(--s3) var(--s4); display: flex; align-items: center; gap: var(--s2); }
.brand i { width: 18px; height: 18px; border-radius: 5px; background: var(--accent); display: inline-block; }
.nav a { display: flex; align-items: center; gap: var(--s2); padding: 7px var(--s3); border-radius: var(--r-sm); color: var(--text-2); transition: background var(--fast); }
.nav a.on { background: var(--surface-2); color: var(--text); font-weight: 500; }
.side-foot { margin-top: auto; padding: var(--s3); border-top: 1px solid var(--border); font-size: 13px; }
.main { display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.top { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s5); border-bottom: 1px solid var(--border); background: var(--surface); min-height: 56px; }
.top .menu { display: none; }
.content { flex: 1; overflow-y: auto; padding: var(--s5); container-type: inline-size; }
.content > * + * { margin-top: var(--s4); }
.tabs { display: flex; gap: var(--s1); padding: 0 var(--s5); border-bottom: 1px solid var(--border); background: var(--surface); overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 9px var(--s3); color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tabs a.on { color: var(--text); border-color: var(--accent); font-weight: 500; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(78vw, 260px); z-index: 30; transform: translateX(-102%); transition: transform var(--mid) ease; padding-top: max(var(--s4), env(safe-area-inset-top)); }
  .shell.drawer .side { transform: none; box-shadow: var(--shadow); }
  .shell.drawer::after { content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; }
  .top { padding: var(--s2) var(--s3); min-height: 48px; padding-top: max(var(--s2), env(safe-area-inset-top)); }
  .top .menu { display: inline-flex; }
  .tabs { padding: 0 var(--s2); }
  .content { padding: var(--s3); padding-bottom: max(var(--s5), env(safe-area-inset-bottom)); }
  .desk-only { display: none !important; }
  input, textarea { font-size: 16px !important; }
}

/* ---- 控件 ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 var(--s3); border-radius: var(--r-sm); border: 1px solid var(--border-strong); background: var(--surface); font-weight: 500; white-space: nowrap; transition: background var(--fast), transform var(--fast), border-color var(--fast); user-select: none; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); } .btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.sm { height: 26px; padding: 0 var(--s2); font-size: 12.5px; }
.btn.icon { width: 32px; padding: 0; } .btn.icon.sm { width: 26px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--text-3); border-top-color: transparent; animation: spin .7s linear infinite; }
.btn.primary.busy::after { border-color: var(--on-accent); border-top-color: transparent; }
@media (hover: hover) {
  .btn:hover:not([disabled]) { background: var(--surface-2); } .btn.primary:hover:not([disabled]) { background: var(--accent-hover); border-color: var(--accent-hover); }
  .btn.danger.solid:hover:not([disabled]) { filter: brightness(.92); background: var(--danger); }
  .nav a:hover, .tabs a:hover { color: var(--text); } .nav a:hover { background: var(--surface-2); }
  tr.click:hover td { background: var(--surface-2); }
}
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); } .field .err { font-size: 12px; color: var(--danger); }
.input, textarea.input { width: 100%; min-height: 32px; padding: 5px 10px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); transition: border-color var(--fast), box-shadow var(--fast); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--text-3); } .input[readonly] { background: var(--surface-2); color: var(--text-2); }
.input.bad { border-color: var(--danger); }
textarea.input { resize: vertical; line-height: 1.5; min-height: 72px; }
textarea.code { font-family: var(--mono); font-size: 12.5px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s3) var(--s4); }
.seg { display: inline-flex; padding: 2px; background: var(--surface-2); border-radius: var(--r-sm); border: 1px solid var(--border); }
.seg button { height: 26px; padding: 0 var(--s3); border-radius: 4px; color: var(--text-2); transition: background var(--fast); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: 0 0 0 1px var(--border-strong); }
.seg button[disabled] { cursor: not-allowed; opacity: .6; }
.switch { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i { width: 34px; height: 20px; border-radius: 10px; background: var(--border-strong); position: relative; transition: background var(--fast); flex: none; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform var(--fast); }
.switch input:checked + i { background: var(--accent); } .switch input:checked + i::after { transform: translateX(14px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.check { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; user-select: none; padding: 3px 0; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check i { width: 16px; height: 16px; border-radius: 4px; border: 1px solid var(--border-strong); background: var(--surface); flex: none; display: grid; place-items: center; transition: background var(--fast); }
.check input:checked + i { background: var(--accent); border-color: var(--accent); }
.check input:checked + i::after { content: ""; width: 8px; height: 4px; border: 2px solid var(--on-accent); border-top: 0; border-right: 0; transform: rotate(-45deg) translateY(-1px); }
.check input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- 卡片、徽标、表格 ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); min-width: 0; }
.card > .head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); min-height: 26px; }
.card.flush { padding: 0; overflow: hidden; } .card.flush > .head { padding: var(--s3) var(--s4); margin: 0; border-bottom: 1px solid var(--border); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s3) var(--s4); min-width: 0; }
.tile .k { font-size: 12.5px; color: var(--text-2); } .tile .v { font-size: 20px; font-weight: 600; margin: 2px 0; } .tile .d { font-size: 12.5px; color: var(--text-3); }
.badge { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: 10px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.plain::before { display: none; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); } .badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.callout { border: 1px solid var(--border); border-left: 3px solid var(--text-3); border-radius: var(--r-sm); padding: var(--s2) var(--s3); background: var(--surface); font-size: 13px; overflow-wrap: anywhere; }
.callout.warn { border-left-color: var(--warn); background: var(--warn-soft); } .callout.danger { border-left-color: var(--danger); background: var(--danger-soft); }
.callout.info { border-left-color: var(--info); background: var(--info-soft); }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width var(--mid); }
.bar.hot > i { background: var(--warn); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--text-3); padding: 8px var(--s3); border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
td { padding: 9px var(--s3); border-bottom: 1px solid var(--border); vertical-align: middle; max-width: 420px; }
tr:last-child td { border-bottom: 0; } tr.click { cursor: pointer; } td.num, th.num { text-align: right; }
td .sub { font-size: 12px; color: var(--text-3); }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.tbl { overflow-x: auto; }
@container (max-width: 860px) { .c3 { display: none; } }
@container (max-width: 640px) {
  .c2 { display: none; }
  .tbl.cards thead { display: none; }
  .tbl.cards tr { display: grid; grid-template-columns: 1fr auto; gap: 2px var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
  .tbl.cards tr:last-child { border-bottom: 0; }
  .tbl.cards td { border: 0; padding: 0; max-width: none; min-width: 0; }
  .tbl.cards td.full { grid-column: 1 / -1; }
  .tbl.cards td.num { text-align: left; }
  .tbl.cards td.lbl::before { content: attr(data-label) "  "; color: var(--text-3); font-size: 12px; }
  .tbl.cards td.lbl > * { display: inline-block; vertical-align: top; }
}
.empty { padding: var(--s6) var(--s4); text-align: center; color: var(--text-3); }
.empty .btn { margin-top: var(--s3); }
.skel { border-radius: var(--r-sm); background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s linear infinite; min-height: 16px; }
@keyframes sk { to { background-position: -200% 0; } }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px var(--s4); font-size: 13px; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 11px; border: 1px solid var(--border); font-size: 12px; color: var(--text-2); background: var(--surface); }
.chip button { color: var(--text-3); font-size: 14px; line-height: 1; padding: 0 2px; }
.copy { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
.copy code { font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fresh { animation: fresh 1.2s ease-out; } @keyframes fresh { from { background: var(--accent-soft); } }

/* ---- 上下文 ---- */
.ctx { display: flex; flex-direction: column; gap: var(--s3); }
.ctx-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.ctx-item > .meta { display: flex; align-items: center; gap: var(--s2); padding: 7px var(--s3); border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text-3); background: var(--surface-2); }
.blk { padding: var(--s2) var(--s3); border-bottom: 1px dashed var(--border); font-size: 13px; }
.blk:last-child { border-bottom: 0; }
.blk pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: inherit; max-height: 320px; overflow: auto; }
.blk.open pre { max-height: none; }
.blk pre.code { font-family: var(--mono); font-size: 12.5px; }
.blk .tag { font-size: 11.5px; color: var(--text-3); margin-bottom: 2px; display: flex; gap: var(--s2); align-items: center; }
.blk.thinking { color: var(--text-2); background: var(--surface-2); } .blk.err pre { color: var(--danger); }

/* ---- 浮层 ---- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; display: grid; place-items: center; padding: var(--s4); animation: fade var(--mid); }
.dialog { background: var(--overlay); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); width: min(560px, 100%); max-height: min(86dvh, 900px); display: flex; flex-direction: column; animation: pop var(--mid) ease-out; }
.dialog.wide { width: min(760px, 100%); }
.dialog > header { padding: var(--s4); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: var(--s2); }
.dialog > .body { padding: var(--s4); overflow-y: auto; display: flex; flex-direction: column; gap: var(--s3); }
.dialog > footer { padding: var(--s3) var(--s4); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--s2); }
@media (max-width: 760px) {
  .scrim { place-items: end center; padding: 0; }
  .dialog, .dialog.wide { width: 100%; max-height: 92dvh; border-radius: var(--r-lg) var(--r-lg) 0 0; animation: sheet var(--mid) ease-out; padding-bottom: env(safe-area-inset-bottom); }
}
@keyframes fade { from { opacity: 0; } } @keyframes pop { from { opacity: 0; transform: scale(.97); } } @keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
.menu-pop { position: fixed; z-index: 60; min-width: 168px; background: var(--overlay); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow); padding: 4px; animation: pop var(--fast) ease-out; }
.menu-pop button { display: flex; width: 100%; padding: 7px 10px; border-radius: 4px; text-align: left; }
.menu-pop button.danger { color: var(--danger); }
@media (hover: hover) { .menu-pop button:hover { background: var(--surface-2); } }
#toasts { position: fixed; right: var(--s4); bottom: max(var(--s4), env(safe-area-inset-bottom)); z-index: 80; display: flex; flex-direction: column; gap: var(--s2); align-items: flex-end; pointer-events: none; }
.toast { pointer-events: auto; background: var(--overlay); border: 1px solid var(--border); border-left: 3px solid var(--ok); border-radius: var(--r-md); box-shadow: var(--shadow); padding: var(--s2) var(--s3); max-width: min(420px, 92vw); animation: sheet var(--mid) ease-out; overflow-wrap: anywhere; }
.toast.error { border-left-color: var(--danger); }

/* ---- 登录 ---- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s4); }
.login .card { width: min(360px, 100%); padding: var(--s5); display: flex; flex-direction: column; gap: var(--s4); }
.login input { text-align: center; font-size: 22px !important; letter-spacing: .35em; height: 48px; font-family: var(--mono); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01s !important; transition-duration: .01s !important; } .btn:active { transform: none; } }
