/* ═══════════════════════════════════════════════════════════
   Comments — threaded, curved connectors, red send button
   ═══════════════════════════════════════════════════════════ */

/* Trigger bar */
.cm-trigger-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--mat-thin, var(--white));
  backdrop-filter: var(--blur-sm);
  border-radius: var(--r);
  cursor: pointer;
  border: 1.5px solid var(--light);
  margin-top: 24px;
  transition: border-color .18s, box-shadow .18s;
  user-select: none;
}
.cm-trigger-bar:hover {
  border-color: var(--red);
  box-shadow: var(--sh-card);
}
.cm-trigger-count { font-size: 14px; font-weight: 700; color: var(--ink); flex: 1; }
.cm-trigger-hint  { font-size: 12px; color: var(--grey); }

/* Overlay */
.cm-sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000; opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
.cm-sheet-overlay.open { opacity: 1; pointer-events: all; }

/* Sheet */
.cm-sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 1001;
  background: var(--mat-mid, var(--white));
  backdrop-filter: var(--blur-md);
  border-radius: 20px 20px 0 0;
  height: 82vh;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.32,1,.58,1);
  will-change: transform;
  overflow: hidden;
}
.cm-sheet.open { transform: translateY(0); }

@media (min-width: 768px) {
  .cm-sheet {
    left: auto; right: 0; top: 0; bottom: 0;
    width: 420px; height: 100vh;
    border-radius: 0;
    transform: translateX(110%);
    box-shadow: var(--sh-float);
  }
  .cm-sheet.open { transform: translateX(0); }
  .cm-sheet-overlay { right: 420px; }
}

/* Drag handle */
.cm-drag-handle {
  display: flex; justify-content: center;
  padding: 10px 0 2px;
  flex-shrink: 0; cursor: grab; touch-action: none;
}
.cm-drag-handle-bar {
  width: 36px; height: 4px;
  border-radius: 99px; background: var(--light);
}
@media (min-width: 768px) { .cm-drag-handle { display: none; } }

/* Header */
.cm-sheet-head {
  display: flex; align-items: center;
  padding: 8px 16px 10px;
  border-bottom: 1px solid var(--light);
  gap: 10px; flex-shrink: 0;
}
.cm-sheet-title { font-size: 15px; font-weight: 900; color: var(--ink); flex: 1; }
.cm-sheet-count { font-size: 13px; color: var(--grey); }
.cm-sheet-close {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--light); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--grey); flex-shrink: 0;
  transition: background .15s;
}
.cm-sheet-close:hover { background: var(--mid); color: var(--dk); }

/* Sort */
.cm-sort-bar {
  display: flex; gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--light);
  flex-shrink: 0;
}
.cm-sort-btn {
  padding: 5px 14px; border-radius: 99px;
  border: 1.5px solid var(--light); background: transparent;
  font-size: 12px; font-weight: 700; color: var(--grey);
  cursor: pointer; font-family: var(--font); transition: all .15s;
}
.cm-sort-btn.active { background: var(--ink); color: var(--white); border-color: var(--ink); }

/* Scroll body */
.cm-sheet-body {
  flex: 1;
  overflow-y: auto; overflow-x: hidden;
  padding: 0 16px 8px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

/* ════════════════════════════════════════════════════════════
   THREAD NODE (curved grey connectors)
   ════════════════════════════════════════════════════════════ */
.cm-thread-node {
  display: flex; flex-direction: row;
}

/* Connector column */
.cm-thread-connector {
  flex-shrink: 0; width: 20px; position: relative;
}
.cm-thread-node[data-depth="0"] > .cm-thread-connector {
  display: none;
}

/* Vertical line – starts at the curve level for children */
.cm-thread-line {
  position: absolute;
  left: 9px;              /* centre of 20px column */
  width: 2px;
  border-radius: 1px;
  background: var(--mid);
}
/* Root children: line runs from top to bottom */
.cm-thread-node[data-depth="1"] > .cm-thread-connector .cm-thread-line {
  top: 0; bottom: 0;
}
/* Deeper children: line starts at the curve (10px) */
.cm-thread-node:not([data-depth="0"]):not([data-depth="1"]) > .cm-thread-connector .cm-thread-line {
  top: 10px; bottom: 0;
}

/* Content area */
.cm-thread-content {
  flex: 1; min-width: 0;
  padding-top: 10px; padding-bottom: 2px;
  position: relative;
}

/* ✨ Curved connector (L‑shape) – only for replies (depth ≥ 1) */
.cm-thread-node:not([data-depth="0"]) > .cm-thread-content::before {
  content: '';
  position: absolute;
  left: -11px;            /* align with vertical line at 9px in connector */
  top: 10px;
  width: 16px;            /* reaches toward the avatar */
  height: 14px;           /* from top:10 down to 24 (avatar centre) */
  border-left: 2px solid var(--mid);
  border-bottom: 2px solid var(--mid);
  border-bottom-left-radius: 7px;
  box-sizing: border-box;
}

/* Row */
.cm-item-row {
  display: flex; gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--light);
}
.cm-thread-node:last-child > .cm-thread-content > .cm-item-row {
  border-bottom: none;
}

/* Avatar */
.cm-av { flex-shrink: 0; }
.cm-av-img {
  width: 36px; height: 36px;
  border-radius: 50%; object-fit: cover; display: block;
}
.cm-av-ph {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--red); color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 900; flex-shrink: 0;
}
.cm-thread-node:not([data-depth="0"]) .cm-av-img,
.cm-thread-node:not([data-depth="0"]) .cm-av-ph {
  width: 28px; height: 28px; font-size: 11px;
}

/* Body */
.cm-body  { flex: 1; min-width: 0; }
.cm-meta  { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; flex-wrap: wrap; }
.cm-name  { font-size: 13px; font-weight: 700; color: var(--ink); }
.cm-time  { font-size: 11px; color: var(--grey); }
.cm-text {
  font-size: 14px; color: var(--dk);
  line-height: 1.5; word-break: break-word; white-space: pre-wrap;
}
.cm-deleted { color: var(--grey); font-style: italic; font-size: 13px; }

/* ↳ @username */
.cm-reply-to {
  font-size: 11px; font-weight: 600;
  color: var(--red);
  margin-right: 4px; white-space: nowrap;
}

/* Actions */
.cm-actions { display: flex; gap: 12px; margin-top: 5px; flex-wrap: wrap; }
.cm-act {
  font-size: 12px; font-weight: 700; color: var(--grey);
  background: none; border: none; cursor: pointer;
  padding: 0; font-family: var(--font); transition: color .15s;
}
.cm-act:hover { color: var(--dk); }
.cm-del-btn:hover { color: var(--red); }

/* Collapse */
.cm-collapse-btn {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 4px;
  font-size: 12px; font-weight: 700;
  color: var(--red);
  background: none; border: none; cursor: pointer;
  padding: 0; font-family: var(--font); transition: opacity .15s;
}
.cm-collapse-btn:hover { opacity: .75; }

/* ════════════════════════════════════════════════════════════
   WRITE AREA
   ════════════════════════════════════════════════════════════ */
.cm-write-wrap {
  flex-shrink: 0;
  border-top: 1px solid var(--light);
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--mat-thick, var(--white));
}
.cm-replying-to {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--grey);
  margin-bottom: 6px;
  padding: 4px 10px;
  background: var(--light); border-radius: var(--r-sm);
}
.cm-replying-to strong { color: var(--red); }
.cm-replying-cancel {
  margin-left: auto; background: none; border: none;
  font-size: 16px; color: var(--grey); cursor: pointer;
  padding: 0; line-height: 1;
}
.cm-write-inner { display: flex; gap: 8px; align-items: flex-end; }
.cm-ta {
  flex: 1;
  min-height: 40px; max-height: 100px;
  padding: 10px 14px;
  border: 1.5px solid var(--light); border-radius: 20px;
  font-size: 14px; font-family: var(--font);
  background: var(--off); color: var(--ink);
  resize: none; outline: none;
  transition: border-color .18s;
  line-height: 1.4; overflow-y: auto;
}
.cm-ta:focus { border-color: var(--red); }
.cm-ta::placeholder { color: var(--mid); }

/* ★ Red send button */
.cm-send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--red);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity .15s, transform .12s, box-shadow .18s;
  box-shadow: 0 2px 8px var(--red-dim);
}
.cm-send-btn:hover  { opacity: .9; box-shadow: 0 4px 16px var(--red-glow); }
.cm-send-btn:active { transform: scale(.9); }
.cm-send-btn svg    { width: 18px; height: 18px; color: var(--white); }
.cm-send-btn.loading { opacity: .55; pointer-events: none; }
.cm-spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: var(--white); border-radius: 50%;
  animation: cm-spin .7s linear infinite; display: none;
}
.cm-send-btn.loading .cm-spinner { display: block; }
.cm-send-btn.loading svg { display: none; }
@keyframes cm-spin { to { transform: rotate(360deg); } }

.cm-write-hint {
  font-size: 13px; color: var(--grey);
  text-align: center; padding: 6px 0;
}
.cm-write-hint a {
  color: var(--red); font-weight: 700; text-decoration: none;
}

/* Skeleton */
.cm-skeleton {
  padding: 14px 0; border-bottom: 1px solid var(--light);
  display: flex; gap: 10px;
}
.cm-sk-av {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  animation: cm-shimmer 1.3s infinite linear;
  background: linear-gradient(90deg, var(--light) 25%, var(--mid) 50%, var(--light) 75%);
  background-size: 200% 100%;
}
.cm-sk-body { flex: 1; display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.cm-sk-line {
  height: 10px; border-radius: 6px;
  animation: cm-shimmer 1.3s infinite linear;
  background: linear-gradient(90deg, var(--light) 25%, var(--mid) 50%, var(--light) 75%);
  background-size: 200% 100%;
}
@keyframes cm-shimmer { to { background-position: -200% 0; } }

/* Load more */
.cm-load-more {
  display: block; width: 100%;
  padding: 11px; margin: 6px 0 12px;
  border-radius: var(--r-sm); border: 1.5px solid var(--light);
  background: transparent;
  font-size: 13px; font-weight: 700; color: var(--grey);
  cursor: pointer; font-family: var(--font); text-align: center;
  transition: background .15s, color .15s;
}
.cm-load-more:hover { background: var(--light); color: var(--dk); }

/* Empty state */
.cm-empty { text-align: center; padding: 40px 20px; color: var(--grey); font-size: 14px; }
.cm-empty-icon { font-size: 32px; opacity: .4; margin-bottom: 8px; }

/* Bookmark pulse */
.bm-btn.bm-saved {
  background: var(--red) !important;
  color: var(--white) !important;
  border-color: var(--red) !important;
}
@keyframes bm-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}
.bm-btn.bm-pulse { animation: bm-pulse .28s ease; }