/* ======================================================
   🎋 豆竹 · 划线笔记系统样式
   微信读书式：选中→划线→写注→云端留存
   ====================================================== */

/* --- 高亮颜色主题 --- */
:root {
  --ag-bamboo: #8BC34A;       /* 🎋 竹绿 - 默认 */
  --ag-bamboo-bg: rgba(139,195,74,0.22);
  --ag-bamboo-hover: rgba(139,195,74,0.32);
  --ag-bamboo-note: #e8f5e9;

  --ag-sunset: #FF8A65;      /* 🏮 晚霞 - 洞见 */
  --ag-sunset-bg: rgba(255,138,101,0.18);
  --ag-sunset-hover: rgba(255,138,101,0.28);
  --ag-sunset-note: #fbe9e7;

  --ag-sky: #64B5F6;         /* 🌊 天蓝 - 思考 */
  --ag-sky-bg: rgba(100,181,246,0.18);
  --ag-sky-hover: rgba(100,181,246,0.28);
  --ag-sky-note: #e3f2fd;

  --ag-gold: #FFD54F;        /* 📜 金萱 - 经典 */
  --ag-gold-bg: rgba(255,213,79,0.25);
  --ag-gold-hover: rgba(255,213,79,0.35);
  --ag-gold-note: #fff8e1;

  --ag-cherry: #F48FB1;      /* 🌸 樱粉 - 切己 */
  --ag-cherry-bg: rgba(244,143,177,0.20);
  --ag-cherry-hover: rgba(244,143,177,0.30);
  --ag-cherry-note: #fce4ec;

  --ag-toolbar-bg: #1a1a2e;
  --ag-toolbar-text: #eee;
  --ag-toolbar-border: #333;
  --ag-popup-bg: #fff;
  --ag-popup-shadow: 0 4px 24px rgba(0,0,0,0.15);
}

/* --- 高亮标记 --- */
mark.ag-highlight {
  cursor: pointer;
  border-radius: 3px;
  padding: 1px 2px;
  transition: background-color 0.15s ease;
  position: relative;
}
mark.ag-highlight::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 1px;
  opacity: 0.5;
}

/* 各颜色方案 */
mark.ag-highlight.ag-bamboo {
  background: var(--ag-bamboo-bg);
  border-bottom: 2px solid var(--ag-bamboo);
}
mark.ag-highlight.ag-bamboo:hover { background: var(--ag-bamboo-hover); }

mark.ag-highlight.ag-sunset {
  background: var(--ag-sunset-bg);
  border-bottom: 2px solid var(--ag-sunset);
}
mark.ag-highlight.ag-sunset:hover { background: var(--ag-sunset-hover); }

mark.ag-highlight.ag-sky {
  background: var(--ag-sky-bg);
  border-bottom: 2px solid var(--ag-sky);
}
mark.ag-highlight.ag-sky:hover { background: var(--ag-sky-hover); }

mark.ag-highlight.ag-gold {
  background: var(--ag-gold-bg);
  border-bottom: 2px solid var(--ag-gold);
}
mark.ag-highlight.ag-gold:hover { background: var(--ag-gold-hover); }

mark.ag-highlight.ag-cherry {
  background: var(--ag-cherry-bg);
  border-bottom: 2px solid var(--ag-cherry);
}
mark.ag-highlight.ag-cherry:hover { background: var(--ag-cherry-hover); }

/* 有笔记的高亮右侧加小标记 */
mark.ag-highlight.has-note::after {
  content: '✍';
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: 10px;
  background: var(--ag-toolbar-bg);
  color: #fff;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  pointer-events: none;
}

/* --- 浮动工具栏 --- */
.ag-toolbar {
  position: fixed;
  z-index: 99999;
  display: none;
  background: var(--ag-toolbar-bg);
  border: 1px solid var(--ag-toolbar-border);
  border-radius: 10px;
  padding: 6px 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
  font-family: 'Noto Sans SC', sans-serif;
  user-select: none;
  transform: translateX(-50%);
}
.ag-toolbar.visible { display: flex; align-items: center; gap: 4px; }

.ag-toolbar .ag-color-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.12s ease;
  position: relative;
}
.ag-toolbar .ag-color-btn:hover {
  transform: scale(1.2);
}
.ag-toolbar .ag-color-btn.active {
  border-color: #fff;
  box-shadow: 0 0 6px rgba(255,255,255,0.5);
}

.ag-toolbar .ag-divider {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.15);
  margin: 0 4px;
}

.ag-toolbar .ag-note-btn,
.ag-toolbar .ag-cancel-btn {
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
  font-family: 'Noto Sans SC', sans-serif;
  transition: all 0.12s ease;
}
.ag-toolbar .ag-note-btn:hover {
  background: rgba(255,255,255,0.12);
  color: #fff;
}
.ag-toolbar .ag-cancel-btn:hover {
  background: rgba(255,80,80,0.2);
  color: #ff6b6b;
}

/* --- 笔记弹窗(写) --- */
.ag-note-popup {
  position: fixed;
  z-index: 99999;
  display: none;
  background: var(--ag-popup-bg);
  border-radius: 12px;
  box-shadow: var(--ag-popup-shadow);
  padding: 16px;
  width: 360px;
  font-family: 'Noto Sans SC', sans-serif;
}
.ag-note-popup.visible { display: block; }

.ag-note-popup .ag-note-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 14px;
  color: #666;
}
.ag-note-popup .ag-note-header .ag-note-close {
  background: none;
  border: none;
  cursor: pointer;
  color: #999;
  font-size: 18px;
  padding: 0 4px;
}
.ag-note-popup .ag-note-header .ag-note-close:hover { color: #333; }

.ag-note-popup .ag-quote-text {
  background: #f5f5f5;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.6;
  color: #555;
  margin-bottom: 10px;
  border-left: 3px solid #4caf50;
  max-height: 80px;
  overflow-y: auto;
}

.ag-note-popup textarea {
  width: 100%;
  min-height: 80px;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 10px;
  font-size: 14px;
  line-height: 1.6;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
  transition: border-color 0.15s;
}
.ag-note-popup textarea:focus {
  outline: none;
  border-color: var(--ag-bamboo);
  box-shadow: 0 0 0 2px rgba(139,195,74,0.15);
}

.ag-note-popup .ag-note-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}
.ag-note-popup .ag-note-footer button {
  padding: 6px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.12s;
}
.ag-note-popup .ag-note-footer .ag-save-btn {
  background: #4caf50;
  color: #fff;
}
.ag-note-popup .ag-note-footer .ag-save-btn:hover { background: #388e3c; }
.ag-note-popup .ag-note-footer .ag-delete-btn {
  background: #ffebee;
  color: #c62828;
}
.ag-note-popup .ag-note-footer .ag-delete-btn:hover { background: #ffcdd2; }

/* --- 笔记气泡(读) --- */
.ag-bubble {
  position: fixed;
  z-index: 99998;
  display: none;
  background: var(--ag-popup-bg);
  border-radius: 10px;
  box-shadow: var(--ag-popup-shadow);
  padding: 14px 16px;
  max-width: 340px;
  font-family: 'Noto Sans SC', sans-serif;
  animation: ag-fadein 0.15s ease;
}
.ag-bubble.visible { display: block; }

@keyframes ag-fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.ag-bubble .ag-bubble-text {
  font-size: 13px;
  line-height: 1.7;
  color: #444;
  margin-bottom: 8px;
}
.ag-bubble .ag-bubble-text:empty { display: none; }

.ag-bubble .ag-bubble-meta {
  font-size: 11px;
  color: #aaa;
  display: flex;
  justify-content: space-between;
}
.ag-bubble .ag-bubble-color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.ag-bubble .ag-bubble-action {
  background: none;
  border: none;
  cursor: pointer;
  color: #4caf50;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
}
.ag-bubble .ag-bubble-action:hover {
  background: #e8f5e9;
}

/* --- 侧边栏计数 --- */
.ag-counter {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99997;
  background: var(--ag-toolbar-bg);
  color: #ddd;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-family: 'Noto Sans SC', sans-serif;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
  transition: all 0.15s ease;
  user-select: none;
  opacity: 0.6;
}
.ag-counter:hover {
  opacity: 1;
  transform: translateY(-1px);
}
.ag-counter.has-annotations {
  opacity: 0.9;
  border: 1px solid rgba(139,195,74,0.3);
}

/* --- 侧边栏展开 --- */
.ag-sidebar {
  position: fixed;
  right: -380px;
  top: 0;
  bottom: 0;
  width: 360px;
  z-index: 99996;
  background: #fff;
  box-shadow: -4px 0 40px rgba(0,0,0,0.12);
  font-family: 'Noto Sans SC', sans-serif;
  transition: right 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
}
.ag-sidebar.open { right: 0; }

.ag-sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.ag-sidebar-header h3 {
  font-size: 16px;
  color: #2d7d3a;
  margin: 0;
  font-family: 'Ma Shan Zheng', serif;
}
.ag-sidebar-header .ag-sidebar-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: #999;
  padding: 0 4px;
}

.ag-sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}
.ag-sidebar-body .ag-sidebar-empty {
  text-align: center;
  color: #bbb;
  padding: 40px 20px;
  font-size: 14px;
}

.ag-sidebar-item {
  padding: 12px 20px;
  border-bottom: 1px solid #f5f5f5;
  transition: background 0.12s;
  cursor: pointer;
}
.ag-sidebar-item:hover { background: #fafafa; }

.ag-sidebar-item .ag-sidebar-color {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.ag-sidebar-item .ag-sidebar-quote {
  font-size: 13px;
  line-height: 1.5;
  color: #555;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ag-sidebar-item .ag-sidebar-note {
  font-size: 13px;
  line-height: 1.6;
  color: #333;
  padding: 6px 8px;
  background: #f9f9f9;
  border-radius: 4px;
}
.ag-sidebar-item .ag-sidebar-time {
  font-size: 11px;
  color: #ccc;
  margin-top: 4px;
}

/* 遮罩层 */
.ag-overlay {
  position: fixed;
  inset: 0;
  z-index: 99995;
  background: rgba(0,0,0,0.2);
  display: none;
}
.ag-overlay.visible { display: block; }

/* 响应式 */
@media (max-width: 768px) {
  .ag-note-popup { width: calc(100% - 32px); left: 16px !important; }
  .ag-sidebar { width: 100%; right: -100%; }
  .ag-toolbar { transform: translateX(-20%); }
  .ag-counter { bottom: 12px; right: 12px; }
}

/* --- 初始化状态标记（页面右上角） --- */
.ag-status {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 99999;
  font-size: 18px;
  line-height: 1;
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
  transition: opacity 0.3s;
}
.ag-status:hover { opacity: 1; }
