/* ====== 设计令牌 ====== */
:root {
  --color-primary: #0078D7;
  --color-primary-dark: #005A9E;
  --color-bg: #F3F3F3;
  --color-bg-panel: #FFFFFF;
  --color-bg-alt: #EAEAEA;
  --color-text: #1A1A1A;
  --color-text-muted: #555555;
  --color-border: #C9C9C9;
  --color-error: #D13438;
  --color-success: #107C10;
  --color-warning: #FFB900;
  --color-sel-bg: #0078D7;
  --color-sel-text: #FFFFFF;
  --color-bookmark: #FFB900;

  --font-ui: "Segoe UI", -apple-system, BlinkMacSystemFont, "Microsoft YaHei", sans-serif;
  --font-mono: "Consolas", "Courier New", "Menlo", monospace;

  --size-heading: 15px;
  --size-sub: 13px;
  --size-body: 13px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-ui);
  font-size: var(--size-body);
  color: var(--color-text);
  background: var(--color-bg);
  overflow: hidden;
}

/* ====== 应用网格布局 ====== */
#app {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100vh;
  width: 100vw;
}

/* ====== 菜单栏 ====== */
#menubar {
  display: flex;
  background: linear-gradient(to bottom, #FBFBFB, #F0F0F0);
  border-bottom: 1px solid var(--color-border);
  padding: 0 4px;
  user-select: none;
}
.menu-item { position: relative; }
.menu-label {
  display: block;
  padding: 6px 12px;
  font-size: var(--size-sub);
  cursor: default;
  border-radius: 3px;
  transition: background .15s ease;
}
.menu-item:hover > .menu-label,
.menu-item.open > .menu-label {
  background: var(--color-primary);
  color: var(--color-sel-text);
}
.menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  background: var(--color-bg-panel);
  border: 1px solid var(--color-border);
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
  padding: 4px 0;
  z-index: 100;
  list-style: none;
}
.menu-item.open > .menu-dropdown { display: block; }
.menu-dropdown li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-size: var(--size-body);
  cursor: default;
  position: relative;
  transition: background .12s ease, color .12s ease;
}
.menu-dropdown li:hover {
  background: var(--color-primary);
  color: var(--color-sel-text);
}
.menu-dropdown li.menu-sep {
  height: 1px;
  padding: 0;
  margin: 4px 0;
  background: var(--color-border);
}
.mi-icon { width: 18px; text-align: center; }

/* 编码子菜单 */
.menu-submenu {
  display: none;
  position: absolute;
  left: 100%;
  top: -4px;
  min-width: 160px;
  background: var(--color-bg-panel);
  border: 1px solid var(--color-border);
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
  padding: 4px 0;
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
}
.menu-submenu li { padding: 6px 14px; }
.menu-submenu li.selected { font-weight: 600; color: var(--color-primary); }
.has-sub:hover > .menu-submenu { display: block; }

/* ====== 工具栏 ====== */
#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(to bottom, #FCFCFC, #EDEDED);
  border-bottom: 1px solid var(--color-border);
  padding: 5px 8px;
  user-select: none;
}
.tb-btn {
  border: 1px solid transparent;
  background: transparent;
  font-size: 16px;
  min-width: 32px;
  width: auto;
  height: 30px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  padding: 0 6px;
  transition: background .15s ease, border-color .15s ease, transform .08s ease;
}
.tb-btn:hover {
  background: #E3E3E3;
  border-color: var(--color-border);
}
.tb-btn:active { transform: scale(.94); }
.tb-sep {
  width: 1px;
  height: 22px;
  background: var(--color-border);
  margin: 0 4px;
}
.tb-group { display: flex; gap: 2px; }
.tb-tab {
  border: 1px solid var(--color-border);
  background: var(--color-bg-alt);
  padding: 4px 12px;
  font-size: var(--size-sub);
  border-radius: 4px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.tb-tab:hover { background: #DCDCDC; }
.tb-tab.active {
  background: var(--color-primary);
  color: var(--color-sel-text);
  border-color: var(--color-primary-dark);
}
.tb-spacer { flex: 1; }
.tb-indicator {
  font-size: 12px;
  color: var(--color-text-muted);
  padding: 3px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-bg-panel);
}

/* ====== 工作区 ====== */
#workspace {
  display: grid;
  grid-template-columns: 320px 1fr;
  overflow: hidden;
  min-height: 0;
}

/* 左侧面板 */
#leftPanel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--color-border);
  background: var(--color-bg-panel);
  min-height: 0;
  overflow: hidden;
}
.panel-section { display: flex; flex-direction: column; min-height: 0; }
#treeSection { flex: 1 1 100%; border-bottom: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: var(--size-sub);
  font-weight: 600;
  background: linear-gradient(to bottom, #F4F4F4, #E8E8E8);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
}

.tree-container {
  flex: 1;
  overflow: auto;
  padding: 4px 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
}
.tree-container.full { position: absolute; inset: 0; padding: 8px 12px; }

/* 树节点 */
.tree-node { white-space: nowrap; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  cursor: default;
  border-radius: 3px;
  transition: background .1s ease;
}
.tree-row:hover { background: #EAF2FB; }
.tree-row.selected { background: var(--color-primary); color: var(--color-sel-text); }
.tree-row.bookmarked { box-shadow: inset 3px 0 0 var(--color-bookmark); }

/* 表格内部的 tree-row 是 <tr>，不能是 flex */
.data-table .tree-row {
  display: table-row;
}

/* 动态数据表格：有横竖线边框 */
.data-table {
  min-width: max-content;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: auto;
}
.data-table th, .data-table td {
  border: 1px solid #d4d4d4;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}
.data-table thead th {
  position: sticky;
  top: 0;
  background: #f3f3f3;
  font-weight: 600;
  z-index: 1;
  padding: 4px 6px;
}
.data-table tbody tr:hover { background: #e5f3ff; }
.data-table .tree-row.selected { background: #cce8ff !important; }
.data-table .tree-row.bookmarked { box-shadow: inset 3px 0 0 var(--color-bookmark); background: #fffbe6; }
.flat-th {
  position: relative;
  min-width: 70px;
  padding-bottom: 22px;
}
.data-table thead th.flat-th {
  padding-bottom: 22px;
}
.flat-th-label {
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
  font-weight: 600;
}
.flat-th-label:hover { color: #0078D7; }
.flat-th-filter {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 4px;
  width: auto;
  box-sizing: border-box;
  border: 1px solid #ccc;
  border-radius: 2px;
  padding: 2px 4px;
  font-size: 12px;
  font-weight: normal;
}
.flat-th-filter:focus {
  outline: none;
  border-color: #0078D7;
}
.flat-cell-edit {
  font: inherit;
  color: inherit;
  background: #fff;
}

.tree-toggle {
  width: 14px;
  text-align: center;
  cursor: pointer;
  color: var(--color-text-muted);
  user-select: none;
}
.tree-label { display: inline-flex; align-items: center; gap: 4px; }
.node-tag { color: var(--color-primary-dark); font-weight: 600; }
.tree-row.selected .node-tag { color: #D6E8FB; }
.node-attr { color: #8A6D3B; }
.node-text { color: var(--color-text-muted); }
.tree-children { padding-left: 16px; }
.tree-children.collapsed { display: none; }
.node-type-badge {
  font-size: 10px;
  padding: 0 4px;
  border-radius: 3px;
  background: var(--color-bg-alt);
  color: var(--color-text-muted);
}

/* 右侧视图 */
#rightPanel { position: relative; min-width: 0; min-height: 0; background: var(--color-bg-panel); }
.view-pane {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
}
.view-pane.active { display: block; }

.source-editor {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  color: var(--color-text);
  background: var(--color-bg-panel);
  tab-size: 2;
}
/* 书签叠加层：覆盖在 textarea 之上，不拦截鼠标事件 */
.source-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}
.bookmark-gutter {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
}
.bookmark-line {
  position: absolute;
  left: 0;
  right: 0;
  box-sizing: border-box;
  background: rgba(255, 185, 0, 0.22);
  border-left: 3px solid #FFB900;
  box-shadow: inset 0 0 0 1px rgba(255, 185, 0, 0.35);
}
.browser-frame { width: 100%; height: 100%; border: none; background: #fff; }

/* ====== 状态栏 ====== */
#statusbar {
  display: flex;
  align-items: center;
  gap: 0;
  background: linear-gradient(to bottom, #EDEDED, #E0E0E0);
  border-top: 1px solid var(--color-border);
  font-size: 12px;
  color: var(--color-text-muted);
  user-select: none;
}
.status-item {
  padding: 4px 12px;
  border-right: 1px solid var(--color-border);
  white-space: nowrap;
}
.status-item:last-child { border-right: none; flex: 1; text-align: right; }
.status-ok { color: var(--color-success); }
.status-error { color: var(--color-error); font-weight: 600; }

/* 滚动条风格 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #C2C2C2; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #A8A8A8; }
::-webkit-scrollbar-track { background: #F2F2F2; }

/* 书签标记行（源视图用 overlay 表示，这里仅占位） */
.bookmark-line { background: rgba(255,185,0,.15); }
