/* ══ Variables ══════════════════════════════════════════════════ */
:root {
  --sw: 272px;
  --sb-bg: #13131a;
  --sb-surface: #1b1b24;
  --sb-border: rgba(255,255,255,.07);
  --sb-text: #ddd8ce;
  --sb-muted: rgba(255,255,255,.28);
  --accent: #c0392b;
  --accent-hover: #a93226;
  --accent-dim: rgba(192,57,43,.18);
  --accent-border: rgba(192,57,43,.45);
  --radius: 8px;
  --paper-bg: #fdf8ee;
  --font-hw: "ActiveFont","Indie Flower",cursive;
}

/* Mismo archivo: el canvas usa "Indie Flower" (con espacio) como respaldo de ActiveFont */
@font-face {
  font-family: "IndieFlower";
  src: url("./assets/IndieFlower-Regular.ttf") format("truetype");
}
@font-face {
  font-family: "Indie Flower";
  src: url("./assets/IndieFlower-Regular.ttf") format("truetype");
}

*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  display: flex;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
  background: #d4cfc6;
  color: var(--sb-text);
}

/* ══ Sidebar ════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sw);
  min-width: var(--sw);
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  gap: 0;
  border-right: 1px solid var(--sb-border);
}

/* Scrollbar sidebar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.10); border-radius: 4px; }

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: #f0ece4;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--sb-border);
  letter-spacing: .02em;
  flex-shrink: 0;
}

/* Sections */
.sb-section {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sb-section-footer { margin-top: auto; }

.sb-divider {
  height: 1px;
  background: var(--sb-border);
  flex-shrink: 0;
}

.sb-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-family: ui-monospace, monospace;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--sb-muted);
  padding-bottom: 2px;
}

.sb-section-header svg {
  width: 12px;
  height: 12px;
  stroke: var(--sb-muted);
  flex-shrink: 0;
}

/* Control groups */
.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ctrl-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: rgba(255,255,255,.5);
  font-family: ui-monospace, monospace;
}

.badge {
  display: inline-block;
  min-width: 38px;
  background: rgba(255,255,255,.08);
  border-radius: 4px;
  padding: 1px 5px;
  font-variant-numeric: tabular-nums;
  color: rgba(255,255,255,.65);
  font-size: 10px;
  text-align: right;
}

/* Textarea */
.sidebar textarea {
  width: 100%;
  height: 180px;
  resize: vertical;
  background: #0d0d14;
  color: #ddd8ce;
  border: 1px solid var(--sb-border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font: 12px/1.6 ui-monospace, monospace;
  outline: none;
  transition: border-color .15s;
}
.sidebar textarea:focus { border-color: rgba(255,255,255,.18); }

/* Buttons */
.row {
  display: flex;
  gap: 6px;
}

.btn {
  flex: 1;
  font: inherit;
  font-size: 12px;
  border: none;
  border-radius: 7px;
  padding: 7px 10px;
  cursor: pointer;
  transition: background .14s, border-color .14s;
  text-align: center;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent-hover); }

.btn.ghost {
  background: rgba(255,255,255,.06);
  color: #bbb;
  border: 1px solid var(--sb-border);
}
.btn.ghost:hover { background: rgba(255,255,255,.11); }

.btn.sq {
  flex: 0;
  padding: 7px 10px;
}

.btn.tiny {
  font-size: 11px;
  padding: 4px 8px;
}

/* File btn */
.file-btn {
  display: flex;
  position: relative;
  overflow: hidden;
  justify-content: center;
  cursor: pointer;
}
.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Select */
.ctrl {
  width: 100%;
  background: #0d0d14;
  color: #ddd8ce;
  border: 1px solid var(--sb-border);
  border-radius: var(--radius);
  padding: 6px 9px;
  font: inherit;
  font-size: 12px;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='rgba(255,255,255,.3)'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 26px;
}

/* Slider */
.slider {
  width: 100%;
  height: 4px;
  accent-color: var(--accent);
  background: rgba(255,255,255,.1);
  border-radius: 2px;
  cursor: pointer;
  display: block;
}

/* Orientation buttons */
.orient-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: rgba(255,255,255,.05);
  color: #999;
  border: 1px solid var(--sb-border);
  border-radius: 7px;
  padding: 6px 6px;
  cursor: pointer;
  font-size: 10px;
  font-family: ui-monospace, monospace;
  text-transform: uppercase;
  letter-spacing: .06em;
  transition: background .13s, border-color .13s, color .13s;
}
.orient-btn:hover,
.orient-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent-border);
  color: #e88;
}

/* Paper types */
.paper-types {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.paper-type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,.05);
  color: #999;
  border: 1px solid var(--sb-border);
  border-radius: 7px;
  padding: 7px 4px 5px;
  cursor: pointer;
  font-size: 9px;
  font-family: ui-monospace, monospace;
  text-transform: uppercase;
  letter-spacing: .06em;
  transition: background .13s, border-color .13s, color .13s;
}

.paper-type-btn svg { width: 28px; height: 21px; }

.paper-type-btn:hover,
.paper-type-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent-border);
  color: #e88;
}

/* Swatches */
.swatch-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.swatch, .ink-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color .12s, transform .12s;
  flex-shrink: 0;
  outline: none;
}

.swatch.active, .ink-swatch.active {
  border-color: rgba(255,255,255,.8);
  transform: scale(1.18);
}

/* Wrap del picker personalizado — actúa como swatch circular */
.swatch-custom-wrap {
  position: relative;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px dashed rgba(255,255,255,.28);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .12s, transform .12s;
  overflow: hidden;
}
.swatch-custom-wrap:hover {
  border-color: rgba(255,255,255,.6);
  transform: scale(1.15);
}

/* El dot de color que muestra el valor actual */
.swatch-custom-dot {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  display: block;
}

/* El input real ocupa todo el wrap, invisible */
.swatch-picker {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  opacity: 0;
  cursor: pointer;
  border: none;
  padding: 0;
}

input[type="color"] {
  width: 24px;
  height: 24px;
  border: 2px solid rgba(255,255,255,.15);
  background: none;
  cursor: pointer;
  border-radius: 50%;
  padding: 0;
  outline: none;
}

/* ── Reglas de color ───────────────────────────────────────────── */
.rules-tip {
  font-size: 10px;
  color: var(--sb-muted);
  line-height: 1.5;
  margin-top: -2px;
}

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Cada bloque de regla */
.rule-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 7px 9px;
  border-radius: 8px;
  background: rgba(255,255,255,.03);
  border: 1px solid transparent;
  transition: background .13s, border-color .13s;
  opacity: 0.45;
}
.rule-wrap.enabled {
  opacity: 1;
  background: rgba(255,255,255,.055);
  border-color: rgba(255,255,255,.07);
}

/* Fila superior: toggle + label */
.rule-top {
  display: flex;
  align-items: center;
  gap: 7px;
}

/* Toggle button */
.rule-toggle {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  color: rgba(255,255,255,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .13s, border-color .13s, color .13s;
  padding: 0;
}
.rule-toggle svg { width: 11px; height: 11px; }
.rule-toggle.on {
  background: rgba(46,204,113,.18);
  border-color: rgba(46,204,113,.45);
  color: #2ecc71;
}
.rule-toggle:hover { border-color: rgba(255,255,255,.22); }

/* Label */
.rule-label {
  font-size: 11px;
  color: rgba(255,255,255,.55);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, monospace;
  letter-spacing: .02em;
}
.rule-wrap.enabled .rule-label { color: rgba(255,255,255,.85); }

/* Fila de swatches */
.rule-swatch-row {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
  padding-left: 27px; /* alinea con el label, después del toggle */
}

.rule-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  outline: none;
  transition: border-color .1s, transform .1s;
  padding: 0;
}
.rule-swatch:hover { transform: scale(1.2); }
.rule-swatch.active {
  border-color: rgba(255,255,255,.85);
  transform: scale(1.18);
}

/* Picker personalizado dentro de la fila de regla */
.rule-swatch-custom {
  width: 16px;
  height: 16px;
}

/* ── Estilos legacy (ya no usados pero no eliminamos por si acaso) */
.rule-row { display: none; }
.rule-dot  { display: none; }
.rule-color { display: none; }

/* ── Config diagrama: fila de color ──────────────────────────────── */
.diag-color-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.diag-color-input {
  width: 28px;
  height: 28px;
  border: 1.5px solid var(--sb-border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: opacity .15s;
}

.diag-color-clear {
  flex: 1;
  font-size: 11px;
  padding: 5px 8px;
}

.diag-color-clear.active-transp {
  background: rgba(192,57,43,.18);
  border-color: rgba(192,57,43,.45);
  color: #e88;
}

/* ── Perfiles ──────────────────────────────────────────────────── */
.profile-save-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.profile-input {
  flex: 1;
  background: #0d0d14;
  color: #ddd8ce;
  border: 1px solid var(--sb-border);
  border-radius: 7px;
  padding: 6px 9px;
  font: 12px ui-sans-serif, system-ui, sans-serif;
  outline: none;
  transition: border-color .15s;
}
.profile-input::placeholder { color: rgba(255,255,255,.2); }
.profile-input:focus { border-color: rgba(255,255,255,.2); }

.profiles-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 160px;
  overflow-y: auto;
}

.profiles-empty {
  font-size: 11px;
  color: var(--sb-muted);
  padding: 4px 2px;
}

.profile-item {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--sb-border);
  border-radius: 6px;
  padding: 4px 6px 4px 8px;
  transition: background .12s;
}
.profile-item:hover { background: rgba(255,255,255,.08); }

.profile-load {
  flex: 1;
  background: none;
  border: none;
  color: rgba(255,255,255,.75);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-load:hover { color: #fff; }

.profile-del {
  width: 20px;
  height: 20px;
  background: none;
  border: none;
  color: rgba(255,255,255,.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  flex-shrink: 0;
  padding: 0;
  transition: color .12s, background .12s;
}
.profile-del:hover { color: #e88; background: rgba(192,57,43,.2); }

/* Scrollbar de la lista de perfiles */
.profiles-list::-webkit-scrollbar { width: 3px; }
.profiles-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }

/* Tip footer */
.tip {
  font-size: 10px;
  color: var(--sb-muted);
  line-height: 1.5;
}

.tip code {
  background: rgba(255,255,255,.07);
  border-radius: 3px;
  padding: 0 4px;
  font-family: ui-monospace, monospace;
}

/* ══ Workspace ══════════════════════════════════════════════════ */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Paneles fijos fuera del flex (hijos de body): no ocupan hueco ni bloquean el layout */
.app-float-ui {
  position: fixed;
  inset: 0;
  width: 0;
  height: 0;
  overflow: visible;
  flex: 0 0 0;
  align-self: stretch;
  z-index: 8000;
  pointer-events: none;
}

/* ── Responsive ───────────────────────────────────────────────── */

/* Tablet vertical (≤900px): sidebar arriba, scroll horizontal */
@media (max-width: 900px) {
  html, body { overflow: hidden; height: 100%; }
  body { flex-direction: column; }

  .sidebar {
    width: 100%;
    min-width: 0;
    height: auto;
    max-height: 42vh;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: none;
    border-bottom: 1px solid var(--sb-border);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
  }

  /* Brand siempre ancho completo */
  .brand {
    width: 100%;
    padding: 10px 14px 8px;
  }

  /* Secciones en fila horizontal scrolleable */
  .sb-section {
    flex: 0 0 auto;
    min-width: 200px;
    max-width: 260px;
    padding: 10px 12px;
    border-right: 1px solid var(--sb-border);
  }

  .sb-section-footer { margin-top: 0; }
  .sb-divider { display: none; }

  .workspace {
    flex: 1;
    height: calc(58vh);
    min-height: 0;
  }

  .page-wrap { padding: 16px 12px 24px; }
  .sidebar textarea { height: 100px; }
}

/* Móvil (≤600px): layout vertical con sidebar colapsable arriba */
@media (max-width: 600px) {
  html, body { overflow: hidden; height: 100%; }
  body { flex-direction: column; }

  .sidebar {
    width: 100%;
    min-width: 0;
    height: auto;
    max-height: 44vh;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: none;
    border-bottom: 1px solid var(--sb-border);
    flex-direction: column;
  }

  .sb-section {
    min-width: unset;
    max-width: unset;
    border-right: none;
    padding: 10px 12px;
  }

  .sb-divider { display: block; }

  .workspace {
    flex: 1;
    height: calc(56vh);
    min-height: 0;
  }

  .page-wrap { padding: 12px 8px 20px; }
  .pages-container { gap: 18px; }

  .sidebar textarea { height: 90px; }

  .swatch-row { gap: 5px; }
  .swatch, .ink-swatch, .swatch-custom-wrap { width: 18px; height: 18px; }

  .paper-types { grid-template-columns: 1fr 1fr; }
  .ctrl-label { font-size: 10px; }
}

/* ══ Page wrap — scroll container ══════════════════════════════ */
.page-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 28px 24px 40px;
  background: #ccc8be;
}

/* Columna centrada de páginas */
.pages-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  min-height: 100%;
}

/* Cada hoja individual */
.page {
  position: relative;
  flex-shrink: 0;
  isolation: isolate; /* stacking claro: el botón cfg por encima del canvas */
  background: var(--paper-bg);
  border-radius: 3px;
  box-shadow:
    2px 2px 0 rgba(0,0,0,.04),
    0 8px 32px rgba(0,0,0,.18),
    0 2px 6px rgba(0,0,0,.10);
  overflow: hidden;
}

/* Número de página */
.page-num {
  position: absolute;
  bottom: 10px;
  right: 16px;
  font-size: 10px;
  font-family: ui-monospace, monospace;
  color: rgba(0,0,0,.22);
  z-index: 3;
  pointer-events: none;
  letter-spacing: .05em;
}

/* Canvas de fondo */
.bg-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
}

/* Canvas de texto (clic para editar diagramas) */
.text-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: auto;
  z-index: 1;
}

/* Botón configurar página (encima del canvas) */
.page-cfg-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 50;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,.12);
  background: rgba(255,255,255,.88);
  color: #444;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  transition: background .15s, transform .12s;
  padding: 0;
  pointer-events: auto;
}
/* El icono no debe quedarse como target del clic (evita fallos en algunos navegadores) */
.page-cfg-btn svg {
  pointer-events: none;
}
.page-cfg-btn:hover {
  background: #fff;
  transform: scale(1.05);
}

/* ══ Scrollbars globales ════════════════════════════════════════ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 4px; }

/* ══ Panel flotante de edición de diagrama ══════════════════════ */
.diag-edit-panel {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  right: max(16px, env(safe-area-inset-right, 0px));
  width: min(360px, calc(100vw - 24px));
  max-height: min(85vh, calc(100dvh - env(safe-area-inset-bottom, 0px) - 24px));
  background: #1b1b24;
  color: #e8e4dc;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45), 0 2px 8px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  z-index: 1;
  overflow: hidden;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform .22s cubic-bezier(.16,1,.3,1), opacity .18s;
}
.diag-edit-panel.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.diag-edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.diag-edit-title {
  font-size: 11px;
  font-family: ui-monospace, monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.45);
}
.diag-edit-close {
  background: none;
  border: none;
  color: rgba(255,255,255,.35);
  cursor: pointer;
  padding: 4px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  transition: color .12s, background .12s;
}
.diag-edit-close:hover { color: #e88; background: rgba(192,57,43,.2); }

.diag-edit-textarea {
  width: 100%;
  height: 160px;
  resize: vertical;
  background: #0d0d14;
  color: #ddd8ce;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,.07);
  padding: 10px 12px;
  font: 12px/1.6 ui-monospace, monospace;
  outline: none;
  flex-shrink: 0;
}

.diag-edit-controls {
  padding: 8px 12px 6px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.diag-ctrl-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.diag-ctrl-label {
  flex: 0 0 52px;
  font-size: 10px;
  font-family: ui-monospace, monospace;
  color: rgba(255,255,255,.45);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.diag-slider {
  flex: 1;
  min-width: 0;
}
.diag-ctrl-val {
  flex: 0 0 36px;
  font-size: 10px;
  font-family: ui-monospace, monospace;
  color: rgba(255,255,255,.55);
  text-align: right;
}
.diag-export-row {
  padding-top: 4px;
  gap: 6px !important;
}
.diag-export-row .btn { flex: 1; }
.diag-edit-actions {
  gap: 8px;
  padding: 10px 12px 12px;
}

/* Estilo + colores dentro de Editar diagrama */
.diag-edit-style {
  padding: 8px 12px 10px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.diag-style-title {
  font-size: 10px;
  font-family: ui-monospace, monospace;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: rgba(255,255,255,.4);
  margin-bottom: 2px;
}
.diag-edit-colors {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}
.diag-edit-color-group {
  gap: 4px;
}
.diag-edit-color-group .diag-color-lbl {
  flex: 0 0 100%;
  width: 100%;
  margin-bottom: 0;
}
.diag-edit-color-group .diag-color-row {
  width: 100%;
}

/* Panel configuración por página (a la derecha de la sidebar, no bajo ella) */
.page-cfg-panel {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  left: clamp(10px, calc(var(--sw, 272px) + 12px), calc(100vw - 300px));
  width: min(280px, calc(100vw - var(--sw, 272px) - 28px));
  max-height: min(72vh, calc(100dvh - env(safe-area-inset-bottom, 0px) - 32px));
  overflow-y: auto;
  overflow-x: hidden;
  background: #1b1b24;
  color: #e8e4dc;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45), 0 2px 8px rgba(0,0,0,.25);
  z-index: 2;
  isolation: isolate;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform .22s cubic-bezier(.16,1,.3,1), opacity .18s;
}
.page-cfg-panel.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.page-cfg-body,
.page-cfg-header {
  color: inherit;
}

@media (max-width: 900px) {
  .page-cfg-panel {
    left: max(10px, env(safe-area-inset-left, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
    width: auto;
    max-width: min(400px, calc(100vw - 20px));
  }
}
.page-cfg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.page-cfg-title {
  font-size: 11px;
  font-family: ui-monospace, monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.55);
}
.page-cfg-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.page-cfg-body .ctrl-group { gap: 4px; }
.page-cfg-select {
  background: #0d0d14;
  color: #ddd8ce;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  width: 100%;
}
.page-cfg-papers {
  grid-template-columns: 1fr 1fr;
}
.page-cfg-color {
  width: 100%;
  height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.12);
  cursor: pointer;
  background: #0d0d14;
}

/* Canvas de diagrama clickeable en el preview */
.text-canvas.has-diagrams { cursor: pointer; }
.diag-hit-hint {
  position: absolute;
  background: rgba(192,57,43,.85);
  color: #fff;
  font-size: 10px;
  font-family: ui-monospace, monospace;
  padding: 2px 7px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .15s;
}
.diag-hit-hint.show { opacity: 1; }

/* ══ Jitter UI — pequeña variación de píxeles en la sidebar ════ */
.jitter {
  transform: translate(var(--jx, 0px), var(--jy, 0px)) rotate(var(--jr, 0deg));
}
