:root {
  /* brand-wheat-v3 · light */
  --bg: #f6f3ed;
  --bg-2: #efe9dd;
  --panel: #ffffff;
  --raised: #eee8de;
  --ink: #201c18;
  --ink-2: #6c5f52;
  --ink-3: #9b8d7d;
  --line: #d6c9b9;
  --line-2: #e9e0d3;
  --primary: #bd2824;
  --primary-2: #d93a32;
  --primary-soft: #fbeeea;
  --gold: #805016;
  --gold-2: #b07a2c;
  --gold-soft: #f8eeda;
  --green: #176b49;
  --green-soft: #e9f3ee;
  --red: #b42318;
  --red-soft: #fbecea;
  --blue: #1d4ed8;
  --blue-soft: #eef2ff;
  --sidebar: #111110;
  --sidebar-2: #1c1a18;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(32, 28, 24, .04), 0 2px 6px rgba(32, 28, 24, .04);
  --shadow-lg: 0 18px 48px rgba(17, 17, 16, .22);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cdbfae; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
.serif { font-family: "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, serif; }

/* ---------------- login ---------------- */
.login-wrap { display: grid; grid-template-columns: 1.08fr .92fr; min-height: 100vh; background: var(--bg); }
.login-brand {
  position: relative; overflow: hidden; padding: 48px 56px; color: #fff9ef;
  background: radial-gradient(900px 520px at 12% 4%, #2a2520 0%, #141311 52%, #0b0b0a 100%);
  display: flex; flex-direction: column; justify-content: space-between;
}
.login-brand::before {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255, 203, 131, .07) 1px, transparent 1px);
  background-size: 22px 22px; opacity: .7; pointer-events: none;
}
.login-brand::after {
  content: ""; position: absolute; width: 760px; height: 760px; right: -300px; bottom: -380px;
  background: radial-gradient(circle, rgba(240, 68, 56, .30), transparent 60%);
  pointer-events: none;
}
.brand-mark { display: flex; align-items: center; gap: 12px; font-weight: 700; letter-spacing: .2px; position: relative; z-index: 1; }
.brand-mark img { width: 40px; height: 40px; filter: drop-shadow(0 6px 16px rgba(240,68,56,.35)); }
.wordmark { display: flex; align-items: center; gap: 8px; font-size: 20px; }
.wordmark b { font-weight: 800; letter-spacing: .5px; }
.wordmark span.pill { background: linear-gradient(135deg, #f04438, #bd2824); color: #fff; font-size: 11px; letter-spacing: .6px; padding: 3px 9px; border-radius: 999px; font-weight: 600; text-transform: lowercase; }
.login-hero { position: relative; z-index: 1; max-width: 560px; }
.login-hero .eyebrow { display: inline-flex; align-items: center; gap: 8px; font-size: 11px; letter-spacing: 2px; color: #ffcb83; text-transform: uppercase; margin-bottom: 18px; }
.login-hero .eyebrow i { width: 26px; height: 1px; background: #805016; display: inline-block; }
.login-hero h1 { font-family: "Songti SC", "Noto Serif SC", Georgia, serif; font-size: 46px; line-height: 1.18; margin: 0 0 18px; font-weight: 700; letter-spacing: -.4px; }
.login-hero h1 em { font-style: normal; background: linear-gradient(120deg, #ffcb83, #f04438 82%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-hero p { color: #c9bdae; max-width: 470px; margin: 0 0 26px; font-size: 14.5px; }
.brand-chips { display: flex; gap: 10px; flex-wrap: wrap; }
.brand-chips span { border: 1px solid rgba(255, 203, 131, .22); padding: 6px 12px; border-radius: 999px; font-size: 12px; color: #ecd9bd; background: rgba(255,255,255,.02); }
.brand-foot { color: #8a7d6e; font-size: 12px; position: relative; z-index: 1; display: flex; align-items: center; gap: 10px; }
.brand-foot .seal { width: 26px; height: 26px; border-radius: 50%; border: 1px solid rgba(255,203,131,.3); display: grid; place-items: center; color: #ffcb83; font-size: 12px; }

.login-panel { display: flex; align-items: center; justify-content: center; padding: 40px; background: #fffdf9; position: relative; }
.login-panel::before { content: ""; position: absolute; inset: 22px; border: 1px solid #ede3d4; border-radius: 20px; pointer-events: none; }
.login-card { width: 384px; position: relative; }
.login-card .kicker { font-size: 11px; letter-spacing: 2.4px; color: var(--gold); text-transform: uppercase; margin-bottom: 12px; }
.login-card h2 { font-family: "Songti SC", "Noto Serif SC", Georgia, serif; font-size: 30px; margin: 0 0 8px; letter-spacing: -.3px; }
.login-card .muted { margin: 0 0 28px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; letter-spacing: .2px; }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 12px;
  background: #fff; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:hover, .select:hover, .textarea:hover { border-color: #c6b6a3; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(189, 40, 36, .10); }
.textarea { min-height: 110px; resize: vertical; line-height: 1.65; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; border-radius: var(--radius-sm); padding: 9px 15px;
  cursor: pointer; transition: .16s; white-space: nowrap; color: var(--ink);
}
.btn:hover { border-color: #c6b6a3; background: #fdfaf5; }
.btn.primary { background: linear-gradient(180deg, #c92f2a, #bd2824); border-color: #a9211e; color: #fff; box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 6px 14px rgba(189,40,36,.18); }
.btn.primary:hover { background: linear-gradient(180deg, #d33a34, #b0211d); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn.danger { color: var(--red); border-color: #eec9c5; background: var(--red-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; letter-spacing: 1px; }
.login-hint { margin-top: 18px; font-size: 12px; color: var(--ink-3); line-height: 1.7; }
.login-hint code { background: var(--raised); padding: 2px 6px; border-radius: 5px; color: var(--ink-2); }

/* ---------------- shell ---------------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: #cbbfae; padding: 20px 12px 10px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow: hidden; }
.sidebar-nav { flex: 1; overflow: auto; margin: 0 -4px; padding: 0 4px 6px; }
.sidebar .logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; color: #fff9ef; }
.sidebar .logo img { width: 34px; height: 34px; filter: drop-shadow(0 4px 12px rgba(240,68,56,.28)); }
.sidebar .logo b { font-size: 15px; letter-spacing: .3px; display: block; line-height: 1.2; }
.sidebar .logo small { display: block; font-weight: 400; font-size: 9px; color: #8a7d6e; letter-spacing: 1.7px; margin-top: 2px; }
.nav-group { margin-top: 14px; }
.nav-group h4 { font-size: 10px; color: #6f6458; font-weight: 500; padding: 0 10px; margin: 0 0 6px; letter-spacing: 1.6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
  color: #b3a695; cursor: pointer; font-size: 13.5px; transition: .16s; position: relative;
}
.nav-item svg { opacity: .85; }
.nav-item:hover { background: var(--sidebar-2); color: #fff3e2; }
.nav-item.active { background: linear-gradient(90deg, rgba(240,68,56,.16), rgba(240,68,56,.04)); color: #fff9ef; }
.nav-item.active::before { content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: #f04438; }
.nav-item.active svg { opacity: 1; color: #ffcb83; }
.nav-item .dot { width: 5px; height: 5px; border-radius: 50%; background: #3a352f; margin-left: auto; }
.nav-item.active .dot { background: #f04438; }
.sidebar-foot { margin-top: auto; font-size: 10.5px; color: #6f6458; padding: 12px 10px 4px; line-height: 1.7; border-top: 1px solid #241f1b; }
.sidebar-foot b { color: #b3a695; font-weight: 500; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; background: rgba(255, 253, 249, .88); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 22px; position: sticky; top: 0; z-index: 20;
}
.crumb { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 13px; }
.crumb b { color: var(--ink); font-weight: 650; }
.topbar .spacer { flex: 1; }
.search-box { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; color: var(--ink-3); width: 250px; background: #fff; }
.search-box input { border: 0; outline: 0; background: transparent; width: 100%; font-size: 13px; }
.search-box kbd { font-size: 10px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; color: var(--ink-3); }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 5px 12px 5px 5px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg, #d93a32, #7c1d1a); color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 600; }

.tabsbar { display: flex; align-items: center; gap: 6px; padding: 9px 18px 0; background: transparent; border-bottom: 1px solid var(--line); overflow: auto; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 13px; border: 1px solid transparent;
  border-radius: 10px 10px 0 0; background: transparent; color: var(--ink-2); font-size: 13px; cursor: pointer; white-space: nowrap;
}
.tab:hover { background: rgba(255,255,255,.6); }
.tab.active { background: #fff; color: var(--ink); font-weight: 650; border-color: var(--line); border-bottom-color: #fff; margin-bottom: -1px; }
.tab .x { color: var(--ink-3); border: 0; background: transparent; cursor: pointer; padding: 0 2px; border-radius: 4px; font-size: 12px; }
.tab .x:hover { background: var(--primary-soft); color: var(--primary); }

.content { padding: 22px; flex: 1; min-width: 0; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-family: "Songti SC", "Noto Serif SC", Georgia, serif; font-size: 24px; letter-spacing: -.2px; }
.page-head p { margin: 0; color: var(--ink-3); font-size: 12.5px; }
.page-head .spacer { flex: 1; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--line-2); }
.card-head h3 { margin: 0; font-size: 15px; letter-spacing: -.1px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; right: -30px; top: -30px; width: 90px; height: 90px; border-radius: 50%; background: radial-gradient(circle, rgba(240,68,56,.08), transparent 70%); }
.stat label { color: var(--ink-3); font-size: 12px; letter-spacing: .2px; }
.stat b { display: block; font-size: 28px; letter-spacing: -.8px; margin: 6px 0 2px; font-variant-numeric: tabular-nums; font-family: ui-monospace, "SFMono-Regular", Menlo, serif; }
.stat small { color: var(--ink-3); font-size: 12px; }
.stat .accent { color: var(--primary); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar .input, .toolbar .select { width: auto; min-width: 150px; padding: 8px 10px; }

.table-wrap { overflow: auto; border-radius: var(--radius-sm); border: 1px solid var(--line); background: #fff; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
thead th {
  text-align: left; font-weight: 600; color: var(--ink-2); background: #faf6ef;
  padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; z-index: 2;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tbody tr:hover td { background: #fdfaf5; }
tbody tr:last-child td { border-bottom: 0; }
.table-empty { padding: 46px; text-align: center; color: var(--ink-3); }
.pager { display: flex; align-items: center; gap: 10px; padding: 12px 14px; color: var(--ink-3); font-size: 12px; }
.pager .spacer { flex: 1; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; line-height: 18px; background: var(--raised); color: var(--ink-2); white-space: nowrap; }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.amber { background: var(--gold-soft); color: var(--gold); }
.tag.blue { background: var(--blue-soft); color: var(--blue); }
.tag.gray { background: #f1ede5; color: #7c7063; }

.switch { width: 38px; height: 21px; border-radius: 999px; background: #d8ccbc; border: 0; position: relative; cursor: pointer; transition: .18s; flex: none; }
.switch::after { content: ""; position: absolute; width: 17px; height: 17px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: .18s; box-shadow: 0 1px 2px rgba(0,0,0,.18); }
.switch.on { background: var(--green); }
.switch.on::after { left: 19px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: #f6f1e8; color: var(--ink-2); font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

/* ---------------- drawer / modal ---------------- */
.overlay { position: fixed; inset: 0; background: rgba(17,17,16,.42); z-index: 60; display: flex; justify-content: flex-end; animation: fade .16s ease; backdrop-filter: blur(2px); }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.drawer { width: 660px; max-width: 94vw; background: #fffdf9; height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slide .2s ease; }
@keyframes slide { from { transform: translateX(24px); opacity: .6 } to { transform: none; opacity: 1 } }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 17px 20px; border-bottom: 1px solid var(--line); background: #fff; }
.drawer-head h3 { margin: 0; font-size: 16px; }
.drawer-head .spacer { flex: 1; }
.drawer-body { padding: 20px; overflow: auto; flex: 1; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; background: #fff; }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--ink-3); font-size: 18px; line-height: 1; padding: 4px; border-radius: 6px; }
.icon-btn:hover { background: var(--raised); color: var(--ink); }

/* ---------------- chat ---------------- */
.simulate { display: grid; grid-template-columns: 306px 1fr; gap: 16px; height: calc(100vh - 214px); min-height: 520px; }
.sim-side { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; overflow: auto; box-shadow: var(--shadow); }
.sim-side h3 { margin: 0 0 4px; font-size: 15px; }
.sim-side .hint { color: var(--ink-3); font-size: 12px; margin-bottom: 16px; }
.sim-main { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 13px 18px; border-bottom: 1px solid var(--line-2); background: #fdfaf5; }
.chat-head .spacer { flex: 1; }
.chat-body { flex: 1; overflow: auto; padding: 20px; background: linear-gradient(180deg, #fdfbf7, #f7f2e9); }
.msg { display: flex; gap: 10px; margin-bottom: 16px; }
.msg .bubble { max-width: 78%; padding: 11px 14px; border-radius: 14px; background: #fff; border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(32,28,24,.04); }
.msg.bot .bubble { border-top-left-radius: 4px; }
.msg.user { flex-direction: row-reverse; }
.msg.user .bubble { background: #fff3ec; border-color: #f2cdbc; border-top-right-radius: 4px; }
.msg.system { justify-content: center; }
.msg.system .bubble { background: var(--raised); border-style: dashed; color: var(--ink-2); font-size: 12.5px; max-width: 92%; }
.bubble .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 9px; font-size: 11px; color: var(--ink-3); align-items: center; }
.bubble .meta .link { color: var(--primary); cursor: pointer; font-weight: 600; }
.chat-input { border-top: 1px solid var(--line); padding: 12px 14px; display: flex; gap: 10px; align-items: flex-end; background: #fff; }
.chat-input textarea { flex: 1; min-height: 44px; max-height: 120px; resize: none; }
.chat-empty { color: var(--ink-3); text-align: center; padding: 46px 20px; font-size: 13px; }

/* ---------------- trace ---------------- */
.trace-summary { display: flex; gap: 18px; padding: 13px 15px; background: #faf6ef; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.trace-summary b { color: var(--ink); }
.timeline { display: flex; flex-direction: column; gap: 0; }
.step { display: grid; grid-template-columns: 118px 1fr; gap: 12px; padding: 11px 0; border-bottom: 1px dashed var(--line-2); }
.step:last-child { border-bottom: 0; }
.step .theme { color: var(--ink-2); font-size: 12px; font-weight: 650; display: flex; gap: 6px; align-items: baseline; }
.step .theme i { width: 6px; height: 6px; border-radius: 50%; background: var(--gold-2); display: inline-block; flex: none; }
.step .body { font-size: 12.5px; color: var(--ink); }
.step .body .sub { color: var(--ink-3); font-size: 11.5px; margin-top: 5px; display: flex; gap: 10px; flex-wrap: wrap; }
.step .body .sub .m { color: var(--blue); }
.step.human .theme i, .step.fail .theme i { background: var(--primary); }

/* ---------------- misc ---------------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.section-title { font-size: 13px; font-weight: 650; margin: 0 0 10px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.section-title::before { content: ""; width: 3px; height: 13px; border-radius: 2px; background: var(--primary); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 44px; gap: 10px; align-items: center; margin-bottom: 9px; font-size: 12.5px; }
.bar { height: 8px; border-radius: 999px; background: #f1eadd; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #d93a32, #7c1d1a); border-radius: 999px; }
.empty { padding: 34px; text-align: center; color: var(--ink-3); font-size: 13px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; }
.warn-box { background: var(--gold-soft); border: 1px solid #e8cf9f; color: #6b4210; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 12.5px; }
.ok-box { background: var(--green-soft); border: 1px solid #b7d9c8; color: #0f5239; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 12.5px; }
.code-box { background: #141311; color: #e6dccb; padding: 15px; border-radius: var(--radius-sm); font-family: ui-monospace, Consolas, monospace; font-size: 12px; overflow: auto; line-height: 1.75; white-space: pre-wrap; }
.dot-live { width: 7px; height: 7px; border-radius: 50%; background: var(--green); display: inline-block; box-shadow: 0 0 0 3px rgba(23,107,73,.12); }
.spin { width: 14px; height: 14px; border: 2px solid #e7ddcd; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg) } }

@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .simulate { grid-template-columns: 260px 1fr; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .simulate { grid-template-columns: 1fr; height: auto; }
}
