/* ============================================================
   备忘录 · 样式
   浅色 / 深色自动跟随系统，移动端单列 + 抽屉式编辑区
   ============================================================ */

:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --border: #e3e7ef;
  --text: #1e2430;
  --muted: #6b7583;
  --accent: #3b6cf6;
  --accent-soft: #eaf0ff;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(18, 25, 40, .06), 0 8px 24px rgba(18, 25, 40, .05);
  --radius: 12px;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --panel: #191d24;
    --panel-2: #1e232b;
    --border: #2a3039;
    --text: #e6eaf1;
    --muted: #8c96a5;
    --accent: #6b93ff;
    --accent-soft: #1d2740;
    --danger: #ff6b6b;
    --danger-soft: #2a1a1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
        "PingFang SC", "Hiragino Sans GB", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }

#app {
  display: flex;
  height: 100dvh;
}

/* ------------------------------------------------------------ 左侧栏 */

#sidebar {
  width: 330px;
  flex: 0 0 330px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 10px;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .5px;
}
.brand .dot { color: var(--accent); }

.search-wrap { padding: 0 16px 10px; }

#search {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* 标签栏 */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 10px;
  max-height: 104px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
}
.tags:empty { display: none; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  user-select: none;
}
.tag:hover { color: var(--text); border-color: var(--accent); }
.tag.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
.tag .num { opacity: .6; font-size: 11px; }

/* 列表 */
.list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px;
  min-height: 0;
}

.item {
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .12s, border-color .12s;
}
.item:hover { background: var(--panel-2); }
.item.active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.item-top {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.item-title {
  font-weight: 600;
  font-size: 14px;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-time {
  font-size: 11px;
  color: var(--muted);
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
.item-preview {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.item-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 5px;
}
.chip {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.item .pin-flag { font-size: 11px; opacity: .85; }

.list-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.9;
}

/* 底栏 */
.side-foot {
  display: flex;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.side-foot .btn { flex: 1 1 0; }

.pill {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  font-size: 11px;
  line-height: 17px;
  text-align: center;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.btn.active-ghost {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ------------------------------------------------------------ 按钮 */

.btn {
  font: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.07); color: #fff; }

.btn.ghost { background: transparent; }
.btn.icon { padding: 7px 9px; font-size: 14px; line-height: 1; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ------------------------------------------------------------ 编辑区 */

#editor {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

.empty-state {
  margin: auto;
  padding: 40px 28px;
  text-align: center;
  color: var(--muted);
  max-width: 460px;
}
.empty-icon { font-size: 46px; line-height: 1; margin-bottom: 14px; }
.empty-state h2 { margin: 0 0 8px; font-size: 17px; color: var(--text); font-weight: 600; }
.empty-state p { margin: 6px 0; font-size: 13.5px; }
.empty-state .hint { font-size: 12.5px; opacity: .8; margin-top: 18px; }
.empty-state code {
  font-family: var(--mono);
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

#editor-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
}

.ed-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 8px;
}

#title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 19px;
  font-weight: 650;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  outline: none;
}
#title:hover { border-color: var(--border); }
#title:focus { border-color: var(--accent); background: var(--panel-2); }

.ed-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.ed-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px 8px;
}

#tags-input {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12.5px;
  padding: 6px 10px;
  border: 1px dashed var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  outline: none;
}
#tags-input:focus { border-style: solid; border-color: var(--accent); }

.status {
  font-size: 12px;
  color: var(--muted);
  flex: 0 0 auto;
  min-width: 62px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.status.ok { color: #2f9e63; }
.status.err { color: var(--danger); }

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 16px 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent);
  border-radius: 9px;
}
.banner span { flex: 1 1 auto; }

#body {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  padding: 4px 18px 20px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  line-height: 1.75;
  resize: none;
  outline: none;
  font-family: inherit;
}
#body[readonly] { color: var(--muted); }

.preview {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 20px 24px;
  font-size: 15px;
  line-height: 1.78;
  word-break: break-word;
}
.preview h1, .preview h2, .preview h3,
.preview h4, .preview h5, .preview h6 {
  margin: 1.1em 0 .5em;
  line-height: 1.35;
  font-weight: 650;
}
.preview h1 { font-size: 1.5em; }
.preview h2 { font-size: 1.3em; }
.preview h3 { font-size: 1.12em; }
.preview p { margin: .6em 0; }
.preview ul, .preview ol { margin: .6em 0; padding-left: 1.5em; }
.preview li { margin: .2em 0; }
.preview blockquote {
  margin: .7em 0;
  padding: .1em 0 .1em 12px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
.preview code {
  font-family: var(--mono);
  font-size: .88em;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.preview pre {
  padding: 12px 14px;
  overflow-x: auto;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.preview pre code { padding: 0; border: none; background: none; }
.preview a { color: var(--accent); }
.preview hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
.preview img { max-width: 100%; border-radius: 8px; }
.preview table { border-collapse: collapse; }
.preview th, .preview td {
  border: 1px solid var(--border);
  padding: 5px 10px;
}
.preview .preview-empty { color: var(--muted); font-style: italic; }

.ed-foot {
  flex: 0 0 auto;
  padding: 6px 18px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11.5px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.meta-time { font-variant-numeric: tabular-nums; }
.meta-count { flex: 0 0 auto; opacity: .85; font-variant-numeric: tabular-nums; }

.only-mobile { display: none; }

/* 滚动条 */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* ------------------------------------------------------------ 移动端 */

@media (max-width: 780px) {
  #sidebar {
    width: 100%;
    flex: 1 1 auto;
    border-right: none;
  }

  #editor {
    position: fixed;
    inset: 0;
    z-index: 20;
    transform: translateX(102%);
    transition: transform .22s cubic-bezier(.4, 0, .2, 1);
    will-change: transform;
  }
  body.mobile-open #editor { transform: translateX(0); }

  .only-mobile { display: inline-flex; }

  .ed-head { padding: 10px 10px 6px; gap: 6px; }
  #title { font-size: 17px; }
  .ed-meta { padding: 0 12px 8px; }
  .banner { margin: 0 12px 8px; }
  #body { padding: 4px 14px 16px; }
  .preview { padding: 4px 16px 20px; }
  .side-head { padding: 12px 14px 8px; }
  .search-wrap, .tags { padding-left: 14px; padding-right: 14px; }
}
