:root {
  --bg: #f4ede0;
  --fg: #33302b;
  --card: #fdfaf3;
  --muted: #8a8378;
  --muted2: #b8b0a2;
  --border: #e4dccc;
  --secondary: #ece4d6;
  --topbar: rgba(253, 250, 243, 0.72);
  --primary: #c2745b;
  --sage: #8a9a7b;
  --ocre: #d9a35a;
  --idea-bg: #f6e7cf;
  --idea-border: #e3c08e;
  --danger: #bd4b3f;
  --radius: 14px;
  --shadow: 0 2px 12px -2px rgba(58, 51, 44, 0.1);
  --shadow-lg: 0 12px 34px -10px rgba(58, 51, 44, 0.22);
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Nunito', system-ui, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
  flex: none;
}
.icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

#app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* PWA/standalone: la altura dinámica cuenta bien el área visible (evita que los
                     controles de abajo —zoom, minimapa, "¿dónde estoy?"— queden fuera de pantalla) */
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
#sidebar {
  width: 284px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--secondary);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width 0.22s ease, opacity 0.18s ease;
}
#app.sidebar-collapsed #sidebar {
  width: 0;
  opacity: 0;
  border-right-color: transparent;
  pointer-events: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
}
.brand-txt {
  min-width: 0;
}
.brand-spacer {
  flex: 1;
}
.sidebar-collapse-btn {
  display: inline-flex;
  border: none;
  background: none;
  padding: 6px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}
.sidebar-collapse-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--fg);
}
.sidebar-collapse-btn .icon {
  width: 16px;
  height: 16px;
}
.brand-ico {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: rgba(138, 154, 123, 0.2);
  color: var(--sage);
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-ico .icon {
  width: 19px;
  height: 19px;
}
.brand-name {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.1;
}
.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.tree {
  flex: 1;
  overflow: auto;
  padding: 4px 8px 8px;
}
.row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-radius: 10px;
}
.row:hover {
  background: rgba(0, 0, 0, 0.035);
}
.chev {
  display: inline-flex;
  border: none;
  background: none;
  padding: 2px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
}
.chev .icon {
  width: 15px;
  height: 15px;
}
.emoji {
  font-size: 15px;
  line-height: 1;
}
.item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
  cursor: text;
}
.nb-row .item-name {
  font-weight: 700;
}
.sec-row .item-name {
  font-weight: 600;
  color: #4a463f;
}
.act {
  display: inline-flex;
  border: none;
  background: none;
  padding: 4px;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: 0.15s;
}
.row:hover .act {
  opacity: 1;
}
.act:hover {
  background: var(--card);
  color: var(--fg);
}
.act.danger:hover {
  background: rgba(193, 75, 63, 0.12);
  color: var(--danger);
}
.act .icon {
  width: 14px;
  height: 14px;
}
.children {
  margin-left: 14px;
  border-left: 1px solid var(--border);
  padding-left: 6px;
}
.note-row {
  cursor: pointer;
  font-size: 13.5px;
}
.note-row > .icon {
  width: 15px;
  height: 15px;
  color: var(--muted);
}
.note-row.active {
  background: rgba(194, 116, 91, 0.16);
}
.note-row.active > .icon {
  color: var(--primary);
}
.tree-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 4px 10px;
  margin: 0;
}
.add-nb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 10px 12px;
  padding: 8px 10px;
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  border-radius: 10px;
  cursor: pointer;
}
.add-nb:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--fg);
}
.sidebar-groups {
  margin: 8px 10px 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.sidebar-sec-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  padding: 0 4px 6px;
}
.sidebar-sec-title .icon { width: 14px; height: 14px; }
.sidebar-group-list { display: flex; flex-direction: column; gap: 2px; }
.group-row {
  cursor: pointer;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 8px;
}
.group-row:hover { background: rgba(0, 0, 0, 0.04); }
.group-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 7px;
  flex-shrink: 0;
}
.group-dot.g-sage { background: #8a9a7b; }
.group-dot.g-blue { background: #4f84c4; }
.group-dot.g-ocre { background: #d9a35a; }
.group-dot.g-lila { background: #9d72d6; }
.group-dot.g-rose { background: #cf6295; }
.inline-edit {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13.5px;
  padding: 2px 6px;
  border: 1px solid var(--primary);
  border-radius: 7px;
  background: var(--card);
  color: var(--fg);
  outline: none;
}

/* ---------- Main / Topbar ---------- */
#main {
  flex: 1;
  min-width: 0;
  min-height: 0; /* clave en PWA: permite que #canvas ocupe el alto real y no empuje los
                    controles de abajo (zoom/centrar/minimapa) hacia arriba con las notas */
  display: flex;
  flex-direction: column;
}
#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--topbar, rgba(253, 250, 243, 0.75));
  backdrop-filter: blur(6px);
}
.tb-left {
  flex: 1;
  min-width: 0;
}
.crumb {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}
.crumb .sep {
  opacity: 0.5;
}
.note-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 21px;
  font-weight: 600;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
}
.note-title.is-muted {
  color: var(--muted);
}
.hint {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--secondary);
  color: var(--muted);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
}
.hint .icon {
  width: 14px;
  height: 14px;
}
.ai-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 10px;
  cursor: pointer;
}
.ai-btn:hover {
  border-color: var(--ocre);
}
.ai-btn.ready {
  border-color: var(--ocre);
  background: rgba(217, 163, 90, 0.12);
}
.ai-btn .icon {
  width: 16px;
  height: 16px;
  color: var(--ocre);
}
@media (max-width: 820px) {
  .hint {
    display: none;
  }
}

/* ---------- Canvas ---------- */
#canvas {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(120, 108, 92, 0.18) 1px, transparent 1px);
  background-size: 20px 20px;
}
#canvas.drag-over::after {
  content: 'Suelta para importar (.md, .pdf o imagen)';
  position: absolute;
  inset: 12px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--sage);
  border-radius: 18px;
  background: rgba(138, 154, 123, 0.12);
  color: var(--sage);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  pointer-events: none;
}
body.space-pan #canvas {
  cursor: grab;
}
body.panning,
body.panning #canvas {
  cursor: grabbing !important;
}
#canvas.tablet-active {
  touch-action: none;
}
body.panning {
  user-select: none;
}
.canvas-content {
  position: relative;
  width: 4000px;
  height: 3000px;
  min-width: 100%;
  min-height: 100%;
  transform-origin: 0 0;
  will-change: transform;
}
.zoom-ctl {
  position: absolute;
  right: 16px;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 50; /* siempre visible por encima del contenido del lienzo */
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 50;
}
.zoom-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  background: none;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  color: var(--fg);
  cursor: pointer;
}
.zoom-btn:hover {
  background: rgba(120, 108, 92, 0.12);
}
.zoom-btn .icon {
  width: 16px;
  height: 16px;
}
.zoom-pct {
  min-width: 52px;
  height: 30px;
  border: none;
  background: none;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg);
  border-radius: 8px;
  cursor: pointer;
}
.zoom-pct:hover {
  background: rgba(120, 108, 92, 0.12);
}
.zoom-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
}
/* Ayudas de navegación: aviso "volver al contenido" y minimapa */
.lost-hint {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  animation: pop 0.16s ease-out;
}
.lost-hint .icon { width: 15px; height: 15px; }
.lost-hint:hover { filter: brightness(1.06); }
.mini-map {
  position: absolute;
  left: 14px;
  left: calc(14px + env(safe-area-inset-left, 0px));
  bottom: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  width: 156px;
  height: 108px;
  z-index: 30;
  background: color-mix(in srgb, var(--card) 86%, transparent);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  opacity: 0.72;
  transition: opacity 0.15s ease;
}
.mini-map:hover { opacity: 1; }
.mini-inner { position: absolute; inset: 0; }
.mini-inner i {
  position: absolute;
  background: var(--sage);
  border-radius: 2px;
  opacity: 0.7;
}
.mini-vp {
  position: absolute;
  border: 1.5px solid var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border-radius: 2px;
  pointer-events: none;
}
.mini-hide {
  position: absolute;
  top: 1px;
  right: 5px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
.mini-hide:hover { color: var(--fg); }

/* ---------- Tour visual guiado ---------- */
.tour-catch { position: fixed; inset: 0; z-index: 5000; }
.tour-spot {
  position: fixed;
  z-index: 5001;
  border-radius: 12px;
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 9999px rgba(30, 26, 22, 0.55);
  pointer-events: none;
  transition: left 0.22s ease, top 0.22s ease, width 0.22s ease, height 0.22s ease;
}
.tour-pop {
  position: fixed;
  z-index: 5002;
  width: 300px;
  max-width: calc(100vw - 28px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 14px 16px;
  animation: pop 0.16s ease-out;
}
.tour-step { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.tour-title { font-family: 'Fraunces', Georgia, serif; font-size: 17px; font-weight: 600; margin: 3px 0 6px; }
.tour-body { font-size: 13.5px; line-height: 1.5; color: var(--fg); }
.tour-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.tour-nav-right { display: inline-flex; gap: 8px; }
.tour-btn { padding: 6px 14px; border: none; border-radius: 999px; background: var(--primary); color: #fff; font-weight: 700; font-size: 13px; cursor: pointer; }
.tour-btn.ghost { background: transparent; color: var(--fg); border: 1px solid var(--border); }
.tour-btn:hover { filter: brightness(1.06); }
.tour-skip { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.tour-skip:hover { color: var(--fg); }
.empty-tour-btn {
  margin-top: 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: filter 0.14s ease, transform 0.14s ease;
}
.empty-tour-btn .icon { width: 16px; height: 16px; }
.empty-tour-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }

/* ---------- Puerta de acceso por token ---------- */
/* .overlay.token-gate: mayor especificidad que .overlay (que centra a la derecha). */
.overlay.token-gate {
  justify-content: center;
  align-items: center;
  z-index: 6000;
  background: rgba(30, 26, 22, 0.5);
  backdrop-filter: blur(3px);
}
.gate-card {
  width: 420px;
  max-width: calc(100vw - 32px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 28px 26px 22px;
  text-align: center;
  animation: pop 0.18s ease-out;
}
.gate-ico {
  display: inline-flex;
  width: 52px;
  height: 52px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--secondary);
  color: var(--primary);
  margin-bottom: 10px;
}
.gate-ico .icon { width: 26px; height: 26px; }
.gate-title { font-family: 'Fraunces', Georgia, serif; font-size: 22px; font-weight: 600; margin: 0 0 6px; }
.gate-sub { font-size: 14px; color: var(--muted); line-height: 1.5; margin: 0 auto 18px; max-width: 340px; }
.gate-row { display: flex; gap: 8px; }
.gate-input {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}
.gate-input:focus { outline: none; border-color: var(--primary); }
.gate-btn {
  padding: 11px 20px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.gate-btn:hover { filter: brightness(1.06); }
.gate-btn:disabled { opacity: 0.6; cursor: default; }
.gate-msg { min-height: 18px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.gate-msg.err { color: #c0563c; }
.gate-skip {
  margin-top: 14px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: underline;
}
.gate-skip:hover { color: var(--fg); }
.card {
  position: absolute;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  resize: both;
  min-width: 160px;
  min-height: 92px;
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
}
@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}
/* Solo los bloques recién creados entran con rebote (no cada re-render). */
.card.card-enter {
  animation: cardIn 0.32s cubic-bezier(0.34, 1.45, 0.64, 1) both;
}
@keyframes cardIn {
  from {
    opacity: 0;
    transform: scale(0.86) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}
.card:hover {
  box-shadow: var(--shadow-lg);
}
.card:focus-within {
  box-shadow: var(--shadow-lg);
  border-color: var(--sage);
}
.card.idea {
  background: var(--idea-bg);
  border-color: var(--idea-border);
}
.card-head {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  cursor: grab;
  user-select: none;
}
.card-head:active {
  cursor: grabbing;
}
.card-head > .icon {
  width: 14px;
  height: 14px;
  color: var(--muted);
}
.card.idea .card-head > .icon {
  color: var(--ocre);
}
.card-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.card-del {
  margin-left: auto;
  display: inline-flex;
  border: none;
  background: none;
  padding: 2px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: 0.15s;
}
.card:hover .card-del {
  opacity: 1;
}
.card-del:hover {
  background: rgba(193, 75, 63, 0.12);
  color: var(--danger);
}
.card-del .icon {
  width: 14px;
  height: 14px;
}
.card-ta {
  flex: 1;
  width: 100%;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--fg);
  padding: 0 12px 12px;
}
.card-ta::placeholder {
  color: var(--muted2);
}
/* Notas de texto/idea con alto auto-adaptable: la tarjeta crece con el contenido. */
.card.note-auto { height: auto !important; }
.card.note-auto .card-ta { flex: none; overflow: hidden; min-height: 22px; }
/* Nota con tamaño manual (alto fijo elegido por el usuario): el texto se desplaza dentro. */
.card.note-manual .card-ta { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
/* Las notas/ideas usan el tirador propio (ancho + alto); sin el redimensionador nativo del
   navegador, que ocupaba la esquina y capturaba el arrastre antes que nuestro tirador. */
.card.note-auto, .card.note-manual { resize: none; }

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 24px;
}
.empty-ico {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: rgba(138, 154, 123, 0.16);
  color: var(--sage);
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-ico .icon {
  width: 28px;
  height: 28px;
}
.empty-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 19px;
  margin: 0;
}
.empty-sub {
  max-width: 320px;
  color: var(--muted);
  font-size: 13.5px;
  margin: 0;
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: #d8cfbe;
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------- Boton icono / Combinar / Historial ---------- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  flex: none;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.icon-btn:hover {
  color: var(--fg);
  border-color: var(--muted2);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px -6px rgba(58, 51, 44, 0.35);
}
.icon-btn:active {
  transform: translateY(0) scale(0.95);
  box-shadow: none;
}
.icon-btn .icon {
  width: 17px;
  height: 17px;
}

.card.merge-target {
  outline: 2px dashed var(--sage);
  outline-offset: 2px;
  box-shadow: var(--shadow-lg);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 35, 30, 0.32);
  display: flex;
  justify-content: flex-end;
  z-index: 1000;
  animation: fade 0.15s ease-out;
}
@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.log-panel {
  width: 370px;
  max-width: 92vw;
  height: 100%;
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: slidein 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes slidein {
  from {
    transform: translateX(36px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.log-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 17px;
  font-weight: 600;
}
.log-title .icon {
  width: 18px;
  height: 18px;
  color: var(--primary);
}
.log-body {
  flex: 1;
  overflow: auto;
  padding: 4px 16px 16px;
}
/* ---------- Integraciones ---------- */
.integ-panel {
  width: 440px;
}
.integ-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 2px;
  border-bottom: 1px solid var(--border);
}
.integ-dot {
  flex: none;
  width: 9px;
  height: 9px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--muted2);
}
.integ-dot.ok {
  background: #3fae87;
  box-shadow: 0 0 0 3px rgba(63, 174, 135, 0.18);
}
.integ-dot.off {
  background: #d98b6a;
  box-shadow: 0 0 0 3px rgba(217, 139, 106, 0.18);
}
.integ-main {
  flex: 1;
  min-width: 0;
}
.integ-name {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
}
.integ-ver {
  font-family: ui-monospace, Consolas, Menlo, monospace;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--primary);
  background: var(--secondary);
  padding: 1px 7px;
  border-radius: 6px;
}
.integ-desc {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.integ-url {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted2);
  text-decoration: none;
  word-break: break-all;
}
.integ-url:hover {
  color: var(--primary);
  text-decoration: underline;
}
.integ-status {
  flex: none;
  align-self: center;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.integ-status.ok {
  color: #2f8f6d;
  background: rgba(63, 174, 135, 0.14);
}
.integ-status.off {
  color: #b5623f;
  background: rgba(217, 139, 106, 0.16);
}
.integ-note {
  margin-top: 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  background: var(--secondary);
  padding: 10px 12px;
  border-radius: 10px;
}
.log-date {
  position: sticky;
  top: 0;
  background: var(--card);
  padding: 12px 0 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.log-item {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}
.log-time {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted2);
  padding-top: 1px;
  flex: none;
  width: 46px;
}
.log-text {
  min-width: 0;
}
.log-action {
  font-size: 13.5px;
  font-weight: 600;
}
.log-detail {
  font-size: 12.5px;
  color: var(--muted);
  word-break: break-word;
}

/* ---------- Tarjetas: pop-out + imagenes ---------- */
.card-spacer {
  flex: 1;
}
.card-pop {
  display: inline-flex;
  border: none;
  background: none;
  padding: 2px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: 0.15s;
}
.card:hover .card-pop {
  opacity: 1;
}
.card-pop:hover {
  background: var(--secondary);
  color: var(--fg);
}
.card-pop .icon {
  width: 14px;
  height: 14px;
}
.card-imgs {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}
.card-imgs .icon {
  width: 13px;
  height: 13px;
}
.card-img-btn,
.card-fmt-btn,
.card-dl-all {
  display: inline-flex;
  border: none;
  background: none;
  align-items: center;
  justify-content: center;
  padding: 3px;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: 0.15s;
}
.card:hover .card-img-btn,
.card:hover .card-fmt-btn,
.card:hover .card-dl-all {
  opacity: 1;
}
/* Mantener visibles los controles de cabecera mientras se edita o selecciona la tarjeta,
   para que no se oculten al mover el ratón hacia ellos. */
.card:focus-within .card-fmt-btn,
.card:focus-within .card-img-btn,
.card:focus-within .card-dl-all,
.card:focus-within .card-pop,
.card:focus-within .card-del,
.card:focus-within .card-menu,
.card.selected .card-fmt-btn,
.card.selected .card-img-btn,
.card.selected .card-dl-all,
.card.selected .card-pop {
  opacity: 1;
}

/* ---------- Barra flotante de formato sobre la selección ---------- */
.sel-fmt-bar {
  position: fixed;
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 11px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  pointer-events: none;
}
.sel-fmt-bar.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.sel-fmt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border: none;
  background: none;
  border-radius: 7px;
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s;
}
.sel-fmt-btn:hover {
  background: var(--secondary);
}
.sel-fmt-sep {
  width: 1px;
  height: 18px;
  margin: 0 3px;
  background: var(--border);
}
.theme-toggle {
  cursor: pointer;
  gap: 9px;
}
.theme-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}
.card-img-btn:hover,
.card-fmt-btn:hover,
.card-dl-all:hover {
  background: var(--secondary);
  color: var(--fg);
}
.card-img-btn .icon,
.card-fmt-btn .icon,
.card-dl-all .icon {
  width: 14px;
  height: 14px;
}
.card-media {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 12px 10px;
  overflow: auto;
}
.card-fig {
  position: relative;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--card);
  line-height: 0;
}
.card-fig img {
  display: block;
  width: 120px;
  max-width: none;
  height: auto;
  user-select: none;
}
.card-fig .fig-del {
  position: absolute;
  top: 5px;
  right: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: rgba(20, 16, 12, 0.55);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: 0.15s;
}
.card-fig:hover .fig-del {
  opacity: 1;
}
.card-fig .fig-del:hover {
  background: var(--danger);
}
.card-fig .fig-del .icon {
  width: 14px;
  height: 14px;
}
.card-fig .fig-dl {
  position: absolute;
  bottom: 5px;
  left: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: rgba(20, 16, 12, 0.55);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: 0.15s;
  z-index: 2;
}
.card-fig:hover .fig-dl {
  opacity: 1;
}
.card-fig .fig-dl:hover {
  background: var(--primary);
}
.card-fig .fig-dl .icon {
  width: 14px;
  height: 14px;
}
.fig-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 45%, rgba(255, 255, 255, 0.9) 46%, rgba(255, 255, 255, 0.9) 58%, transparent 59%),
    rgba(20, 16, 12, 0.45);
  border-top-left-radius: 8px;
}
.card.is-popped {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.card.is-popped .card-ta {
  opacity: 0.7;
}

/* ---------- Categor\00edas de color de tarjeta ---------- */
.card.card-c-q { background: #fdecec; border-color: #ecc1bd; }
.card.card-c-q .card-head { background: rgba(217, 83, 79, 0.1); }
.card.card-c-q .card-head > .icon, .card.card-c-q .card-label { color: #b6473f; }
.card.card-c-a { background: #e9f6ee; border-color: #bfe0cc; }
.card.card-c-a .card-head { background: rgba(63, 158, 111, 0.1); }
.card.card-c-a .card-head > .icon, .card.card-c-a .card-label { color: #35855e; }
.card.card-c-p { background: #fdf4e1; border-color: #ecdcae; }
.card.card-c-p .card-head { background: rgba(217, 160, 58, 0.12); }
.card.card-c-p .card-head > .icon, .card.card-c-p .card-label { color: #a9781f; }
.card.card-c-i { background: #e9f1fb; border-color: #c2d6f0; }
.card.card-c-i .card-head { background: rgba(63, 120, 201, 0.1); }
.card.card-c-i .card-head > .icon, .card.card-c-i .card-label { color: #366bb5; }
.card.card-c-n { background: #f3ecfb; border-color: #d8c6f0; }
.card.card-c-n .card-head { background: rgba(138, 92, 201, 0.1); }
.card.card-c-n .card-head > .icon, .card.card-c-n .card-label { color: #7a4fb8; }
.card.card-c-g { background: #e6f5f2; border-color: #bfe0da; }
.card.card-c-g .card-head { background: rgba(47, 138, 126, 0.1); }
.card.card-c-g .card-head > .icon, .card.card-c-g .card-label { color: #2b7d72; }
.card.card-c-v { background: #fbe9f1; border-color: #f0c3d7; }
.card.card-c-v .card-head { background: rgba(181, 73, 126, 0.1); }
.card.card-c-v .card-head > .icon, .card.card-c-v .card-label { color: #a84371; }

.card-cat-badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 7px;
  border-radius: 999px;
  margin-right: 2px;
  white-space: nowrap;
}
.card-cat-badge.cat-q { background: #f6d3d0; color: #a83a34; }
.card-cat-badge.cat-a { background: #cdebda; color: #2f7a53; }
.card-cat-badge.cat-p { background: #f6e6bf; color: #97690f; }
.card-cat-badge.cat-i { background: #d3e2f7; color: #315f9e; }
.card-cat-badge.cat-n { background: #e5d6f7; color: #6d43a8; }
.card-cat-badge.cat-g { background: #cceae4; color: #23756a; }
.card-cat-badge.cat-v { background: #f6d3e2; color: #a03a6d; }

/* ---------- Selector de color en el men\00fa de tarjeta ---------- */
.cm-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 12px 10px;
}
.cm-color {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.12);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.cm-color.on {
  border-color: var(--fg);
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--fg);
}
.cm-color.none {
  background: var(--card);
  color: var(--muted);
}
.cm-color.none .icon {
  width: 13px;
  height: 13px;
}
.cm-color.cat-q { background: #e8756e; }
.cm-color.cat-a { background: #57b083; }
.cm-color.cat-p { background: #e0ad4b; }
.cm-color.cat-i { background: #5a90d8; }
.cm-color.cat-n { background: #9d72d6; }
.cm-color.cat-g { background: #43a291; }
.cm-color.cat-v { background: #cf6295; }

/* ---------- Tarjeta de imagen independiente ---------- */
.card-media.img-media {
  flex: 1;
  flex-direction: column;
  flex-wrap: nowrap;
  min-height: 0;
  padding: 0;
  gap: 0;
  overflow: hidden;
  outline: none;
}
.card-media.img-media .card-fig {
  flex: 1;
  min-height: 0;
  width: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
}
/* La imagen llena la tarjeta; se redimensiona arrastrando la esquina de la tarjeta. */
.card-media.img-media .card-fig img {
  width: 100% !important;
  height: 100%;
  object-fit: contain;
}
/* Sin tirador propio de la figura ni bot\u00f3n de borrar dentro: la imagen sola. */
.card-media.img-media .fig-resize {
  display: none;
}
/* La tarjeta de imagen usa su propio tirador (mantiene proporci\u00f3n), no el nativo. */
.card.image {
  resize: none;
}
.img-card-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  z-index: 5;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 45%, rgba(255, 255, 255, 0.9) 46%, rgba(255, 255, 255, 0.9) 58%, transparent 59%),
    rgba(20, 16, 12, 0.5);
  border-top-left-radius: 8px;
  opacity: 0;
  transition: 0.15s;
}
.card.image:hover .img-card-resize {
  opacity: 1;
}
/* ---------- Descripción al lado de la imagen ---------- */
.img-row {
  display: flex;
  flex: 1;
  min-height: 0;
}
.img-row .img-media { flex: 1; min-width: 0; }
.img-desc { display: none; }
.card.image.has-desc .img-desc,
.card.image.desc-open .img-desc {
  display: flex;
  flex-direction: column;
  flex: 0 0 42%;
  min-width: 0;
  border-left: 1px solid var(--border);
  background: var(--card);
}
.card.image.has-desc .img-media,
.card.image.desc-open .img-media { flex: 0 0 58%; }
.img-desc-ta {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
  line-height: 1.45;
  padding: 8px 10px;
}
.img-desc-ta::placeholder { color: var(--muted2); }
/* Botón "descripción" de la cabecera (mismo estilo que insertar imagen) */
.card-desc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  border: none;
  background: none;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: 0.15s;
}
.card:hover .card-desc-btn,
.card:focus-within .card-desc-btn,
.card.has-desc .card-desc-btn { opacity: 1; }
.card-desc-btn:hover { background: var(--secondary); color: var(--fg); }
.card-desc-btn .icon { width: 14px; height: 14px; }
/* ---------- Panel de Sincronización (Apple / Google Drive) ---------- */
.sync-panel { max-width: 480px; width: 94vw; }
.sync-body { display: flex; flex-direction: column; gap: 10px; }
.sync-sec-title {
  margin-top: 8px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
}
.sync-sec-title:first-child { margin-top: 0; }
.sync-hint { margin: 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
.sync-row { display: flex; align-items: center; gap: 10px; }
.sync-lbl { flex: 0 0 84px; font-size: 12.5px; color: var(--muted); }
.sync-inp {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  outline: none;
}
.sync-inp:focus { border-color: var(--primary); }
.sync-toggle { display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--fg); cursor: pointer; }
.sync-toggle input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.sync-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.sync-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.12s, background 0.12s;
}
.sync-btn .icon { width: 15px; height: 15px; }
.sync-btn:hover { background: var(--secondary); }
.sync-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.sync-btn.primary:hover { filter: brightness(1.06); background: var(--primary); }

/* ---------- Bloque "lienzo": portal a un lienzo (nota) anidado ---------- */
.card.canvas .card-head > .icon { color: var(--primary); }
.canvas-portal {
  display: flex;
  align-items: center;
  flex: 1;
  padding: 6px 12px 12px;
}
.portal-open,
.portal-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--primary);
  border-radius: 10px;
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.portal-open .icon,
.portal-btn .icon { width: 16px; height: 16px; flex: none; }
.portal-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portal-arrow { font-size: 17px; line-height: 1; }
.portal-open:hover { background: color-mix(in srgb, var(--primary) 20%, transparent); }
.portal-btn {
  color: var(--muted);
  border-color: var(--border);
  border-style: dashed;
  background: transparent;
  justify-content: center;
}
.portal-btn:hover { background: var(--secondary); color: var(--fg); }
/* Botón "guardar grupo como plantilla" (cabecera del grupo y fila del árbol) */
.group-tpl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  padding: 2px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.85;
}
.group-tpl:hover { background: var(--secondary); color: var(--primary); }
.group-tpl .icon { width: 14px; height: 14px; }

/* ---------- Editor de imágenes (doble clic sobre una imagen) ---------- */
.imed-overlay {
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 16, 12, 0.78);
  backdrop-filter: blur(2px);
}
.imed-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 95vw;
  height: 93vh;
  max-width: 1500px;
}
.imed-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}
.imed-tool {
  min-width: 34px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.imed-tool.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.imed-tool:hover { background: var(--secondary); }
.imed-tool.on:hover { background: var(--primary); }
.imed-btn {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.imed-btn:hover { background: var(--secondary); }
.imed-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.imed-btn.primary:hover { filter: brightness(1.06); background: var(--primary); }
.imed-btn.ghost { color: var(--muted); }
.imed-color { width: 34px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: none; cursor: pointer; }
.imed-size { width: 96px; }
.imed-sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.imed-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 12px;
  overflow: hidden;
}
.imed-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.45);
  border-radius: 4px;
  touch-action: none;
  cursor: crosshair;
}
.imed-textlayer { position: absolute; inset: 0; pointer-events: none; }
.imed-text-input {
  position: absolute;
  transform: translateY(-2px);
  pointer-events: auto;
  min-width: 130px;
  padding: 2px 5px;
  border: 1px dashed var(--primary);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.92);
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.25;
  resize: none;
  outline: none;
  overflow: hidden;
}

.text-card-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  z-index: 5;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 45%, rgba(255, 255, 255, 0.9) 46%, rgba(255, 255, 255, 0.9) 58%, transparent 59%),
    rgba(20, 16, 12, 0.5);
  border-top-left-radius: 8px;
  opacity: 0;
  transition: 0.15s;
}
.card:hover .text-card-resize,
.card.selected .text-card-resize {
  opacity: 1;
}
/* Imagen libre: solo la imagen, sin cromo de tarjeta. */
.card.freeimage {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  overflow: visible;
  resize: none;
}
.card.freeimage .card-head {
  position: absolute;
  top: -34px;
  left: 0;
  right: 0;
  height: 32px;
  min-height: 32px;
  padding: 4px 8px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 10;
}
.card.freeimage:hover .card-head,
.card.freeimage.selected .card-head {
  opacity: 1;
  pointer-events: auto;
}
.card.freeimage .freeimg-media {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card.freeimage .freeimg-media img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
}
.card.freeimage:hover .img-card-resize {
  opacity: 1;
}
.card.freeimage .card-link-anchor {
  display: none;
}
.card.freeimage:hover .card-link-anchor,
.card.freeimage.selected .card-link-anchor,
.canvas-content.link-mode .card.freeimage .card-link-anchor {
  display: block;
}
.card.freeimage.selected {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  box-shadow: none;
  border-radius: 4px;
}
.card-media-empty {
  margin: auto;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  padding: 12px;
}

/* ---------- Tarjeta Markdown ---------- */
.md-render {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px 14px 14px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--fg);
  overflow-wrap: break-word;
  word-break: break-word;
}
.card.md .md-src {
  display: none;
}
.card.md.editing-md .md-render {
  display: none;
}
.card.md.editing-md .md-src {
  display: block;
  flex: 1;
  min-height: 0;
}
.md-render h1,
.md-render h2,
.md-render h3,
.md-render h4,
.md-render h5,
.md-render h6 {
  font-family: 'Fraunces', Georgia, serif;
  line-height: 1.25;
  margin: 0.6em 0 0.35em;
}
.md-render h1 { font-size: 1.5em; }
.md-render h2 { font-size: 1.3em; }
.md-render h3 { font-size: 1.13em; }
.md-render h4 { font-size: 1em; }
.md-render p { margin: 0.5em 0; }
.md-render ul,
.md-render ol {
  margin: 0.4em 0;
  padding-left: 1.4em;
}
.md-render li { margin: 0.15em 0; }
.md-render a {
  color: var(--primary);
  text-decoration: underline;
}
.md-render code.md-code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(20, 16, 12, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.md-render pre.md-pre {
  background: #2b2622;
  color: #f3ede3;
  padding: 10px 12px;
  border-radius: 8px;
  overflow: auto;
  margin: 0.6em 0;
}
.md-render pre.md-pre code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre;
}
.md-render blockquote {
  margin: 0.6em 0;
  padding: 0.2em 0.9em;
  border-left: 3px solid var(--sage);
  color: var(--muted);
  background: rgba(0, 0, 0, 0.03);
  border-radius: 0 6px 6px 0;
}
.md-render hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}
.md-render img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}
.md-render table.md-table {
  border-collapse: collapse;
  margin: 0.6em 0;
  font-size: 0.92em;
}
.md-render table.md-table th,
.md-render table.md-table td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}
.md-render table.md-table th {
  background: rgba(0, 0, 0, 0.04);
  font-weight: 700;
}
.md-render .md-empty {
  color: var(--muted);
  font-style: italic;
}

/* ---------- Tarjeta Mermaid ---------- */
.mmd-render {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 12px;
  display: flex;
  align-items: safe center;
  justify-content: safe center;
  background: #fff;
}
.mmd-render svg {
  max-width: 100%;
  height: auto;
}
.mmd-render .mmd-empty {
  color: var(--muted);
  font-style: italic;
}
.mmd-render .mmd-err,
.mmd-render.mmd-has-error {
  color: var(--danger);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  text-align: left;
  align-self: stretch;
}
.card.mmd .mmd-src {
  display: none;
}
.card.mmd.editing-mmd .mmd-render {
  display: none;
}
.card.mmd.editing-mmd .mmd-src {
  display: block;
  flex: 1;
  min-height: 0;
}
.card-mmd-edit,
.card-mmd-dl,
.card-mmd-move {
  display: inline-flex;
  border: none;
  background: none;
  padding: 4px;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: 0.15s;
}
.card:hover .card-mmd-edit,
.card:hover .card-mmd-dl,
.card:hover .card-mmd-move {
  opacity: 1;
}
.card-mmd-edit:hover,
.card-mmd-dl:hover,
.card-mmd-move:hover {
  background: var(--secondary);
  color: var(--fg);
}
.card-mmd-edit .icon,
.card-mmd-dl .icon,
.card-mmd-move .icon {
  width: 14px;
  height: 14px;
}
.card-mmd-explode {
  display: inline-flex;
  border: none;
  background: none;
  padding: 4px;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: 0.15s;
}
.card:hover .card-mmd-explode { opacity: 1; }
.card-mmd-explode:hover { background: var(--secondary); color: var(--fg); }
.card-mmd-explode .icon { width: 14px; height: 14px; }
.card.mmd-interactive .card-mmd-move {
  opacity: 1;
  background: var(--primary);
  color: #fff;
}
/* ---- Modo interactivo Mermaid ---- */
.card.mmd-interactive .mmd-render {
  overflow: hidden;
  cursor: grab;
  align-items: stretch;
  justify-content: stretch;
  position: relative;
}
.card.mmd-interactive .mmd-render.mmd-panning {
  cursor: grabbing;
}
.card.mmd-interactive .mmd-render svg {
  width: 100%;
  height: 100%;
  max-width: none;
}
.card.mmd-interactive .mmd-vp {
  will-change: transform;
}
.card.mmd-interactive .mmd-render .node {
  cursor: move;
}
.card.mmd-interactive .mmd-render .node.mmd-sel > rect,
.card.mmd-interactive .mmd-render .node.mmd-sel > circle,
.card.mmd-interactive .mmd-render .node.mmd-sel > polygon,
.card.mmd-interactive .mmd-render .node.mmd-sel > path,
.card.mmd-interactive .mmd-render .node.mmd-sel > ellipse {
  outline: none;
  stroke: var(--primary);
  stroke-width: 2.5px;
}
.mmd-render .mmd-handle {
  fill: var(--primary);
  stroke: #fff;
  stroke-width: 1.5px;
  cursor: nwse-resize;
}
.mmd-render .mmd-edit-input {
  position: absolute;
  z-index: 20;
  transform: translate(-1px, -1px);
  border: 2px solid var(--primary);
  border-radius: 6px;
  padding: 2px 6px;
  font: inherit;
  font-size: 13px;
  text-align: center;
  background: #fff;
  color: var(--fg);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  outline: none;
}
/* ---- Edici\u00f3n de flechas ---- */
.card.mmd-interactive .mmd-render .mmd-edge-hit {
  stroke: transparent;
  stroke-width: 14px;
  cursor: pointer;
  pointer-events: stroke;
  fill: none;
}
.card.mmd-interactive .mmd-render .edgePaths path.mmd-edge-sel,
.card.mmd-interactive .mmd-render path.flowchart-link.mmd-edge-sel {
  stroke: var(--primary) !important;
  stroke-width: 3px !important;
}
.mmd-render .mmd-bend {
  fill: #fff;
  stroke: var(--primary);
  stroke-width: 2px;
  cursor: move;
}
.mmd-render .mmd-ep {
  fill: var(--primary);
  stroke: #fff;
  stroke-width: 2px;
  cursor: crosshair;
}
.mmd-render .mmd-reconnect-line {
  stroke: var(--primary);
  stroke-width: 2px;
  stroke-dasharray: 5 4;
  pointer-events: none;
}
.card.mmd-interactive .mmd-render .node.mmd-drop > rect,
.card.mmd-interactive .mmd-render .node.mmd-drop > circle,
.card.mmd-interactive .mmd-render .node.mmd-drop > polygon,
.card.mmd-interactive .mmd-render .node.mmd-drop > path,
.card.mmd-interactive .mmd-render .node.mmd-drop > ellipse {
  stroke: var(--sage, #6a9);
  stroke-width: 3px;
}
.mmd-render .mmd-edge-toolbar {
  position: absolute;
  z-index: 21;
  transform: translate(-50%, calc(-100% - 10px));
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}
.mmd-render .mmd-etb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 5px;
  border: none;
  background: none;
  border-radius: 6px;
  color: var(--fg);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.mmd-render .mmd-etb-btn:hover {
  background: var(--secondary);
}
.mmd-render .mmd-etb-btn .icon {
  width: 14px;
  height: 14px;
}
.nw-mmd {
  flex: 1;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
}

/* ---------- Tarjeta PDF ---------- */
.pdf-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
}
.pdf-frame {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  background: #f0ece4;
}

/* ---------- Ventana emergente de nota ---------- */
body.note-window {
  background: var(--bg);
}
#noteRoot {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.nw-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--secondary);
}
.nw-route {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
  font-size: 12.5px;
  color: var(--muted);
}
.nw-route .seg {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}
.nw-route .sep {
  opacity: 0.5;
  flex: none;
}
.nw-head.idea {
  background: var(--idea-bg);
  border-color: var(--idea-border);
}
.nw-head-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.nw-type {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
  padding: 4px 9px;
  border-radius: 999px;
  flex: none;
}
.nw-titles {
  min-width: 0;
  flex: 1;
}
.nw-crumb {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 11.5px;
  color: var(--muted);
  padding: 0 8px;
}
.nw-crumb .sep {
  opacity: 0.5;
}
.nw-title {
  flex: 1;
  min-width: 70px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 2px 6px;
}
.nw-title:hover {
  border-color: var(--border);
}
.nw-title:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--card);
}
.nw-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.nw-pdf-body {
  padding: 0;
  overflow: hidden;
}
.nw-pdf {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  background: #f0ece4;
}
.nw-md {
  flex: 1;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  padding: 4px 16px 16px;
}
.nw-grid-big {
  flex: 1;
  min-height: 0;
}
.nw-grid-big .nw-fig {
  width: 100%;
}
.nw-grid-big .nw-fig img {
  width: 100% !important;
  height: auto;
}
.nw-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nw-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 10px;
  cursor: pointer;
}
.nw-btn:hover {
  border-color: var(--muted2);
}
.nw-btn .icon {
  width: 16px;
  height: 16px;
  color: var(--sage);
}
.nw-hint {
  font-size: 12px;
  color: var(--muted);
}
.nw-ta {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 15px;
  line-height: 1.6;
  padding: 14px;
  outline: none;
}
.nw-ta:focus {
  border-color: var(--sage);
  box-shadow: var(--shadow);
}
.nw-ta.mono {
  font-family: ui-monospace, 'SFMono-Regular', Consolas, Menlo, 'Liberation Mono', monospace;
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
  background: #2b2622;
  color: #efe7da;
  caret-color: #e8a060;
}
.nw-ta.mono::placeholder {
  color: #8b8073;
}
.nw-mono-body .nw-ta {
  flex: 1;
  min-height: 160px;
}
.nw-mono-body .mono-bar {
  flex: none;
}
.nw-mono-body .curl-out {
  margin: 0;
  flex: none;
  max-height: 45%;
  overflow: auto;
}
.nw-btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.nw-btn.primary:hover {
  filter: brightness(1.06);
}
.nw-btn.primary .icon {
  color: #fff;
}
.nw-imgs-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.nw-imgs-title .icon {
  width: 14px;
  height: 14px;
}
.nw-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px;
}
.nw-fig {
  position: relative;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
  line-height: 0;
}
.nw-fig img {
  display: block;
  width: 200px;
  max-width: none;
  height: auto;
  user-select: none;
}
.nw-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 45%, rgba(255, 255, 255, 0.92) 46%, rgba(255, 255, 255, 0.92) 58%, transparent 59%),
    rgba(20, 16, 12, 0.45);
  border-top-left-radius: 8px;
}
.nw-fig .rm {
  position: absolute;
  top: 6px;
  right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  cursor: pointer;
}
.nw-fig .rm:hover {
  background: var(--danger);
}
.nw-fig .rm .icon {
  width: 15px;
  height: 15px;
}
.nw-empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  text-align: center;
}
.nw-msg {
  margin: auto;
  color: var(--muted);
  font-size: 15px;
  padding: 40px;
  text-align: center;
}

/* ---------- Tipos de bloque: codigo / json / curl ---------- */
.card.code .card-head {
  background: #edeefa;
}
.card.code .card-head > .icon,
.card.code .card-label {
  color: #5b6bc0;
}
.card.table .card-head {
  background: #e8f5ef;
  border-bottom: 1px solid #d3ebe1;
}
.card.table .card-head > .icon,
.card.table .card-label {
  color: #4f9a86;
}
.card-ta.mono {
  font-family: ui-monospace, 'SFMono-Regular', Consolas, Menlo, 'Liberation Mono', monospace;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre;
  tab-size: 2;
}
/* Cuerpo oscuro tipo editor para codigo / JSON / cURL */
.card.code .card-ta.mono {
  background: #2b2622;
  color: #efe7da;
  padding: 9px 12px;
  caret-color: #e8a060;
}
.card.code .card-ta.mono::placeholder {
  color: #8b8073;
}
.card.code .card-ta.mono::selection {
  background: rgba(232, 160, 96, 0.32);
}
.mono-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 8px;
  background: #2b2622;
}
.mono-fmt {
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: #efe7da;
  border-radius: 7px;
  cursor: pointer;
}
.mono-fmt:hover {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.1);
}
.mono-status {
  font-size: 11px;
  color: #b3a695;
}
.mono-status.ok {
  color: #7fd1bb;
}
.mono-status.err {
  color: #f0a59c;
}
.mono-fmt.run {
  background: #e8a060;
  color: #2b2622;
  border-color: #e8a060;
  font-weight: 700;
}
.mono-fmt.run:hover {
  background: #f0b273;
  border-color: #f0b273;
}
.mono-fmt:disabled {
  opacity: 0.55;
  cursor: default;
}
.curl-out {
  margin: 0;
  padding: 10px 12px;
  background: #211d1a;
  color: #efe7da;
  font-family: ui-monospace, 'SFMono-Regular', Consolas, Menlo, 'Liberation Mono', monospace;
  font-size: 12px;
  line-height: 1.5;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
/* cURL: input que se ajusta a la caja y respuesta redimensionable */
.card.code .card-ta.curl-input {
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 0;
}
.card.code .curl-out {
  max-height: none;
  flex: none;
  min-height: 40px;
}
.card.code .curl-out.empty {
  color: #8b8073;
  font-style: italic;
}
.curl-resize {
  flex: none;
  height: 9px;
  background: #211d1a;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  cursor: ns-resize;
  position: relative;
}
.curl-resize::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 3px;
  transform: translate(-50%, -50%);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.24);
}
.curl-resize:hover::before {
  background: rgba(255, 255, 255, 0.45);
}
body.curl-resizing {
  cursor: ns-resize;
  user-select: none;
}
.curl-out .j-key {
  color: #8fc7ff;
}
.curl-out .j-str {
  color: #b9e6a0;
}
.curl-out .j-num {
  color: #f0b273;
}
.curl-out .j-bool {
  color: #e59bd8;
}
.curl-out .j-null {
  color: #a79a8b;
}

/* ---------- Tablas ---------- */
.card-table-wrap {
  flex: 1;
  overflow: auto;
  padding: 6px 8px 8px;
}
.mini-table {
  border-collapse: collapse;
  width: 100%;
}
.mini-table td {
  border: 1px solid var(--border);
  padding: 0;
}
.mini-table tr.thead td {
  background: #eef6f1;
}
.mini-table tr.thead .cell {
  font-weight: 700;
  color: var(--fg);
}
.mini-table .cell {
  width: 100%;
  min-width: 52px;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  color: var(--fg);
  padding: 5px 7px;
  outline: none;
}
.mini-table .cell:focus {
  background: var(--secondary);
}
.tbl-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}
.tbl-btn {
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 7px;
  cursor: pointer;
}
.tbl-btn:hover {
  color: var(--fg);
  border-color: var(--muted2);
}

/* ---------- Seleccion multiple (marquee) ---------- */
.marquee {
  position: absolute;
  border: 1px solid #3b82f6;
  background: rgba(59, 130, 246, 0.12);
  pointer-events: none;
  z-index: 9;
  border-radius: 2px;
}
.card.selected {
  outline: 2px solid #3b82f6;
  outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}
.sel-bar {
  position: fixed;
  left: 50%;
  bottom: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 8px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  z-index: 1500;
}
.sel-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}
.sel-del {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border: none;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
}
.sel-del .icon {
  width: 14px;
  height: 14px;
}
.sel-del:hover {
  filter: brightness(1.05);
}
.sel-align {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 4px;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.sel-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease, transform 0.14s ease;
}
.sel-mini:hover {
  background: var(--secondary);
  color: var(--fg);
}
.sel-mini:active {
  transform: scale(0.92);
}
.sel-mini .icon {
  width: 15px;
  height: 15px;
}
.sel-ai {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: filter 0.14s ease, transform 0.14s ease;
}
.sel-ai .icon {
  width: 14px;
  height: 14px;
}
.sel-ai:hover {
  filter: brightness(1.06);
}
.sel-ai:active {
  transform: scale(0.96);
}
.sel-mmd {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border: 1px solid var(--sage);
  border-radius: 999px;
  background: transparent;
  color: var(--sage);
  cursor: pointer;
  transition: background 0.14s ease, transform 0.14s ease;
}
.sel-mmd .icon { width: 14px; height: 14px; }
.sel-mmd:hover { background: color-mix(in srgb, var(--sage) 14%, transparent); }
.sel-mmd:active { transform: scale(0.96); }
.sel-flow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border: 1px solid var(--ocre);
  border-radius: 999px;
  background: transparent;
  color: var(--ocre);
  cursor: pointer;
  transition: background 0.14s ease, transform 0.14s ease;
}
.sel-flow .icon { width: 14px; height: 14px; }
.sel-flow:hover { background: color-mix(in srgb, var(--ocre) 14%, transparent); }
.sel-flow:active { transform: scale(0.96); }

/* ---------- Barra de pestañas (lienzos abiertos/recientes) ---------- */
.note-tabs {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  border-bottom: 1px solid var(--border);
  background: var(--topbar, rgba(253, 250, 243, 0.72));
  scrollbar-width: thin;
  flex: none;
}
.note-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 210px;
  padding: 5px 6px 5px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.note-tab .icon { width: 13px; height: 13px; flex: none; }
.note-tab:hover { background: var(--secondary); color: var(--fg); }
/* Hoja actual: fondo destacado (solo esta pestaña) para identificarla de un vistazo. */
.note-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 700;
  box-shadow: 0 2px 8px -2px rgba(58, 51, 44, 0.28);
}
.note-tab.active .icon { color: #fff; }
.note-tab.active:hover { background: var(--primary); color: #fff; }
.note-tab.active .note-tab-close { color: rgba(255, 255, 255, 0.85); }
.note-tab.active .note-tab-close:hover { background: rgba(255, 255, 255, 0.22); color: #fff; }
.note-tab-title { overflow: hidden; text-overflow: ellipsis; }
.note-tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  color: var(--muted2);
  font-size: 14px;
  line-height: 1;
}
.note-tab-close:hover { background: rgba(193, 75, 63, 0.14); color: var(--danger); }

/* Relaciones entre lienzos (hojas) en el mapa de conocimiento */
.graph-rel { fill: none; stroke: var(--primary); stroke-width: 2; stroke-dasharray: 6 5; opacity: 0.8; }
.graph-rel-link { stroke: var(--ocre); }

/* ---------- Menu radial (Alt) ---------- */
.radial {
  position: fixed;
  width: 0;
  height: 0;
  z-index: 2000;
}
.radial-item {
  position: absolute;
  left: 0;
  top: 0;
  width: 58px;
  height: 58px;
  margin-left: -29px;
  margin-top: -29px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  animation: radialIn 0.12s ease-out;
  transition: background 0.12s, border-color 0.12s;
}
@keyframes radialIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.radial-item:hover {
  background: var(--secondary);
  border-color: var(--primary);
}
.radial-item .icon {
  width: 18px;
  height: 18px;
  color: var(--primary);
}
.radial-lbl {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.radial-center {
  position: absolute;
  left: 0;
  top: 0;
  width: 34px;
  height: 34px;
  margin-left: -17px;
  margin-top: -17px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.radial-center svg {
  width: 16px;
  height: 16px;
}

/* ---------- Recordatorios / alarmas ---------- */
.card-remind {
  display: inline-flex;
  border: none;
  background: none;
  padding: 2px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: 0.15s;
}
.card:hover .card-remind {
  opacity: 1;
}
.card-remind:hover {
  background: rgba(217, 163, 90, 0.16);
  color: var(--ocre);
}
.card-remind.on {
  opacity: 1;
  color: var(--ocre);
}
.card-remind .icon {
  width: 14px;
  height: 14px;
}
.card-remind-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-right: 2px;
  padding: 1px 7px 1px 5px;
  border-radius: 999px;
  background: rgba(217, 163, 90, 0.16);
  color: #9a6a23;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.card-remind-badge .icon {
  width: 11px;
  height: 11px;
}
.card.reminder-on {
  border-color: var(--ocre);
  box-shadow: 0 0 0 1px rgba(217, 163, 90, 0.35), var(--shadow);
}
.pop-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2600;
  background: transparent;
}
.reminder-pop {
  position: fixed;
  width: 248px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  animation: pop 0.12s ease-out;
}
.rem-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 2px;
}
.rem-title .icon {
  width: 16px;
  height: 16px;
  color: var(--ocre);
}
.rem-lbl {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.rem-input {
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--secondary);
  color: var(--fg);
  outline: none;
}
.rem-input:focus {
  border-color: var(--ocre);
  background: var(--card);
}
.rem-msg {
  font-size: 11.5px;
  color: var(--danger);
  min-height: 4px;
}
.rem-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}
.rem-save {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  border: none;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}
.rem-save:hover {
  filter: brightness(1.05);
}
.rem-del {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  color: var(--danger);
  cursor: pointer;
}
.rem-del:hover {
  background: rgba(193, 75, 63, 0.1);
  border-color: var(--danger);
}
.alarm-overlay {
  justify-content: center;
  align-items: center;
  z-index: 3000;
}
.alarm-card {
  width: 380px;
  max-width: 92vw;
  background: var(--card);
  border: 1px solid var(--idea-border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop 0.16s ease-out;
}
.alarm-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 14px 18px;
  background: var(--idea-bg);
  border-bottom: 1px solid var(--idea-border);
  font-family: 'Fraunces', Georgia, serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
}
.alarm-head .icon {
  width: 20px;
  height: 20px;
  color: var(--ocre);
  animation: bellShake 1s ease-in-out infinite;
}
@keyframes bellShake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-12deg); }
  40% { transform: rotate(10deg); }
  60% { transform: rotate(-6deg); }
  80% { transform: rotate(4deg); }
}
.alarm-list {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow: auto;
}
.alarm-item {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--secondary);
}
.alarm-text {
  font-size: 14px;
  color: var(--fg);
  margin-bottom: 4px;
  word-break: break-word;
}
.alarm-when {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}
.alarm-when .icon {
  width: 13px;
  height: 13px;
}
.alarm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.alarm-btn {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 13px;
  border: none;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}
.alarm-btn:hover {
  filter: brightness(1.05);
}
.alarm-btn.ghost {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
}
.alarm-btn.ghost:hover {
  color: var(--fg);
  border-color: var(--muted2);
  filter: none;
}

/* ---------- Tarjeta: men\00fa, importante, insignia kanban ---------- */
.card-menu {
  display: inline-flex;
  border: none;
  background: none;
  padding: 2px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: 0.15s;
}
.card:hover .card-menu {
  opacity: 1;
}
.card-menu:hover {
  background: var(--secondary);
  color: var(--fg);
}
.card-menu .icon {
  width: 16px;
  height: 16px;
}
.card-imp-badge,
.card-kanban-badge {
  display: inline-flex;
  align-items: center;
  margin-right: 2px;
}
.card-imp-badge .icon {
  width: 13px;
  height: 13px;
  color: var(--ocre);
  fill: var(--ocre);
}
.card-kanban-badge .icon {
  width: 13px;
  height: 13px;
  color: var(--muted2);
}
.card-kanban-badge.k-doing .icon {
  color: var(--ocre);
}
.card-kanban-badge.k-done .icon {
  color: var(--sage);
}
.card.important {
  border-color: var(--ocre);
  box-shadow: inset 3px 0 0 var(--ocre), var(--shadow);
}

/* ---------- Men\00fa de tarjeta (popover) ---------- */
.card-menu-pop {
  position: fixed;
  width: 240px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 7px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  animation: pop 0.12s ease-out;
}
.cm-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 9px;
  border: none;
  border-radius: 9px;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.cm-item:hover {
  background: var(--secondary);
}
.cm-item .icon {
  width: 15px;
  height: 15px;
  color: var(--muted);
}
.cm-item.active {
  color: #9a6a23;
}
.cm-item.active .icon {
  color: var(--ocre);
  fill: var(--ocre);
}
.cm-item.danger {
  color: var(--danger);
}
.cm-item.danger:hover {
  background: rgba(193, 75, 63, 0.1);
}
.cm-item.danger .icon {
  color: var(--danger);
}
.cm-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 2px;
}
.cm-label {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}
.cm-label .icon {
  width: 13px;
  height: 13px;
}
.cm-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 6px 4px;
}
.cm-chip {
  flex: 1 1 auto;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--secondary);
  color: var(--fg);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.cm-chip:hover {
  border-color: var(--ocre);
  color: var(--ocre);
}
.cm-chip.on {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.cm-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 9px 5px;
  font-size: 11.5px;
  color: var(--muted);
}
.cm-mini {
  border: none;
  background: none;
  color: var(--danger);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  padding: 2px 4px;
}
.cm-mini:hover {
  text-decoration: underline;
}

/* ---------- Mapa de conocimiento (grafo) ---------- */
.graph-overlay {
  justify-content: center;
  align-items: center;
  z-index: 2800;
}
.graph-panel {
  width: 1100px;
  max-width: 96vw;
  height: 88vh;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: pop 0.16s ease-out;
}
.graph-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--secondary);
}
.graph-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 17px;
  font-weight: 600;
}
.graph-title .icon {
  color: var(--sage);
}
.graph-head-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.graph-hint {
  font-size: 12px;
  color: var(--muted);
}
.graph-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  cursor: grab;
  background:
    radial-gradient(circle at 50% 50%, rgba(138, 154, 123, 0.08), transparent 60%),
    var(--bg);
}
.graph-stage.grabbing {
  cursor: grabbing;
}
.graph-world {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
}
.graph-edges {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.graph-edge {
  fill: none;
  stroke: var(--muted2);
  stroke-width: 1.4;
  opacity: 0.45;
  transition: opacity 0.12s, stroke-width 0.12s;
}
.graph-edge.k-section {
  stroke: var(--sage);
  opacity: 0.5;
}
.graph-edge.k-note {
  stroke: var(--primary);
  opacity: 0.4;
}
.graph-edge.k-doc {
  stroke: var(--ocre);
  opacity: 0.45;
  stroke-dasharray: 3 4;
}
.graph-edge.hl {
  opacity: 0.95;
  stroke-width: 2.4;
}
.graph-edge.dim {
  opacity: 0.08;
}
.graph-node.dim {
  opacity: 0.3;
}
.graph-node.hl {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
  z-index: 6;
}
.graph-count {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 4px;
}
.graph-ctl {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 8;
}
.graph-node {
  position: absolute;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 190px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
  white-space: nowrap;
}
.graph-node:hover {
  border-color: var(--sage);
  box-shadow: var(--shadow-lg);
  z-index: 5;
}
.graph-node .gn-label {
  overflow: hidden;
  text-overflow: ellipsis;
}
.graph-node .gn-dot {
  display: inline-flex;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted2);
  flex: none;
}
.graph-node .gn-dot .icon {
  width: 14px;
  height: 14px;
}
.graph-node.k-root {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 16px;
  font-weight: 700;
  padding: 10px 18px;
  background: var(--sage);
  color: #fff;
  border-color: var(--sage);
}
.graph-node.k-root .gn-dot {
  display: none;
}
.graph-node.k-notebook {
  font-weight: 700;
  border-color: var(--sage);
}
.graph-node.k-notebook .gn-dot {
  background: var(--sage);
}
.graph-node.k-section .gn-dot {
  background: var(--primary);
}
.graph-node.k-note {
  color: var(--primary);
}
.graph-node.k-note .gn-dot {
  width: auto;
  height: auto;
  background: none;
  color: var(--primary);
}
.graph-node.k-doc {
  background: rgba(217, 163, 90, 0.14);
  border-color: rgba(217, 163, 90, 0.5);
}
.graph-node.k-doc .gn-dot {
  width: auto;
  height: auto;
  background: none;
  color: var(--ocre);
}
.graph-node.k-group {
  background: rgba(138, 154, 123, 0.16);
  border-color: rgba(138, 154, 123, 0.55);
}
.graph-node.k-group .gn-dot {
  width: auto;
  height: auto;
  background: none;
  color: var(--sage);
}

/* ---------- Tablero Kanban ---------- */
.kanban-overlay {
  justify-content: center;
  align-items: center;
  z-index: 2800;
}
.kanban-panel {
  width: 1000px;
  max-width: 94vw;
  height: 84vh;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pop 0.16s ease-out;
}
.kanban-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.kanban-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 19px;
  font-weight: 600;
  color: var(--fg);
}
.kanban-title .icon {
  width: 20px;
  height: 20px;
  color: var(--primary);
}
.kanban-cols {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 14px;
  overflow: auto;
  min-height: 0;
}
.kanban-col {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  min-height: 0;
  overflow: hidden;
}
.kanban-col-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 13px;
  font-weight: 700;
  font-size: 13px;
  color: var(--fg);
  border-bottom: 1px solid var(--border);
}
.kc-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted2);
  flex: none;
}
.k-doing .kc-dot {
  background: var(--ocre);
}
.k-done .kc-dot {
  background: var(--sage);
}
.kc-name {
  flex: 1;
}
.kc-count {
  min-width: 22px;
  text-align: center;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--muted);
  font-size: 12px;
}
.kanban-add {
  display: flex;
  gap: 6px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}
.kanban-add-inp {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  color: var(--fg);
  outline: none;
}
.kanban-add-inp:focus {
  border-color: var(--primary);
}
.kanban-add-btn {
  flex: none;
  width: 34px;
  border: none;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}
.kanban-add-btn:disabled,
.kanban-add-inp:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.kanban-add-btn .icon {
  width: 16px;
  height: 16px;
}
.kanban-col-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 10px;
  overflow: auto;
  min-height: 60px;
}
.kanban-col-body.drop {
  background: rgba(217, 163, 90, 0.08);
  outline: 2px dashed var(--ocre);
  outline-offset: -6px;
  border-radius: 12px;
}
.kanban-empty {
  text-align: center;
  color: var(--muted2);
  font-size: 12.5px;
  padding: 18px 0;
}
.kanban-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 11px;
  box-shadow: var(--shadow);
  cursor: grab;
}
.kanban-card.dragging {
  opacity: 0.5;
}
.kanban-card.important {
  box-shadow: inset 3px 0 0 var(--ocre), var(--shadow);
}
.kc-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}
.kc-top > .icon {
  width: 13px;
  height: 13px;
  color: var(--muted);
  flex: none;
}
.kc-loc {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.kc-star {
  margin-left: auto;
  flex: none;
}
.kc-star .icon {
  width: 13px;
  height: 13px;
  color: var(--ocre);
  fill: var(--ocre);
}
.kc-task {
  font-size: 13.5px;
  color: var(--fg);
  line-height: 1.35;
  word-break: break-word;
  margin-bottom: 4px;
}
.kc-sub {
  font-size: 11px;
  color: var(--muted);
}
.kc-rem {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(217, 163, 90, 0.16);
  color: #9a6a23;
  font-size: 11px;
  font-weight: 700;
}
.kc-rem .icon {
  width: 11px;
  height: 11px;
}
.kc-actions {
  display: flex;
  gap: 4px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.kc-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
.kc-btn:hover:not(:disabled) {
  color: var(--fg);
  border-color: var(--muted2);
}
.kc-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.kc-btn .icon {
  width: 14px;
  height: 14px;
}
@media (max-width: 720px) {
  .kanban-cols {
    grid-template-columns: 1fr;
  }
  .kanban-panel {
    height: 90vh;
  }
}

/* ---------- Filtro de libro en Kanban ---------- */
.kanban-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.kanban-filter-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 9px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
}
.kanban-filter-wrap .icon {
  width: 15px;
  height: 15px;
}
.kanban-filter {
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  cursor: pointer;
  outline: none;
  max-width: 200px;
}

/* ---------- Conexiones entre bloques (relaciones) ---------- */
.link-layer {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}
.link-path {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: 0.6;
  pointer-events: none;
}
.link-path.temp {
  stroke-dasharray: 6 5;
  opacity: 0.85;
}
.link-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 16;
  pointer-events: stroke;
  cursor: pointer;
}
.link-hit:hover + .link-path {
  stroke: var(--primary);
  opacity: 0.95;
  stroke-width: 3.2;
}
.card-link-anchor {
  display: none;
  position: absolute;
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: var(--card);
  cursor: crosshair;
  z-index: 6;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.18);
}
.card-link-anchor::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 6px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--primary);
}
.card-link-anchor:hover {
  background: var(--primary);
  transform: translateY(-50%) scale(1.15);
}
.card-link-anchor:hover::after {
  background: #fff;
}
.canvas-content.link-mode .card {
  overflow: visible;
}
.canvas-content.link-mode .card-link-anchor {
  display: block;
}
.card.link-target {
  outline: 2px dashed var(--primary);
  outline-offset: 2px;
}

/* ---------- Tinta libre (modo tablet) ---------- */
.ink-layer {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
  touch-action: none;
  z-index: 50;
}
.canvas-content.tablet-mode .ink-layer {
  pointer-events: auto;
}
.ink-path {
  pointer-events: visibleFill;
}
.ink-path.ink-hi {
  fill-opacity: 0.55;
}
.ink-path.ink-selected {
  filter: drop-shadow(0 0 2px var(--primary));
  opacity: 0.85;
}
.ink-cur-path {
  pointer-events: none;
}
.ink-lasso-rect {
  fill: rgba(194, 116, 91, 0.12);
  stroke: var(--primary);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  pointer-events: none;
}
.tablet-toolbar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.tablet-row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}
.tablet-tool {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 48px;
  height: 44px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  color: var(--fg);
  cursor: pointer;
  font-size: 11px;
}
.tablet-tool:hover {
  background: rgba(120, 108, 92, 0.1);
}
.tablet-tool.on {
  background: rgba(194, 116, 91, 0.14);
  border-color: var(--primary);
  color: var(--primary);
}
.tablet-tool .icon {
  width: 18px;
  height: 18px;
}
.tt-lbl {
  font-size: 10px;
  line-height: 1;
}
.tablet-color {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: none;
  cursor: pointer;
}
.tablet-size {
  width: 72px;
  cursor: pointer;
}
.icon-btn.on {
  background: rgba(194, 116, 91, 0.16);
  color: var(--primary);
  border-color: var(--primary);
}
.link-hint {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: var(--fg);
  color: var(--bg);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 3000;
  animation: pop 0.14s ease-out;
}
.link-hint .icon {
  width: 15px;
  height: 15px;
}

/* ---------- Panel de tema / colores ---------- */
.theme-panel {
  max-width: 380px;
}
.theme-sec-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 10px 2px 6px;
}
.theme-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.theme-preset-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 999px;
  padding: 5px 12px 5px 6px;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
}
.theme-preset-btn:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.preset-sw {
  display: inline-flex;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.08);
  flex: none;
}
.preset-dot {
  width: 11px;
  height: 18px;
}
.preset-name {
  white-space: nowrap;
}
.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.theme-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.theme-color {
  width: 34px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
.theme-reset-btn {
  margin-top: 14px;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--secondary);
  color: var(--fg);
  border-radius: 10px;
  padding: 9px;
  font-size: 13px;
  cursor: pointer;
}
.theme-reset-btn:hover {
  border-color: var(--primary);
}

/* ---------- Texto transl\u00facido (freetext) ---------- */
.card.freetext {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  overflow: visible;
  min-height: 0;
}
.card.freetext .card-head {
  position: absolute;
  top: -32px;
  left: 0;
  right: 0;
  height: 28px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s ease;
}
.card.freetext:hover .card-head,
.card.freetext.selected .card-head,
.card.freetext:focus-within .card-head {
  opacity: 1;
  pointer-events: auto;
}
/* Margen semi-visible: marca el contorno de la caja al pasar el ratón o editar,
   dejando claro que se puede redimensionar (el hueco del offset es el "margen"). */
.card.freetext:hover,
.card.freetext:focus-within {
  outline: 1px dashed color-mix(in srgb, var(--primary) 42%, transparent);
  outline-offset: 5px;
  border-radius: 7px;
}
.card.freetext.selected {
  outline: 1.5px dashed var(--primary);
  outline-offset: 5px;
  border-radius: 7px;
}
.free-resize {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 6;
  opacity: 0;
  transition: opacity 0.12s;
}
.card.freetext:hover .free-resize,
.card.freetext:focus-within .free-resize,
.card.freetext.selected .free-resize { opacity: 1; }
.free-resize::before {
  content: '';
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--primary);
  border-bottom: 2px solid var(--primary);
  border-bottom-right-radius: 3px;
}
body.resizing-free { cursor: nwse-resize; user-select: none; }
.card.freetext .free-ta {
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  width: 100%;
  padding: 2px 6px;
  margin: 0;
  overflow: hidden;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--fg);
}
.card.freetext .card-link-anchor {
  opacity: 0;
}
.card.freetext:hover .card-link-anchor {
  opacity: 1;
}
.free-format-pop {
  position: absolute;
  top: -8px;
  left: calc(100% + 10px);
  z-index: 60;
  width: 210px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.free-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.free-lbl {
  font-size: 12px;
  color: var(--muted);
  min-width: 48px;
}
.free-size {
  flex: 1;
}
.free-size-lbl {
  font-size: 11px;
  color: var(--muted);
  min-width: 34px;
  text-align: right;
}
.free-color {
  width: 32px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
.free-chip {
  min-width: 28px;
  height: 26px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
}
.free-chip.on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
/* Ventana de configuración del texto libre ("Personalizar texto") */
.free-fmt-panel { max-width: 380px; width: 92vw; }
.free-fmt-body { display: flex; flex-direction: column; gap: 9px; }
.free-fmt-body .free-chip { padding: 0 10px; }
.free-sec {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.free-font-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.free-font {
  padding: 12px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  font-size: 17px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.free-font:hover { border-color: var(--primary); }
.free-font.on { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent); }
.free-chip.fc-b { font-weight: 800; }
.free-chip.fc-i { font-style: italic; }
.free-chip.fc-u { text-decoration: underline; }
.free-chip.fc-s { text-decoration: line-through; }
/* Panel flotante de "Personalizar texto" (al costado del bloque, no ocupa toda la hoja) */
.free-fmt-pop {
  position: fixed;
  z-index: 1300;
  width: 300px;
  max-height: 82vh;
  overflow-y: auto;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
}
.free-fmt-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.free-fmt-title {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}
.free-fmt-title .icon { width: 16px; height: 16px; color: var(--primary); }

/* Grupos anidados bajo la nota en el árbol lateral */
.note-groups { margin-left: 20px; }

/* Chips de hipervínculo bajo el texto de una nota */
.card-hlinks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 12px 10px;
}
.hlink-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 3px 4px 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 32%, transparent);
  font-size: 12px;
}
.hlink-go {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  max-width: 220px;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
}
.hlink-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.hlink-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}
.hlink-del:hover { background: rgba(193, 75, 63, 0.14); color: var(--danger); }
.hlink-pop { max-height: 60vh; overflow-y: auto; }

/* ---------- Salida de Python ---------- */
.py-out {
  overflow: auto;
  background: #1e1f25;
  color: #e6e3da;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 8px 10px;
  font-family: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
}
.py-out.empty {
  background: var(--secondary);
  color: var(--muted);
  font-family: inherit;
}
.py-stdout {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.py-err {
  margin: 6px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #ff9b8a;
}
.py-img {
  display: block;
  max-width: 100%;
  margin: 6px 0;
  border-radius: 6px;
  background: #fff;
}

/* ---------- Panel de IA ---------- */
.ai-panel {
  max-width: 460px;
  width: 92vw;
  height: 78vh;
  display: flex;
  flex-direction: column;
}
.ai-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.ai-settings {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.ai-settings.open {
  display: flex;
}
.ai-set-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-set-row label {
  font-size: 12.5px;
  color: var(--muted);
  min-width: 72px;
}
.ai-input {
  flex: 1;
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
}
.ai-warn {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}
.ai-save-btn {
  align-self: flex-end;
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: 9px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.ai-btn-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.ai-test-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 9px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.ai-test-btn:hover { border-color: var(--primary); color: var(--primary); }
.ai-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px;
}
.ai-msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.45;
  position: relative;
  word-wrap: break-word;
}
.ai-msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.ai-msg.bot {
  align-self: flex-start;
  background: var(--secondary);
  color: var(--fg);
  border-bottom-left-radius: 4px;
}
.ai-msg.note {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
}
.ai-msg.thinking {
  opacity: 0.7;
}
.ai-msg.bot.md-render :first-child {
  margin-top: 0;
}
.ai-msg.bot.md-render :last-child {
  margin-bottom: 0;
}
.ai-insert {
  display: inline-block;
  margin-top: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 7px;
  padding: 3px 10px;
  font-size: 11.5px;
  cursor: pointer;
}
.ai-insert:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.ai-quick {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.ai-model-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--secondary);
  margin-bottom: 2px;
}
.ai-effort-sel {
  flex: none;
  width: 92px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.ai-model-bar .icon { width: 15px; height: 15px; color: var(--primary); }
.ai-model-lbl { font-size: 12px; font-weight: 700; color: var(--muted); }
.ai-model-sel {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.ai-chip {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.ai-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.ai-inbar {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.ai-textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 130px;
  font: inherit;
  font-size: 13.5px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--fg);
  outline: none;
}
.ai-textarea:focus {
  border-color: var(--primary);
}
.ai-send-btn {
  flex: none;
  width: 42px;
  height: 42px;
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.ai-send-btn .icon {
  width: 18px;
  height: 18px;
}

/* ---------- Bloque de dibujo (l\u00e1piz / Apple Pencil) ---------- */
.card.draw .card-body,
.draw-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 0 0 var(--radius) var(--radius);
  background: #fff;
}
.draw-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}
.draw-toolbar {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.15s ease;
}
.card.draw:hover .draw-toolbar,
.card.draw.selected .draw-toolbar {
  opacity: 1;
}
.draw-color {
  width: 26px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
.draw-size {
  width: 90px;
}
.draw-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  border: 1px solid transparent;
  background: none;
  color: var(--fg);
  border-radius: 7px;
  cursor: pointer;
}
.draw-tool:hover {
  background: var(--secondary);
}
.draw-tool.on {
  background: var(--primary);
  color: #fff;
}
.draw-tool .icon {
  width: 15px;
  height: 15px;
}

/* ---------- Aviso de guardado fallido ---------- */
.save-banner {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(92vw, 560px);
  padding: 12px 16px;
  background: #fbeae2;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  font-weight: 600;
}
.save-banner-btn {
  flex: none;
  padding: 7px 12px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 9px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.save-banner-btn:hover {
  filter: brightness(1.08);
}

/* ---------- Copias de seguridad ---------- */
.backup-panel {
  width: 420px;
}
.backup-actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.backup-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  background: var(--secondary);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 9px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.backup-btn:hover {
  background: var(--border);
}
.backup-btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.backup-btn.primary:hover {
  filter: brightness(1.06);
  background: var(--primary);
}
.backup-btn .icon {
  width: 14px;
  height: 14px;
}
.backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--border);
}
.backup-info {
  min-width: 0;
}
.backup-when {
  font-size: 13.5px;
  font-weight: 600;
}
.backup-meta {
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Toast ---------- */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(12px);
  z-index: 320;
  max-width: min(90vw, 480px);
  padding: 10px 16px;
  background: var(--fg);
  color: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.app-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.app-toast.warn {
  background: var(--danger);
}

.app-toast.progress {
  background: var(--primary);
  color: #fff;
}

/* ---------- Plantillas de canvas ---------- */
.tpl-panel {
  width: 460px;
}
.tpl-hint {
  margin: 0 0 12px;
  font-size: 12.5px;
  color: var(--muted);
}
.tpl-ai-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 9px 11px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--primary);
}
.tpl-ai-row .icon {
  width: 15px;
  height: 15px;
  flex: none;
}
.tpl-ai-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  color: var(--fg);
}
.tpl-ai-input:disabled {
  color: var(--muted);
}
.tpl-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.tpl-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 14px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  text-align: left;
  cursor: pointer;
  position: relative;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.tpl-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}
.tpl-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
}
.tpl-icon .icon {
  width: 18px;
  height: 18px;
}
.tpl-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--fg);
}
/* ---------- Plantillas de usuario (Mis plantillas) ---------- */
.tpl-sec-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 8px 2px 2px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.tpl-sec-title .icon { width: 14px; height: 14px; }
.tpl-tools {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 3px;
  opacity: 0;
  transition: opacity 0.12s;
}
.tpl-user:hover .tpl-tools { opacity: 1; }
.tpl-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 7px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
.tpl-tool:hover { background: var(--bg); color: var(--fg); }
.tpl-tool.tpl-del:hover { background: rgba(193, 75, 63, 0.14); color: var(--danger); }
.tpl-tool .icon { width: 13px; height: 13px; }
.tpl-rename-input {
  width: 100%;
  padding: 2px 6px;
  border: 1px solid var(--primary);
  border-radius: 7px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  outline: none;
}
/* Botón "Plantilla" de la barra de selección */
.sel-tpl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border: 1px solid var(--ocre);
  border-radius: 999px;
  background: transparent;
  color: var(--ocre);
  cursor: pointer;
  transition: background 0.14s ease, transform 0.14s ease;
}
.sel-tpl .icon { width: 14px; height: 14px; }
.sel-tpl:hover { background: color-mix(in srgb, var(--ocre) 14%, transparent); }
.sel-tpl:active { transform: scale(0.96); }
.tpl-desc {
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

/* ---------- Búsqueda global (Ctrl+K) ---------- */
.search-overlay {
  align-items: flex-start;
  justify-content: center;
  padding-top: 11vh;
}
.search-panel {
  width: min(92vw, 620px);
  max-height: 64vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}
.search-bar .icon {
  width: 18px;
  height: 18px;
  flex: none;
}
.search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 15px;
  color: var(--fg);
}
.search-results {
  overflow-y: auto;
  padding: 6px;
}
.search-empty {
  padding: 22px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.search-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 11px;
  background: transparent;
  border: none;
  border-radius: 10px;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.search-row.sel {
  background: var(--secondary);
}
.search-row-icon {
  display: inline-flex;
  flex: none;
  color: var(--muted);
}
.search-row-icon .icon {
  width: 16px;
  height: 16px;
}
.search-row-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.search-row-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-row-path {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Resalte del bloque encontrado */
.card.search-hit {
  animation: searchHit 1.6s ease;
}
@keyframes searchHit {
  0%, 55% { box-shadow: 0 0 0 3px var(--primary), var(--shadow-lg); }
  100% { box-shadow: none; }
}

/* ---------- Panel de atajos ---------- */
.shortcut-panel {
  width: 420px;
}
.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}
.shortcut-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 2px;
}
.shortcut-key {
  flex: none;
  min-width: 108px;
  padding: 3px 9px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  font-weight: 600;
  text-align: center;
  color: var(--fg);
}
.shortcut-desc {
  font-size: 13px;
  color: var(--fg);
}

/* ---------- IA sobre bloques ---------- */
.cm-ai {
  flex-wrap: wrap;
}
.card.ai-busy {
  pointer-events: none;
}
.card.ai-busy::after {
  content: 'Pensando…';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 252, 246, 0.72);
  border-radius: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  z-index: 5;
  animation: aiPulse 1.2s ease-in-out infinite;
}
@keyframes aiPulse {
  0%, 100% { opacity: 0.75; }
  50% { opacity: 1; }
}

/* ---------- Herramienta de diagramas (menú del bloque Mermaid) ---------- */
.diagram-pop {
  width: 300px;
}
.dg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 2px;
}
.dg-type {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 8px 10px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 9px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.14s ease, transform 0.14s ease, box-shadow 0.14s ease;
}
.dg-type:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 5px 12px -8px rgba(58, 51, 44, 0.4);
}
.dg-type:active {
  transform: translateY(0) scale(0.97);
}
.dg-type-name {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--fg);
}
.dg-type-desc {
  font-size: 10.5px;
  color: var(--muted);
}
.dg-shapes {
  flex-wrap: wrap;
}
.dg-ai-row {
  display: flex;
  gap: 6px;
  padding: 2px;
}
.dg-ai-input {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  font: inherit;
  font-size: 12px;
  color: var(--fg);
}
.dg-ai-input:focus {
  outline: none;
  border-color: var(--primary);
}
.dg-ai-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.14s ease, transform 0.14s ease;
}
.dg-ai-btn:hover {
  filter: brightness(1.08);
}
.dg-ai-btn:active {
  transform: scale(0.96);
}
.dg-ai-btn .icon {
  width: 13px;
  height: 13px;
}

/* ---------- Microinteracciones globales ---------- */
.cm-chip,
.ai-chip,
.backup-btn,
.tpl-card,
.search-row {
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.14s ease, box-shadow 0.14s ease;
}
.cm-chip:hover,
.ai-chip:hover {
  border-color: var(--primary);
}
.cm-chip:active,
.ai-chip:active,
.backup-btn:active,
.tpl-card:active {
  transform: scale(0.96);
}
.kanban-card {
  transition: box-shadow 0.16s ease, transform 0.16s ease, border-color 0.16s ease;
}
.kanban-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}
.ai-btn {
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.ai-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}
.ai-btn:active {
  transform: scale(0.96);
}
.card-menu-pop {
  animation: menuIn 0.18s cubic-bezier(0.34, 1.4, 0.64, 1);
  transform-origin: top right;
}
@keyframes menuIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(-4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}
.search-panel {
  animation: searchIn 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes searchIn {
  from {
    opacity: 0;
    transform: translateY(-14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---------- Topbar: menú "⋯" y estado vacío ---------- */
.topbar-pop {
  width: 250px;
}
.empty-ico {
  animation: leafFloat 4.5s ease-in-out infinite;
}
@keyframes leafFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-7px) rotate(4deg); }
}
.empty-keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 14px;
  margin-top: 18px;
  font-size: 12px;
  color: var(--muted);
}
.empty-key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.empty-key kbd {
  padding: 2px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--fg);
}

/* Conexiones: resaltar al pasar el ratón (el hit va justo antes del path) */
.link-path {
  transition: opacity 0.15s ease, stroke-width 0.15s ease;
}
.link-hit:hover + .link-path {
  opacity: 1;
  stroke-width: 3.5;
}

/* ---------- Guías inteligentes de alineación (snap) ---------- */
.snap-guides {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}
.snap-guide {
  position: absolute;
  background: var(--primary);
  opacity: 0.85;
}
.snap-guide.v {
  width: 1px;
}
.snap-guide.h {
  height: 1px;
}

/* ---------- Conexiones: flecha y etiqueta ---------- */
.link-arrow {
  fill: context-stroke;
  fill-opacity: 0.75;
}
/* Tipos de conector (color semántico) */
.link-path.link-t-dep { stroke: var(--ocre); }
.link-path.link-t-block { stroke: var(--danger); stroke-dasharray: 7 5; }
.link-path.link-t-flow { stroke: var(--sage); }
.link-path.link-selected { stroke-width: 3.5px; filter: drop-shadow(0 0 3px var(--primary)); }
.link-t-chip.t-dep.on { border-color: var(--ocre); color: var(--ocre); }
.link-t-chip.t-block.on { border-color: var(--danger); color: var(--danger); }
.link-t-chip.t-flow.on { border-color: var(--sage); color: var(--sage); }
.link-label-input {
  width: 100%;
  margin-bottom: 2px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  outline: none;
}
.link-label-input:focus { border-color: var(--primary); }
.link-dir-chip { min-width: 36px; font-size: 15px; font-weight: 700; line-height: 1; }
.link-label {
  fill: var(--fg);
  font-size: 11px;
  font-weight: 700;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 3.5px;
  stroke-linejoin: round;
  cursor: pointer;
}
.link-menu {
  min-width: 190px;
}

/* ---------- Formas / stencils (diagramación) ---------- */
.card.shape {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  min-height: 72px;
  overflow: visible;   /* deja ver las manijas de conexión rápida */
  resize: none;        /* se redimensiona con su propia manija */
}
/* Formas coloreadas por categoría (para nodos de inicio/fin/decisión). */
.card.card-c-q .shape-box { border-color: #c0563c; background: color-mix(in srgb, #c0563c 12%, var(--card)); }
.card.card-c-a .shape-box { border-color: #3f9e6f; background: color-mix(in srgb, #3f9e6f 12%, var(--card)); }
.card.card-c-p .shape-box { border-color: #d09a3a; background: color-mix(in srgb, #d09a3a 12%, var(--card)); }
.card.card-c-i .shape-box { border-color: #4f84c4; background: color-mix(in srgb, #4f84c4 12%, var(--card)); }
.card.card-c-n .shape-box { border-color: #9d72d6; background: color-mix(in srgb, #9d72d6 12%, var(--card)); }
.card.card-c-g .shape-box { border-color: #43a291; background: color-mix(in srgb, #43a291 12%, var(--card)); }
.card.card-c-v .shape-box { border-color: #cf6295; background: color-mix(in srgb, #cf6295 12%, var(--card)); }
/* Manijas de conexión rápida (+) en los 4 costados de una forma. */
.qc-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--primary);
  background: var(--card);
  color: var(--primary);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, transform 0.12s, background 0.12s;
  z-index: 5;
  box-shadow: var(--shadow);
}
.card.shape:hover .qc-handle,
.card.shape.selected .qc-handle { opacity: 0.9; }
.qc-handle:hover { opacity: 1; background: var(--primary); color: #fff; }
.qc-top { top: -27px; left: 50%; margin-left: -10px; }
.qc-bottom { bottom: -27px; left: 50%; margin-left: -10px; }
.qc-left { left: -27px; top: 50%; margin-top: -10px; }
.qc-right { right: -27px; top: 50%; margin-top: -10px; }
.shape-resize {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.12s;
}
.card.shape:hover .shape-resize,
.card.shape.selected .shape-resize { opacity: 1; }
.shape-resize::before {
  content: '';
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted2);
  border-bottom: 2px solid var(--muted2);
}
.shape-mini.qc-red { border-color: #c0563c; background: color-mix(in srgb, #c0563c 16%, var(--card)); }
.card.shape .card-head {
  background: transparent;
  opacity: 0.5;
  transition: opacity 0.12s;
}
.card.shape:hover .card-head,
.card.shape.selected .card-head {
  opacity: 1;
}
.card.shape.selected .shape-box {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.shape-box {
  flex: 1;
  min-height: 0;
  margin: 0 3px 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--primary) 12%, var(--card));
  border: 2px solid var(--primary);
  color: var(--fg);
  border-radius: 4px;
}
.shape-round { border-radius: 16px; }
.shape-pill { border-radius: 999px; }
.shape-ellipse { border-radius: 50%; }
/* Rombo y paralelogramo: el clip-path recortaba el borde rectangular y la figura se veía
   incompleta. El borde se dibuja con la capa exterior (color sólido) y el relleno con un
   ::before encogido — así el contorno completo del rombo siempre es visible. */
.shape-diamond,
.shape-parallelogram {
  border: none;
  background: var(--primary);
  position: relative;
}
.shape-diamond { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.shape-parallelogram { clip-path: polygon(14% 0, 100% 0, 86% 100%, 0 100%); }
.shape-diamond::before,
.shape-parallelogram::before {
  content: '';
  position: absolute;
  inset: 2.5px;
  background: color-mix(in srgb, var(--primary) 12%, var(--card));
  z-index: 0;
}
.shape-diamond::before { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.shape-parallelogram::before { clip-path: polygon(14% 0, 100% 0, 86% 100%, 0 100%); }
.shape-diamond .shape-ta,
.shape-parallelogram .shape-ta { position: relative; z-index: 1; }
.shape-ta {
  width: 84%;
  height: 70%;
  border: none;
  background: transparent;
  color: inherit;
  text-align: center;
  resize: none;
  outline: none;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
}
.shape-diamond .shape-ta,
.shape-ellipse .shape-ta { width: 66%; height: 60%; }

/* Paleta y selector de forma */
.shape-pop { padding: 8px; }
.shape-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 4px;
}
.shape-tile,
.shape-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  cursor: pointer;
  color: var(--fg);
}
.shape-tile {
  flex-direction: column;
  padding: 10px 6px;
  font-size: 11px;
  text-align: center;
}
.shape-opt {
  width: 100%;
  padding: 6px 10px;
  font-size: 12.5px;
  margin-bottom: 2px;
}
.shape-tile:hover,
.shape-opt:hover { border-color: var(--primary); }
.shape-opt.on { border-color: var(--primary); background: var(--secondary); }
.shape-mini {
  width: 26px;
  height: 18px;
  flex: none;
  background: color-mix(in srgb, var(--primary) 16%, var(--card));
  border: 1.5px solid var(--primary);
  border-radius: 3px;
}
.shape-mini.shape-round { border-radius: 6px; }
.shape-mini.shape-pill { border-radius: 999px; }
.shape-mini.shape-ellipse { border-radius: 50%; }
.shape-mini.shape-diamond { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.shape-mini.shape-parallelogram { clip-path: polygon(14% 0, 100% 0, 86% 100%, 0 100%); }
.card-shape-type { color: var(--muted); }

/* ---------- Título de bloque (doble clic en la etiqueta) ---------- */
.card-label.has-title { color: var(--fg); text-transform: none; letter-spacing: 0; font-weight: 700; }
.card-label { cursor: text; }
.card-title-input {
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  width: 120px;
  min-width: 0;
}

/* ---------- Grupos (áreas combinadas) ---------- */
.group-area {
  position: absolute;
  z-index: 0; /* detrás de las tarjetas */
  border-radius: 16px;
  border: 1.5px solid;
  pointer-events: none;
}
.group-head { pointer-events: auto; }
.group-area.g-sage { background: rgba(138, 154, 123, 0.10); border-color: rgba(138, 154, 123, 0.45); }
.group-area.g-blue { background: rgba(79, 132, 196, 0.08); border-color: rgba(79, 132, 196, 0.4); }
.group-area.g-ocre { background: rgba(217, 163, 90, 0.10); border-color: rgba(217, 163, 90, 0.45); }
.group-area.g-lila { background: rgba(157, 114, 214, 0.08); border-color: rgba(157, 114, 214, 0.4); }
.group-area.g-rose { background: rgba(207, 98, 149, 0.08); border-color: rgba(207, 98, 149, 0.4); }
.group-head {
  position: absolute; /* hermano de las tarjetas, colocado por JS (left/top/width) y con z-index sobre ellas */
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  cursor: grab;
  user-select: none;
  /* Fondo esmerilado sutil: la cabecera flota sobre las tarjetas, así sus botones y el nombre son
     siempre legibles y clicables aunque una tarjeta quede debajo de la franja del título. */
  background: color-mix(in srgb, var(--card) 72%, transparent);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  border-radius: 14px 14px 10px 10px;
}
.group-head:active { cursor: grabbing; }
.group-name { font-size: 12.5px; font-weight: 800; color: var(--fg); opacity: 0.75; }
.group-name-input {
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  width: 160px;
}
.group-color {
  width: 13px; height: 13px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: currentColor;
  opacity: 0.8;
}
.g-sage .group-color { color: #8a9a7b; } .g-blue .group-color { color: #4f84c4; }
.g-ocre .group-color { color: #d9a35a; } .g-lila .group-color { color: #9d72d6; }
.g-rose .group-color { color: #cf6295; }
.group-edit {
  border: none; background: none;
  color: var(--muted); font-size: 12px; line-height: 1;
  cursor: pointer; padding: 0 2px;
  opacity: 0.65;
}
.group-edit:hover { color: var(--primary); opacity: 1; }
.group-merge {
  border: none; background: none;
  color: var(--muted);
  cursor: pointer; padding: 0 2px;
  opacity: 0.65;
  display: inline-flex; align-items: center;
}
.group-merge:hover { color: var(--primary); opacity: 1; }
.group-merge .icon { width: 14px; height: 14px; }
.group-del {
  border: none; background: none;
  color: var(--muted); font-size: 15px; line-height: 1;
  cursor: pointer; padding: 0 3px;
}
.group-del:hover { color: var(--danger); }
.group-tabs {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 6px;
  z-index: 45;
  max-width: 70%;
  overflow-x: auto;
  padding: 3px;
}
.group-tab {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit; font-size: 12px; font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.group-tab:hover { border-color: var(--primary); }
.group-tab-dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.group-tab.g-sage .group-tab-dot { color: #8a9a7b; } .group-tab.g-blue .group-tab-dot { color: #4f84c4; }
.group-tab.g-ocre .group-tab-dot { color: #d9a35a; } .group-tab.g-lila .group-tab-dot { color: #9d72d6; }
.group-tab.g-rose .group-tab-dot { color: #cf6295; }
.sel-group {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 6px 12px;
  border: 1px solid var(--ocre);
  border-radius: 999px;
  background: transparent; color: var(--ocre);
  cursor: pointer;
}
.sel-group .icon { width: 14px; height: 14px; }
.sel-group:hover { background: color-mix(in srgb, var(--ocre) 14%, transparent); }
.sel-dl {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent; color: var(--primary);
  cursor: pointer;
}
.sel-dl .icon { width: 14px; height: 14px; }
.sel-dl:hover { background: color-mix(in srgb, var(--primary) 14%, transparent); }

/* ---------- Vista vertical ---------- */
.vert-panel { width: 560px; max-width: 94vw; }
.vert-body { display: flex; flex-direction: column; gap: 10px; }
.vert-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.vert-item:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.vert-item.important { border-color: var(--ocre); border-width: 2px; background: color-mix(in srgb, var(--ocre) 6%, var(--card)); }
.vert-item-head { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 13.5px; }
.vert-item-head .icon { width: 15px; height: 15px; color: var(--muted); }
.vert-star { color: var(--ocre); display: inline-flex; }
.vert-star .icon { width: 14px; height: 14px; color: var(--ocre); }
.vert-rem { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.vert-rem .icon { width: 12px; height: 12px; }
.vert-item-text { margin-top: 6px; font-size: 13px; color: var(--fg); white-space: pre-wrap; }
.vert-item-md { margin-top: 6px; font-size: 13px; }

/* ---------- Chat flotante del lienzo ---------- */
.float-chat-btn {
  position: absolute;
  right: 16px;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: 64px;
  bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 19px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s, box-shadow 0.12s;
}
.float-chat-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.float-chat {
  position: fixed;
  right: 18px;
  bottom: 118px;
  width: 340px;
  max-height: 60vh;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop 0.16s ease-out;
}
.fc-head { display: flex; align-items: center; gap: 7px; padding: 10px 12px; background: var(--secondary); border-bottom: 1px solid var(--border); }
.fc-head .icon { width: 15px; height: 15px; color: var(--primary); }
.fc-title { font-weight: 800; font-size: 13.5px; }
.fc-refbar { display: flex; align-items: center; gap: 6px; padding: 7px 10px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.fc-pick {
  border: 1px dashed var(--primary);
  background: transparent; color: var(--primary);
  border-radius: 999px; padding: 4px 10px;
  font: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
}
.fc-pick.on, .fc-pick:hover { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.fc-ref-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 8px;
  font-size: 12px; font-weight: 600;
  max-width: 200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.fc-ref-chip .icon { width: 12px; height: 12px; flex: none; }
.fc-ref-x { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0 1px; }
.fc-ref-x:hover { color: var(--danger); }
.fc-log { flex: 1; min-height: 90px; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 7px; }
.fc-msg { border-radius: 10px; padding: 7px 10px; font-size: 12.5px; line-height: 1.45; max-width: 95%; }
.fc-msg.user { align-self: flex-end; background: var(--primary); color: #fff; }
.fc-msg.bot { align-self: flex-start; background: var(--secondary); }
.fc-msg.note { align-self: center; color: var(--muted); font-size: 11.5px; font-style: italic; background: none; padding: 1px; }
.fc-inbar { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); }
.fc-input {
  flex: 1; min-width: 0; resize: none; height: 40px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--fg);
  font: inherit; font-size: 13px; padding: 8px 10px;
}
.fc-send {
  width: 40px; border: none; border-radius: 10px;
  background: var(--primary); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.fc-send .icon { width: 16px; height: 16px; }
body.fc-picking .card { cursor: crosshair !important; }
.card.fc-linked { outline: 2px dashed var(--primary); outline-offset: 3px; }

/* ---------- Casillas de tarea en Markdown ---------- */
.md-render li.md-task {
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-left: -18px;
}
.md-task-cb { accent-color: var(--primary); cursor: pointer; flex: none; transform: translateY(1px); }
.md-task.done .md-task-txt { text-decoration: line-through; color: var(--muted); }
.md-task-bell {
  border: none;
  background: none;
  padding: 1px 3px;
  color: var(--muted2);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s;
  flex: none;
}
.md-task:hover .md-task-bell { opacity: 1; }
.md-task-bell:hover { color: var(--primary); }
.md-task-bell svg { width: 13px; height: 13px; }

/* ---------- Barra de formato Markdown ---------- */
.md-fmt-bar {
  display: none;
  gap: 3px;
  flex-wrap: wrap;
  padding: 4px 6px;
  border-top: 1px solid var(--border);
  background: var(--secondary);
}
.card.editing-md .md-fmt-bar { display: flex; }
.md-fmt-b {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 6px;
  min-width: 26px;
  padding: 3px 7px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}
.md-fmt-b:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Recordatorio: calendario y sonido ---------- */
.rem-cal-row { display: flex; gap: 6px; }
.rem-cal-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.rem-cal-btn:hover { border-color: var(--primary); color: var(--primary); }
.alarm-sound-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 12px;
  border-top: 1px solid var(--border);
}
.alarm-sound-lbl { font-size: 12px; font-weight: 700; color: var(--muted); }
.alarm-sound-sel {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
}
.app-toast-btn {
  margin-left: 10px;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  padding: 5px 12px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.app-toast-btn:hover { filter: brightness(1.08); }

/* ---------- Bloque "Imagen IA": buscar/generar ---------- */
.aiimg-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  overflow: auto;
  height: 100%;
}
.aiimg-tabs {
  display: flex;
  gap: 6px;
}
.aiimg-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 8px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}
.aiimg-tab .icon {
  width: 14px;
  height: 14px;
}
.aiimg-tab.on {
  background: var(--secondary);
  border-color: var(--primary);
  color: var(--primary);
}
.aiimg-inbar {
  display: flex;
  gap: 6px;
}
.aiimg-input {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
}
.aiimg-go {
  padding: 7px 12px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.aiimg-go:disabled {
  opacity: 0.6;
  cursor: default;
}
.aiimg-status {
  font-size: 12px;
  color: var(--muted);
  min-height: 15px;
}
.aiimg-status.err {
  color: #c0563c;
}
.aiimg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
}
.aiimg-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  background: var(--secondary);
}
.aiimg-thumb:hover {
  border-color: var(--primary);
}
.aiimg-figure {
  margin: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.aiimg-result {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  object-fit: contain;
}
.aiimg-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.aiimg-caption {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.aiimg-mini {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  color: var(--primary);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}
.aiimg-mini .icon {
  width: 13px;
  height: 13px;
}

/* ---------- Recorte libre de imágenes ---------- */
.crop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 12, 0.85);
  z-index: 360;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}
.crop-box {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  max-width: 98vw;
  max-height: 98vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.crop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.crop-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 13px;
  color: var(--fg);
}
.crop-hint {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.crop-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}
.crop-inner {
  position: relative;
  display: inline-block;
  margin: 4px;
}
.crop-img {
  display: block;
  flex-shrink: 0;
  border-radius: 4px;
}
.crop-canvas {
  position: absolute;
  top: 0;
  left: 0;
  cursor: crosshair;
  touch-action: none;
}
.crop-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}
.crop-btn {
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}
.crop-btn:hover { background: rgba(0, 0, 0, 0.05); }
.crop-btn.primary { background: var(--primary); color: #fff; border-color: transparent; }
.crop-btn.primary:hover { filter: brightness(1.05); }
.crop-btn.zoom {
  padding: 4px 6px;
  display: inline-flex;
  align-items: center;
}
.crop-btn.zoom .icon { width: 14px; height: 14px; }
.crop-zoom {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.crop-zoom-val {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  min-width: 36px;
  text-align: center;
}
.card-crop,
.card-dl,
.card-copy {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 13px;
  line-height: 1;
}
.card-crop:hover,
.card-dl:hover,
.card-copy:hover { color: var(--primary); }

/* Accesibilidad: sin animaciones si el sistema lo pide */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Tour: puntos de progreso y CTA ---------- */
.tour-dots { display: flex; gap: 5px; margin-bottom: 8px; }
.tour-dot { width: 8px; height: 8px; border-radius: 50%; border: none; padding: 0; cursor: pointer; background: var(--border); transition: background 0.15s, transform 0.15s; }
.tour-dot.done { background: var(--muted2); }
.tour-dot.on { background: var(--primary); transform: scale(1.3); }
.tour-count { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; color: var(--muted); align-self: center; }
.tour-cta { display: block; width: 100%; margin: 10px 0 2px; background: var(--sage); }

/* ---------- Guía de funciones (documento in-app) ---------- */
.guide-panel { width: min(980px, 94vw); height: min(86vh, 900px); display: flex; flex-direction: column; }
.guide-search { flex: 1; max-width: 260px; margin: 0 10px; padding: 7px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg); color: var(--fg); font: inherit; font-size: 13px; }
.guide-main { display: flex; flex: 1; min-height: 0; }
.guide-toc { width: 200px; flex-shrink: 0; overflow-y: auto; padding: 12px 8px; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.guide-toc-item { text-align: left; background: none; border: none; border-radius: 8px; padding: 7px 10px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.guide-toc-item:hover { background: var(--secondary); color: var(--fg); }
.guide-body { flex: 1; overflow-y: auto; padding: 14px 22px 30px; }
.guide-sec-title { position: sticky; top: -14px; background: var(--card); z-index: 1; padding: 10px 0 6px; }
.guide-item { margin: 0 0 22px; }
.guide-item-title { margin: 0 0 4px; font-family: Fraunces, serif; font-size: 17px; }
.guide-item-body { margin: 0 0 8px; font-size: 13.5px; line-height: 1.55; color: var(--fg); }
.guide-img { max-width: 100%; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); cursor: zoom-in; }
.guide-lightbox { position: fixed; inset: 0; z-index: 6000; background: rgba(20, 16, 12, 0.82); display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.guide-lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 10px; box-shadow: var(--shadow-lg); }
@media (max-width: 720px) { .guide-toc { display: none; } .guide-search { max-width: 150px; } }

/* ---------- Apoyar tuNota (Yape) ---------- */
.donate-card { position: relative; width: min(360px, 92vw); max-height: 92vh; overflow-y: auto; background: linear-gradient(160deg, #742284, #4e1560); border-radius: 22px; padding: 26px 24px 22px; text-align: center; color: #fff; box-shadow: var(--shadow-lg); animation: pop 0.16s ease-out; }
.donate-close { position: absolute; top: 10px; right: 10px; color: rgba(255, 255, 255, 0.8); }
.donate-close:hover { color: #fff; background: rgba(255, 255, 255, 0.12); }
.donate-heart { color: #2fd5c8; }
.donate-heart svg { width: 30px; height: 30px; }
.donate-title { margin: 4px 0 8px; font-family: Fraunces, serif; font-size: 24px; color: #fff; }
.donate-text { margin: 0 0 16px; font-size: 13.5px; line-height: 1.55; color: rgba(255, 255, 255, 0.9); }
.donate-qr-frame { background: #fff; border-radius: 16px; padding: 14px; margin: 0 auto 14px; width: fit-content; }
.donate-qr { display: block; width: 220px; max-width: 70vw; height: auto; }
.donate-qr-missing { width: 220px; max-width: 70vw; padding: 30px 14px; font-size: 13px; color: #4e1560; }
.donate-pill { display: inline-block; background: #2fd5c8; color: #24123a; font-weight: 800; font-size: 13px; padding: 7px 18px; border-radius: 999px; margin-bottom: 10px; }
.donate-name { font-weight: 700; font-size: 15px; margin-bottom: 10px; }
.donate-small { margin: 0; font-size: 11.5px; color: rgba(255, 255, 255, 0.65); }

/* La guía y la donación se centran como documento/tarjeta (el overlay base es un drawer lateral). */
#guideOverlay, #donateOverlay { justify-content: center; align-items: center; background: rgba(30, 26, 22, 0.45); backdrop-filter: blur(2px); }
.guide-panel { border-radius: 16px; border: 1px solid var(--border); animation: pop 0.16s ease-out; }

/* ---------- Bloque idea: botón «Revisar idea» + panel de validación ---------- */
/* Botón destacado del topbar: lupa grande + «Revisar idea». */
.idea-review-top {
  display: inline-flex; align-items: center; gap: 8px;
  border: none; border-radius: 999px; cursor: pointer;
  padding: 7px 16px 7px 14px; font: inherit; font-size: 13px; font-weight: 800; color: #fff;
  background: linear-gradient(120deg, var(--sage), #6f8256);
  box-shadow: 0 4px 14px -4px rgba(94, 107, 80, 0.6);
  flex: none;
}
.idea-review-top svg { width: 19px; height: 19px; stroke-width: 2.6; }
.idea-review-top:hover { filter: brightness(1.06); transform: translateY(-1px); }
.idea-review-top:active { transform: translateY(0); }
@media (max-width: 900px) { .idea-review-top span, .idea-review-top { font-size: 0; gap: 0; padding: 8px; } .idea-review-top svg { width: 20px; height: 20px; } }
/* Panel de revisión: campo editable de la idea + botón de consulta. */
.idea-rev-src { padding: 10px 18px 2px; color: var(--muted); font-size: 12.5px; }
.idea-rev-input { margin: 6px 18px; width: calc(100% - 36px); min-height: 74px; resize: vertical; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--fg); font: inherit; font-size: 14px; line-height: 1.5; box-sizing: border-box; }
.idea-rev-run { display: flex; justify-content: flex-end; padding: 0 18px 6px; }
.idea-rev-go { display: inline-flex; align-items: center; gap: 7px; }
.idea-rev-go svg { width: 16px; height: 16px; }
#ideaRevOverlay { justify-content: center; align-items: center; background: rgba(30, 26, 22, 0.45); backdrop-filter: blur(2px); }
.idea-rev-panel { width: min(680px, 94vw); max-height: min(86vh, 860px); border-radius: 16px; border: 1px solid var(--border); animation: pop 0.16s ease-out; }
.idea-rev-quote { margin: 0; padding: 10px 18px; font-family: Fraunces, serif; font-size: 16px; border-left: 4px solid var(--ocre); background: var(--idea-bg); color: var(--fg); }
.idea-rev-status { padding: 14px 18px; color: var(--muted); font-size: 13.5px; }
.idea-rev-status::after { content: '…'; animation: pulse 1.2s infinite; }
.idea-rev-body { flex: 1; overflow-y: auto; padding: 6px 18px 12px; font-size: 13.5px; line-height: 1.55; }
.idea-rev-body h2 { font-family: Fraunces, serif; font-size: 16px; margin: 14px 0 4px; }
.idea-rev-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 10px 18px 16px; border-top: 1px solid var(--border); }
.idea-rev-actions:empty { display: none; }

/* ---------- Botón de donación destacado en el topbar ---------- */
.donate-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; border-radius: 999px; cursor: pointer;
  padding: 7px 15px; font: inherit; font-size: 13px; font-weight: 800; color: #fff;
  background: linear-gradient(120deg, #ff4d8d, #b0329b);
  box-shadow: 0 4px 14px -4px rgba(176, 50, 155, 0.6);
  flex: none;
}
.donate-btn svg { width: 15px; height: 15px; fill: currentColor; stroke: none; animation: heart-beat 1.7s ease-in-out infinite; }
.donate-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.donate-btn:active { transform: translateY(0); }
@keyframes heart-beat { 0%, 70%, 100% { transform: scale(1); } 35% { transform: scale(1.22); } }
@media (max-width: 900px) { .donate-btn span, .donate-btn { font-size: 0; gap: 0; padding: 8px; } .donate-btn svg { font-size: 15px; } }

/* ---------- Panel de control de funcionalidades ---------- */
#featCtlOverlay { justify-content: center; align-items: center; background: rgba(30, 26, 22, 0.45); backdrop-filter: blur(2px); }
.feat-panel { width: min(460px, 94vw); max-height: min(84vh, 640px); border-radius: 16px; border: 1px solid var(--border); animation: pop 0.16s ease-out; }
.feat-intro { margin: 0; padding: 10px 18px 4px; color: var(--muted); font-size: 12.5px; }
.feat-body { flex: 1; overflow-y: auto; padding: 8px 18px; }
.feat-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--border); cursor: pointer; }
.feat-name { font-size: 13.5px; font-weight: 600; }
.feat-toggle input { width: 18px; height: 18px; accent-color: var(--sage); cursor: pointer; }
.feat-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 18px 16px; border-top: 1px solid var(--border); }

/* ---------- Clasificación de notas por tono ---------- */
/* Tintes opacos (no color-mix) para que el contraste automático del texto los lea bien. */
.card.rank-relevant { background: #e9f0e1; border-color: #b9cbab; box-shadow: var(--shadow), inset 3px 0 0 #6f9257; }
.card.rank-idea { background: #f7ead2; border-color: var(--idea-border); box-shadow: var(--shadow), inset 3px 0 0 var(--ocre); }
.card.rank-important { background: #fbe6d1; border-color: #e6a765; box-shadow: var(--shadow), inset 3px 0 0 #e0873c; }
.card.rank-crucial { background: #fbdfda; border-color: #e0a49c; box-shadow: var(--shadow), inset 3px 0 0 var(--danger); }
.card-rank-badge { display: inline-flex; align-items: center; gap: 3px; font-size: 10px; font-weight: 800; padding: 2px 8px; border: none; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; color: #fff; cursor: pointer; font-family: inherit; transition: filter .12s, transform .1s; }
.card-rank-badge svg { width: 11px; height: 11px; }
.card-rank-badge:hover { filter: brightness(1.08); transform: translateY(-1px); }
.card-rank-badge:active { transform: translateY(0); }
.card-rank-badge.rank-relevant { background: #6f9257; }
.card-rank-badge.rank-idea { background: var(--ocre); }
.card-rank-badge.rank-important { background: #e0873c; }
.card-rank-badge.rank-crucial { background: var(--danger); }

/* ---------- Tooltips (nombre + descripción, a los 3.5 s) ---------- */
.ui-tip { position: fixed; z-index: 7000; max-width: 260px; background: #2a2620; color: #fbf8f1; border-radius: 8px; padding: 7px 11px; box-shadow: 0 10px 28px -8px rgba(0,0,0,.5); font-size: 12.5px; line-height: 1.4; pointer-events: none; opacity: 0; transform: translateY(-3px); transition: opacity .12s ease, transform .12s ease; }
.ui-tip.on { opacity: 1; transform: none; }
.ui-tip-name { font-weight: 800; }
.ui-tip-desc { margin-top: 2px; color: rgba(251,248,241,.72); font-size: 11.5px; }
.cm-ranks { display: flex; flex-wrap: wrap; gap: 6px; }
.rank-chip { border-left-width: 3px !important; border-left-style: solid !important; }
.rank-chip-relevant { border-left-color: #6f9257 !important; }
.rank-chip-idea { border-left-color: var(--ocre) !important; }
.rank-chip-important { border-left-color: #e0873c !important; }
.rank-chip-crucial { border-left-color: var(--danger) !important; }
.rank-chip.on { outline: 2px solid var(--fg); outline-offset: 1px; }

/* ---------- Botón «analizar con IA» (robot) + panel de resultado bajo la nota ---------- */
.analyze-emoji { font-size: 13px; line-height: 1; }
.card-analyze-btn.busy { opacity: 1 !important; pointer-events: none; }
.card-analyze-btn.busy .analyze-emoji { display: inline-block; animation: robotPulse .9s ease-in-out infinite; }
@keyframes robotPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } }
@keyframes analyzeSpin { to { transform: rotate(360deg); } }
.note-analysis-robot { font-size: 13px; line-height: 1; }
.note-analysis-loading { display: flex; align-items: center; }
.note-analysis-loading.err { color: var(--danger); font-style: normal; }
.note-spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--sage); border-radius: 50%; display: inline-block; flex: none; margin-right: 8px; animation: analyzeSpin .8s linear infinite; }
.note-analysis { margin: 6px 10px 10px; border: 1px solid var(--border); border-radius: 10px; background: #fbf8f1; color: #2a2620; overflow: hidden; }
.note-analysis-body { color: #2a2620; }
.note-analysis-head { display: flex; align-items: center; gap: 6px; padding: 6px 10px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--border); }
.note-analysis-head svg { width: 13px; height: 13px; }
.note-analysis-x { border: none; background: none; color: var(--muted); cursor: pointer; padding: 0; display: inline-flex; }
.note-analysis-x:hover { color: var(--fg); }
.note-analysis-x svg { width: 13px; height: 13px; }
.note-analysis-body { padding: 8px 12px; font-size: 12.5px; line-height: 1.5; max-height: 260px; overflow-y: auto; }
.note-analysis-body h2, .note-analysis-body h3 { font-family: Fraunces, serif; font-size: 14px; margin: 8px 0 3px; }
.note-analysis-loading { color: var(--muted); font-style: italic; }
.note-analysis.anim-in { animation: analysisIn .34s cubic-bezier(.22,1,.36,1); }
.note-analysis.anim-out { animation: analysisOut .18s ease-in forwards; }
@keyframes analysisIn { from { opacity: 0; transform: translateY(-8px) scaleY(.9); } to { opacity: 1; transform: none; } }
@keyframes analysisOut { to { opacity: 0; transform: translateY(-6px); } }

/* ---------- Botón de apoyo combinado (café / corazón) ---------- */
.support-btn { display: inline-flex; align-items: stretch; border-radius: 999px; overflow: hidden; box-shadow: 0 4px 14px -4px rgba(58,51,44,.35); flex: none; }
.support-half { display: inline-flex; align-items: center; gap: 6px; border: none; cursor: pointer; padding: 7px 13px; font: inherit; font-size: 12.5px; font-weight: 800; color: #fff; transition: filter .15s, transform .12s; }
.support-coffee { background: #6f4a30; transition: background .28s ease, filter .15s, transform .12s; }
.support-heart { background: linear-gradient(120deg, #ff4d8d, #b0329b); }
.support-half svg { width: 17px; height: 17px; flex: none; }
.support-heart svg { fill: currentColor; stroke: none; }
.support-half .support-lbl { max-width: 0; overflow: hidden; white-space: nowrap; opacity: 0; transition: max-width .28s ease, opacity .22s ease; }
.support-half:hover { filter: brightness(1.06); }
.support-half:hover .support-lbl { max-width: 110px; opacity: 1; }
.support-coffee:hover svg { animation: heart-beat 1.4s ease-in-out infinite; }
.support-heart:hover svg { animation: heart-beat 1.2s ease-in-out infinite; }
/* Café: por defecto SOLO el icono; al pasar el ratón se expande a «Un cafecito» con un
   gradiente café → crema y las palabras en color de contraste que resalta sobre el fondo. */
.support-solo .support-lbl { max-width: 0; opacity: 0; }
.support-solo:hover .support-lbl { max-width: 110px; opacity: 1; }
.support-solo .support-coffee { padding: 7px 11px; }
.support-solo:hover .support-coffee, .support-coffee:hover { background: linear-gradient(120deg, #4a2e1c 0%, #8a5a37 55%, #d8b48a 100%); }
.support-coffee .support-lbl { color: #fff6ea; text-shadow: 0 1px 2px rgba(40, 24, 12, .55); letter-spacing: .01em; }
.support-coffee svg { color: #fff6ea; }

/* ---------- Modal de apoyo: pestañas Yape / Stripe ---------- */
.donate-tabs { display: flex; gap: 8px; justify-content: center; margin: 4px 0 16px; }
.donate-tab { border: 1px solid rgba(255,255,255,.4); background: transparent; color: rgba(255,255,255,.85); border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.donate-tab.on { background: #fff; color: #4e1560; border-color: #fff; }
.donate-pane { display: flex; flex-direction: column; align-items: center; }
.donate-stripe-btn { display: inline-flex; align-items: center; gap: 8px; background: #635bff; color: #fff; text-decoration: none; font-weight: 800; font-size: 14px; padding: 12px 22px; border-radius: 12px; margin: 6px 0 12px; }
.donate-stripe-btn svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.donate-stripe-btn:hover { filter: brightness(1.08); }

/* ---------- Mover notas: arrastre en el árbol + menú «Mover a…» ---------- */
.row.drop-ok { outline: 2px dashed var(--primary); outline-offset: -2px; background: var(--secondary); border-radius: 8px; }
.row[draggable='true'] { cursor: grab; }
.move-pop { max-height: min(70vh, 560px); overflow-y: auto; }
.move-book { padding: 7px 10px 3px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.move-pop .cm-item.move-here { opacity: .55; cursor: default; }

/* ---------- Plan del día ---------- */
.planner-panel { width: 420px; max-width: 94vw; }
.planner-date { margin-left: 8px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: capitalize; }
.planner-summary { display: flex; align-items: center; gap: 10px; padding: 12px 16px 4px; }
.planner-progress { flex: 1; height: 8px; border-radius: 999px; background: var(--secondary); overflow: hidden; }
.planner-progress-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--sage), #6f9257); transition: width .3s ease; }
.planner-count { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.planner-add { display: flex; gap: 8px; padding: 10px 16px; }
.planner-inp { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--fg); font: inherit; font-size: 13.5px; }
.planner-body { flex: 1; overflow-y: auto; padding: 4px 12px 20px; }
.planner-task { border: 1px solid var(--border); border-radius: 12px; background: var(--card); padding: 8px 10px; margin: 8px 4px; animation: pop .16s ease-out; }
.planner-task.done { opacity: .62; }
.planner-task-row { display: flex; align-items: center; gap: 8px; }
.planner-task-row input[type='checkbox'] { width: 17px; height: 17px; accent-color: var(--sage); cursor: pointer; flex: none; }
.planner-title { flex: 1; font-size: 13.5px; font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.planner-title.done { text-decoration: line-through; color: var(--muted); }
.planner-carried { font-size: 10px; font-weight: 800; background: var(--ocre); color: #fff; border-radius: 999px; padding: 1px 7px; flex: none; }
.planner-subcount { font-size: 11px; font-weight: 800; color: var(--muted); flex: none; }
.planner-subcount.all { color: #6f9257; }
.planner-task .act { opacity: .7; }
.planner-bar { height: 5px; border-radius: 999px; background: var(--secondary); overflow: hidden; margin: 7px 2px 2px 25px; }
.planner-bar-fill { height: 100%; border-radius: 999px; background: var(--sage); transition: width .3s ease; }
.planner-subs { margin: 6px 0 2px 25px; display: flex; flex-direction: column; gap: 2px; }
.planner-sub { display: flex; align-items: center; gap: 7px; font-size: 12.5px; padding: 3px 2px; border-radius: 7px; cursor: pointer; }
.planner-sub:hover { background: var(--secondary); }
.planner-sub input[type='checkbox'] { width: 14px; height: 14px; accent-color: var(--sage); flex: none; }
.planner-sub-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.planner-sub.done .planner-sub-text { text-decoration: line-through; color: var(--muted); }
.planner-sub-at { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.planner-sub-add { margin-top: 5px; }
.planner-sub-inp { width: 100%; box-sizing: border-box; font-size: 12.5px; padding: 6px 10px; }

/* ---------- Plan del día: metadatos (fecha de inserción, tipo, hoja, recordatorio) ---------- */
.planner-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 6px 0 0 25px; }
.planner-meta-at { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.planner-kind { border: none; cursor: pointer; font-family: inherit; font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; color: #fff; border-radius: 999px; padding: 2px 8px; transition: filter .12s, transform .1s; }
.planner-kind:hover { filter: brightness(1.08); transform: translateY(-1px); }
.planner-kind.rank-relevant { background: #6f9257; }
.planner-kind.rank-idea { background: var(--ocre); }
.planner-kind.rank-important { background: #e0873c; }
.planner-kind.rank-crucial { background: var(--danger); }
.planner-note-chip { border: 1px solid var(--border); background: var(--secondary); color: var(--fg); cursor: pointer; font-family: inherit; font-size: 10.5px; font-weight: 700; border-radius: 999px; padding: 2px 9px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.planner-note-chip:hover { border-color: var(--primary); }
.planner-remind-chip { font-size: 10.5px; font-weight: 800; color: #fff; background: var(--primary); border-radius: 999px; padding: 2px 8px; font-variant-numeric: tabular-nums; }
.planner-meta .act { opacity: .65; }
.planner-meta .act:hover { opacity: 1; }
.planner-min-inp { width: 110px; font-size: 12px; padding: 5px 9px; }
.planner-min-row { align-items: center; }

/* ---------- Picker de emoji del libro ---------- */
.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; padding: 4px 6px; }
.emoji-opt { border: 1px solid transparent; background: none; font-size: 19px; padding: 4px; border-radius: 8px; cursor: pointer; line-height: 1; }
.emoji-opt:hover { background: var(--secondary); }
.emoji-opt.on { border-color: var(--primary); background: var(--secondary); }
.emoji-row { padding: 4px 8px 8px; align-items: center; }
.emoji-inp { width: 90px; font-size: 14px; }
.nb-row .emoji { border: none; background: none; cursor: pointer; padding: 1px 3px; border-radius: 6px; font-size: inherit; }
.nb-row .emoji:hover { background: var(--secondary); }
