:root {
  --bg: #0f1420;
  --panel: #161c2c;
  --panel-2: #1d2538;
  --border: #2a3450;
  --text: #e6ebf5;
  --muted: #8a97b3;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --zh: #f59e0b;
  --en: #93c5fd;
  --ok: #22c55e;
  --err: #ef4444;
  --shadow: 0 4px 18px rgba(0,0,0,.35);
  --topbar-h: 56px;
  --composer-h: 116px;
  --rail-left-w: 268px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.55;
  display: flex; flex-direction: column; overflow: hidden; /* workspace fills viewport */
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: .8em; }
.hidden { display: none !important; }

/* Topbar */
.topbar {
  flex: 0 0 var(--topbar-h);
  display: flex; align-items: center; gap: 24px; padding: 0 22px;
  background: linear-gradient(180deg, #131a2b, #11162400);
  border-bottom: 1px solid var(--border); position: relative; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px; color: #fff;
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.topbar-stats { color: var(--muted); font-size: 12px; }
.lang-toggle { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.lang-toggle select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 5px 8px; border-radius: 6px;
}

/* ===== 2-PANE WORKSPACE SHELL ===== */
.app-shell {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: var(--rail-left-w) 1fr;
}
.rail, .center { min-height: 0; height: 100%; overflow: hidden; display: flex; flex-direction: column; }
.rail { padding: 14px; }
.rail-left { border-right: 1px solid var(--border); }
.center { padding: 16px 22px; overflow-y: auto; } /* center scrolls independently */

.rail-section { margin-bottom: 14px; }
.rail-browse { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.rail-label { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }

/* Left-rail inputs */
.rail-left input {
  width: 100%; padding: 9px 11px; font-size: 14px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
}
#tcodeBox { font-family: monospace; }
.rail-left input:focus { outline: none; border-color: var(--accent); }
.tcode-tags { margin-top: 6px; }
#treeFilter { margin-bottom: 8px; font-size: 13px; }

/* Browse tree */
.domain-tree { font-size: 13px; overflow-y: auto; flex: 1 1 auto; min-height: 0; padding-right: 2px; }
.dom-block { margin-bottom: 10px; }
.dom-head { font-weight: 700; padding: 3px 0; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-size: 13px; }
.dom-head .count { color: var(--muted); font-weight: 400; font-size: 11px; }
.mod-link { display: block; padding: 4px 7px; border-radius: 6px; color: var(--text); font-size: 12.5px; }
.mod-link:hover { background: var(--panel-2); text-decoration: none; }
.mod-link .tr { float: right; font-size: 10px; color: var(--ok); }
.mod-link .tr.partial { color: var(--zh); }

/* Center: home + welcome */
.center-head h1 { font-size: 20px; margin: 0 0 8px; }
.center-head h1 .muted { font-size: 13px; font-weight: 400; }
.home-hint {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px;
  margin-bottom: 14px; font-size: 13.5px;
}
.home-hint .hint-side { color: var(--accent-2); font-weight: 600; }
.home-hint ul { margin: 8px 0; padding-left: 18px; }
.home-hint li { margin: 4px 0; }

.search-results, .tcode-results { margin-bottom: 14px; }

.search-result {
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px;
  background: var(--panel); cursor: pointer; transition: border-color .15s;
}
.search-result:hover { border-color: var(--accent); }
.sr-title { font-weight: 600; }
.sr-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.sr-snip { font-size: 13px; color: #c3cbe0; margin-top: 5px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
mark { background: rgba(59,130,246,.28); color: #fff; border-radius: 2px; padding: 0 2px; }

/* T-Code cards */
.tcode-head { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.tcode-card {
  display: block; padding: 8px 12px; margin: 4px 0; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--border); font-size: 13px; cursor: pointer;
}
.tcode-card:hover { border-color: var(--accent); }
.tcode-card .mod { color: var(--muted); }
.tcode-card .ctx { display: block; color: #c3cbe0; font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcode-empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
.tcode-tag {
  display: inline-block; padding: 1px 7px; margin: 2px; border-radius: 4px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--border); cursor: pointer; font-family: monospace;
}
.tcode-tag:hover { border-color: var(--accent); color: var(--accent-2); }
.live-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 8px 0 12px; }
.live-title { font-size: 14px; color: var(--text); margin-bottom: 4px; }
.live-meta { font-size: 12px; margin-bottom: 8px; }
.live-btns { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.live-btn { font-size: 11px; padding: 2px 7px; border-radius: 4px; background: rgba(59,130,246,.14); border: 1px solid rgba(59,130,246,.3); color: var(--accent-2); font-family: monospace; }
.live-shot { max-width: 100%; max-height: 420px; border-radius: 6px; border: 1px solid var(--border); cursor: zoom-in; display: block; }
.live-shot.zoomed { max-height: none; cursor: zoom-out; position: fixed; inset: 60px; z-index: 80; object-fit: contain; background: rgba(0,0,0,.9); border-radius: 8px; }

/* ===== AI thread (in center) ===== */
.ai-thread { margin-top: 6px; }
.thread-label { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .04em; }
.chat-log { background: transparent; border-radius: 8px; padding: 4px 2px; }
.chat-hint { color: var(--muted); font-size: 13px; padding: 10px 12px; background: var(--panel); border: 1px dashed var(--border); border-radius: 8px; }
.msg { margin-bottom: 14px; }
.msg.user { text-align: right; }
.msg .bubble { display: inline-block; padding: 10px 14px; border-radius: 12px; max-width: 88%; text-align: left; white-space: pre-wrap; font-size: 14px; }
.msg.user .bubble { background: var(--accent); color: #fff; }
.msg.ai .bubble { background: var(--panel); border: 1px solid var(--border); max-width: 96%; }
.msg .refs { font-size: 12px; margin-top: 8px; color: var(--muted); }
.msg .refs a, .msg .refs .ref-live { display: inline-block; margin: 2px 8px 2px 0; }

/* Figure gallery (图解) attached to AI answers */
.fig-gallery { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.fig-thumb { margin: 0; width: 200px; max-width: 100%; }
.fig-thumb img { width: 100%; height: 130px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); cursor: zoom-in; display: block; }
.fig-thumb img.zoomed { height: auto; cursor: zoom-out; position: fixed; inset: 60px; z-index: 80; object-fit: contain; width: auto; max-width: 90vw; background: rgba(0,0,0,.9); border-radius: 8px; }
.fig-thumb figcaption { font-size: 11px; margin-top: 4px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ===== PERSISTENT BOTTOM COMPOSER BAR ===== */
.composer-bar {
  flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px;
  padding: 8px 18px 10px; border-top: 1px solid var(--border);
  background: linear-gradient(180deg, #11162400, #0c111c);
}
.img-preview { display: flex; align-items: center; gap: 6px; min-height: 0; }
.img-preview:empty { display: none; }
.img-preview img { max-height: 56px; border-radius: 6px; border: 1px solid var(--border); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#chatInput {
  flex: 1 1 auto; resize: none; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-family: inherit; font-size: 14px;
  min-height: 44px; max-height: 120px; overflow-y: auto;
}
#chatInput:focus { outline: none; border-color: var(--accent); }
.composer-actions { flex: 0 0 auto; display: flex; gap: 8px; align-items: center; }
.btn-file, .btn-primary { cursor: pointer; border: none; border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.btn-file { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:disabled { opacity: .5; cursor: wait; }
.ai-status { font-size: 12px; color: var(--muted); min-height: 14px; }
.ai-status.err { color: var(--err); }

/* ===== Detail (inside center) ===== */
.detail-layout { display: grid; grid-template-columns: 200px 1fr; gap: 14px; min-height: 100%; }
.detail-nav {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px;
  position: sticky; top: 0; align-self: start; max-height: calc(100vh - var(--topbar-h) - var(--composer-h) - 28px); overflow-y: auto;
}
.detail-nav a { display: block; padding: 4px 6px; border-radius: 5px; font-size: 12.5px; color: #c3cbe0; }
.detail-nav a:hover { background: var(--panel-2); }
.detail-nav a.l2 { padding-left: 16px; }
.detail-nav a.l3 { padding-left: 26px; }
.detail-nav a.active { background: var(--accent); color: #fff; }
.breadcrumb { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.detail-main { min-width: 0; }
.section {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 18px; margin-bottom: 12px; scroll-margin-top: 12px;
}
.section h2, .section h3, .section h4 { margin: 4px 0 10px; }
.sec-title .zh { color: var(--zh); }
.sec-title .en { color: var(--en); }
.para { margin: 8px 0; }
.para.bilingual { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.para .en { color: #cdd6ee; }
.para .zh { color: #f3d68a; }
.para.zh-only .zh, .para.en-only .en { display: block; }
.list { margin: 6px 0 6px 18px; }
.list li { margin: 3px 0; }
table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 13px; }
table th, table td { border: 1px solid var(--border); padding: 5px 8px; vertical-align: top; }
table th, table td { color: var(--text) !important; background: var(--panel) !important; }
table td * { color: inherit !important; }
table th { background: var(--panel-2) !important; color: var(--text) !important; }
table td a, table th a { color: var(--accent-2) !important; }
table td[style*="background"], table th[style*="background"] { background: var(--panel) !important; }
table th[style*="background"] { background: var(--panel-2) !important; }
.imgs img { max-width: 100%; border-radius: 6px; margin: 6px 0; border: 1px solid var(--border); }
.badge { display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); color: var(--muted); margin-left: 6px; }
.badge.tr { color: var(--ok); }

/* Operation Flows */
.flow-summary { padding: 8px 12px; border-left: 3px solid var(--accent); margin: 8px 0 16px; line-height: 1.5; }
.flow-step { border: 1px solid var(--panel-2); border-radius: 8px; padding: 14px 18px; margin-bottom: 18px; background: var(--panel); }
.flow-step h2.sec-title { font-size: 1.05rem; margin-top: 0; }
.flow-fields { width: 100%; border-collapse: collapse; margin: 6px 0 10px; font-size: 0.9rem; }
.flow-fields th, .flow-fields td { border: 1px solid var(--panel-2); padding: 5px 8px; text-align: left; vertical-align: top; }
.flow-fields th { background: var(--panel-2) !important; color: var(--text) !important; }

.toast {
  position: fixed; bottom: 130px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); padding: 10px 18px; border-radius: 8px;
  box-shadow: var(--shadow); z-index: 70;
}

/* Responsive */
@media (max-width: 900px) {
  html, body { height: auto; overflow: auto; }
  body { display: block; }
  .app-shell { display: flex; flex-direction: column; height: auto; }
  .rail, .center { height: auto; overflow: visible; }
  .rail-left { border: none; border-bottom: 1px solid var(--border); }
  .rail-browse { flex: none; }
  .domain-tree { overflow: visible; max-height: 240px; }
  .composer-bar { position: sticky; bottom: 0; }
  .detail-layout { grid-template-columns: 1fr; }
  .detail-nav { position: static; max-height: none; margin-bottom: 10px; }
  .para.bilingual { grid-template-columns: 1fr; }
}
