/* 日记：和学习页同一套配色和字体 */
:root {
  --bg: #f7f6f2;
  --fg: #1f1f1d;
  --muted: #6b6a66;
  --card: #ffffff;
  --line: #e4e2dc;
  --track: #f0eee8;
  --accent: #2f5bea;
  --accent-soft: rgba(47, 91, 234, 0.08);
  --danger: #c93a3a;
  --danger-soft: rgba(201, 58, 58, 0.07);
  --ok: #2f9e6a;
  --warn: #b7791f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --fg: #ececea;
    --muted: #9b9a95;
    --card: #1e2027;
    --line: #2c2f38;
    --track: #262932;
    --accent: #7c9bff;
    --accent-soft: rgba(124, 155, 255, 0.12);
    --danger: #ff7b7b;
    --danger-soft: rgba(255, 123, 123, 0.1);
    --ok: #4fc08d;
    --warn: #e0a54a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: 0.35; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.5em; margin: 0; }
.center { min-height: 60vh; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }

.primary { padding: 11px 16px; border: none; border-radius: 10px; background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; }
.ghost { padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--muted); font-size: 14px; }
.ghost:hover { color: var(--fg); }
.ghost.danger:hover { color: var(--danger); border-color: var(--danger); }
.small-btn { padding: 7px 12px; font-size: 14px; }

/* ---------- 登录 ---------- */
.auth { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; display: flex; flex-direction: column; gap: 12px; }
.auth h1 { margin: 0; font-size: 26px; }
.auth p { margin: 0; }
.auth input { font: inherit; font-size: 17px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg); }

/* ---------- 版式 ---------- */
.app { max-width: 1080px; margin: 0 auto; padding: 16px 16px 32px; }

.masthead { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }
.crest-link img { display: block; border-radius: 10px; }
.masthead h1 { margin: 0; font-size: 24px; line-height: 1.2; }
.masthead p { margin: 2px 0 0; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.card h2 { margin: 0; font-size: 15px; }

/* ---------- 编辑区 ---------- */
.editor { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px 24px 14px; }

.editor-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.date-block { flex: 1; min-width: 0; }
.date-main { margin: 0; font-size: 22px; font-weight: 600; line-height: 1.3; }
.date-main .today-tag {
  display: inline-block; margin-left: 8px; padding: 0 7px; vertical-align: 3px;
  border-radius: 6px; background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 600; line-height: 1.7;
}
.date-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.day-nav { display: flex; gap: 6px; }
.day-nav button, .cal-bar button {
  width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 10px;
  background: transparent; font-size: 20px; line-height: 1;
}

.title {
  display: block; width: 100%;
  font: inherit; font-size: 19px; font-weight: 600; color: var(--fg);
  padding: 8px 0; margin: 0 0 8px;
  border: none; border-bottom: 1px solid var(--line); border-radius: 0;
  background: transparent; outline: none;
}
.title::placeholder, .body::placeholder { color: var(--muted); opacity: 0.7; font-weight: 400; }

.body {
  display: block; width: 100%;
  min-height: 420px;
  padding: 6px 0; margin: 0;
  border: none; outline: none; resize: none; overflow: hidden;
  background: transparent; color: var(--fg);
  font: inherit; font-size: 17px; line-height: 1.85;
}
.body:disabled, .title:disabled { opacity: 0.5; }

.editor-foot {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 13px; color: var(--muted);
}
.editor-foot .spacer { flex: 1; }
.save-state { display: inline-flex; align-items: center; gap: 6px; }
.save-state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.save-state.ok::before { background: var(--ok); }
.save-state.busy::before { background: var(--warn); }
.save-state.bad { color: var(--danger); }
.save-state.bad::before { background: var(--danger); }
.char-count { font-variant-numeric: tabular-nums; }

/* ---------- 冲突提示 ---------- */
.banner { margin: 0 0 14px; padding: 12px 14px; border: 1px solid var(--danger); border-radius: 10px; background: var(--danger-soft); font-size: 14px; }
.banner p { margin: 0 0 8px; }
.banner details { margin-bottom: 10px; }
.banner summary { cursor: pointer; color: var(--accent); }
.their { margin-top: 8px; max-height: 240px; overflow: auto; padding: 10px 12px; background: var(--card); border-radius: 8px; border: 1px solid var(--line); }
.their strong { display: block; margin-bottom: 4px; }
.their div { white-space: pre-wrap; line-height: 1.7; }
.banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 侧栏 ---------- */
.side { display: flex; flex-direction: column; gap: 14px; }

.cal-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-bar h2 { font-size: 16px; }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-week span { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0; }
.cal-day {
  position: relative; aspect-ratio: 1; min-height: 32px;
  border: none; border-radius: 8px; background: transparent;
  font-size: 14px; font-variant-numeric: tabular-nums;
  display: flex; align-items: center; justify-content: center;
}
.cal-day:hover:not(:disabled) { background: var(--track); }
.cal-day.has { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-day.selected { background: var(--accent); color: #fff; }
.cal-day.pending::before { content: ""; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }
.cal-day:disabled { opacity: 0.25; }
.go-today { display: block; margin: 8px auto 0; font-size: 13px; }

.pending-note { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 13px; color: var(--warn); border: 1px solid var(--warn); }
.backup { margin: 0; padding: 0 4px; font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.backup::before { content: ""; flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; background: var(--line); transform: translateY(-1px); }
.backup.ok::before { background: var(--ok); }
.backup.warn { color: var(--warn); }
.backup.warn::before { background: var(--warn); }
.backup.bad { color: var(--danger); }
.backup.bad::before { background: var(--danger); }

.foot { margin-top: 24px; display: flex; justify-content: space-between; font-size: 14px; }
.foot a { color: var(--accent); }

/* ---------- 历史版本 ---------- */
.rev-dialog {
  width: min(860px, calc(100vw - 24px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); color: var(--fg); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.rev-dialog[open] { display: flex; flex-direction: column; }
.rev-dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.rev-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.rev-head h2 { margin: 0; font-size: 17px; }
.rev-layout { display: grid; grid-template-columns: 230px 1fr; min-height: 0; flex: 1; overflow: hidden; }
.rev-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; border-right: 1px solid var(--line); max-height: 62vh; }
.rev-list button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: none; border-radius: 8px; background: transparent; font-size: 13px; }
.rev-list button:hover { background: var(--track); }
.rev-list button.selected { background: var(--accent-soft); }
.rev-list b { display: block; font-size: 14px; }
.rev-list span { color: var(--muted); }
.rev-list .cur { color: var(--ok); font-size: 12px; margin-left: 4px; }
.rev-list .del { color: var(--danger); }
.rev-preview { padding: 14px 18px; overflow-y: auto; max-height: 62vh; }
.rev-preview h3 { margin: 4px 0 8px; font-size: 17px; }
.rev-body { white-space: pre-wrap; font-size: 15px; line-height: 1.8; margin-bottom: 16px; }
.rev-note { margin: 0; padding: 10px 16px 14px; border-top: 1px solid var(--line); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 12px; z-index: 10;
  background: #24262b; color: #fff; font-size: 15px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.toast.error-toast { background: var(--danger); }

/* ---------- 窄屏：编辑区在上，月历在下 ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 14px; }
}

@media (max-width: 520px) {
  .app { padding: 12px 12px 28px; }
  .crest-link img { width: 38px; height: 38px; }
  .editor { padding: 16px 16px 12px; }
  .date-main { font-size: 20px; }
  .day-nav button { width: 34px; height: 34px; }
  .body { min-height: 300px; font-size: 16.5px; }
  .save-state { flex: 1 1 100%; }
  .rev-layout { grid-template-columns: 1fr; overflow-y: auto; }
  .rev-list { max-height: 30vh; border-right: none; border-bottom: 1px solid var(--line); }
  .rev-preview { max-height: none; overflow: visible; }
}
