/* app.css - keep the original visual language, add layout */
:root {
  --topbar-h: 2.1em;
}

body {
  /* style.css already sets overflow hidden; keep */
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: rgb(255, 255, 255);
  border-bottom: 1px solid rgb(198, 198, 198);
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.app-title {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

.app-version {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-top {
  appearance: none;
  border: 1px solid rgb(198, 198, 198);
  background: rgb(246, 246, 246);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 2px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  line-height: 1;
}

.btn-top:hover {
  border-color: rgb(160, 160, 160);
}

.btn-top.primary {
  background: rgba(35, 128, 229, 0.10);
  border-color: rgba(35, 128, 229, 0.45);
}

.workspace {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  height: calc(100vh - var(--topbar-h));
}

.pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
}

.pane-header {
  padding: 10px 12px;
  background: rgb(255, 255, 255);
  border-bottom: 1px solid rgb(220, 220, 220);
}

.pane-title {
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 4px;
}

.pane-sub {
  font-size: 12px;
  color: var(--muted);
}

.pane.left {
  width: 300px;
  min-width: 250px;
  background: #ffffff;

  overflow-x: hidden;
}

.pane.right {
  flex: 1 1 auto;
  background: var(--panel);
  border-left: 0;
}

.def-list {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 8px 0;
}

.def-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #0000000a;
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.def-key {
  color: #0b2a6e;
  /* deep blue */
  font-weight: 700;
  font-size: 12px;
}

.def-line {
  color: var(--muted);
  font-size: 11px;

  white-space: nowrap;
}

.def-item:hover {
  background: rgba(0, 0, 0, 0.03);
}

.def-item.active {
  background: rgb(242, 242, 242);
  /* light gray like your list selection */
}

.divider {
  width: 8px;
  cursor: col-resize;
  background: transparent;
  position: relative;
}

.divider::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3px;
  width: 2px;
  background: rgba(0, 0, 0, 0.08);
}

.editor {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px 18px;
  display: grid;
  gap: 12px;
}

textarea {
  box-sizing: border-box;
  max-width: 100%;
  width: 100%;
  padding: 10px 12px;
  border-radius: 3px;
  border: 1px solid rgb(199, 199, 199);
  background: rgb(242, 242, 242);
  color: var(--text);
  outline: none;
  font-size: 14px;
  resize: vertical;
  min-height: 6em;
}

textarea:focus {
  border-color: rgba(35, 128, 229, 0.65);
  box-shadow: 0 0 0 3px rgba(35, 128, 229, 0.15);
}

.current-key {
  padding: 10px 12px;
  border: 1px dashed rgba(0, 0, 0, 0.18);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.6);
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 12px;
  bottom: 12px;
  background: rgba(0, 0, 0, 0.78);
  color: white;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 12px;
  max-width: min(720px, calc(100vw - 24px));
  z-index: 40;
  display: none;
  white-space: pre-line;
}


/* ===== 內容欄位：Wiki 風格（textarea + 背後語法高亮層）===== */
.syntax-wrap {
  position: relative;
  width: 100%;
}

/* 把原本 textarea 的視覺外觀搬到包裝層，讓 pre 與 textarea 完全重疊一致 */
.syntax-wrap {
  box-sizing: border-box;
  border-radius: 3px;
  border: 1px solid rgb(199, 199, 199);
  background: rgb(242, 242, 242);
}

.syntax-wrap:focus-within {
  border-color: rgba(35, 128, 229, 0.65);
  box-shadow: 0 0 0 3px rgba(35, 128, 229, 0.15);
}

/* 讓 pre 成為底層顯示（顏色/粗體） */
.syntax-pre {
  box-sizing: border-box;
  margin: 0;
  padding: 10px 12px;
  min-height: 6em;
  /* 與原 textarea 一致 */
  font-size: 14px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  pointer-events: none;
  overflow: hidden;
  /* 由 textarea 控制捲動 */

  font-family: inherit;
  font-weight: 400;
  letter-spacing: 0;
  tab-size: 2;
  -moz-tab-size: 2;
  font-variant-ligatures: none;
}

/* textarea 變成透明字，靠 pre 顯示；仍可選取/輸入 */
textarea.syntax-textarea {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 3px;
  background: transparent;
  outline: none;
  font-size: 14px;
  line-height: 1.35;
  resize: vertical;
  min-height: 6em;

  color: transparent;
  caret-color: var(--text);

  font-family: inherit;
  font-weight: 400;
  letter-spacing: 0;
  tab-size: 2;
  -moz-tab-size: 2;
  font-variant-ligatures: none;
}

/* 捲動：以 textarea 為主；pre 跟著同步 */
textarea.syntax-textarea {
  overflow: auto;
}

/* 高亮樣式 */
.hl-n {
  color: #166f54;
}

.hl-section {
  color: #8e5523;
}

.hl-bracket {
  color: #6c32b9;
}

textarea.syntax-textarea:focus {
  box-shadow: none;
}


/* ===== CodeMirror 5 編輯器（避免游標/選取錯位） ===== */
.cm-wrap {
  box-sizing: border-box;
  border-radius: 3px;
  border: 1px solid rgb(199, 199, 199);
  background: rgb(242, 242, 242);
  overflow: hidden;
  min-height: 6em;
}

.cm-wrap:focus-within {
  border-color: rgba(35, 128, 229, 0.65);
  box-shadow: 0 0 0 3px rgba(35, 128, 229, 0.15);
}

/* CodeMirror 本體 */
.cm-wrap .CodeMirror {
  height: 240px;
  /* 類似 rows=8 的高度；避免 auto-height 造成跳動 */
  background: transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 14px;
  line-height: 1.45;
}

.cm-wrap .CodeMirror-scroll {
  min-height: 6em;
}

.cm-wrap .CodeMirror-lines {
  padding: 10px 12px;
  /* 對齊你原本 textarea 的 padding */
}

/* 停用狀態 */
.cm-wrap.is-disabled {
  opacity: 0.7;
}

.cm-wrap.is-disabled .CodeMirror {
  pointer-events: none;
}

/* 高亮：CodeMirror 會加上 cm- 前綴 */
.cm-hl-n {
  color: #166f54;
}

.cm-hl-section {
  color: #8e5523;
}

.cm-hl-bracket {
  color: #6c32b9;
}