/* ============================================================
   Agent 轨迹可视化 — design tokens
   Dark is the default (:root). Light overrides live in
   [data-theme="light"]. Accent is a soft indigo.
   ============================================================ */
:root {
  /* surfaces (soft charcoal — deliberately lifted off pure black) */
  --bg: #1a1e25;
  --panel: #21262f;
  --panel-2: #282d38;
  --panel-3: #313745;
  --border: #353c49;
  --border-strong: #434b5b;

  /* text */
  --text: #d8dde6;
  --muted: #939bac;
  --faint: #6a7282;

  /* accent (soft indigo) */
  --accent: #818cf8;
  --accent-hover: #99a2fb;
  --accent-weak: rgba(129, 140, 248, .14);
  --accent-border: rgba(129, 140, 248, .45);
  --on-accent: #10132a;
  --badge-ink: #0e1116;

  /* misc */
  --code-bg: #171a21;
  --rail: #3a4250;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, .18);
  --focus-ring: 0 0 0 3px var(--accent-weak);

  /* role colors — one distinct hue per message type */
  --sys: #7c8698;
  --user: #5b9dff;
  --asst: #46c99b;
  --think: #b083f0;
  --call: #eaa040;
  --result: #40c4d6;
  --skill: #e87eb0;
  --err: #f2777a;
  --ok: #46c99b;
  --ok-bg: rgba(70, 201, 155, .14);
  --err-bg: rgba(242, 119, 122, .14);
  --think-text: #cbbcea;

  /* radii */
  --r-xs: 5px;
  --r-sm: 7px;
  --r-md: 9px;
  --r-lg: 12px;
  --r-pill: 999px;

  /* sidebar width (overridden inline by the resizer) */
  --sidebar-w: 320px;
}

[data-theme="light"] {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f6;
  --panel-3: #e6e9f0;
  --border: #e4e8ef;
  --border-strong: #d2d8e2;

  --text: #1e2430;
  --muted: #64707f;
  --faint: #98a2b0;

  --accent: #5b60e6;
  --accent-hover: #4a4fd8;
  --accent-weak: rgba(91, 96, 230, .10);
  --accent-border: rgba(91, 96, 230, .40);
  --on-accent: #ffffff;
  --badge-ink: #ffffff;

  --code-bg: #f2f4f8;
  --rail: #dbe0ea;
  --card-shadow: 0 1px 2px rgba(20, 30, 60, .06);

  --sys: #6b7688;
  --user: #2f6fe0;
  --asst: #0f9d74;
  --think: #7c53c8;
  --call: #bd7a15;
  --result: #0f93a8;
  --skill: #c65a92;
  --err: #d64545;
  --ok: #0f9d74;
  --ok-bg: rgba(15, 157, 116, .12);
  --err-bg: rgba(214, 69, 69, .12);
  --think-text: #6a4bb0;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  transition: background-color .2s ease, color .2s ease;
}

/* custom scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-pill);
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; }

::selection { background: var(--accent-weak); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 11px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border);
  flex-shrink: 0;
}
.brand {
  font-weight: 650;
  font-size: 15px;
  letter-spacing: .2px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand-logo {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}
.dir-input { display: flex; flex: 1; gap: 8px; max-width: 900px; }
.dir-field { position: relative; flex: 1; display: flex; }
.dir-input input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  font-size: 13px;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .2s ease;
}
input::placeholder { color: var(--faint); }
.dir-input input:focus { outline: none; border-color: var(--accent-border); box-shadow: var(--focus-ring); }

/* path autocomplete dropdown */
.path-suggest {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  max-height: 340px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  z-index: 60;
  padding: 5px;
}
.ps-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: var(--r-xs);
  cursor: pointer;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
}
.ps-item .ps-icon { flex-shrink: 0; opacity: .85; }
.ps-item .ps-name { overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.ps-item .ps-name b { color: var(--accent); font-weight: 600; }
.ps-item.active, .ps-item:hover { background: var(--accent-weak); }
.ps-foot { padding: 5px 9px 3px; font-size: 11px; color: var(--faint); }
.ps-empty { padding: 6px 9px; font-size: 12.5px; color: var(--faint); }
.ps-head { padding: 4px 9px 6px; font-size: 11px; color: var(--faint); }
/* history rows: path fills the row so the ✕ delete button aligns right */
.ps-item .ps-name { flex: 1 1 auto; min-width: 0; }
.ps-del {
  flex-shrink: 0; background: none; border: none; color: var(--faint);
  cursor: pointer; font-size: 12px; line-height: 1; padding: 2px 5px;
  border-radius: var(--r-xs); opacity: 0;
}
.ps-hist:hover .ps-del, .ps-hist.active .ps-del { opacity: .75; }
.ps-del:hover { color: var(--err); background: var(--panel-2); opacity: 1; }

button, .btn-link {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: var(--r-sm);
  padding: 8px 15px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  display: inline-block;
  transition: filter .15s ease, background-color .15s ease, transform .05s ease;
}
button:hover, .btn-link:hover { background: var(--accent-hover); }
button:active { transform: translateY(1px); }
button:focus-visible, .btn-link:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* secondary / ghost text button (e.g. 清除) */
.btn-secondary { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); font-weight: 500; }
.btn-secondary:hover { background: var(--panel-3); color: var(--text); border-color: var(--border-strong); }

/* ghost / icon button (theme toggle, secondary actions) */
.icon-btn {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); border-color: var(--border-strong); }

.dir-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.dir-status.err { color: var(--err); }

.stats-bar { display: flex; gap: 8px; margin-left: auto; white-space: nowrap; }
.stat {
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 4px 11px;
}
.stat b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: var(--sidebar-w, 320px);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.resizer {
  width: 6px;
  flex-shrink: 0;
  cursor: col-resize;
  background: transparent;
  position: relative;
  z-index: 5;
  transition: background-color .15s ease;
}
.resizer:hover, .resizer.dragging { background: var(--accent-border); }
body.resizing { cursor: col-resize; user-select: none; }

.sidebar-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
}
.sh-row { display: flex; align-items: center; gap: 8px; }
#taskCount { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.sh-controls { display: flex; gap: 6px; margin-left: auto; }
.mini-select {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 3px 6px;
  font-size: 11.5px;
  cursor: pointer;
}
.mini-select:hover { color: var(--text); border-color: var(--border-strong); }
.chip-toggle {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 600;
}
.chip-toggle:hover { color: var(--text); border-color: var(--border-strong); background: var(--panel-3); }
.chip-toggle.active {
  background: var(--err-bg);
  color: var(--err);
  border-color: transparent;
}
.sidebar-head input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-xs);
  padding: 6px 9px;
  font-size: 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.sidebar-head input:focus { outline: none; border-color: var(--accent-border); box-shadow: var(--focus-ring); }

.task-list { list-style: none; margin: 0; padding: 7px; overflow-y: auto; }
.task-item {
  position: relative;
  padding: 9px 11px;
  border-radius: var(--r-md);
  cursor: pointer;
  margin-bottom: 4px;
  border: 1px solid transparent;
  transition: background-color .13s ease, border-color .13s ease;
}
.task-item:hover { background: var(--panel-2); }
.task-item.active {
  background: var(--accent-weak);
  border-color: var(--accent-border);
}
.ti-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}
.ti-id { display: flex; align-items: center; gap: 7px; min-width: 0; }
.ti-id .id-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ti-msgs { flex-shrink: 0; font-variant-numeric: tabular-nums; color: var(--faint); }
.ti-meta { display: flex; align-items: center; flex-shrink: 0; }
.ti-deliv { font-variant-numeric: tabular-nums; color: var(--muted); }
.ti-deliv::before { content: "·"; margin: 0 7px; color: var(--faint); }
.ti-deliv.zero { color: var(--faint); }

/* status dot */
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--faint);
}
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.err { background: var(--err); box-shadow: 0 0 0 3px var(--err-bg); }

.ti-title {
  font-size: 13px;
  color: var(--text);
  margin-top: 5px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.task-item.active .ti-title { color: var(--text); }
.ti-tags { margin-top: 7px; display: flex; gap: 6px; flex-wrap: wrap; }

.pill {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: var(--r-pill);
  background: var(--panel-3);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.err { background: var(--err-bg); color: var(--err); }

/* ---------- Content ---------- */
.content { flex: 1; min-width: 0; overflow: hidden; display: flex; flex-direction: column; }
.empty { padding: 72px 40px; color: var(--muted); text-align: center; max-width: 460px; margin: 40px auto 0; }
.empty p { margin: 8px 0; }
.empty .muted { font-size: 13px; color: var(--faint); }
.hidden { display: none !important; }

.task-view { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.task-header { padding: 12px 22px 10px; background: var(--panel); border-bottom: 1px solid var(--border); }
.meta-chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.chip b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip.chip-err { color: var(--err); border-color: var(--err-bg); }
.chip.chip-err b { color: var(--err); }

.tabs {
  display: flex;
  gap: 2px;
  padding: 10px 22px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border);
}
.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 14px;
  font-weight: 600;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); background: transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { flex: 1; min-height: 0; overflow-y: auto; overflow-anchor: none; }

/* tab count badge */
.tab-count {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--panel-3);
  color: var(--muted);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
.tab.active .tab-count { background: var(--accent); color: var(--on-accent); }

/* ---------- Trace (timeline) ---------- */
.trace { padding: 20px 22px 64px; max-width: 1040px; }
.event {
  position: relative;
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  --role: var(--muted);
}
/* timeline rail: a vertical line running through the centered badges;
   each event tiles a segment down into the gap so they join seamlessly */
.event::before {
  content: "";
  position: absolute;
  left: 37px;
  top: 0;
  bottom: -14px;
  width: 2px;
  margin-left: -1px;
  background: var(--rail);
  z-index: 0;
}
.event:first-child::before { top: 12px; }
.event:last-child::before { bottom: auto; height: 12px; }

/* elapsed-time marker sitting on the rail between two timestamped events */
.gap-marker {
  position: relative;
  height: 20px;
  margin-bottom: 14px;
}
.gap-marker::before {
  content: "";
  position: absolute;
  left: 37px;
  top: 0;
  bottom: -14px;
  width: 2px;
  margin-left: -1px;
  background: var(--rail);
  z-index: 0;
}
.gap-pill {
  position: absolute;
  left: 37px;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--bg));
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  padding: 1px 8px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.event.system { --role: var(--sys); }
.event.user { --role: var(--user); }
.event.assistant_text { --role: var(--asst); }
.event.thinking { --role: var(--think); }
.event.tool_call { --role: var(--call); }
.event.tool_result { --role: var(--result); }
.event.tool_pair { --role: var(--call); }
.event.skill { --role: var(--skill); }
.event.tool_result.is-error { --role: var(--err); }
.event.tool_pair.is-error { --role: var(--err); }

/* ---------- side minimap (quick-nav rail) ---------- */
.trace-minimap {
  position: fixed;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 32px;
  padding: 6px 4px;
  box-sizing: border-box;
  border-radius: 9px;
  background: var(--panel-2);
  box-shadow: 0 1px 8px rgba(0, 0, 0, .22);
  opacity: .7;
  overflow-y: auto;
  scrollbar-width: none;
  transition: opacity .15s ease, width .15s ease;
}
.trace-minimap::-webkit-scrollbar { width: 0; height: 0; }
.trace-minimap:hover { opacity: 1; width: 40px; }
.mm-tick {
  flex: 1 1 0;
  min-height: 6px;
  width: 100%;
  border: 0;
  padding: 0;
  border-radius: 3px;
  background: var(--muted);
  opacity: .55;
  cursor: pointer;
  transition: opacity .12s ease, transform .12s ease;
}
.mm-tick:hover { opacity: 1; transform: scale(1.12); }
.mm-tick.in-view { opacity: 1; }
.trace-minimap:not(:hover) .mm-tick.in-view {
  box-shadow: inset 3px 0 0 0 var(--text);
}
.mm-tick.system { background: var(--sys); }
.mm-tick.user { background: var(--user); }
.mm-tick.skill { background: var(--skill); }
.mm-tick.assistant_text { background: var(--asst); }
.mm-tick.thinking { background: var(--think); }
.mm-tick.tool_call { background: var(--call); }
.mm-tick.tool_result { background: var(--result); }
/* a pair tick reads call → result top-to-bottom, matching the card it points at */
.mm-tick.tool_pair { background: linear-gradient(to bottom, var(--call), var(--result)); }
.mm-tick.is-error { background: var(--err); }
.mm-tick.tool_pair.is-error { background: linear-gradient(to bottom, var(--call), var(--err)); }

/* hover preview card */
.mm-tip {
  position: fixed;
  z-index: 40;
  display: none;
  max-width: 380px;
  min-width: 160px;
  padding: 8px 11px;
  box-sizing: border-box;
  border-radius: 9px;
  background: var(--panel-2);
  border: 1px solid var(--border, rgba(127, 127, 127, .25));
  box-shadow: 0 4px 18px rgba(0, 0, 0, .3);
  font-size: 12.5px;
  line-height: 1.5;
  pointer-events: none;
}
.mm-tip-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.mm-tip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--muted);
}
.mm-tip-dot.system { background: var(--sys); }
.mm-tip-dot.user { background: var(--user); }
.mm-tip-dot.skill { background: var(--skill); }
.mm-tip-dot.assistant_text { background: var(--asst); }
.mm-tip-dot.thinking { background: var(--think); }
.mm-tip-dot.tool_call { background: var(--call); }
.mm-tip-dot.tool_result { background: var(--result); }
.mm-tip-dot.tool_pair { background: linear-gradient(to bottom, var(--call), var(--result)); }
.mm-tip-dot.is-error { background: var(--err); }
.mm-tip-dot.tool_pair.is-error { background: linear-gradient(to bottom, var(--call), var(--err)); }
.mm-tip-body {
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 8;
  line-clamp: 8;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* brief ring on the event we jumped to */
.event.mm-flash { animation: mmFlash 1.2s ease-out; }
@keyframes mmFlash {
  0%, 35% { box-shadow: 0 0 0 2px var(--role, var(--text)); }
  100% { box-shadow: 0 0 0 0 transparent; }
}



.ev-gutter {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: 74px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 2px;
}
.ev-badge {
  position: relative;
  z-index: 1;
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
  padding: 3px 8px;
  border-radius: var(--r-xs);
  color: var(--badge-ink);
  background: var(--role);
  box-shadow: 0 0 0 3px var(--bg);
}
.ev-ts {
  position: relative;
  z-index: 1;
  font-size: 10px;
  color: var(--muted);
  margin-top: 5px;
  background: var(--bg);
  display: inline-block;
  padding: 0 2px;
  font-variant-numeric: tabular-nums;
}

.ev-body {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  background: color-mix(in srgb, var(--role) 12%, var(--panel));
  border: 1px solid var(--border);
  border-color: color-mix(in srgb, var(--role) 42%, var(--border));
  border-radius: var(--r-md);
  padding: 11px 14px;
  box-shadow: inset 3px 0 0 var(--role), var(--card-shadow);
}
.ev-tool-name { font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.ev-tool-name b { color: var(--text); }
.err-tag { color: var(--err); }

/* "并行 2/6" — marks a call that shared its turn with other calls */
.par-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  font-size: 10px;
  font-weight: 600;
  line-height: 16px;
  vertical-align: 1px;
  color: var(--call);
  background: color-mix(in srgb, var(--call) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--call) 40%, transparent);
  border-radius: var(--r-pill);
  font-variant-numeric: tabular-nums;
}

/* call → result seam inside a paired card */
.pair-sep {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 11px 0 9px;
}
.pair-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: color-mix(in srgb, var(--result) 34%, transparent);
}
.pair-sep-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .4px;
  color: var(--result);
}
.pair-result {
  border-left: 2px solid color-mix(in srgb, var(--result) 55%, transparent);
  padding-left: 10px;
}
.event.tool_pair.is-error .pair-sep-label { color: var(--err); }
.event.tool_pair.is-error .pair-sep::after {
  background: color-mix(in srgb, var(--err) 40%, transparent);
}
.event.tool_pair.is-error .pair-result { border-left-color: var(--err); }

.event.thinking .md { color: var(--think-text); font-style: italic; }
.event.tool_result.is-error .ev-body { border-color: var(--err); }
.event.tool_pair.is-error .ev-body { border-color: var(--err); }

/* compaction seam */
.compaction-divider { display: flex; align-items: center; gap: 12px; margin: 24px 0; }
.compaction-divider .cd-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border-strong), transparent);
}
.compaction-divider .cd-label {
  flex: none;
  font-size: 11px;
  color: var(--muted);
  padding: 4px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-pill);
  white-space: nowrap;
}

/* markdown + code */
.md { word-break: break-word; }
.md p { margin: 6px 0; }
.md p:first-child { margin-top: 0; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { margin: 12px 0 6px; font-size: 15px; font-weight: 650; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 2px 0; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md blockquote {
  margin: 8px 0;
  padding: 2px 12px;
  border-left: 3px solid var(--border-strong);
  color: var(--muted);
}
.md table { border-collapse: collapse; margin: 8px 0; font-size: 12px; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 9px; }
.md th { background: var(--panel-2); }
.md code {
  background: var(--code-bg);
  padding: 1.5px 5px;
  border-radius: var(--r-xs);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
}
.md pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px;
  overflow-x: auto;
}
.md pre code { background: none; padding: 0; }
pre.raw {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  margin: 0;
}
.cmd-line {
  color: var(--asst);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
.cmd-desc { color: var(--muted); font-size: 11px; margin-top: 5px; }
.kv { font-size: 12px; margin: 2px 0; }
.kv .k { color: var(--muted); }

.collapsed-wrap { position: relative; }
.collapsible-body { overflow: hidden; }
.collapsed { max-height: 260px; }
.expander {
  display: inline-block;
  margin-top: 8px;
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  background: none;
  padding: 0;
  font-weight: 600;
}
.expander:hover { background: none; color: var(--accent-hover); }
.fade {
  position: absolute; bottom: 28px; left: 0; right: 0; height: 44px;
  background: linear-gradient(transparent, var(--panel));
  background: linear-gradient(transparent, color-mix(in srgb, var(--role) 12%, var(--panel)));
  pointer-events: none;
}

/* ---------- File browser ---------- */
.tab-panel.filepanel { overflow: hidden; container-type: inline-size; }
.fb { display: flex; height: 100%; min-height: 0; position: relative; }
.fb-tree {
  width: var(--fb-tree-w, 240px);
  flex-shrink: 0;
  overflow: auto;
  border-right: 1px solid var(--border);
  padding: 10px 6px 40px;
  font-size: 13px;
}
.fb.tree-collapsed .fb-tree,
.fb.tree-collapsed .fb-rail { display: none; }

/* drag handle between tree and preview */
.fb-rail {
  flex: 0 0 6px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  z-index: 3;
  transition: background-color .15s ease;
}
.fb-rail:hover, .fb-rail.dragging { background: var(--accent-border); }

.fb-empty { padding: 34px; color: var(--muted); }
.fb-preview { flex: 1; min-width: 0; overflow: auto; display: flex; flex-direction: column; }

/* collapse / expand toggle, lives at the left of the preview bar */
.fb-toggle {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 4px 9px;
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
}
.fb-toggle:hover { color: var(--text); border-color: var(--border-strong); background: var(--panel-3); }

/* narrow available width: stack the tree on top, preview fills the width below */
@container (max-width: 640px) {
  .fb { flex-direction: column; }
  .fb-tree {
    width: auto !important;
    max-height: 38vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .fb-rail { display: none; }
}

.fb-ul { list-style: none; margin: 0; padding: 0; }
.fb-ul .fb-ul { padding-left: 14px; }
.fb-node {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: var(--r-xs);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .12s ease, color .12s ease;
}
.fb-node:hover { background: var(--panel-2); }
.fb-node.active { background: var(--accent); color: var(--on-accent); }
.fb-node .fb-icon { flex-shrink: 0; width: 16px; text-align: center; opacity: .9; }
.fb-node .fb-name { overflow: hidden; text-overflow: ellipsis; }
.fb-node .fb-size { margin-left: auto; font-size: 10px; color: var(--muted); padding-left: 10px; font-variant-numeric: tabular-nums; }
.fb-node.active .fb-size { color: var(--on-accent); opacity: .8; }
.fb-dir > .fb-node .fb-caret { display: inline-block; width: 10px; transition: transform .12s ease; color: var(--muted); }
.fb-dir.collapsed > .fb-ul { display: none; }
.fb-dir.collapsed > .fb-node .fb-caret { transform: rotate(-90deg); }

/* preview pane */
.pv-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 2;
}
.pv-bar .pv-title { font-weight: 600; word-break: break-all; }
.pv-bar .muted { font-size: 12px; color: var(--muted); }
.pv-bar .btn-link { margin-left: auto; }
.pv-body { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.pv-hint { padding: 44px; color: var(--muted); text-align: center; }
.pv-body img { max-width: 100%; display: block; margin: 16px auto; background: #fff; border-radius: var(--r-xs); }
.pv-body iframe { width: 100%; flex: 1; min-height: 80vh; border: 0; background: #fff; }
.pv-body .docx-wrapper { background: #fff; padding: 16px; }

/* 一键渲染 progress text in the top bar */
.render-status { font-size: 12px; color: var(--muted); white-space: nowrap; align-self: center; }
/* font-substitution notice (fonts referenced by the deck but missing server-side) */
.pv-font-warn {
  display: flex; align-items: baseline; gap: 6px 8px; flex-wrap: wrap;
  padding: 8px 18px; border-bottom: 1px solid var(--border);
  background: rgba(224, 161, 46, .10);
  font-size: 12px; color: var(--muted); line-height: 1.5; flex-shrink: 0;
}
.pv-font-warn .ff-ico { color: #e0a12e; font-weight: 700; }
.pv-font-warn .ff-txt { color: var(--text); }
.pv-font-warn .ff-chips { display: inline-flex; gap: 5px; flex-wrap: wrap; }
.pv-font-warn .ff-chip {
  padding: 1px 7px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border-strong);
  color: var(--text); font-size: 11.5px; white-space: nowrap;
}
.pv-stage { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.pv-stage iframe { flex: 1; width: 100%; border: 0; background: #fff; min-height: 80vh; }
.pv-body pre.filetext {
  margin: 0;
  padding: 16px 18px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text);
}
.pv-body .md { padding: 18px 22px; }
.pv-body table.csv { border-collapse: collapse; margin: 16px; font-size: 12px; }
.pv-body table.csv th, .pv-body table.csv td { border: 1px solid var(--border); padding: 5px 9px; }
.pv-body table.csv th { background: var(--panel-2); position: sticky; top: 0; }

.slide-loading { color: var(--muted); padding: 44px; }
