/* 简易记事本 - 样式（从 index.html 外置，配合 CSP style-src 'self'） */

  :root {
    --bg: #f2f4f8;
    --card: #ffffff;
    --text: #1f2430;
    --text-light: #8a91a5;
    --accent: #4f6ef2;
    --accent-dark: #3b56d9;
    --danger: #e5484d;
    --border: #e4e8f0;
    --radius: 14px;
    --shadow: 0 2px 10px rgba(31, 36, 48, .06);
    --shadow-lg: 0 8px 28px rgba(31, 36, 48, .10);
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  html, body { height: 100%; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }
  button { font-family: inherit; cursor: pointer; }
  [hidden] { display: none !important; }

  .container {
    max-width: 780px;
    margin: 0 auto;
    padding: 0 16px 48px;
  }

  /* ---------- 顶部栏 ---------- */
  header {
    position: sticky; top: 0; z-index: 10;
    background: rgba(242, 244, 248, .92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
  }
  .header-inner {
    max-width: 780px; margin: 0 auto;
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
  }
  .search-row {
    max-width: 780px; margin: 0 auto;
    padding: 0 16px 12px;
  }
  .search-box {
    display: flex; align-items: center; gap: 8px;
    background: #fff; border: 1px solid var(--border);
    border-radius: 10px; padding: 8px 12px;
    transition: border-color .15s, box-shadow .15s;
  }
  .search-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 110, 242, .12);
  }
  .search-icon { font-size: 14px; opacity: .6; }
  .search-box input {
    flex: 1; border: none; outline: none; background: transparent;
    font-size: 14px; font-family: inherit; color: var(--text);
    min-width: 0;
  }
  .search-box input::placeholder { color: #b3b9c9; }
  .search-clear {
    background: none; border: none; color: var(--text-light);
    font-size: 13px; padding: 2px 6px; border-radius: 6px;
  }
  .search-clear:hover { color: var(--danger); background: #fdecec; }
  .logo { font-size: 18px; font-weight: 700; letter-spacing: .5px; }
  .logo .logo-main { color: var(--accent); }
  .spacer { flex: 1; }
  .user-chip {
    font-size: 13px; color: var(--text-light);
    background: #fff; border: 1px solid var(--border);
    padding: 5px 12px; border-radius: 999px;
    max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .btn-logout {
    font-size: 13px; color: var(--text-light); background: none;
    border: none; padding: 6px 10px; border-radius: 8px;
  }
  .btn-logout:hover { color: var(--danger); background: #fdecec; }

  /* ---------- 编辑区 ---------- */
  .editor {
    margin-top: 20px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  .editor textarea {
    width: 100%; min-height: 150px;
    border: none; outline: none; resize: vertical;
    padding: 16px;
    font-size: 15px; font-family: inherit; line-height: 1.7;
    color: var(--text);
    background: transparent;
  }
  .editor textarea::placeholder { color: #b3b9c9; }
  .editor-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: #fafbfe;
  }
  .edit-hint {
    font-size: 13px; color: var(--accent);
    display: flex; align-items: center; gap: 6px;
  }
  .edit-hint .cancel {
    background: none; border: none; color: var(--text-light);
    font-size: 13px; padding: 2px 6px; border-radius: 6px;
  }
  .edit-hint .cancel:hover { color: var(--danger); }
  .draft-hint {
    font-size: 13px; color: #b25e00;
    display: flex; align-items: center; gap: 6px;
  }
  .draft-hint .draft-discard {
    background: #fff2dc; border: 1px solid #f0d9a8;
    color: #b25e00; font-size: 12px;
    padding: 2px 10px; border-radius: 999px;
    transition: background .15s;
  }
  .draft-hint .draft-discard:hover { background: #ffe3b3; }
  .spacer { flex: 1; }
  .btn-save {
    background: var(--accent); color: #fff;
    border: none; border-radius: 10px;
    padding: 10px 26px; font-size: 15px; font-weight: 600;
    transition: background .15s, transform .05s;
  }
  .btn-save:hover { background: var(--accent-dark); }
  .btn-save:active { transform: scale(.97); }
  .btn-save:disabled { opacity: .6; cursor: not-allowed; }

  .toast {
    position: fixed; top: 16px; left: 50%; transform: translateX(-50%) translateY(-8px);
    background: #1f2430; color: #fff; font-size: 14px;
    padding: 10px 20px; border-radius: 10px;
    box-shadow: var(--shadow-lg); opacity: 0; transition: all .25s;
    z-index: 100; pointer-events: none;
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

  /* ---------- 列表区 ---------- */
  .list-head {
    margin: 28px 2px 12px;
    font-size: 13px; font-weight: 600; color: var(--text-light);
    letter-spacing: 1px; text-transform: uppercase;
  }
  .list { display: flex; flex-direction: column; gap: 14px; }

  .note-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 16px 12px;
    animation: fadeUp .3s ease;
  }
  @keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .note-head {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 10px;
  }
  .note-time {
    font-size: 12px; color: var(--text-light);
    display: flex; align-items: center; gap: 5px;
    white-space: nowrap;      /* 日期单行显示，不换行 */
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .note-time .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .6; }
  .note-head .spacer { flex: 1; }
  .btn-icon {
    background: none; border: none;
    font-size: 13px; padding: 4px 10px; border-radius: 8px;
    color: var(--text-light); transition: all .15s;
    flex-shrink: 0;
  }
  .btn-icon.edit:hover { color: var(--accent); background: #eef1fe; }
  .btn-icon.del:hover  { color: var(--danger); background: #fdecec; }

  .note-body {
    font-size: 14.5px; color: var(--text);
    word-break: break-word;
  }
  .note-body.markdown { padding: 2px 0 6px; }
  .note-body.markdown > :first-child { margin-top: 0; }
  .note-body.markdown > :last-child { margin-bottom: 0; }
  .note-body.markdown h1, .note-body.markdown h2, .note-body.markdown h3,
  .note-body.markdown h4, .note-body.markdown h5, .note-body.markdown h6 {
    margin: .8em 0 .4em; line-height: 1.35;
  }
  .note-body.markdown h1 { font-size: 1.4em; }
  .note-body.markdown h2 { font-size: 1.25em; }
  .note-body.markdown h3 { font-size: 1.1em; }
  .note-body.markdown p { margin: .5em 0; }
  .note-body.markdown ul, .note-body.markdown ol { margin: .5em 0; padding-left: 1.6em; }
  .note-body.markdown code {
    background: #eef1f6; border-radius: 5px;
    padding: .15em .4em; font-size: .92em;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  }
  .note-body.markdown pre {
    background: #f6f7fb; border: 1px solid var(--border);
    border-radius: 10px; padding: 12px; overflow-x: auto; margin: .6em 0;
  }
  .note-body.markdown pre code { background: none; padding: 0; }
  .note-body.markdown blockquote {
    border-left: 3px solid var(--accent);
    margin: .6em 0; padding: 2px 12px; color: var(--text-light);
    background: #f6f7fb; border-radius: 0 8px 8px 0;
  }
  .note-body.markdown img { max-width: 100%; border-radius: 8px; }
  .note-body.markdown a { color: var(--accent); }
  .note-body.markdown mark.hl {
    background: #ffe58f;
    color: inherit;
    border-radius: 3px;
    padding: 0 2px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
  }
  /* Mermaid 图表容器：手机端横向可滚动、SVG 自适应宽度 */
  .mermaid-container {
    margin: .6em 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    overflow-x: auto;
    line-height: 1.2;
  }
  .mermaid-container svg { max-width: 100%; height: auto; }
  .mermaid-container svg * { font-family: inherit; }
  .mermaid-error {
    color: var(--danger);
    font-size: 13px;
    margin: 2px 0 10px;
  }

  .empty {
    text-align: center; color: var(--text-light);
    padding: 60px 20px; font-size: 14px;
  }
  .empty .big { font-size: 44px; margin-bottom: 12px; opacity: .5; }

  .load-status {
    text-align: center; color: var(--text-light);
    font-size: 13px; padding: 20px 0 6px;
  }
  .load-status .spinner {
    display: inline-block; width: 18px; height: 18px;
    border: 2px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .7s linear infinite;
    vertical-align: -4px; margin-right: 8px;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ---------- 登录 / 注册 ---------- */
  .auth-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
  }
  .auth-card {
    width: 100%; max-width: 380px;
    background: var(--card);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    padding: 36px 30px 28px;
  }
  .auth-logo { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 4px; }
  .auth-logo span { color: var(--accent); }
  .auth-sub { text-align: center; color: var(--text-light); font-size: 13px; margin-bottom: 26px; }
  .field { margin-bottom: 16px; }
  .field label { display: block; font-size: 13px; color: var(--text-light); margin-bottom: 6px; }
  .field input {
    width: 100%; padding: 11px 14px;
    border: 1px solid var(--border); border-radius: 10px;
    font-size: 15px; outline: none; transition: border-color .15s;
    background: #fafbfe;
  }
  .field input:focus { border-color: var(--accent); background: #fff; }
  .btn-auth {
    width: 100%; padding: 12px; margin-top: 6px;
    background: var(--accent); color: #fff;
    border: none; border-radius: 10px; font-size: 15px; font-weight: 600;
    transition: background .15s;
  }
  .btn-auth:hover { background: var(--accent-dark); }
  .btn-auth:disabled { opacity: .6; cursor: not-allowed; }
  .auth-switch {
    text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-light);
  }
  .auth-switch a { color: var(--accent); cursor: pointer; text-decoration: none; font-weight: 600; }
  .auth-err {
    background: #fdecec; color: var(--danger);
    font-size: 13px; padding: 9px 12px; border-radius: 8px;
    margin-bottom: 14px; display: none;
  }
  .auth-err.show { display: block; }

  footer {
    text-align: center; color: #b3b9c9; font-size: 12px;
    padding: 30px 0 10px;
  }

  /* ---------- 回到顶部按钮 ---------- */
  .back-top {
    position: fixed;
    right: 18px;
    bottom: 24px;
    z-index: 50;
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    box-shadow: 0 4px 14px rgba(31, 36, 48, .25);
    opacity: .92;
    transition: opacity .2s, transform .15s, background .15s;
  }
  .back-top:hover { background: var(--accent-dark); opacity: 1; }
  .back-top:active { transform: scale(.92); }

  /* ---------- 移动端适配（≤640px） ---------- */
  @media (max-width: 640px) {
    .logo-simple { display: none; }                 /* 标题去掉"简易" */
    .btn-icon { font-size: 17px; padding: 6px 9px; } /* 图标更大，方便点按 */
    .btn-text { display: none; }                     /* 隐藏按钮文字，只留图标 */
    .note-time { font-size: 11px; }
    .note-head { gap: 4px; }
    /* 压缩左右边距，显示更多内容 */
    .container { padding-left: 6px; padding-right: 6px; }
    .note-card { padding: 12px 10px 10px; }
    .editor textarea { padding: 12px; }
    .editor-bar { padding: 10px 12px; }
    .header-inner { padding: 10px 12px; }
    .search-row { padding-left: 12px; padding-right: 12px; }
    .list-head { margin-left: 2px; margin-right: 2px; }
    /* 回到顶部按钮适配底部安全区（iPhone 等） */
    .back-top {
      right: 14px;
      bottom: calc(16px + env(safe-area-inset-bottom, 0px));
      width: 44px;
      height: 44px;
      font-size: 20px;
    }
  }
