/* Rapizza OS · panel v3 — Comentarios flotantes (comentarios.js)
   Botón flotante (rojo de marca con sombra dura, como el botón primario), modo comentar (marco + banda),
   globos numerados con la punta en el lugar comentado, hilo (popover en escritorio, hoja en móvil) y el panel
   lateral con todos los comentarios. Todo con los tokens de estilo.css (claro y oscuro). */

/* ───────────── botón flotante ───────────── */
.cm-fab {
  position: fixed; right: 24px; bottom: calc(var(--inf-h) + 24px + env(safe-area-inset-bottom)); z-index: 31;
  width: 56px; height: 56px; padding: 0; border: 0; border-radius: 18px; cursor: pointer;
  display: grid; place-items: center; color: #fff; background: var(--btn-pri);
  box-shadow: 0 3px 0 var(--brand-deep), 0 14px 28px -12px rgba(122, 14, 18, .6);
  transition: transform .15s, box-shadow .15s, background-color .15s; -webkit-tap-highlight-color: transparent;
}
.cm-fab:hover { background: var(--btn-pri-h); transform: translateY(-1px); }
.cm-fab:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--brand-deep), 0 6px 16px -8px rgba(122, 14, 18, .5); }
.cm-fab:focus-visible { outline: 3px solid var(--foco); outline-offset: 3px; border-radius: 18px; }
/* que el botón no tape el final de la página ni los avisos de abajo */
body:has(.cm-fab) .cont { padding-bottom: 108px; }

/* ───────────── globos ───────────── */
.cm-globos { position: fixed; left: 0; top: 0; width: 0; height: 0; z-index: 24; }
.cm-globo {
  position: fixed; left: 0; top: 0; margin: -28px 0 0 0; width: 28px; height: 28px; padding: 0;
  display: grid; place-items: center; border: 2px solid var(--surface); border-radius: 14px 14px 14px 3px;
  background: var(--c, #64748B); color: #fff; font: 700 12.5px/1 var(--f-texto); font-variant-numeric: tabular-nums;
  cursor: pointer; box-shadow: 0 4px 12px -4px rgba(0, 0, 0, .5); transform-origin: 0 100%; scale: 1;
  transition: scale .15s ease, box-shadow .15s ease, opacity .15s ease; -webkit-tap-highlight-color: transparent;
}
.cm-globo:hover, .cm-globo:focus-visible { scale: 1.14; z-index: 1; }
.cm-globo:focus-visible { outline: 2px solid var(--foco); outline-offset: 2px; }
.cm-globo--activo { scale: 1.16; z-index: 2; box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 30%, transparent), 0 4px 12px -4px rgba(0, 0, 0, .5); }
.cm-globo--fuera { visibility: hidden; }
.cm-globo--latido { animation: cmLatido 1.2s ease-out 2; }
@keyframes cmLatido {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 65%, transparent), 0 4px 12px -4px rgba(0, 0, 0, .5); }
  70%, 100% { box-shadow: 0 0 0 14px transparent, 0 4px 12px -4px rgba(0, 0, 0, .5); }
}
.cm-globo-r {
  position: absolute; top: -8px; right: -9px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--surface); color: var(--ink); font: 700 10px/16px var(--f-texto); font-style: normal; text-align: center;
  box-shadow: 0 0 0 1px var(--line-2);
}
.cm-elegido { outline: 2px solid var(--btn-pri) !important; outline-offset: 4px; }
.cm-destello { animation: cmDestello 1.9s ease-out; }
@keyframes cmDestello {
  0%, 35% { outline: 3px solid var(--accent); outline-offset: 7px; }
  100% { outline: 3px solid transparent; outline-offset: 2px; }
}

/* ───────────── modo comentar ───────────── */
html.cm-modo, html.cm-modo body, html.cm-modo #contenido, html.cm-modo #contenido * { cursor: crosshair !important; }
html.cm-modo .cm-globo { pointer-events: none; opacity: .5; }
html.cm-modo .cm-banda, html.cm-modo .cm-banda * { cursor: default !important; }
html.cm-modo .cm-banda button { cursor: pointer !important; }
.cm-marco {
  position: fixed; left: 0; top: 0; z-index: 76; pointer-events: none; border: 2px solid var(--btn-pri); border-radius: 12px;
  background: color-mix(in srgb, var(--btn-pri) 6%, transparent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--btn-pri) 14%, transparent);
  transition: transform .08s ease-out, width .08s ease-out, height .08s ease-out;
}
.cm-marco-t {
  position: absolute; left: -2px; bottom: calc(100% + 6px); max-width: min(380px, 80vw); padding: 5px 9px; border-radius: 7px;
  background: var(--btn-pri); color: #fff; font: 600 12.5px/1.25 var(--f-texto); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  box-shadow: 2px 2px 0 var(--brand-deep);
}
.cm-marco--adentro .cm-marco-t { bottom: auto; top: 6px; left: 6px; }
.cm-banda {
  position: fixed; left: 50%; bottom: calc(var(--inf-h) + 20px + env(safe-area-inset-bottom)); z-index: 78; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; width: max-content; max-width: calc(100vw - 24px);
  padding: 8px 8px 8px 10px; border-radius: 14px; background: var(--tip-bg); color: var(--tip-ink);
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, .55); animation: cmEntrar .2s cubic-bezier(.2, .8, .3, 1);
}
@keyframes cmEntrar { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
.cm-banda-ic { flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--btn-pri); color: #fff; box-shadow: 0 2px 0 var(--brand-deep); }
.cm-banda-t { display: flex; flex-direction: column; gap: 1px; min-width: 0; font-size: 13.5px; line-height: 1.35; }
.cm-banda-t b { font-size: 14px; }
.cm-banda-x { color: var(--tip-ink-2); }
.cm-banda .btn { flex: none; }
.cm-banda .btn kbd { margin-left: 2px; }
.cm-banda--aviso { animation: cmSacudir .42s ease; }
.cm-banda--aviso .cm-banda-x { color: var(--accent); }
@keyframes cmSacudir { 20%, 60% { transform: translateX(calc(-50% - 6px)); } 40%, 80% { transform: translateX(calc(-50% + 6px)); } }

/* ───────────── popover (hilo y caja para escribir) ───────────── */
.capa--cm { display: block; padding: 0; pointer-events: none; }
.cm-pop {
  position: fixed; left: 0; top: 0; pointer-events: auto; width: min(var(--ancho, 380px), calc(100vw - 24px));
  max-height: min(calc(100vh - 108px), 640px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--sombra-capa);
  animation: subir .16s ease-out;
}
.capa.saliendo .cm-pop { animation: bajar .14s ease-in forwards; }
.cm-pop:focus { outline: none; }
.cm-pop-cab { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 6px 2px 16px; }
.cm-pop-cab h2 { font: 600 15px/1.3 var(--f-texto); }
.cm-pop-cuerpo { padding: 4px 16px 14px; overflow-y: auto; min-height: 0; }

.cm-comp { display: flex; flex-direction: column; gap: 10px; }
.cm-donde { display: flex; align-items: flex-start; gap: 6px; font-size: 13px; line-height: 1.4; color: var(--ink-3); }
.cm-donde .ic { flex: none; margin-top: 2px; }
.cm-donde b { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.cm-ta {
  display: block; width: 100%; min-height: 96px; resize: vertical; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink); font: 400 15px/1.5 var(--f-texto); transition: border-color .15s, box-shadow .15s;
}
.cm-ta::placeholder { color: var(--ink-3); }
.cm-ta:focus { border-color: var(--foco); box-shadow: 0 0 0 3px color-mix(in srgb, var(--foco) 22%, transparent); outline: none; }
.cm-ta--resp { min-height: 64px; }
.cm-ta--vacia { border-color: var(--bad); animation: cmTa .3s ease; }
@keyframes cmTa { 25%, 75% { transform: translateX(-4px); } 50% { transform: translateX(4px); } }
.cm-cuenta { font-size: 12px; color: var(--ink-3); text-align: right; margin-top: -4px; }
.cm-cuenta:empty { display: none; }
.cm-comp-pie, .cm-resp-pie, .cm-ed-pie { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.cm-atajo { margin-right: auto; font-size: 12px; color: var(--ink-3); }
@media (pointer: coarse) { .cm-atajo { display: none; } }

/* ───────────── hilo ───────────── */
.cm-hilo { display: flex; flex-direction: column; gap: 12px; }
.cm-hilo-cab { display: flex; flex-direction: column; gap: 8px; }
.cm-est .chip { height: auto; min-height: 24px; padding: 4px 9px; white-space: normal; line-height: 1.3; }
.cm-sinancla { display: inline-flex; align-items: flex-start; gap: 6px; font-size: 12.5px; line-height: 1.4; color: var(--warn-tx); }
.cm-sinancla .ic { flex: none; margin-top: 1px; }
.cm-msjs { display: flex; flex-direction: column; gap: 12px; }
.cm-pop .cm-msjs { max-height: 320px; overflow-y: auto; overscroll-behavior: contain; padding: 2px 2px 2px 0; }
.cm-msj { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 10px; align-items: start; }
.cm-av {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c, #64748B); color: #fff; font: 400 14px/1 var(--f-titulo); letter-spacing: .02em;
}
.cm-av--sm { width: 22px; height: 22px; font-size: 11px; }
.cm-msj-c { min-width: 0; }
.cm-msj:not(.cm-msj--raiz) .cm-msj-c { background: var(--surface-2); border-radius: 4px 12px 12px 12px; padding: 8px 11px 9px; }
.cm-msj-cab { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.cm-msj-cab b { font-size: 14px; }
.cm-msj-cab small { font-size: 12px; color: var(--ink-3); }
.cm-msj-tx { margin-top: 3px; font-size: 14.5px; line-height: 1.5; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.cm-msj--raiz .cm-msj-tx { font-size: 15px; }
.cm-link {
  appearance: none; border: 0; background: none; padding: 6px 0 0; margin-right: 14px; display: inline-flex; align-items: center; gap: 4px;
  font: 600 12.5px/1 var(--f-texto); color: var(--ink-3); cursor: pointer;
}
.cm-link:hover { color: var(--ink); }
.cm-link--pel:hover { color: var(--bad-tx); }
.cm-ed { margin-top: 6px; display: flex; flex-direction: column; gap: 8px; }
.cm-ed .cm-ta { min-height: 80px; }
.cm-resp { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.cm-cerrado { font-size: 13px; line-height: 1.45; color: var(--ink-3); padding-top: 10px; border-top: 1px solid var(--line); }
.cm-hilo-acc { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cm-hilo-acc:empty { display: none; }
.cm-esp { flex: 1; }

/* ───────────── panel lateral ───────────── */
.cm-panel .drawer-cuerpo { padding: 14px 16px 24px; }
.cm-p-lista { display: flex; flex-direction: column; gap: 12px; }
.cm-p-top { display: flex; flex-direction: column; gap: 10px; }
.cm-p-top .btn .ic { flex: none; }
.cm-p-fil { position: sticky; top: -14px; z-index: 2; display: flex; flex-direction: column; gap: 8px; margin: -4px 0 0; padding: 8px 0 10px; background: var(--surface); border-bottom: 1px solid var(--line); }
.cm-p-seg { display: flex; width: 100%; }
.cm-p-seg > button { flex: 1; gap: 6px; }
.cm-p-n { font-size: 11.5px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.cm-p-seg > button[aria-pressed="true"] .cm-p-n { color: var(--ink-2); }
.cm-p-sels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.cm-p-sels .sel, .cm-p-sels select { width: 100%; }
.cm-p-sels select { height: 36px; font-size: 13px; }
.cm-p-fil .busq { max-width: none; min-width: 0; }
.cm-p-items { display: flex; flex-direction: column; gap: 10px; }
.cm-item { position: relative; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.cm-item:hover { border-color: var(--line-2); box-shadow: var(--sombra); }
.cm-item--cerrado { background: color-mix(in srgb, var(--surface) 65%, var(--bg)); }
.cm-item--cerrado .cm-item-tx { color: var(--ink-2); }
.cm-item-main {
  appearance: none; border: 0; background: none; color: inherit; width: 100%; text-align: left; cursor: pointer;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; border-radius: 12px; font: inherit;
}
.cm-item-cab { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding-right: 62px; min-width: 0; }
.cm-item-cab b { font-size: 14px; }
.cm-item-cab small { font-size: 12px; color: var(--ink-3); }
.cm-num { flex: none; width: 22px; height: 22px; border-radius: 11px 11px 11px 3px; background: var(--c); color: #fff; font: 700 11.5px/22px var(--f-texto); text-align: center; }
.cm-item-donde { display: flex; align-items: center; gap: 5px; min-width: 0; font-size: 12.5px; color: var(--ink-3); }
.cm-item-donde .ic { flex: none; }
.cm-item-donde span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-item-tx { font-size: 14.5px; line-height: 1.45; color: var(--ink); white-space: pre-line; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.cm-item-pie { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--ink-3); }
.cm-item-n { display: inline-flex; align-items: center; gap: 4px; }
.cm-item-ir { position: absolute; top: 8px; right: 8px; }
.cm-volver {
  appearance: none; border: 0; background: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px; margin: -4px 0 12px -8px;
  border-radius: 8px; font: 600 13.5px/1 var(--f-texto); color: var(--ink-2); cursor: pointer;
}
.cm-volver:hover { background: var(--surface-2); color: var(--ink); }
.cm-hoja .drawer-cuerpo { padding-top: 10px; }

/* ───────────── móvil ───────────── */
@media (max-width: 767.98px) {
  .cm-fab { right: 16px; bottom: calc(var(--inf-h) + 16px + env(safe-area-inset-bottom)); width: 52px; height: 52px; border-radius: 16px; transition: transform .2s ease, opacity .2s ease, box-shadow .15s, background-color .15s; }
  .cm-fab--corrido { transform: scale(.5); opacity: 0; pointer-events: none; }
  body:has(.cm-fab) .cont { padding-bottom: calc(var(--inf-h) + 96px + env(safe-area-inset-bottom)); }
  body:has(.cm-fab) .toasts { bottom: calc(var(--inf-h) + 82px + env(safe-area-inset-bottom)); }
  .cm-banda { bottom: calc(var(--inf-h) + 12px + env(safe-area-inset-bottom)); width: calc(100vw - 24px); }
  .cm-ta { font-size: 16px; }   /* iOS no hace zoom al escribir */
  .cm-hoja .cm-ta { min-height: 110px; }
  .cm-p-sels { grid-template-columns: minmax(0, 1fr); }
}

@media print { .cm-fab, .cm-globos, .cm-banda, .cm-marco { display: none !important; } }
