/* ==========================================================================
   Annotator — mark elements, jot what should change, copy the lot.
   Self contained: everything lives under #tb-anno and the .tb-anno-* prefix.
   ========================================================================== */

#tb-anno {
  position: fixed;
  inset: 0;
  z-index: 2000;
  pointer-events: none;
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text, #e9ecf3);
}

/* pointer-events inherits, so only the interactive pieces opt back in — the
   halo and the markers must stay click-through. */
#tb-anno .tb-anno-hint,
#tb-anno .tb-anno-pop,
#tb-anno .tb-anno-panel,
#tb-anno .tb-anno-fab { pointer-events: auto; }

#tb-anno [hidden] { display: none !important; }

html.tb-anno-picking,
html.tb-anno-picking * { cursor: crosshair !important; }
html.tb-anno-picking #tb-anno,
html.tb-anno-picking #tb-anno * { cursor: default !important; }
html.tb-anno-picking .tb-anno-pop,
html.tb-anno-picking .tb-anno-pop * { cursor: auto !important; }

/* ------------------------------------------------------------- hover halo -- */

.tb-anno-halo {
  position: fixed;
  pointer-events: none;
  border: 1.5px solid var(--accent, #6d5efc);
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent, #6d5efc) 12%, transparent);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 8px 30px -12px rgba(0, 0, 0, 0.8);
  transition: all 70ms cubic-bezier(0.22, 0.61, 0.36, 1);
  transition-property: top, left, width, height;
}

.tb-anno-halo__tag {
  position: absolute;
  left: -1.5px;
  bottom: 100%;
  margin-bottom: 4px;
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--accent, #6d5efc);
  color: #fff;
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  letter-spacing: -0.01em;
}

/* ---------------------------------------------------------------- markers -- */

.tb-anno-markers { position: fixed; inset: 0; pointer-events: none; }

.tb-anno-marker {
  position: fixed;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent, #6d5efc);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--bg, #0a0c11), 0 6px 16px -6px rgba(0, 0, 0, 0.8);
  transform: translate(-45%, -45%);
}

.tb-anno-marker--active { background: var(--success, #3ecf8e); }

.tb-anno-ring {
  position: fixed;
  pointer-events: none;
  border: 2px dashed var(--success, #3ecf8e);
  border-radius: 8px;
  animation: tb-anno-flash 1.1s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes tb-anno-flash {
  0%   { opacity: 0; transform: scale(1.04); }
  22%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; }
}

/* ------------------------------------------------------------------- hint -- */

.tb-anno-hint {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface-3, #1d2230);
  border: 1px solid var(--border-strong, rgba(255, 255, 255, 0.14));
  box-shadow: var(--shadow-lg, 0 24px 60px -20px rgba(0, 0, 0, 0.85));
  animation: tb-anno-drop 220ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes tb-anno-drop {
  from { opacity: 0; transform: translate(-50%, -10px); }
}

.tb-anno-hint__dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent, #6d5efc);
  animation: tb-anno-pulse 1.6s infinite;
}

@keyframes tb-anno-pulse {
  50% { opacity: 0.25; }
}

/* ---------------------------------------------------------------- popover -- */

.tb-anno-pop {
  position: fixed;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: var(--r-lg, 14px);
  background: var(--surface, #12151d);
  border: 1px solid var(--border-strong, rgba(255, 255, 255, 0.14));
  box-shadow: var(--shadow-lg, 0 24px 60px -20px rgba(0, 0, 0, 0.85));
  animation: tb-anno-pop-in 160ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes tb-anno-pop-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
}

.tb-anno-pop__target {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted, #99a0b2);
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tb-anno-pop__target b {
  color: var(--accent, #6d5efc);
  font-weight: 700;
}

.tb-anno-pop textarea {
  width: 100%;
  min-height: 74px;
  resize: vertical;
  padding: 9px 10px;
  border-radius: var(--r-md, 10px);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.075));
  background: var(--surface-2, #171b25);
  color: inherit;
  font: inherit;
}

.tb-anno-pop textarea:focus {
  outline: none;
  border-color: var(--accent, #6d5efc);
  box-shadow: 0 0 0 3px var(--accent-soft, rgba(109, 94, 252, 0.16));
}

.tb-anno-pop__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tb-anno-pop__actions kbd {
  margin-left: auto;
  color: var(--text-faint, #6b7285);
  font-family: var(--font-mono, monospace);
  font-size: 10.5px;
}

/* ------------------------------------------------------------------ panel -- */

.tb-anno-panel {
  position: fixed;
  right: 20px;
  bottom: 76px;
  width: 348px;
  max-height: min(66vh, 620px);
  display: flex;
  flex-direction: column;
  border-radius: var(--r-xl, 20px);
  background: var(--surface, #12151d);
  border: 1px solid var(--border-strong, rgba(255, 255, 255, 0.14));
  box-shadow: var(--shadow-lg, 0 24px 60px -20px rgba(0, 0, 0, 0.85));
  overflow: hidden;
  animation: tb-anno-pop-in 180ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.tb-anno-panel__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.075));
}

.tb-anno-panel__head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 640;
  letter-spacing: -0.01em;
}

.tb-anno-panel__count {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-3, #1d2230);
  color: var(--text-muted, #99a0b2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.tb-anno-panel__head .tb-anno-btn { margin-left: auto; }
.tb-anno-panel__head .tb-anno-btn + .tb-anno-btn { margin-left: 0; }

.tb-anno-list {
  margin: 0;
  padding: 8px;
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tb-anno-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 4px 10px;
  padding: 10px;
  border-radius: var(--r-md, 10px);
  background: var(--surface-2, #171b25);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}

.tb-anno-item:hover {
  background: var(--surface-3, #1d2230);
  border-color: var(--border, rgba(255, 255, 255, 0.075));
}

.tb-anno-item__n {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent-soft, rgba(109, 94, 252, 0.16));
  color: var(--accent, #6d5efc);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tb-anno-item__note {
  margin: 0;
  overflow-wrap: anywhere;
}

.tb-anno-item__sel {
  grid-column: 2;
  color: var(--text-faint, #6b7285);
  font-family: var(--font-mono, monospace);
  font-size: 10.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tb-anno-item__sel.is-stale::after {
  content: " · gone from page";
  color: var(--danger, #f2555a);
}

.tb-anno-item__x {
  grid-row: span 2;
  align-self: start;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--text-faint, #6b7285);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms, color 120ms;
}

.tb-anno-item:hover .tb-anno-item__x { opacity: 1; }
.tb-anno-item__x:hover { color: var(--danger, #f2555a); }

.tb-anno-empty {
  padding: 26px 20px;
  text-align: center;
  color: var(--text-muted, #99a0b2);
}

.tb-anno-empty kbd { color: var(--text, #e9ecf3); }

.tb-anno-panel__foot {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.075));
  background: var(--surface-2, #171b25);
}

/* -------------------------------------------------------------------- fab -- */

.tb-anno-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong, rgba(255, 255, 255, 0.14));
  background: var(--surface, #12151d);
  color: var(--text-muted, #99a0b2);
  font: inherit;
  font-weight: 560;
  cursor: pointer;
  box-shadow: var(--shadow-md, 0 8px 24px -8px rgba(0, 0, 0, 0.7));
  opacity: 0.62;
  transition: opacity 140ms, color 140ms, border-color 140ms, transform 140ms;
}

.tb-anno-fab:hover { opacity: 1; transform: translateY(-1px); }

.tb-anno-fab.is-live {
  opacity: 1;
  color: var(--accent, #6d5efc);
  border-color: var(--accent, #6d5efc);
}

.tb-anno-fab svg { width: 16px; height: 16px; fill: currentColor; }

.tb-anno-fab__count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent, #6d5efc);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- buttons -- */

.tb-anno-btn {
  padding: 6px 11px;
  border-radius: var(--r-md, 10px);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.075));
  background: var(--surface-3, #1d2230);
  color: var(--text, #e9ecf3);
  font: inherit;
  font-size: 12.5px;
  font-weight: 560;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms;
}

.tb-anno-btn:hover { border-color: var(--border-strong, rgba(255, 255, 255, 0.14)); }

.tb-anno-btn--primary {
  background: var(--accent, #6d5efc);
  border-color: transparent;
  color: #fff;
}

.tb-anno-btn--primary:hover { background: var(--accent-hover, #7d70ff); }
.tb-anno-btn--grow { flex: 1; }
.tb-anno-btn--quiet { background: none; }
.tb-anno-btn--danger:hover { color: var(--danger, #f2555a); }

@media (prefers-reduced-motion: reduce) {
  #tb-anno *,
  #tb-anno *::before { animation: none !important; transition: none !important; }
}
