/* ============================================================
   思想集 · 布局与外壳
   顶栏 / 画布容器 / 右侧详情面板 / 迷你地图
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-canvas);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: var(--fs-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ---------- 顶栏 ---------- */
.bar {
  flex: 0 0 auto;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  background: var(--bar-bg);
  color: var(--bar-text);
  position: relative;
  z-index: var(--z-bar);
  user-select: none;
}

.bar .brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: .3px;
  margin-right: var(--sp-2);
  white-space: nowrap;
}

.bar .brand .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--bar-active);
  box-shadow: 0 0 0 3px rgba(224, 85, 63, .2);
}

.bar .sep {
  width: 1px;
  height: 20px;
  background: var(--bar-line);
  flex: 0 0 auto;
}

/* 工具按钮 */
.tbtn {
  height: 32px;
  min-width: 32px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--bar-text-dim);
  font-size: var(--fs-small);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.tbtn:hover { background: var(--bar-hover); color: var(--bar-text); }
.tbtn:active { transform: translateY(1px); }
.tbtn.on { background: rgba(224, 85, 63, .16); color: #ff8a75; }
.tbtn svg { width: 16px; height: 16px; display: block; }
.tbtn[disabled] { opacity: .32; cursor: default; pointer-events: none; }

.tbtn .lbl { font-size: var(--fs-small); }

/* 搜索框 */
.searchbox {
  position: relative;
  flex: 1 1 auto;
  max-width: 320px;
  min-width: 0;
}
.searchbox input {
  width: 100%;
  height: 32px;
  padding: 0 30px 0 30px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, .08);
  color: var(--bar-text);
  font-size: var(--fs-small);
  outline: none;
  transition: background .15s, border-color .15s;
}
.searchbox input::placeholder { color: var(--bar-text-dim); }
.searchbox input:focus {
  background: rgba(255, 255, 255, .13);
  border-color: rgba(255, 255, 255, .18);
}
.searchbox .icon {
  position: absolute;
  left: 9px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  color: var(--bar-text-dim);
  pointer-events: none;
}
.searchbox .clear {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 20px; height: 20px;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--bar-text-dim);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
}
.searchbox .clear:hover { background: var(--bar-hover); color: var(--bar-text); }
.searchbox.has-val .clear { display: flex; }

.bar .spacer { flex: 1 1 auto; }

/* 有信息量的计数 */
.bar .counter {
  font-size: var(--fs-mini);
  color: var(--bar-text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bar .counter b { color: var(--bar-text); font-weight: 600; }

/* ---------- 画布区 ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-canvas);
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: default;
}
#canvas.panning { cursor: grabbing; }
#canvas.panready { cursor: grab; }
#canvas.over-note { cursor: pointer; }
#canvas.linking { cursor: crosshair; }

/* ---------- 右下角控件簇 ---------- */
.corner {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sp-2);
  z-index: var(--z-float);
  pointer-events: none;
}
.corner > * { pointer-events: auto; }

/* 缩放簇 */
.zoomcl {
  display: flex;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-note);
  overflow: hidden;
}
.zoomcl button {
  width: 34px; height: 32px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.zoomcl button:hover { background: var(--panel-soft); color: var(--ink); }
.zoomcl .zval {
  min-width: 46px;
  text-align: center;
  font-size: var(--fs-mini);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  border-left: 1px solid var(--panel-line);
  border-right: 1px solid var(--panel-line);
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.zoomcl .zval:hover { background: var(--panel-soft); }

/* 迷你地图 */
.minimap {
  width: 168px;
  height: 112px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-note);
  overflow: hidden;
  position: relative;
  cursor: crosshair;
}
.minimap canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.minimap.collapsed { display: none; }

/* ---------- 右侧详情面板 ---------- */
.panel {
  position: fixed;
  top: var(--bar-h);
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  max-width: 100vw;
  background: var(--panel);
  border-left: 1px solid var(--panel-line);
  box-shadow: var(--shadow-panel);
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.32, .72, .3, 1);
  z-index: var(--z-panel);
  display: flex;
  flex-direction: column;
  will-change: transform;
}
.panel.on { transform: translateX(0); }
.panel.resizing { transition: none; }

/* 面板拖拽改宽 */
.panel .grip {
  position: absolute;
  left: -3px; top: 0; bottom: 0;
  width: 7px;
  cursor: col-resize;
  z-index: 2;
}
.panel .grip:hover { background: rgba(224, 85, 63, .12); }

.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--panel-line);
  background: var(--panel);
}
.panel-head .status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--ink-4);
}
.panel-head .grow { flex: 1 1 auto; }
.panel-head .pbtn {
  width: 30px; height: 30px;
  border: 0; border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.panel-head .pbtn:hover { background: var(--panel-soft); color: var(--ink); }
.panel-head .pbtn svg { width: 16px; height: 16px; }

.panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.panel-foot {
  flex: 0 0 auto;
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--panel-line);
  display: flex;
  gap: var(--sp-2);
  background: var(--panel);
}

/* 字段组 */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label {
  font-size: var(--fs-mini);
  color: var(--ink-3);
  letter-spacing: .4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.field > label .hint { color: var(--ink-4); font-size: var(--fs-mini); }

.field input[type="text"],
.field textarea {
  width: 100%;
  border: 1px solid var(--panel-line);
  border-radius: var(--r-sm);
  background: var(--panel-soft);
  padding: 9px 11px;
  outline: none;
  resize: vertical;
  line-height: 1.6;
  transition: border-color .15s, background .15s;
}
.field input[type="text"]:focus,
.field textarea:focus {
  border-color: var(--accent-line);
  background: var(--panel);
}

.field.title input {
  font-size: var(--fs-h2);
  font-weight: 650;
  padding: 7px 11px;
  letter-spacing: -.2px;
}
.field.summary textarea { min-height: 62px; font-size: var(--fs-small); color: var(--ink-2); }
.field.content textarea { min-height: 200px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* 元信息行 */
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
  font-size: var(--fs-mini);
  color: var(--ink-3);
  padding-top: 2px;
}
.meta-row b { color: var(--ink-2); font-weight: 500; }

/* 分段控件（状态 / 显示密度） */
.seg {
  display: inline-flex;
  align-self: flex-start;
  background: var(--panel-soft);
  border: 1px solid var(--panel-line);
  border-radius: var(--r-sm);
  padding: 2px;
  gap: 2px;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 5px 11px;
  border-radius: 5px;
  font-size: var(--fs-mini);
  color: var(--ink-3);
  cursor: pointer;
  white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button.on {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(35, 34, 31, .12);
  font-weight: 600;
}

/* 关系列表 */
.rellist { display: flex; flex-direction: column; gap: 5px; }
.relrow {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 7px 9px;
  border-radius: var(--r-sm);
  background: var(--panel-soft);
  border: 1px solid transparent;
  font-size: var(--fs-small);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.relrow:hover { background: var(--panel); border-color: var(--panel-line); }
.relrow .rtype {
  flex: 0 0 auto;
  font-size: var(--fs-mini);
  padding: 1px 6px;
  border-radius: var(--r-pill);
  border: 1px solid currentColor;
  opacity: .85;
  white-space: nowrap;
}
.relrow .rtitle {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}
.relrow .rdir { flex: 0 0 auto; color: var(--ink-4); font-size: var(--fs-mini); }
.relrow .rdel {
  flex: 0 0 auto;
  width: 20px; height: 20px;
  border: 0; border-radius: 4px;
  background: transparent;
  color: var(--ink-4);
  cursor: pointer;
  opacity: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  line-height: 1;
}
.relrow:hover .rdel { opacity: 1; }
.relrow .rdel:hover { background: var(--danger-soft); color: var(--danger); }

.empty-hint {
  font-size: var(--fs-small);
  color: var(--ink-4);
  padding: 10px 0;
  text-align: center;
}

/* 修改记录 */
.revlist { display: flex; flex-direction: column; gap: 4px; }
.revrow {
  display: flex;
  gap: var(--sp-2);
  font-size: var(--fs-mini);
  color: var(--ink-3);
  padding: 4px 0;
  border-bottom: 1px dashed var(--panel-line);
}
.revrow:last-child { border-bottom: 0; }
.revrow .rtime { flex: 0 0 auto; color: var(--ink-4); font-variant-numeric: tabular-nums; }
.revrow .rwhat { flex: 1 1 auto; min-width: 0; }

/* Markdown 预览 */
.md {
  font-size: var(--fs-body);
  line-height: 1.75;
  color: var(--ink);
  word-break: break-word;
}
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 {
  margin: 1.1em 0 .5em;
  line-height: 1.35;
  font-weight: 650;
  letter-spacing: -.2px;
}
.md h1 { font-size: 1.32em; }
.md h2 { font-size: 1.16em; }
.md h3 { font-size: 1.04em; }
.md h4 { font-size: 1em; color: var(--ink-2); }
.md p { margin: .7em 0; }
.md ul, .md ol { margin: .7em 0; padding-left: 1.5em; }
.md li { margin: .25em 0; }
.md li > p { margin: .2em 0; }
.md blockquote {
  margin: .8em 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--accent-line);
  color: var(--ink-2);
}
.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .9em;
  background: var(--panel-soft);
  border: 1px solid var(--panel-line);
  border-radius: 4px;
  padding: 1px 5px;
}
.md pre {
  margin: .8em 0;
  padding: 11px 13px;
  background: var(--panel-soft);
  border: 1px solid var(--panel-line);
  border-radius: var(--r-sm);
  overflow-x: auto;
  line-height: 1.55;
}
.md pre code { background: none; border: 0; padding: 0; font-size: 12.5px; }
.md hr { border: 0; border-top: 1px solid var(--panel-line); margin: 1.2em 0; }
.md a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-line); }
.md a:hover { border-bottom-color: var(--accent); }
.md strong { font-weight: 650; }
.md table { border-collapse: collapse; margin: .8em 0; font-size: .94em; width: 100%; }
.md th, .md td { border: 1px solid var(--panel-line); padding: 6px 9px; text-align: left; }
.md th { background: var(--panel-soft); font-weight: 600; }

/* 面板内的标签页 */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--panel-line);
  margin-bottom: var(--sp-3);
  flex: 0 0 auto;
}
.tabs button {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  font-size: var(--fs-small);
  color: var(--ink-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- 通用按钮 ---------- */
.btn {
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: var(--r-sm);
  font-size: var(--fs-small);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .13s, border-color .13s, color .13s;
}
.btn:hover { background: var(--panel-soft); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
.btn.primary:hover { background: #cc4a36; border-color: #cc4a36; }
.btn.danger { color: var(--danger); border-color: var(--accent-line); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-3); }
.btn.ghost:hover { background: var(--panel-soft); color: var(--ink); }
.btn.grow { flex: 1 1 auto; }
.btn[disabled] { opacity: .4; pointer-events: none; }

/* ---------- 空状态 ---------- */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none;
  z-index: 2;
}
.empty-state .es-inner {
  text-align: center;
  max-width: 420px;
  pointer-events: auto;
}
.empty-state .es-title {
  font-size: 17px;
  font-weight: 650;
  color: var(--ink-2);
  letter-spacing: -.2px;
  margin-bottom: 6px;
}
.empty-state .es-desc {
  font-size: var(--fs-small);
  color: var(--ink-3);
  line-height: 1.7;
  margin-bottom: var(--sp-5);
}
.empty-state .es-acts {
  display: flex;
  gap: var(--sp-2);
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}
.empty-state .es-hint {
  font-size: var(--fs-mini);
  color: var(--ink-4);
  line-height: 2.1;
}
.empty-state .es-hint kbd {
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--ink-3);
}

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  :root { --panel-w: 100vw; --bar-h: 50px; }
  .toast-wrap { bottom: auto; top: calc(var(--bar-h) + 12px); }
  .bar { padding: 0 10px; gap: 5px; }
  .bar .brand .word { display: none; }
  .bar .counter { display: none; }
  .tbtn .lbl { display: none; }
  .tbtn { padding: 0 7px; min-width: 30px; }
  .panel { top: var(--bar-h); }
  .corner { right: 10px; bottom: 10px; }
  .minimap { width: 124px; height: 84px; }
  .panel-body { padding: var(--sp-3); gap: var(--sp-3); }
}

@media (max-width: 400px) {
  .searchbox { max-width: none; }
}
