* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #14171c;
  --panel: #1c2027;
  --panel2: #232834;
  --border: #2b313d;
  --text: #e2e6ee;
  --muted: #8b93a3;
  --accent: #6c9ef8;
  --danger: #e0707a;
}
body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
}
.hidden { display: none !important; }
.view { height: 100vh; }

/* ---------- 登录 ---------- */
#view-login { display: flex; align-items: center; justify-content: center; }
.login-box {
  width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 30px;
  text-align: center;
}
.login-box h1 { font-size: 22px; font-weight: 600; letter-spacing: 1px; margin-bottom: 6px; }
.login-box .sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-box input {
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}
.login-box button:hover { filter: brightness(1.1); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ---------- 主界面 ---------- */
#view-app { display: grid; grid-template-columns: 260px 1fr; }
aside { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 14px 10px; }
.logo { font-weight: 600; font-size: 15px; }
#btn-logout { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; }
#btn-logout:hover { color: var(--text); }
#btn-new {
  margin: 4px 14px 12px;
  padding: 9px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
#note-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.note-item {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.note-item:hover { background: var(--panel2); color: var(--text); }
.note-item.active { background: var(--panel2); color: var(--accent); }
.note-item-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-item-time { font-size: 11px; opacity: 0.65; margin-top: 2px; }

main { display: flex; flex-direction: column; padding: 18px 26px 0; min-width: 0; }
.editor-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
#note-title {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 19px;
  padding: 8px 2px;
  outline: none;
}
#save-status { color: var(--muted); font-size: 12px; white-space: nowrap; }
#note-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
#btn-save {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 16px;
  cursor: pointer;
  font-size: 13px;
}
#btn-save:hover { filter: brightness(1.1); }
#btn-delete {
  background: none;
  border: 1px solid var(--border);
  color: var(--danger);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12.5px;
}
#btn-delete:hover { border-color: var(--danger); }
#note-content {
  flex: 1;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.7;
  padding: 16px;
  resize: none;
  outline: none;
  font-family: inherit;
}

/* ---------- 编辑/预览切换 ---------- */
.mode-switch { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.mode-switch button {
  background: none;
  border: none;
  color: var(--muted);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12.5px;
}
.mode-switch button.active { background: var(--panel2); color: var(--accent); }

/* ---------- Markdown 预览 ---------- */
#note-preview {
  flex: 1;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  font-size: 14.5px;
  line-height: 1.8;
}
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 14px 0 8px; line-height: 1.4; }
.markdown h1 { font-size: 20px; }
.markdown h2 { font-size: 17px; }
.markdown h3 { font-size: 15px; }
.markdown h4 { font-size: 14px; }
.markdown p { margin: 8px 0; }
.markdown ul, .markdown ol { padding-left: 22px; margin: 8px 0; }
.markdown blockquote {
  border-left: 3px solid var(--accent);
  color: var(--muted);
  padding: 2px 12px;
  margin: 10px 0;
}
.markdown code {
  background: var(--panel2);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}
.markdown pre {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}
.markdown pre code { background: none; padding: 0; }
.markdown img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 6px 0;
  cursor: pointer;
}
.markdown a { color: var(--accent); }
.markdown table { border-collapse: collapse; margin: 10px 0; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 12px; }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.img-bar { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
#btn-image {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
}
#btn-image:hover { border-color: var(--accent); }
.hint { color: var(--muted); font-size: 12px; }
#gallery { display: flex; flex-wrap: wrap; gap: 12px; padding: 4px 0 18px; }
.img-wrap { position: relative; }
.img-wrap img { height: 84px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.img-wrap button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  line-height: 20px;
  cursor: pointer;
  padding: 0;
}

/* ---------- 表格块网格 ---------- */
.tbl-block { margin: 12px 0; overflow-x: auto; }
.grid-table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.grid-table th, .grid-table td { border: 1px solid var(--border); padding: 6px 10px; min-width: 48px; text-align: left; }
.grid-table th { background: var(--panel2); font-weight: 600; }
.grid-table th[contenteditable="true"], .grid-table td[contenteditable="true"] { outline: none; }
.grid-table th:focus, .grid-table td:focus { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 2px; }
.grid-table .row-del { border: none; width: 20px; padding: 0; color: var(--muted); cursor: pointer; opacity: 0; text-align: center; }
.grid-table tr:hover .row-del { opacity: 1; }
.grid-table .row-del:hover { color: #e5484d; }
.grid-bar { margin-top: 4px; display: flex; gap: 6px; }
.grid-bar button { font-size: 12px; padding: 2px 10px; background: var(--panel); border: 1px solid var(--border); color: var(--muted); border-radius: 6px; cursor: pointer; }
.grid-bar button:hover { color: var(--text); border-color: var(--accent); }

/* ---------- 表格右键菜单 ---------- */
#grid-menu {
  position: fixed;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  min-width: 130px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
#grid-menu button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
}
#grid-menu button:hover { background: var(--panel2); }
#grid-menu button.danger { color: #e5484d; }
#grid-menu .menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* ---------- 修改密码弹窗 ---------- */
.dialog-title { font-size: 20px; margin: 0 0 4px; }
.dialog-btns { display: flex; gap: 10px; margin-top: 4px; }
.dialog-btns button { flex: 1; }
#btn-passwd { margin-right: 6px; }

/* ---------- 移动端抽屉控件（桌面隐藏） ---------- */
#btn-menu, #btn-side-close, #side-mask { display: none; }
#btn-menu {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
#btn-side-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
}
#side-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 40;
}

/* ---------- 移动端适配 ---------- */
@media (max-width: 720px) {
  body, .view { height: 100dvh; }
  #view-app { display: block; }

  /* 侧栏 → 滑出抽屉 */
  aside {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(78vw, 300px);
    z-index: 50;
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }
  #view-app.sidebar-open aside { transform: translateX(0); }
  #side-mask { display: block; }
  #btn-menu { display: inline-block; }
  #btn-side-close { display: inline-block; }

  /* 登录/弹窗占满小屏 */
  .login-box {
    width: min(340px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
  }

  /* 编辑区收紧（main 需显式占满视口，否则编辑框 flex:1 无约束会塌成默认两行高） */
  main { padding: 10px 12px 0; height: 100dvh; }
  .editor-head { flex-wrap: wrap; gap: 8px; row-gap: 6px; }
  #note-title { font-size: 17px; min-width: 0; flex: 1 1 120px; }
  #note-meta { display: none; }          /* 空间不足，创建时间只在列表里看 */
  #btn-save { padding: 8px 18px; }
  .mode-switch button { padding: 8px 14px; }
  #btn-delete { padding: 7px 12px; }
  #note-content, #note-preview { padding: 12px; font-size: 15px; }

  /* 触控目标加大 */
  .note-item { padding: 12px 12px; }
  #btn-image, #btn-table { padding: 9px 14px; }
  .img-bar { flex-wrap: wrap; gap: 8px; }
  .hint { display: none; }               /* 小屏提示语省略 */

  /* 预览内容与表格 */
  .markdown { word-break: break-word; }
  .markdown pre { font-size: 12.5px; }
  .grid-table th, .grid-table td { padding: 8px 10px; }

  /* 右键菜单在触屏上也能触发（长按），菜单项加大 */
  #grid-menu button { padding: 11px 14px; font-size: 14px; }
}
