/* ============================================================
   Notes App — global stylesheet
   PC + 移动端响应式；模仿华为备忘录视觉风格
   ============================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI",
               Helvetica, Arial, sans-serif;
  color: #1f2329;
  background: #f4f6f9;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: #2c6df1; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

.btn-primary {
  background: linear-gradient(135deg, #2c6df1, #1f57c9);
  color: #fff; border: none;
  padding: 10px 20px; border-radius: 8px;
  font-size: 14px; font-weight: 500;
  transition: transform .1s ease, box-shadow .2s ease;
}
.btn-primary:hover { box-shadow: 0 4px 12px rgba(44,109,241,.3); }
.btn-primary:active { transform: scale(.97); }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.alert.err { background: #ffefef; color: #c0392b; border: 1px solid #f4c7c7; }
.alert.ok  { background: #eaf7ef; color: #1f8a4c; border: 1px solid #c8e6d2; }

/* ====== Auth pages ====== */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background: linear-gradient(135deg, #e8f1ff 0%, #f4f6f9 100%);
}
.auth-card {
  width: 100%; max-width: 380px;
  background: #fff; border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 10px 40px rgba(0,0,0,.06);
}
.auth-card h1 { margin: 0; font-size: 24px; }
.auth-card .sub { color: #888; margin: 4px 0 22px; font-size: 13px; }
.auth-card label { display: block; font-size: 13px; color: #666; margin: 12px 0 6px; }
.auth-card input { width: 100%; padding: 11px 14px; border: 1px solid #dde2ea; border-radius: 8px; font-size: 14px; }
.auth-card input:focus { outline: none; border-color: #2c6df1; box-shadow: 0 0 0 3px rgba(44,109,241,.12); }
.auth-card .btn-primary { width: 100%; margin-top: 22px; padding: 12px; }
.auth-card .readonly { background: #f3f5f9; padding: 10px 14px; border-radius: 8px; color: #555; font-size: 14px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 16px; font-size: 13px; }

/* ====== Main app layout ====== */
.app-page { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 260px; flex: 0 0 260px;
  background: #fff; border-right: 1px solid #eaecf2;
  display: flex; flex-direction: column;
  transition: transform .25s ease;
}
.user-box {
  display: flex; gap: 10px; align-items: center;
  padding: 18px 18px 12px;
  border-bottom: 1px solid #f0f2f5;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, #2c6df1, #6db1ff);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 18px;
}
.username { font-weight: 600; font-size: 14px; }
.vip { font-size: 11px; color: #c98a16; }

.nav { padding: 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 8px; color: #333; font-size: 14px;
  transition: background .15s ease;
}
.nav-item:hover { background: #f3f5f9; }
.nav-item.active { background: rgba(44,109,241,.10); color: #2c6df1; font-weight: 500; }
.ic { width: 20px; display: inline-block; text-align: center; }

.cat-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px 6px; font-size: 12px; color: #888; text-transform: uppercase;
}
.cat-head button {
  background: none; border: none; color: #2c6df1; font-size: 18px; cursor: pointer;
}
.cat-tree {
  list-style: none; margin: 0; padding: 0 6px;
  flex: 1; overflow-y: auto;
}
.cat-tree li { position: relative; }
.cat-tree .cat-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px; border-radius: 8px; font-size: 14px; color: #333; cursor: pointer;
}
.cat-tree .cat-row:hover { background: #f3f5f9; }
.cat-tree .cat-row.active { background: rgba(44,109,241,.10); color: #2c6df1; }
.cat-tree .cat-actions { display: none; gap: 6px; }
.cat-tree .cat-row:hover .cat-actions { display: flex; }
.cat-tree .cat-actions button { background: transparent; border: none; color: #888; font-size: 14px; }

.storage { padding: 14px 18px; font-size: 12px; color: #666; border-top: 1px solid #f0f2f5; }
.storage .bar { height: 4px; border-radius: 2px; background: #eef0f4; margin-top: 6px; overflow: hidden; }
.storage .bar > div { height: 100%; background: linear-gradient(90deg, #2c6df1, #6db1ff); width: 0; transition: width .3s ease; }
.vip-link { display: inline-block; margin-top: 6px; color: #c98a16; }

.sidebar-foot { padding: 12px 18px; border-top: 1px solid #f0f2f5; font-size: 13px; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px;
  background: #fff; border-bottom: 1px solid #eaecf2;
}
.menu-btn {
  background: none; border: none; font-size: 22px; padding: 4px 10px; cursor: pointer;
  border-radius: 8px;
  color: #333;
}
.menu-btn:hover { background: #f3f5f9; color: #2c6df1; }
.menu-btn[hidden] { display: none !important; }

/* PC: collapse the sidebar entirely when the user clicks ☰. */
body.sidebar-collapsed .sidebar { display: none; }
.search-back {
  background: none; border: none; cursor: pointer;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #333; border-radius: 8px;
}
.search-back[hidden] { display: none; }
.search-back:hover { background: #f3f5f9; color: #2c6df1; }
.search { flex: 1; }
.search input {
  width: 100%; padding: 10px 14px;
  background: #f3f5f9; border: 1px solid transparent; border-radius: 22px;
  font-size: 14px;
}
.search input:focus { outline: none; background: #fff; border-color: #2c6df1; }
.topbar .btn-primary { padding: 9px 16px; font-size: 14px; }

.note-list-wrap { flex: 1; overflow-y: auto; padding: 12px 18px 60px; }
.note-list { list-style: none; margin: 0; padding: 0; }

.search-info {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; margin-bottom: 10px;
  background: #eef4ff; color: #2c4a7c;
  border-radius: 8px; font-size: 13px;
}
.search-info[hidden] { display: none; }
.search-info b { color: #2c6df1; font-weight: 600; }
.search-info .kw { color: #888; }
.search-info .none { color: #c0392b; font-weight: 500; }

/* Each note: container holds the swipe wrapper + revealed actions */
.note-item {
  position: relative;
  margin-bottom: 10px;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  touch-action: pan-y;
}
.note-item .actions-pane {
  position: absolute; top: 0; right: 0; height: 100%;
  display: flex; align-items: stretch;
  pointer-events: none;
}
.note-item .actions-pane .act {
  width: 64px; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: none; color: #fff; font-size: 12px;
  pointer-events: auto;
}
.note-item .actions-pane .act .glyph { font-size: 18px; margin-bottom: 4px; }
.act-pin    { background: #f1a626; }
.act-star   { background: #6c7bf2; }
.act-cat    { background: #4ab2b0; }
.act-restore{ background: #3aa76d; }
.act-delete { background: #e74c3c; }

.note-item .swipe-pane {
  position: relative;
  background: #fff;
  padding: 14px 16px;
  transition: transform .25s ease;
  z-index: 1;
}
.note-item.swiped .swipe-pane { transform: translateX(-256px); }
.note-item.swiped-2 .swipe-pane { transform: translateX(-192px); } /* fewer actions when needed */
/* 垃圾箱/回收站只有恢复+删除两个按钮，缩短滑动距离避免拉出空白。 */
.note-item.two-actions.swiped .swipe-pane { transform: translateX(-128px); }

/* PC hover-reveal action bar (pin / star / move / delete).
   Hidden by default; visible when the note row is hovered. Mobile uses
   the swipe gesture instead, so we hide it in the media query below. */
.row-actions {
  position: absolute;
  top: 50%; right: 12px;
  transform: translateY(-50%);
  display: none;
  gap: 2px;
  padding: 4px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.10);
  z-index: 2;
}
.note-item:hover .row-actions { display: flex; }
.row-actions .ra {
  background: transparent; border: none; cursor: pointer;
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px;
  font-size: 20px; line-height: 1;
  color: #555;
  transition: background .12s ease, color .12s ease;
}
.row-actions .ra:hover { background: #f3f5f9; }
.row-actions .ra[data-act="del"]:hover { background: #fdecea; color: #c0392b; }
.row-actions .ra[data-act="pin"]:hover  { background: #fff4e0; }
.row-actions .ra[data-act="star"]:hover { background: #fff7e2; }
.row-actions .ra[data-act="cat"]:hover  { background: #e6f4f3; }
.row-actions .ra[data-act="restore"]:hover { background: #e6f7ee; color: #1f8a4c; }

/* 轻量底部 toast — 用于恢复、移动等不需要弹窗的反馈。 */
.toast {
  position: fixed;
  left: 50%; bottom: 36px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(40, 44, 52, .92);
  color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 22px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.note-title {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 15px; margin-bottom: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.note-flag { font-size: 12px; }
/* 已收藏：实心星显示黄色（未收藏的空心星保持默认色） */
.act-star.on .glyph,
.ra.on[data-act="star"] { color: #f5c518; }
.note-preview {
  color: #6b7180; font-size: 13px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.note-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 8px; font-size: 11px; color: #9aa0aa;
}

.loader { text-align: center; padding: 14px; color: #888; font-size: 13px; }
.empty  { text-align: center; padding: 60px 14px; color: #aaa; font-size: 14px; }

/* Editor modal */
.editor-modal {
  position: fixed; inset: 0;
  background: #fff; z-index: 50;
  display: flex; flex-direction: column;
}
.editor-modal[hidden] { display: none; }
.editor-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-bottom: 1px solid #eaecf2;
}
.editor-bar .back { background: none; border: none; font-size: 22px; padding: 0 6px; cursor: pointer; }
.editor-bar select { padding: 6px 10px; border: 1px solid #dde2ea; border-radius: 6px; background: #fff; }
.editor-bar .grow { flex: 1; }
.editor-bar button { background: transparent; border: none; padding: 8px 10px; font-size: 18px; cursor: pointer; border-radius: 6px; }
.editor-bar button:hover { background: #f3f5f9; }
.editor-bar .btn-primary { background: #2c6df1; color: #fff; font-size: 14px; padding: 8px 16px; }
.editor-bar .btn-primary:hover { background: #245fd6; }
.editor-bar .icon-btn { display: inline-flex; align-items: center; justify-content: center; color: #555; }
.editor-bar .icon-btn .ic-lock   { color: #e74c3c; }   /* 已加密 → 红色锁 */
.editor-bar .icon-btn .ic-unlock { color: #888; }     /* 未加密 → 灰色开锁 */

.edit-title {
  border: none; outline: none; padding: 16px 24px 6px; font-size: 22px; font-weight: 600;
  width: 100%; box-sizing: border-box;
  background: transparent;
  font-family: inherit; line-height: 1.4;
  resize: none; overflow: hidden;
  display: block;
  min-height: 2.4em; /* 保底高度 —— 即使 JS 没设 height 也能看到一行 */
}
.edit-title-wrap { position: relative; }
/* Editor title now always shows the full text; the legacy mask overlay
   is kept in the DOM but never displayed. Truncation moved to the
   note list (see truncateTitle in app.js). */
.edit-title-mask { display: none !important; }
.toolbar {
  display: flex; gap: 4px; padding: 0 24px 8px;
  align-items: center;
}
.toolbar button {
  background: #f3f5f9; border: none; padding: 6px 12px; border-radius: 6px;
  font-size: 13px; cursor: pointer;
}
.toolbar button:hover { background: #e6e9ef; }
.toolbar .tb-sep {
  display: inline-block; width: 1px; height: 18px;
  background: #dde2ea; margin: 0 6px;
}
.toolbar .tb-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 30px; padding: 0;
  color: #555;
}
.toolbar .tb-icon:hover { color: #2c6df1; background: #eaf1ff; }
.toolbar .tb-icon svg { display: block; }
.edit-body {
  flex: 1; padding: 6px 24px 60px; outline: none; font-size: 15px; line-height: 1.7;
  overflow-y: auto;
}
.edit-body img, .edit-body video { max-width: 100%; border-radius: 6px; }

/* Generic modal */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.4); z-index: 60;
}
.modal[hidden] { display: none; }
.modal-body {
  width: 92%; max-width: 360px;
  background: #fff; border-radius: 14px; padding: 22px;
}
.modal-body h3 { margin: 0 0 12px; }
.modal-body input { width: 100%; padding: 11px 14px; border: 1px solid #dde2ea; border-radius: 8px; box-sizing: border-box; }
.modal-body .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal-body .actions button { padding: 9px 18px; border-radius: 8px; border: 1px solid #dde2ea; background: #fff; }
.modal-body .actions .btn-primary { background: #2c6df1; color: #fff; border-color: #2c6df1; }

/* Floating Action Button — visible on mobile only by default. */
.fab {
  display: none;
  position: fixed;
  right: 18px; bottom: 24px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2c6df1, #4a8af6);
  color: #fff; border: none;
  box-shadow: 0 6px 20px rgba(44,109,241,.4);
  align-items: center; justify-content: center;
  z-index: 30;
  cursor: pointer;
  touch-action: none; /* prevent page scroll while dragging the FAB */
  user-select: none; -webkit-user-select: none;
  transition: transform .15s ease, box-shadow .2s ease;
}
.fab:active { transform: scale(.94); }
.fab.dragging { transition: none; box-shadow: 0 10px 28px rgba(44,109,241,.55); }
.fab svg { display: block; }
.vip-page { padding: 30px; min-height: 100vh; background: linear-gradient(135deg, #fffaf2, #f4f6f9); }
.vip-wrap { max-width: 980px; margin: 0 auto; }
.vip-wrap h1 { margin: 16px 0 6px; }
.vip-wrap .sub { color: #888; }
.vip-wrap .back { color: #2c6df1; font-size: 14px; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; margin-top: 24px; }
.plan {
  background: #fff; padding: 28px 22px; border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.06); border: 1px solid #f0e0c8;
}
.plan h3 { margin: 0 0 6px; color: #b8771c; }
.plan .price { font-size: 28px; font-weight: 700; color: #2c6df1; margin: 10px 0; }
.plan ul { list-style: none; padding: 0; margin: 0 0 16px; font-size: 13px; color: #555; }
.plan ul li { padding: 5px 0; border-bottom: 1px dashed #eee; }
.plan .btn-primary { width: 100%; padding: 11px; }
.vip-tip { margin-top: 30px; color: #888; font-size: 12px; text-align: center; }

/* ====== Responsive: mobile ====== */
@media (max-width: 760px) {
  /* Searching on mobile: only the back arrow + search box remain visible. */
  body.searching .topbar #newNote { display: none; }
  /* Mobile uses a floating action button for new notes; hide the inline one. */
  .topbar #newNote { display: none; }
  .fab { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100%; z-index: 40;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,.12);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mask {
    position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 35;
    display: none;
  }
  .sidebar-mask.show { display: block; }
  .topbar { padding: 10px 12px; }
  .note-list-wrap { padding: 10px 12px 60px; }
  .edit-title {
    padding: 12px 16px 4px;
    font-size: 19px;
    /* 手机端：标题自适应屏幕宽度，超出可视区域时自动换行。 */
    white-space: pre-wrap;
    word-break: break-word;
  }
  .toolbar { padding: 0 16px 6px; overflow-x: auto; }
  .edit-body { padding: 4px 16px 50px; }
  /* On mobile, deletion is via swipe — hide PC hover bar entirely. */
  .row-actions { display: none !important; }
}
