/* =============================================================
   atlas-edn · ANNOTATIONS — V1 (POC item 63)
   -------------------------------------------------------------
   Surlignage 4 couleurs (Stabilo doux), gras, post-its dans la
   marge droite, panneau latéral d'export/import.
   Tons calmes, cohérents avec la palette terre du projet.
   ============================================================= */

/* -------------------------------------------------------------
   1) Couleurs surligneur
   ------------------------------------------------------------- */
:root {
  --annot-yellow:   #FEF3A7;
  --annot-blue:     #BEE3F8;
  --annot-red:      #FEB2B2;
  --annot-pink:     #FBB6CE;

  --annot-yellow-strong: #f4d100;
  --annot-blue-strong:   #2196f3;
  --annot-red-strong:    #e53935;
  --annot-pink-strong:   #ec407a;
}

/* -------------------------------------------------------------
   2) Wrappers d'annotations dans la fiche
   ------------------------------------------------------------- */
.annot-highlight {
  padding: 0 1px;
  border-radius: 2px;
  cursor: pointer;
  transition: filter .15s ease;
}
.annot-highlight.annot-yellow { background: var(--annot-yellow); }
.annot-highlight.annot-blue   { background: var(--annot-blue); }
.annot-highlight.annot-red    { background: var(--annot-red); }
.annot-highlight.annot-pink   { background: var(--annot-pink); }
.annot-highlight:hover { filter: brightness(0.95); }

.annot-bold {
  font-weight: 700;
  cursor: pointer;
}

.annot-note-target {
  border-bottom: 1px dashed #999;
  cursor: pointer;
}

/* Flash au survol d'une icône de marge */
.annot-flash {
  animation: annot-flash-anim .7s ease;
}
@keyframes annot-flash-anim {
  0%   { background: transparent; }
  30%  { background: rgba(255, 220, 80, 0.55); box-shadow: 0 0 0 2px rgba(255, 220, 80, 0.55); }
  100% { background: transparent; box-shadow: none; }
}

/* Cohabitation mode ludique : surlignage transparent dans une zone
   masquée (l'icône 💬 reste visible dans la marge). */
body.ludic-on .ludic-hide:not(.revealed) .annot-highlight,
body.ludic-on .ludic-hide:not(.revealed) .annot-bold,
body.ludic-on .ludic-hide:not(.revealed) .annot-note-target {
  background: transparent !important;
  border-bottom: none !important;
}

/* -------------------------------------------------------------
   3) Toolbar flottante (sélection)
   ------------------------------------------------------------- */
.annot-toolbar {
  position: absolute;
  z-index: 9998;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--accent-border, #e0d5b8);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.08);
  font-family: var(--font-sans, sans-serif);
  font-size: 13px;
  animation: annot-fade-in .12s ease;
}
.annot-toolbar[hidden] { display: none; }

@keyframes annot-fade-in {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: translateY(0); }
}

.annot-tool-color {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: transform .12s ease, box-shadow .12s ease;
}
.annot-tool-color:hover {
  transform: scale(1.12);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.06);
}
.annot-tool-color.annot-yellow { background: var(--annot-yellow); }
.annot-tool-color.annot-blue   { background: var(--annot-blue); }
.annot-tool-color.annot-red    { background: var(--annot-red); }
.annot-tool-color.annot-pink   { background: var(--annot-pink); }

.annot-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  min-width: 28px;
  padding: 0 8px;
  border: 1px solid transparent;
  background: var(--bg-card, #faf6ec);
  color: var(--ink, #1a1713);
  font-family: inherit;
  font-size: 13px;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease;
}
.annot-tool-btn:hover {
  background: color-mix(in oklab, var(--ink, #1a1713) 6%, var(--bg-card, #faf6ec));
  border-color: var(--accent-dash, #c4b898);
}
.annot-tool-btn strong { font-weight: 700; font-family: serif; }

.annot-tool-sep {
  width: 1px;
  height: 18px;
  background: var(--accent-dash, #c4b898);
  margin: 0 2px;
}

/* -------------------------------------------------------------
   4) Marge droite + icônes 💬
   ------------------------------------------------------------- */
#annotations-margin {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 0;
  pointer-events: none;
  z-index: 50;
}

.annot-margin-icon {
  position: absolute;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--accent-border, #e0d5b8);
  border-radius: 50%;
  background: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease;
}
.annot-margin-icon:hover {
  transform: scale(1.14);
  background: var(--annot-yellow);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.14);
}
.annot-margin-icon:focus-visible {
  outline: 2px solid var(--spe-psy, #6e3f66);
  outline-offset: 2px;
}

/* -------------------------------------------------------------
   5) Popover (note + création de note)
   ------------------------------------------------------------- */
.annot-popover {
  position: absolute;
  z-index: 9999;
  width: 320px;
  max-width: calc(100vw - 24px);
  background: #fff;
  border: 1px solid var(--accent-border, #e0d5b8);
  border-radius: 8px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.18);
  font-family: var(--font-sans, sans-serif);
  font-size: 14px;
  animation: annot-fade-in .12s ease;
}
.annot-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--accent-border, #e0d5b8);
  font-weight: 500;
  color: var(--ink-muted, #6b5e45);
  font-size: 13px;
}
.annot-popover-close {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--ink-muted, #6b5e45);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
}
.annot-popover-close:hover {
  background: color-mix(in oklab, var(--ink, #1a1713) 6%, transparent);
  color: var(--ink, #1a1713);
}
.annot-popover-textarea {
  display: block;
  width: calc(100% - 24px);
  margin: 12px;
  padding: 8px 10px;
  border: 1px solid var(--accent-border, #e0d5b8);
  border-radius: 6px;
  background: var(--bg-card, #faf6ec);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink, #1a1713);
  resize: vertical;
  min-height: 80px;
  box-sizing: border-box;
}
.annot-popover-textarea:focus {
  outline: 2px solid var(--spe-psy, #6e3f66);
  outline-offset: -1px;
  background: #fff;
}
.annot-popover-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 12px 12px;
}

/* -------------------------------------------------------------
   6) Boutons génériques
   ------------------------------------------------------------- */
.annot-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--accent-dash, #c4b898);
  background: transparent;
  color: var(--ink-muted, #6b5e45);
  font-family: var(--font-sans, sans-serif);
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color .12s ease, color .12s ease, border-color .12s ease;
}
.annot-btn:hover {
  background: color-mix(in oklab, var(--ink, #1a1713) 5%, var(--bg-card, #faf6ec));
  color: var(--ink, #1a1713);
}
.annot-btn-primary {
  background: var(--spe-psy, #6e3f66);
  border-color: var(--spe-psy, #6e3f66);
  color: #fff;
}
.annot-btn-primary:hover {
  background: color-mix(in oklab, var(--spe-psy, #6e3f66) 85%, #000);
  color: #fff;
}
.annot-btn-secondary {
  background: var(--bg-card, #faf6ec);
}
.annot-btn-danger {
  border-color: var(--alert-red, #a52a1a);
  color: var(--alert-red, #a52a1a);
}
.annot-btn-danger:hover {
  background: var(--alert-red-soft, #f3dccf);
  color: var(--alert-red, #a52a1a);
}

/* -------------------------------------------------------------
   7) Menu contextuel (clic sur surlignage existant)
   ------------------------------------------------------------- */
.annot-menu {
  position: absolute;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  min-width: 180px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--accent-border, #e0d5b8);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
  font-family: var(--font-sans, sans-serif);
  font-size: 13px;
  animation: annot-fade-in .12s ease;
}
.annot-menu-row {
  display: flex;
  gap: 6px;
  padding: 4px 6px;
}
.annot-menu-color {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  transition: transform .1s ease, border-color .1s ease;
}
.annot-menu-color:hover { transform: scale(1.1); }
.annot-menu-color.active {
  border-color: var(--ink, #1a1713);
}
.annot-menu-color.annot-yellow { background: var(--annot-yellow); }
.annot-menu-color.annot-blue   { background: var(--annot-blue); }
.annot-menu-color.annot-red    { background: var(--annot-red); }
.annot-menu-color.annot-pink   { background: var(--annot-pink); }

.annot-menu-item {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: transparent;
  color: var(--ink, #1a1713);
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color .1s ease;
}
.annot-menu-item:hover {
  background: var(--bg-card, #faf6ec);
}
.annot-menu-danger { color: var(--alert-red, #a52a1a); }
.annot-menu-danger:hover { background: var(--alert-red-soft, #f3dccf); }

/* -------------------------------------------------------------
   8) Bouton flottant + panneau latéral
   ------------------------------------------------------------- */
#annotations-panel-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 9990;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--accent-border, #e0d5b8);
  background: #fff;
  color: var(--ink, #1a1713);
  font-family: var(--font-sans, sans-serif);
  font-size: 12px;
  letter-spacing: 0.02em;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  transition: transform .12s ease, box-shadow .12s ease;
}
#annotations-panel-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}
#annotations-panel-btn .apb-icon { font-size: 14px; }
#annotations-panel-btn .apb-label { font-weight: 500; }
#annotations-panel-btn .apb-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--spe-psy, #6e3f66);
  color: #fff;
  font-family: var(--font-mono, monospace);
  font-size: 10px;
  border-radius: 9px;
}

#annotations-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 9995;
  width: 380px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  background: var(--bg-cream, #f4efe6);
  border-left: 1px solid var(--accent-border, #e0d5b8);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.08);
  font-family: var(--font-sans, sans-serif);
  animation: annot-panel-slide .2s ease;
}
#annotations-panel[hidden] { display: none; }
@keyframes annot-panel-slide {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.ap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--accent-border, #e0d5b8);
  background: var(--bg-card, #faf6ec);
}
.ap-header h2 {
  font-family: var(--font-serif, serif);
  font-size: 20px;
  font-weight: 500;
  font-style: italic;
  margin: 0;
  color: var(--ink, #1a1713);
}
.ap-close {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--ink-muted, #6b5e45);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
}
.ap-close:hover {
  background: color-mix(in oklab, var(--ink, #1a1713) 6%, transparent);
  color: var(--ink, #1a1713);
}

.ap-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ap-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--ink-muted, #6b5e45);
  font-size: 13px;
  line-height: 1.6;
}

.ap-item {
  background: #fff;
  border: 1px solid var(--accent-border, #e0d5b8);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.ap-item header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.ap-tag {
  display: inline-block;
  padding: 1px 8px;
  font-size: 11px;
  letter-spacing: 0.02em;
  border-radius: 999px;
  background: var(--bg-card, #faf6ec);
  color: var(--ink-muted, #6b5e45);
  border: 1px solid var(--accent-border, #e0d5b8);
}
.ap-tag-yellow { background: var(--annot-yellow); color: #6b5500; border-color: var(--annot-yellow-strong); }
.ap-tag-blue   { background: var(--annot-blue);   color: #135c8e; border-color: var(--annot-blue-strong); }
.ap-tag-red    { background: var(--annot-red);    color: #8a1717; border-color: var(--annot-red-strong); }
.ap-tag-pink   { background: var(--annot-pink);   color: #8a1956; border-color: var(--annot-pink-strong); }
.ap-tag-bold   { background: #efe6cf; color: var(--ink, #1a1713); }
.ap-tag-note   { background: var(--spe-psy-light, #f0e6ec); color: var(--spe-psy, #6e3f66); border-color: var(--spe-psy, #6e3f66); }

.ap-orphan {
  display: inline-block;
  padding: 1px 7px;
  font-size: 11px;
  border-radius: 999px;
  background: var(--alert-red-soft, #f3dccf);
  color: var(--alert-red, #a52a1a);
}
.ap-goto, .ap-del {
  margin-left: auto;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--ink-muted, #6b5e45);
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
}
.ap-goto { margin-left: auto; }
.ap-del  { margin-left: 2px; color: var(--alert-red, #a52a1a); }
.ap-goto:hover, .ap-del:hover {
  background: color-mix(in oklab, var(--ink, #1a1713) 6%, transparent);
}

.ap-quote {
  font-family: var(--font-serif, serif);
  font-style: italic;
  color: var(--ink, #1a1713);
  line-height: 1.45;
  margin-bottom: 4px;
}
.ap-note-content {
  margin-top: 6px;
  padding: 6px 8px;
  background: var(--bg-card, #faf6ec);
  border-left: 2px solid var(--spe-psy, #6e3f66);
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--ink, #1a1713);
  white-space: pre-wrap;
}

.ap-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 14px 16px;
  border-top: 1px solid var(--accent-border, #e0d5b8);
  background: var(--bg-card, #faf6ec);
}

/* -------------------------------------------------------------
   9) Mobile — repli des icônes de marge dans la colonne droite
   ------------------------------------------------------------- */
@media (max-width: 1100px) {
  .annot-margin-icon {
    width: 22px;
    height: 22px;
    font-size: 12px;
  }
}
@media (max-width: 720px) {
  #annotations-panel-btn {
    top: auto;
    bottom: 14px;
    right: 14px;
  }
  #annotations-panel { width: 100vw; max-width: 100vw; }
  .annot-margin-icon { box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
}
