/* annotate.css — 划线评论(高亮 / 工具条 / 面板 / 抽屉)。
   只在 {{if .CommentsOn}} 时注入;配色沿用 styles.css 的 data-theme 变量。

   面板跟 TOC 一样坐在页面画布上:只有一根发丝左边线,没有 --elev 凹槽。
   条目是发丝行 + 选中左条,不是套卡;引文/错误/失联用左条+字色,不用色块。
   正文 mark.anno 的黄底是选区高亮,不是面板 chrome,予以保留。 */

:root {
  --anno-w: 340px;
  --anno-hl: #fff4bf;
  --anno-hl-hover: #ffe566;
  --anno-hl-active: #ffd43b;
  --anno-hl-line: #c49200;
}
html[data-theme="dark"] {
  --anno-hl: rgba(255, 214, 10, .16);
  --anno-hl-hover: rgba(255, 214, 10, .28);
  --anno-hl-active: rgba(255, 214, 10, .4);
  --anno-hl-line: #e6c14a;
}

/* --- 正文高亮 ---------------------------------------------------------- */
.markdown-body mark.anno {
  background: var(--anno-hl);
  color: inherit;
  padding: 0;
  border-radius: 0;
  box-shadow: inset 0 -2px 0 var(--anno-hl-line);
  cursor: pointer;
  transition: background .12s ease;
}
.markdown-body mark.anno:hover { background: var(--anno-hl-hover); }
.markdown-body mark.anno.anno-active { background: var(--anno-hl-active); }

/* --- 划词工具条 -------------------------------------------------------- */
.anno-toolbar {
  position: fixed;
  z-index: 60;
  left: 0;
  top: 0;
  max-width: calc(100vw - 16px);
  animation: anno-toolbar-in .15s ease;
}
.anno-toolbar[hidden] { animation: none; }
@keyframes anno-toolbar-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .anno-toolbar { animation: none; }
}
.anno-toolbar-btn {
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn, 5px);
  box-shadow: none;
  transition: var(--fade, background-color .1s ease, color .1s ease, border-color .1s ease);
}
.anno-toolbar-btn:hover,
.anno-toolbar-btn:focus-visible {
  color: var(--fg);
  border-color: var(--fg);
  background: var(--hover);
  outline: none;
}
/* coarse / 窄屏复用同一颗按钮,热区至少 44px,跟选区走,不贴死屏幕底。 */
@media (pointer: coarse), (max-width: 860px) {
  .anno-toolbar-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 10px 16px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
  }
}

/* --- 段落气泡:右侧发丝 speech-bubble,对齐块的垂直中线 ------------------- */
/* Hit = 块 + 文本到气泡的空隙 + 气泡。气泡是它的子节点,滑过去不是 leave。
   盖在正文上的那一段 pointer-events:none,划词不被抢走;空隙 rail 可命中。 */
.anno-gutter-hit {
  position: fixed;
  z-index: 55;
  pointer-events: none;
}
.anno-gutter-hit[hidden] { display: none; }
.anno-gutter-rail {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  pointer-events: auto;
}
.anno-gutter {
  position: absolute;
  z-index: 1;
  width: 24px;
  height: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: none;
  pointer-events: auto;
  transition: var(--fade, background-color .1s ease, color .1s ease, border-color .1s ease);
}
.anno-gutter:hover,
.anno-gutter:focus-visible {
  color: var(--fg);
  border-color: var(--fg);
  background: var(--hover);
  outline: none;
}
.anno-gutter[hidden] { display: none; }
.anno-gutter svg {
  display: block;
  pointer-events: none;
}

/* --- 悬浮入口 ---------------------------------------------------------- */
.anno-launcher {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn, 5px);
  box-shadow: none;
  transition: var(--fade, background-color .1s ease, color .1s ease, border-color .1s ease);
}
.anno-launcher:hover { border-color: var(--fg); background: var(--hover); }
.anno-launcher-count {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted);
}

/* --- 面板:宽屏右侧固定栏,与 TOC 对称的画布+发丝 ---------------------- */
.anno-panel {
  position: fixed;
  top: 52px;                    /* topbar 高度 */
  right: 0;
  bottom: 0;
  z-index: 30;
  width: var(--anno-w);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
  font-size: 14px;
  box-shadow: none;
}
.anno-panel[hidden] { display: none; }

/* 打开时把正文让开,避免固定栏盖住内容(与左侧 TOC 对称)。
   注意:topbar 在 body 之内,body 的 padding-right 已经把它一并推开,
   不要再给 .topbar 叠加一份右边距——那会让主题切换按钮漂进页面中间。
   launcher 是 fixed 定位、不吃 body padding,所以它需要显式偏移。 */
html.anno-open body { padding-right: var(--anno-w); }
html.anno-open .anno-launcher { right: calc(18px + var(--anno-w)); }

.anno-panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.anno-panel-title {
  flex: 1;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.anno-icon-btn {
  font: inherit;
  font-size: 18px;
  line-height: 1;
  width: 28px;
  height: 28px;
  cursor: pointer;
  color: var(--fg-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-btn, 5px);
}
.anno-icon-btn:hover { color: var(--fg); background: var(--hover); }

.anno-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 28px;
}

.anno-error {
  margin: 0;
  padding: 8px 16px 8px 14px;
  font-size: 13px;
  color: var(--danger);
  background: transparent;
  border: none;
  border-left: 2px solid var(--danger);
  border-radius: 0;
}
.anno-error[hidden] { display: none; }
/* 深链没对上:同一条顶栏提示,字色降为次要,不当成操作失败。 */
.anno-error.anno-miss {
  color: var(--fg-muted);
  border-left-color: var(--border);
}
.anno-retry {
  margin-left: 8px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--danger);
  background: transparent;
  border: 1px solid var(--fg);
  border-radius: var(--radius-btn, 5px);
  cursor: pointer;
}
.anno-retry:hover { background: var(--hover); }

/* --- 分组:下划线 tab,对齐后台 .admin-filter -------------------------- */
.anno-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0 16px;
  padding: 0 16px;
  margin: 0;
  border-bottom: 1px solid var(--border);
}
.anno-tab {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  cursor: pointer;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--fg-muted);
  padding: 10px 0 8px;
  margin-bottom: -1px;
  border-radius: 0;
  white-space: nowrap;
  transition: var(--fade, color .1s ease, border-color .1s ease);
}
.anno-tab:hover { color: var(--fg); }
.anno-tab.is-on {
  color: var(--fg);
  border-bottom-color: var(--fg);
  font-weight: 550;
}
.anno-group-label { flex: 0 1 auto; }
.anno-group-count {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 400;
  color: var(--fg-muted);
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  line-height: inherit;
}
.anno-tab.is-on .anno-group-count { color: var(--fg-muted); }
.anno-empty {
  color: var(--fg-muted);
  font-size: 13px;
  margin: 0;
  padding: 16px;
}

/* --- 条目:发丝行,选中/草稿只加 --fg 左条 ------------------------------ */
.anno-item {
  margin: 0;
  padding: 14px 16px 14px 14px;
  border: none;
  border-bottom: 1px solid var(--border);
  border-left: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  scroll-margin-top: 12px;
}
.anno-item:focus { outline: none; }
.anno-item.anno-item-active,
.anno-item.anno-draft {
  border-left-color: var(--fg);
  background: transparent;
  box-shadow: none;
}
.anno-item[data-group="resolved"] { opacity: .75; }

.anno-orphan-note {
  font-size: 12px;
  color: var(--amber-tx);
  background: transparent;
  border: none;
  border-left: 2px solid var(--amber-bd);
  border-radius: 0;
  padding: 0 0 0 8px;
  margin: 0 0 8px;
}
.anno-quote {
  margin: 0 0 10px;
  padding: 0 0 0 10px;
  border: none;
  border-left: 2px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;          /* 长引文截 3 行,交给省略号而不是生切 */
  overflow: hidden;
}

.anno-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  color: var(--fg-muted);
}
.anno-author { font-weight: 600; color: var(--fg); }
.anno-badge {
  font-size: 11px;
  line-height: 1.6;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: none;
  color: var(--fg-muted);
}
.anno-time { margin-left: auto; font-variant-numeric: tabular-nums; }

.anno-text {
  margin: 5px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
}

.anno-actions { display: flex; gap: 8px; margin-top: 8px; }
.anno-act {
  font: inherit;
  font-size: 12px;
  line-height: 1.5;
  padding: 2px 0;
  cursor: pointer;
  color: var(--fg-muted);
  background: transparent;
  border: none;
  border-radius: 0;
}
.anno-act:hover { color: var(--fg); }
.anno-act.anno-danger:hover { color: var(--danger); }
.anno-act:disabled { opacity: .5; cursor: default; }

/* --- 回复串 ------------------------------------------------------------ */
.anno-replies {
  margin: 10px 0 0;
  padding-left: 10px;
  border-left: 2px solid var(--border);
}
.anno-reply { margin: 8px 0; }
.anno-reply .anno-text { font-size: 13.5px; }

.anno-reply-form { margin-top: 10px; }
.anno-textarea, .anno-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 13.5px;
  padding: 7px 10px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn, 5px);
  resize: vertical;
  box-shadow: none;
}
.anno-textarea:focus, .anno-input:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: none;
}
.anno-textarea { min-height: 72px; }
.anno-name-row { margin-bottom: 8px; }
.anno-form-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.anno-btn {
  font: inherit;
  font-size: 13px;
  padding: 5px 12px;
  cursor: pointer;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--fg);
  border-radius: var(--radius-btn, 5px);
  box-shadow: none;
}
.anno-btn:hover { background: var(--hover); color: var(--fg); }
.anno-btn.anno-primary {
  background: var(--cta, var(--fg));
  border-color: var(--cta, var(--fg));
  color: var(--cta-fg, var(--bg));
}
.anno-btn.anno-primary:hover { opacity: .88; }
.anno-btn:disabled { opacity: .55; cursor: default; }

/* --- 窄屏:底部抽屉 ---------------------------------------------------- */
@media (max-width: 860px) {
  .anno-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 72vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
    background: var(--bg);
  }
  html.anno-open body { padding-right: 0; }
  html.anno-open .topbar { padding-right: 16px; }
  html.anno-open .anno-launcher { right: 18px; }
  html.anno-open .anno-launcher { display: none; }
  .anno-panel-head::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 3px;
    border-radius: 0;
    background: var(--border);
  }
  .anno-panel-head { position: relative; padding-top: 16px; }
}

/* 触摸设备没有 hover:高亮直接给到 hover 强度,免得看不出可点。 */
@media (hover: none) {
  .markdown-body mark.anno { background: var(--anno-hl-hover); }
}
