/*
 * Agent Notes 的网页。宽屏是侧栏 + 主区;手机上(< 900px)一层一层往里走:首页是项目列表,其余页面
 * 占满整屏、顶栏带返回,和系统备忘录一样。颜色跟随系统的浅色 / 深色。
 *
 * 手机上的几条(sites/nodal-web 踩过的):输入框在触屏上 16px,不然 Safari 聚焦时放大整页;顶栏让出
 * 状态栏(safe-area-inset-top);编辑页按 visualViewport 摆(js/viewport.js),键盘弹起时不把整页推走。
 */

:root {
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface-2: #F0F0F3;
  --text: #1C1C1E;
  --muted: #6E6E73;
  --line: rgba(60, 60, 67, 0.16);
  --accent: #1F6FEB;
  --accent-soft: rgba(31, 111, 235, 0.1);
  --agent: #B76E00;
  --agent-soft: rgba(255, 178, 36, 0.12);
  --agent-line: rgba(255, 178, 36, 0.45);
  --danger: #D70015;
  --radius: 12px;
  --sidebar: 300px;
  --vv-height: 100dvh;
  --vv-top: 0px;
  color-scheme: light dark;
  /* 渲染库的变量:正文背景跟着所在的卡片,不画自己的底色。 */
  --chat-background: transparent;
  --chat-link-color: var(--accent);
  --markdown-font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1C1C1E;
    --surface-2: #26262A;
    --text: #F2F2F7;
    --muted: #98989F;
    --line: rgba(235, 235, 245, 0.14);
    --accent: #4C8DFF;
    --accent-soft: rgba(76, 141, 255, 0.16);
    --agent: #FFB224;
    --agent-soft: rgba(255, 178, 36, 0.1);
    --agent-line: rgba(255, 178, 36, 0.35);
    --danger: #FF453A;
    --chat-background: transparent;
    --chat-link-color: var(--accent);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Segoe UI", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.faded { opacity: 0.35; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* 三个点是三段零长的线,圆头画成圆点:线宽就是点的直径。 */
.icon.icon-more { width: 24px; height: 24px; stroke-width: 3.2; }

/* ---------- 按钮与输入 ---------- */

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text); font-weight: 500; cursor: pointer; white-space: nowrap;
}
.button:disabled { opacity: 0.5; cursor: default; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.button.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.button .icon { width: 18px; height: 18px; }
.icon-button {
  display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px;
  border: 0; border-radius: 10px; background: transparent; color: var(--accent); cursor: pointer;
}
.input, .textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  color: var(--text); font: inherit; padding: 10px 12px; outline: none;
}
.input:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.badge {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 6px;
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.kind-status, .badge.kind-plan { background: var(--accent-soft); color: var(--accent); }
.badge.kind-decisions, .badge.kind-log { background: var(--agent-soft); color: var(--agent); }

/* 悬停只给有鼠标的设备:触屏上 :hover 在点过之后一直留着,像按钮卡住了。触屏用按下时的样子。 */
@media (hover: hover) {
  .button:hover { background: var(--surface-2); }
  .button.primary:hover { filter: brightness(1.06); }
  .button.ghost:hover { background: var(--accent-soft); }
  .icon-button:hover { background: var(--accent-soft); }
  .search-link:hover, .project-link:hover, .foot-link:hover { background: var(--surface-2); }
  a.note-row:hover, .note-row.static .note-row-main:hover .note-row-title { background: transparent; color: var(--accent); }
  a.note-row:hover { background: var(--surface-2); color: inherit; }
  .sheet-item:hover { background: var(--surface-2); }
}
.button:active, .icon-button:active, .sheet-item:active, a.note-row:active, .project-link:active, .foot-link:active, .search-link:active { opacity: 0.6; }

/* ---------- 启动、空状态、提示 ---------- */

.boot, .state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 40vh; padding: 32px 24px; text-align: center; }
.boot { min-height: 100dvh; }
.state p { max-width: 420px; margin: 0; }
.spinner { width: 24px; height: 24px; border: 2.5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.notice { margin: 0 0 16px; padding: 10px 14px; border-radius: 10px; background: var(--agent-soft); color: var(--text); }
.form-error { margin: 12px 0 0; color: var(--danger); }
.toasts { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 12px; background: rgba(28, 28, 30, 0.92); color: #fff; font-size: 14px; text-align: center; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); }

/* ---------- 登录 ---------- */

.login { min-height: 100dvh; display: grid; place-items: center; padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom)); }
.login-card { width: min(100%, 380px); text-align: center; }
.login-card h1 { font-size: 28px; margin: 12px 0 6px; }
.login-mark { border-radius: 14px; }
.login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 28px; text-align: left; }
.login-form label { font-size: 13px; color: var(--muted); }
.login-form .button { margin-top: 6px; min-height: 46px; }
.input.code { letter-spacing: 0.3em; font-size: 20px; text-align: center; }

/* ---------- 外框 ---------- */

.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 6px;
  padding: calc(14px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  border-right: 1px solid var(--line); background: var(--surface); overflow-y: auto;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand img { border-radius: 7px; }
.search-link, .project-link, .foot-link {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 10px; border-radius: 10px; color: var(--text);
}
.search-link { background: var(--surface-2); color: var(--muted); margin-bottom: 8px; }
.project-link.current, .foot-link.current, .search-link.current { background: var(--accent-soft); color: var(--accent); }
.project-link .icon { color: var(--accent); }
.project-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-when { font-size: 12px; color: var(--muted); }
.section-label { margin: 8px 10px 4px; font-size: 12px; font-weight: 600; letter-spacing: 0.02em; color: var(--muted); text-transform: uppercase; }
.projects { flex: 1; }
.project-list { display: flex; flex-direction: column; gap: 2px; }
.projects-empty { padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.projects-empty p { margin: 0; }
.archived summary { cursor: pointer; list-style: none; }
.archived summary::-webkit-details-marker { display: none; }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.account { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 10px; }
.account-email { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { min-width: 0; }

/* ---------- 页面 ---------- */

.page { max-width: 860px; margin: 0 auto; padding: 0 28px 48px; }
.page-head {
  position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: calc(14px + env(safe-area-inset-top)) 0 12px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
}
.page-head .back, .back-spacer { display: none; }
.page-title { min-width: 0; }
.page-title h1 { font-size: 24px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-subtitle { margin: 2px 0 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.page-note { margin: 0 0 12px; font-size: 14px; }
.page-body { padding-top: 8px; }
.more { display: flex; margin: 16px auto 0; }

.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.note-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.note-row:last-child { border-bottom: 0; }
.note-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.note-row-title { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.note-row-title span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-row-meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.note-row-meta .icon { width: 15px; height: 15px; color: var(--agent); }
.snippet { margin: 2px 0; font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- 笔记正文 ---------- */

.note { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 24px 28px; }
.note-meta { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.revision-title { font-size: 20px; margin: 0 0 12px; }
.note-body { display: flex; flex-direction: column; gap: 4px; }
.md-body { font-size: 16px; line-height: 1.6; color: var(--text); overflow-wrap: anywhere; }
.md-body > :first-child { margin-top: 0; }
.md-body > :last-child { margin-bottom: 0; }
.md-plain { white-space: pre-wrap; font: inherit; margin: 0; }
.agent-block { margin: 10px 0; padding: 12px 16px 14px; border: 1px solid var(--agent-line); border-left-width: 3px; border-radius: 10px; background: var(--agent-soft); }
.agent-block-label { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 12px; font-weight: 600; color: var(--agent); }
.agent-block-label .icon { width: 15px; height: 15px; }
.agent-block-label code { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--agent-soft); color: var(--muted); font-weight: 500; }

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

.editor-page { display: flex; flex-direction: column; min-height: 100dvh; padding-bottom: 16px; }
.editor-head .page-title h1 { font-size: 17px; text-align: center; }
.editor-head > a { justify-self: start; }
.editor-fields { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.title-input { font-size: 20px; font-weight: 600; }
.body-input { flex: 1; min-height: 60vh; resize: vertical; font: 15px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.editor-error { margin: 0 0 10px; }
.conflict { margin: 0 0 14px; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--agent-line); background: var(--agent-soft); }
.conflict h2 { font-size: 16px; }
.conflict p { margin: 6px 0 12px; }
.conflict-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.conflict-side h3 { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.conflict-text { margin: 0; max-height: 280px; overflow: auto; padding: 10px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); white-space: pre-wrap; font: 13px/1.5 ui-monospace, "SF Mono", Menlo, monospace; }
.conflict-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- 搜索 ---------- */

.search-box { position: relative; margin-bottom: 14px; }
.search-box .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-input { padding-left: 40px; min-height: 44px; }
.search-input::-webkit-search-cancel-button { cursor: pointer; }

/* ---------- 对话框 ---------- */

dialog {
  border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text);
  width: min(92vw, 400px); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.32); }
.dialog-form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.dialog-form h2 { font-size: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.sheet { display: flex; flex-direction: column; padding: 8px; }
.sheet-title { margin: 6px 12px 8px; font-size: 13px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-item { min-height: 48px; border: 0; border-radius: 10px; background: transparent; color: var(--accent); font-size: 16px; cursor: pointer; }
.sheet-item.danger { color: var(--danger); }
.sheet-item.cancel { margin-top: 4px; font-weight: 600; color: var(--text); background: var(--surface-2); }

/* ---------- 手机 ---------- */

@media (max-width: 899px) {
  .app { display: block; }
  .app:not([data-page="home"]) .sidebar { display: none; }
  .app[data-page="home"] .main { display: none; }
  .sidebar { position: static; height: auto; min-height: 100dvh; border-right: 0; background: var(--bg); padding: calc(10px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); }
  .sidebar-head { padding: 4px 0 10px; }
  .brand { font-size: 28px; }
  .brand img { width: 34px; height: 34px; }
  .search-link { background: var(--surface-2); min-height: 44px; }
  .project-list { background: var(--surface); border-radius: var(--radius); overflow: hidden; gap: 0; }
  .project-link { border-radius: 0; min-height: 52px; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 16px; }
  .project-link:last-child { border-bottom: 0; }
  .project-link.current { background: transparent; color: var(--text); }
  .sidebar-foot { border-top: 0; }
  .foot-link { background: var(--surface); min-height: 52px; font-size: 16px; }
  .page { padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
  .page-head { margin: 0 -16px; padding: calc(6px + env(safe-area-inset-top)) 10px 8px; }
  .page-head .back { display: inline-flex; }
  /* 右边没有动作时留出和返回键一样宽的位置,标题才在正中。 */
  .page-actions { min-width: 38px; }
  .page-head .back .icon { width: 24px; height: 24px; }
  .page-title h1 { font-size: 17px; text-align: center; }
  .page-subtitle { text-align: center; }
  .button .label { display: none; }
  .button.small:has(.label) { width: 38px; padding: 0; }
  .note { border: 0; border-radius: 0; margin: 0 -16px; padding: 16px; background: transparent; }
  .list { border-radius: var(--radius); }
  .note-row { min-height: 60px; }
  .conflict-columns { grid-template-columns: 1fr; }
  /* 编辑页贴着看得见的那块(键盘以上),工具栏不被推走。 */
  .editor-page { position: fixed; left: 0; right: 0; top: var(--vv-top); height: var(--vv-height); min-height: 0; padding: 0 12px; overflow: hidden; }
  .editor-page .page-head { margin: 0 -12px; padding-left: 12px; padding-right: 12px; flex: none; }
  .editor-fields { min-height: 0; padding-bottom: 8px; }
  .body-input { min-height: 0; resize: none; }
  .conflict { flex: none; max-height: 45%; overflow: auto; }
  dialog.as-sheet { width: 100%; max-width: none; margin: auto 0 0; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}

@media (pointer: coarse) {
  .input, .textarea, .search-input { font-size: 16px; }
  .body-input { font-size: 16px; }
}
