/* Notepad-- Web —— 仿桌面版布局的浏览器记事本 */

:root {
  --bg: #f3f3f3;
  --panel: #fafafa;
  --panel-2: #eeeeee;
  --border: #d4d4d4;
  --text: #24292f;
  --muted: #6a737d;
  --accent: #1f6feb;
  --accent-soft: rgba(31, 111, 235, .12);
  --hover: rgba(0, 0, 0, .06);
  --active: #cfe3ff;
  --titlebar: #e8edf4;
  --toolbar: #f7f8fa;
  --tabbar: #e4e8ee;
  --tab-active: #ffffff;
  --editor-bg: #ffffff;
  --editor-fg: #1f2328;
  --gutter-bg: #f6f8fa;
  --gutter-fg: #9aa0a6;
  --cm-activeline: rgba(31,111,235,.07);
  --cm-cursor: #1f6feb;
  --sel-bg: #add6ff;
  --shadow: 0 6px 24px rgba(0,0,0,.16);
  --danger: #d1242f;
  --ok: #1a7f37;
  --font-ui: -apple-system, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", Consolas, "SF Mono", Menlo, "Noto Sans Mono CJK SC", monospace;
}

body.dark {
  --bg: #1e1f22;
  --panel: #2b2d30;
  --panel-2: #232528;
  --border: #3c3f44;
  --text: #dfe1e5;
  --muted: #9aa0a6;
  --accent: #539bf5;
  --accent-soft: rgba(83,155,245,.16);
  --hover: rgba(255,255,255,.07);
  --active: #2a4365;
  --titlebar: #17181a;
  --toolbar: #212226;
  --tabbar: #1b1c1f;
  --tab-active: #2b2d30;
  --editor-bg: #222426;
  --editor-fg: #d7dae0;
  --gutter-bg: #26282b;
  --gutter-fg: #7d838b;
  --cm-activeline: rgba(83,155,245,.09);
  --cm-cursor: #539bf5;
  --sel-bg: #264f78;
  --shadow: 0 6px 24px rgba(0,0,0,.5);
  --danger: #f85149;
  --ok: #56d364;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}
button { font-family: inherit; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* 移动/平板浏览器动态视口：避免底部状态栏被地址栏挤出屏幕 */
}

/* ---------- 标题栏 / 菜单 ---------- */
.titlebar {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--titlebar);
  border-bottom: 1px solid var(--border);
  padding: 0 6px;
  height: 34px;
  user-select: none;
}
.app-title { display: flex; align-items: center; gap: 6px; padding: 0 8px; font-size: 13px; }
.app-title img { width: 20px; height: 20px; border-radius: 4px; }
.app-title .sub { color: var(--muted); font-size: 11px; font-weight: normal; }
.menus { display: flex; flex: 1; height: 100%; }
.menu { position: relative; }
.menu-btn {
  background: transparent; border: 0; color: var(--text);
  padding: 0 10px; height: 100%; cursor: pointer; border-radius: 0;
}
.menu-btn:hover, .menu.open > .menu-btn { background: var(--hover); }
.menu-pop {
  position: absolute; top: 32px; left: 0; min-width: 200px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow); padding: 5px; z-index: 200;
  display: none;
}
.menu.open .menu-pop { display: block; }
.menu-pop button {
  display: flex; justify-content: space-between; gap: 24px; width: 100%;
  border: 0; background: transparent; color: var(--text);
  padding: 6px 10px; border-radius: 5px; cursor: pointer; text-align: left;
}
.menu-pop button:hover { background: var(--accent-soft); color: var(--accent); }
.menu-pop button.disabled { opacity: .4; pointer-events: none; }
.menu-pop .mi-sep { height: 1px; background: var(--border); margin: 5px 4px; }
.menu-pop kbd { color: var(--muted); font-family: var(--font-mono); font-size: 11px; }
.titlebar-right { padding: 0 8px; }
.badge {
  font-size: 11px; color: var(--muted); border: 1px solid var(--border);
  background: var(--panel); padding: 2px 8px; border-radius: 20px;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: inline-block; vertical-align: middle;
}

/* ---------- 工具栏 ---------- */
.toolbar {
  display: flex; align-items: center; gap: 2px;
  background: var(--toolbar); border-bottom: 1px solid var(--border);
  padding: 3px 6px; min-height: 34px; user-select: none;
}
.toolbar button, .mini {
  min-width: 28px; height: 26px; padding: 0 6px;
  border: 1px solid transparent; background: transparent;
  color: var(--text); border-radius: 5px; cursor: pointer; font-size: 13px;
}
.toolbar button:hover, .mini:hover { background: var(--hover); border-color: var(--border); }
.toolbar button:disabled { opacity: .35; pointer-events: none; }
.tb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 5px; }

/* ---------- 主体 ---------- */
.main { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 240px; min-width: 160px; resize: horizontal; overflow: hidden;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.panel { display: flex; flex-direction: column; min-height: 0; }
.openfiles { border-bottom: 1px solid var(--border); max-height: 34%; }
.tree { flex: 1; }
.panel-title {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 8px; font-size: 11px; color: var(--muted);
  background: var(--panel-2); border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: .5px;
}
.panel-title .mini { height: 20px; min-width: 20px; font-size: 11px; }
.pt-actions { display: inline-flex; align-items: center; gap: 2px; }
.panel-x { opacity: .8; }
.panel-x:hover { opacity: 1; color: var(--danger); }

/* 左侧面板显隐：隐藏时另一面板自动占满侧栏；都隐藏则收起整条侧栏 */
#sidebar.hide-openfiles .openfiles { display: none; }
#sidebar.hide-tree .tree { display: none; }
#sidebar.hide-tree .openfiles { flex: 1; max-height: none; }
#sidebar.hide-openfiles.hide-tree { display: none; }

#open-list { list-style: none; margin: 0; padding: 2px; overflow-y: auto; }
#open-list li {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 8px; border-radius: 5px; cursor: pointer;
  white-space: nowrap; overflow: hidden;
}
#open-list li:hover { background: var(--hover); }
#open-list li.active { background: var(--active); }
#open-list li .fi { flex: 1; overflow: hidden; text-overflow: ellipsis; }
#open-list li .dirty { color: var(--danger); font-weight: bold; }

.tree-body { flex: 1; overflow: auto; padding: 4px; }
.node { display: flex; align-items: center; white-space: nowrap; border-radius: 5px; }
.node:hover { background: var(--hover); }
.node.selected { background: var(--accent-soft); }
.node > .caret {
  width: 16px; height: 18px; flex: none; text-align: center; cursor: pointer;
  color: var(--muted); font-family: monospace;
}
.node > .icon { flex: none; margin: 0 3px; }
.node > .label {
  flex: 1; overflow: hidden; text-overflow: ellipsis; padding: 2px 4px;
  cursor: pointer; user-select: none;
}
.node > .label:hover { text-decoration: underline; }
.children { margin-left: 16px; }
.tree-root > .node { font-weight: 600; }

/* ---------- 标签页 / 编辑区 ---------- */
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabbar {
  display: flex; align-items: flex-end; background: var(--tabbar);
  border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin;
  min-height: 31px;
}
.tab {
  display: inline-flex; align-items: center; gap: 6px; max-width: 220px;
  padding: 5px 10px; border-right: 1px solid var(--border);
  border-top: 2px solid transparent; cursor: pointer; user-select: none;
  white-space: nowrap; background: transparent; color: var(--muted);
}
.tab .t-name { overflow: hidden; text-overflow: ellipsis; }
.tab:hover { background: var(--hover); }
.tab.active {
  background: var(--tab-active); color: var(--text);
  border-top: 2px solid var(--accent); font-weight: 600;
}
.tab .t-x { font-family: monospace; border-radius: 3px; padding: 0 3px; }
.tab .t-x:hover { background: var(--danger); color: #fff; }
.tab .t-dot { color: var(--danger); font-size: 12px; }
.tab.readonly::after { content: "锁"; font-size: 9px; color: var(--muted); }

.editor-area { flex: 1; position: relative; min-height: 0; background: var(--editor-bg); }
.editor-area .CodeMirror {
  height: 100%; background: var(--editor-bg); color: var(--editor-fg);
  font-family: var(--font-mono); font-size: 14px; line-height: 1.5;
}
.editor-area .CodeMirror-gutters { background: var(--gutter-bg); border-right: 1px solid var(--border); }
.editor-area .CodeMirror-linenumber { color: var(--gutter-fg); }
.editor-area .CodeMirror-activeline-background { background: var(--cm-activeline); }
.editor-area .CodeMirror-cursor { border-left: 2px solid var(--cm-cursor); }
.editor-area .CodeMirror-selected { background: var(--sel-bg); }
.editor-area .CodeMirror-focused .CodeMirror-selected { background: var(--sel-bg); }
.editor-area .CodeMirror-matchingbracket {
  outline: 1px solid var(--muted); background: var(--accent-soft);
}
.editor-area .CodeMirror-foldgutter-open, .editor-area .CodeMirror-foldgutter-folded {
  color: var(--muted); cursor: pointer;
}

/* CodeMirror 简单滚动条（始终可见、触屏可拖动，跟随深浅主题） */
.editor-area .CodeMirror-simplescroll-vertical,
.editor-area .CodeMirror-simplescroll-horizontal {
  background: var(--gutter-bg);
}
.editor-area .CodeMirror-simplescroll-vertical { width: 12px; }
.editor-area .CodeMirror-simplescroll-horizontal { height: 12px; }
.editor-area .CodeMirror-simplescroll-vertical div,
.editor-area .CodeMirror-simplescroll-horizontal div {
  background: var(--gutter-fg);
  border: 0;
  border-radius: 6px;
  opacity: .55;
  transition: opacity .15s;
}
.editor-area .CodeMirror-simplescroll-vertical div:hover,
.editor-area .CodeMirror-simplescroll-horizontal div:hover,
.editor-area .CodeMirror-simplescroll-vertical div:active,
.editor-area .CodeMirror-simplescroll-horizontal div:active {
  opacity: .9;
}
.CodeMirror-search-match {
  background: #ffd33d55; outline: 1px solid #ffd33d;
}
.CodeMirror-search-match.cm-search-match-selected {
  background: #ff8c0055;
}

#cm-host { display: none; }
#empty-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; color: var(--muted);
  text-align: center;
}
.empty-logo {
  width: 74px; height: 74px; border-radius: 16px;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 30px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
}
#empty-hint b { color: var(--accent); }
.dim { font-size: 12px; opacity: .75; }

/* 十六进制视图 */
.hex-view {
  position: absolute; inset: 0; overflow: auto; background: var(--editor-bg);
  font-family: var(--font-mono); font-size: 13px;
}
.hex-head {
  position: sticky; top: 0; background: var(--gutter-bg);
  border-bottom: 1px solid var(--border); padding: 4px 10px;
  display: flex; gap: 10px; align-items: center; z-index: 2;
}
.hex-head button { border: 1px solid var(--border); background: var(--panel); color: var(--text); border-radius: 4px; padding: 2px 8px; cursor: pointer; }
.hex-head button:disabled { opacity: .4; }
.hex-table { border-collapse: collapse; }
.hex-table td, .hex-table th {
  padding: 1px 4px; white-space: pre; font-family: var(--font-mono);
}
.hex-table .addr { color: var(--muted); }
.hex-table .ascii { color: var(--ok); }

/* Markdown 预览 */
.md-preview {
  flex: 1; overflow: auto; padding: 18px 26px; background: var(--editor-bg);
}
.md-preview h1, .md-preview h2 { border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.md-preview pre {
  background: var(--gutter-bg); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 6px; overflow: auto;
  font-family: var(--font-mono); font-size: 13px;
}
.md-preview code { font-family: var(--font-mono); }
.md-preview blockquote { border-left: 4px solid var(--accent); margin-left: 0; padding-left: 12px; color: var(--muted); }
.md-preview table { border-collapse: collapse; }
.md-preview td, .md-preview th { border: 1px solid var(--border); padding: 4px 10px; }
.md-preview img { max-width: 100%; }

/* ---------- 状态栏 ---------- */
#statusbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel-2); border-top: 1px solid var(--border);
  padding: 3px 10px; font-size: 11px; color: var(--muted);
  min-height: 22px; user-select: none;
}
#statusbar .flex { flex: 1; }
#statusbar .msg { color: var(--accent); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 右键菜��� / 弹窗 / 提示 ---------- */
.ctx-menu {
  position: fixed; min-width: 160px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  padding: 5px; z-index: 500;
}
.ctx-menu button {
  display: block; width: 100%; border: 0; background: transparent;
  color: var(--text); text-align: left; padding: 6px 10px; border-radius: 5px; cursor: pointer;
}
.ctx-menu button:hover { background: var(--accent-soft); color: var(--accent); }
.ctx-menu .ctx-sep { height: 1px; background: var(--border); margin: 5px 4px; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 900;
}
.modal {
  width: 460px; max-width: 92vw; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-title { padding: 10px 14px; font-weight: 700; background: var(--panel-2); border-bottom: 1px solid var(--border); }
.modal-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.modal-body label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.modal-body input, .modal-body select {
  border: 1px solid var(--border); background: var(--editor-bg); color: var(--text);
  padding: 6px 8px; border-radius: 6px; font-family: var(--font-mono); font-size: 13px;
}
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); }
.modal-foot button {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 5px 14px; border-radius: 6px; cursor: pointer;
}
.modal-foot button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.modal-foot button.danger { color: var(--danger); }
.modal-foot button:disabled { opacity: .5; }
.modal .hint { font-size: 11px; color: var(--muted); }

#toasts { position: fixed; right: 12px; top: 44px; display: flex; flex-direction: column; gap: 6px; z-index: 1000; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  padding: 8px 12px; border-radius: 8px; box-shadow: var(--shadow);
  max-width: 340px; font-size: 12px;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }

kbd {
  font-family: var(--font-mono); background: var(--panel-2);
  border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 4px; font-size: 11px;
}

/* CodeMirror 对话框（查找/替换）深色适配 */
body.dark .CodeMirror-dialog { background: var(--toolbar); color: var(--text); }
body.dark .CodeMirror-dialog input { color: var(--text); }
body.dark .CodeMirror-dialog-top button { color: var(--text); background: transparent; border: 0; cursor: pointer; }

/* 通用小类 */
.flex { flex: 1; }
.dim { opacity: .75; }
.echip {
  display: inline-block; flex: none; min-width: 27px; text-align: center;
  color: #fff; font-size: 9px; font-weight: 700; line-height: 15px;
  border-radius: 4px; padding: 0 2px; font-family: var(--font-mono);
  margin-right: 4px; letter-spacing: .5px;
}
.node .icon { flex: none; margin: 0 3px; font-size: 13px; }
.tree-root > .children { margin-left: 10px; }

/* ---------- 纯静态部署（无后端，如 Cloudflare Pages） ---------- */
body.ndd-static #sidebar { display: none; }
body.ndd-static #toolbar [data-act="refreshTree"] { display: none; }
body.ndd-static .ndd-static-guide { color: var(--muted); margin-top: 6px; }
body.ndd-static .ndd-static-guide b { color: var(--accent); }
