/* ==========================================================================
   PEI en Ruta · Identidad "mesa de revisión"
   Tinta de bolígrafo para lo que se escribe y decide, resaltador para lo
   vigente o seleccionado, papel de renglones para tablas. Se carga después
   de app.css y pmi.css. Respaldo previo: assets/respaldo-antes-rediseno/
   ========================================================================== */
:root {
  --tinta: #2a44a6;
  --tinta-oscura: #1d3180;
  --tinta-noche: #162250;
  --tinta-suave: #e9edf9;
  --resaltador: #f7e14b;
  --resaltador-suave: #fcf4b8;
  --grafito: #1e2430;
  --papel: #f2f4f7;
  --renglon: #d8dde6;
  --correccion: #c8372d;
  --aprobado: #2d7a4f;

  /* Tokens heredados reapuntados al nuevo sistema */
  --ink: var(--grafito);
  --muted: #5b6273;
  --line: var(--renglon);
  --paper: var(--papel);
  --green: var(--tinta);
  --green-dark: var(--tinta-oscura);
  --green-soft: var(--tinta-suave);
  --primary: var(--tinta);
  --red: var(--correccion);
  --blue: #2f6f86;
  --shadow: none;

  --serif: Literata, Georgia, "Times New Roman", serif;
  --sans: "Atkinson Hyperlegible Next", "Segoe UI", Arial, sans-serif;
}

::selection {
  background: var(--resaltador);
  color: var(--grafito);
}

body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--grafito);
  background: var(--papel);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 650;
  letter-spacing: -0.005em !important;
  font-optical-sizing: auto;
}

/* Rótulos: en tipo oración, sin tracking; informan, no decoran */
.eyebrow,
.kicker {
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
  margin-bottom: 4px;
}

/* ---------- Barra lateral: noche de tinta ---------- */
.sidebar {
  background: var(--tinta-noche);
  color: #e3e7f5;
}
.brand-mark {
  background: #fff;
  border-radius: 6px;
  color: var(--tinta-noche);
}
.brand strong { font-family: var(--serif); font-size: 18px; font-weight: 700; }
.brand small,
.sidebar-foot small { color: #a8b1d2; letter-spacing: 0; }

.sidebar nav a,
.sidebar-admin-group > summary {
  color: #c9d0ea;
  border-radius: 4px;
  font-weight: 500;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.sidebar nav a:hover,
.sidebar-admin-group > summary:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
}
/* Lo memorable: el ítem activo va pintado con resaltador */
.sidebar nav a.active,
.sidebar-admin-group > summary.active {
  background: var(--resaltador);
  color: var(--tinta-noche);
  font-weight: 700;
  box-shadow: none;
  border-radius: 3px 11px 4px 13px / 9px 4px 11px 5px;
}
.sidebar nav a.active svg,
.sidebar-admin-group > summary.active svg { color: var(--tinta-noche); }
.sidebar-admin-group > summary.active:not(:hover) { background: transparent; color: #fff; border-left: 3px solid var(--resaltador); }
.sidebar-foot { border-top-color: rgba(255, 255, 255, 0.14); }
.sidebar-foot .avatar {
  background: var(--resaltador);
  color: var(--tinta-noche);
  font-family: var(--serif);
}

/* ---------- Barra superior ---------- */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--renglon);
}
.topbar h1 {
  font-size: 25px;
  font-weight: 650;
}
.topbar .eyebrow { font-size: 13px; }
.topbar-section-icon {
  background: var(--tinta-suave) !important;
  color: var(--tinta) !important;
  border-radius: 6px !important;
}
.cycle { border-left-color: var(--renglon); }
.cycle span { font-size: 12px; }
.cycle strong {
  font-family: var(--serif);
  font-size: 20px;
  padding: 0 3px;
  box-shadow: inset 0 -0.42em 0 var(--resaltador);
}
.topbar-context-badge {
  background: var(--resaltador-suave) !important;
  color: var(--grafito) !important;
  border: 0 !important;
  border-radius: 4px !important;
}

/* ---------- Superficies ---------- */
.panel,
.stat-card,
.auth-card {
  background: #fff;
  border: 1px solid var(--renglon);
  border-radius: 8px;
  box-shadow: none;
}
.panel-head { border-bottom-color: var(--renglon); }
.panel-head h3 { font-size: 18px; }
.panel-head > a { color: var(--tinta); text-underline-offset: 3px; }
.panel-head > a:hover { text-decoration: underline; }

.stat-card strong {
  font-family: var(--serif);
  font-weight: 700;
  font-variant-numeric: lining-nums tabular-nums;
}
.stat-card span { font-size: 12.5px; }
.stat-card small { font-size: 11.5px; color: var(--muted); }
.stat-icon { border-radius: 6px; }
.stat-icon.green { background: var(--tinta-suave); color: var(--tinta); }
.stat-icon.blue { background: #e4f0f3; color: var(--blue); }
.mini-progress { background: #e6e9ef; }

/* Encabezados de página oscuros: tinta plana */
.hero,
.auth-visual { background: var(--tinta-noche); }
.hero .kicker,
.auth-copy .kicker { color: var(--resaltador); }
.hero p { color: #d3d9ef; }

/* ---------- Acciones ---------- */
.btn {
  border-radius: 6px;
  font-weight: 700;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.btn-primary { background: var(--tinta); color: #fff; }
.btn-primary:hover { background: var(--tinta-oscura); }
.btn-light { color: var(--tinta); }

/* Foco visible: halo de resaltador con borde de tinta */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--tinta);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--resaltador);
}
.sidebar a:focus-visible,
.sidebar summary:focus-visible { outline-color: #fff; }

/* ---------- Formularios ---------- */
label { color: #3e4554; font-size: 12.5px; }
input,
select,
textarea {
  border: 1px solid #c3c9d5;
  border-radius: 6px;
  color: var(--grafito);
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--tinta);
  box-shadow: 0 0 0 3px var(--resaltador-suave);
}
input[type="checkbox"],
input[type="radio"],
input[type="range"] { accent-color: var(--tinta); }

/* ---------- Tablas: papel de renglones ---------- */
th {
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  border-bottom: 2px solid var(--grafito);
}
td { border-top: 1px solid var(--renglon); font-size: 13px; }
tbody tr:hover td { background: #fafbf2; }

/* ---------- Pestañas ---------- */
.tabs { background: #e6e9ef; border-radius: 6px; }
.tabs a { font-size: 12.5px; border-radius: 4px; color: #4d5466; }
.tabs a.active {
  background: #fff;
  color: var(--tinta);
  box-shadow: inset 0 -3px 0 var(--resaltador);
}

/* ---------- Estados ---------- */
.badge { font-size: 11.5px; border-radius: 4px; }
.badge-en-revision { background: var(--tinta-suave); color: var(--tinta-oscura); }
.badge-validado,
.badge-cerrado,
.badge-completado,
.badge-aprobado,
.badge-success { background: #e2f1e8; color: #23613f; }
.badge-bloqueado { background: #f8e2df; color: #9d2b22; }
.alert { border-radius: 6px; font-size: 13px; border-left: 4px solid currentColor; }
.alert-success { background: #e6f3eb; color: #23613f; }
.alert-error { background: #f9e5e2; color: #9d2b22; }

/* ---------- Portada de ingreso: hoja de cuaderno cuadriculado ---------- */
.auth-shell { background: var(--papel); }
.auth-visual {
  background-color: var(--tinta-noche);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 28px 28px;
}
.auth-visual:before,
.auth-visual:after { display: none; }
.auth-copy h1 {
  font-size: clamp(36px, 4.4vw, 56px);
  font-weight: 600;
  line-height: 1.08;
  max-width: 14ch;
}
.auth-copy p { color: #d3d9ef; font-size: 17px; max-width: 46ch; }
.route-art i {
  height: 0;
  background: none;
  border-top: 2px dashed rgba(255, 255, 255, 0.4);
}
.route-art span {
  background: var(--tinta-noche);
  border: 2px solid rgba(255, 255, 255, 0.75);
  font-family: var(--serif);
  font-size: 13px;
}
.route-art .route-step:first-child span {
  background: var(--resaltador);
  border-color: var(--resaltador);
  color: var(--tinta-noche);
}
.route-art small { color: #e3e7f5; font-size: 12.5px; margin-top: 6px; display: block; }
.auth-card { padding: 36px; }
.auth-card h2 { font-size: 27px; }

/* ---------- Barras de desplazamiento ---------- */
* { scrollbar-color: #b9c0cf transparent; }
.sidebar nav { scrollbar-color: rgba(255, 255, 255, 0.25) transparent; }

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .sidebar, .topbar { display: none !important; }
  body { background: #fff; }
}

/* Tarjetas de componente: extracto del contenido redactado */
.guide-component-card p {
  color: #3e4554;
  line-height: 1.5;
}
.guide-component-card p.guide-component-empty {
  color: var(--muted);
  font-style: italic;
}

/* Etiquetas de acción recomendada / origen del hallazgo
   (Hallazgos, Recomendaciones y Plan de Mejoramiento): legibles y destacadas */
.recommendation-inline,
.recommendation-action,
.pmi-origin {
  background: var(--resaltador-suave) !important;
  color: var(--grafito) !important;
  border-left: 4px solid #c9a400;
  border-radius: 4px;
  font-weight: 500;
  line-height: 1.45;
}
.recommendation-inline {
  padding: 9px 12px;
  font-size: 13px;
}
.recommendation-action strong {
  color: #5c4a00;
  font-weight: 700;
}
.recommendation-action span { color: var(--grafito); }
.recommendation-inline svg,
.recommendation-action svg,
.recommendation-action .action-icon,
.pmi-origin i,
.pmi-origin svg {
  color: #8a6d00 !important;
}

/* Colores de las áreas de gestión armonizados con la identidad
   (el color original sigue en la base de datos; aquí se reasigna en pantalla) */
[style*="--area:#236B5D" i], [style*="--area: #236B5D" i] { --area: #2a44a6 !important; }
[style*="--area:#3B6EA8" i], [style*="--area: #3B6EA8" i] { --area: #1f6f78 !important; }
[style*="--area:#C47A32" i], [style*="--area: #C47A32" i] { --area: #a86f12 !important; }
[style*="--area:#75549B" i], [style*="--area: #75549B" i] { --area: #7a3f86 !important; }

/* Encabezado del componente (pei-componente): noche de tinta + franja del área */
.component-editor-head {
  background: var(--tinta-noche) !important;
  color: #fff;
  border-radius: 8px;
  border-left: 8px solid var(--area, var(--resaltador));
  box-shadow: none !important;
}
.component-editor-head .guide34-component-id {
  background: var(--resaltador) !important;
  color: var(--tinta-noche) !important;
  font-family: var(--serif);
  font-weight: 700;
  border-radius: 4px;
}
.component-editor-head .kicker,
.component-editor-head span:not(.guide34-component-id) {
  color: #c9d0ea;
}
.component-editor-head h2 {
  font-family: var(--serif);
  font-weight: 650;
  color: #fff;
}
.component-editor-head p {
  color: #d3d9ef;
}

/* ---------- Editor enriquecido ---------- */
.rich-toolbar {
  border-color: var(--renglon);
  border-radius: 8px 8px 0 0;
  background: #f6f7fa;
}
.rich-toolbar button {
  font: 600 13px var(--sans);
  color: var(--grafito);
  border-color: #cfd4df;
  border-radius: 4px;
}
.rich-toolbar button:hover { background: var(--tinta-suave); border-color: var(--tinta); }
.rich-editor { border-color: var(--renglon); border-radius: 0 0 8px 8px; }

/* Editor del componente: barra fija al desplazarse, grupos y botón de guardado */
.component-rich-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  align-items: center;
  gap: 6px;
  padding: 8px;
}
.component-rich-toolbar .rich-group,
.component-rich-toolbar .alignment-tools {
  display: inline-flex;
  gap: 2px;
  padding-right: 8px;
  margin-right: 2px;
  border-right: 1px solid var(--renglon);
}
.component-rich-toolbar .rich-group button,
.component-rich-toolbar .alignment-tools button {
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
  border-color: transparent;
  background: transparent;
}
.component-rich-toolbar .rich-group button:hover,
.component-rich-toolbar .alignment-tools button:hover {
  background: #fff;
  border-color: #cfd4df;
}
.component-rich-toolbar .rich-group button svg,
.component-rich-toolbar .alignment-tools button svg { width: 17px; height: 17px; }
.component-rich-toolbar .table-builder > button,
.component-rich-toolbar [data-insert-image] { height: 34px; }
.component-rich-toolbar .rich-update-btn {
  margin-left: auto;
  height: 36px;
  padding: 0 16px;
  background: var(--tinta);
  border-color: var(--tinta);
  color: #fff;
  font-weight: 700;
}
.component-rich-toolbar .rich-update-btn:hover {
  background: var(--tinta-oscura);
  border-color: var(--tinta-oscura);
  color: #fff;
}
.component-rich-toolbar .rich-update-btn:disabled {
  background: #c3c9d5;
  border-color: #c3c9d5;
  cursor: not-allowed;
}
@media (max-width: 760px) {
  .component-rich-toolbar .rich-update-btn { width: 100%; margin-left: 0; justify-content: center; }
}

/* ---------- Portada y presentación del PEI ---------- */
.pei-document-intro { align-items: flex-end; gap: 20px; }
.pei-document-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 22px;
  align-items: start;
  margin-top: 18px;
}
.pei-cover-form { display: grid; gap: 18px; }
.pei-cover-panel .panel-head p { margin: 4px 0 0; font-size: 13px; }
.pei-cover-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 16px;
  padding: 6px 22px 22px;
}
.pei-cover-fields label { margin-top: 12px; }
.pei-cover-fields label.wide { grid-column: 1 / -1; }
.pei-cover-fields small { display: block; margin-top: 4px; color: var(--muted); font-weight: 400; font-size: 12px; }
.pei-cover-fields textarea { font-family: var(--sans); font-size: 14px; line-height: 1.6; }
.pei-cover-fields textarea[name="presentation_text"] { text-align: justify; }
.pei-cover-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.pei-cover-actions .btn-light { border: 1px solid var(--renglon); }
.pei-cover-preview-wrap { position: sticky; top: 18px; display: grid; gap: 16px; }
.pei-cover-preview {
  position: relative;
  aspect-ratio: 8.5 / 11;
  padding: 11% 11%;
  background: #fff;
  border: 1px solid var(--renglon);
  box-shadow: 0 1px 0 var(--renglon), 0 6px 0 -3px #fff, 0 6px 0 -2px var(--renglon);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 7.5px;
  line-height: 1.5;
  text-align: center;
  color: #111;
  overflow: hidden;
}
.pei-cover-preview img { display: block; width: 48px; height: 48px; object-fit: contain; margin: 0 auto 10px; }
.pei-cover-preview p { margin: 0; }
.pei-cover-preview .gap { margin-top: 1.4em; }
.pei-preview-title { display: block; margin-top: 1.2em; font-weight: 700; font-size: 1.3em; }
.pei-page-number { position: absolute; top: 5%; right: 11%; }
.pei-format-note { padding: 16px 20px; }
.pei-format-note h3 { font-size: 16px; }
.pei-format-note ul { margin: 10px 0 0; padding-left: 18px; color: #3e4554; font-size: 13px; line-height: 1.6; }
@media (max-width: 1100px) {
  .pei-document-layout { grid-template-columns: 1fr; }
  .pei-cover-preview-wrap { position: static; max-width: 420px; }
}
@media (max-width: 640px) {
  .pei-cover-fields { grid-template-columns: 1fr; }
}

/* ---------- Panel de recomendaciones · Guía 34 (en el editor del componente) ---------- */
.component-recommendations-panel { background: #fff; }
.component-recommendations-panel > summary { color: var(--tinta-noche); }
.component-recommendations-panel > summary b {
  width: auto;
  padding: 0 10px;
  background: var(--resaltador-suave);
  color: #5c4a00;
  font-size: 12px;
  white-space: nowrap;
}
.component-recommendations-panel > .component-recommendations-body {
  display: block;
  padding: 2px 18px 18px;
  border-top: 1px solid var(--renglon);
  font-size: 14px;
  line-height: 1.55;
  color: var(--grafito);
}
.component-recommendations-body .recommendations-intro { margin: 12px 0 4px; color: var(--muted); font-size: 13px; }
.component-recommendations-body h5 {
  margin: 18px 0 6px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  color: var(--tinta-noche);
}
.component-recommendations-body p { margin: 0 0 6px; }
.component-recommendations-body ul { margin: 0; padding-left: 20px; }
.component-recommendations-body li { margin: 3px 0; }
.component-recommendations-body .recommendations-table { overflow-x: auto; margin-top: 6px; }
.component-recommendations-body table { width: 100%; min-width: 620px; border-collapse: collapse; font-size: 13px; }
.component-recommendations-body th {
  padding: 8px 10px;
  border-bottom: 2px solid var(--grafito);
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  background: #fff;
}
.component-recommendations-body td { padding: 8px 10px; border-top: 1px solid var(--renglon); vertical-align: top; }
.component-recommendations-body td a { color: var(--tinta); text-decoration: underline; text-underline-offset: 2px; }
.recommendation-state { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; line-height: 1.4; }
.recommendation-state.is-missing { background: #f9e5e2; color: #9d2b22; }
.recommendation-state.is-mentioned { background: #e6f3eb; color: #23613f; }

/* Viñetas del editor enriquecido con sangría mínima */
.rich-editor ul,
.rich-editor ol {
  margin: 6px 0 10px;
  padding-left: 1.05em;
}
.rich-editor li {
  margin: 2px 0;
  padding-left: 0.15em;
}
.rich-editor li > ul,
.rich-editor li > ol {
  margin: 2px 0;
  padding-left: 1em;
}

/* Redimensionar imágenes en el editor */
.image-resize-handle {
  position: absolute;
  z-index: 40;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 4px;
  background: var(--tinta);
  box-shadow: 0 0 0 1px var(--tinta);
  cursor: nwse-resize;
  touch-action: none;
}
.image-resize-handle::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
}
.image-resize-handle:hover,
.image-resize-handle:focus-visible { background: var(--tinta-oscura); }
.image-resize-badge {
  position: absolute;
  z-index: 41;
  transform: translateX(-50%);
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--tinta-noche);
  color: #fff;
  font: 700 12px var(--sans);
  pointer-events: none;
}
body.is-resizing-image,
body.is-resizing-image * { cursor: nwse-resize !important; user-select: none; }
/* El ancho de la imagen sigue al instante el porcentaje elegido */
.rich-editor img, .rich-editor figure img { transition: none !important; }
.image-size-slider {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 6px;
  font-size: 12px;
  font-weight: 700;
}
.image-size-slider input { width: 140px; accent-color: var(--tinta); }
.image-size-slider output { min-width: 40px; color: var(--tinta-noche); }
.rich-editor img.is-active { outline: 2px solid var(--tinta); outline-offset: 2px; }

/* Contenido de componentes: sin títulos y justificado en ambos sentidos */
.single-component-proposal .rich-editor p,
.single-component-proposal .rich-editor li,
.single-component-proposal .rich-editor blockquote {
  text-align: justify;
  text-justify: inter-word;
  hyphens: manual;
}
.single-component-proposal .rich-editor td p,
.single-component-proposal .rich-editor th p,
.single-component-proposal .rich-editor figcaption { text-align: inherit; }
.single-component-proposal .rich-editor p > strong:only-child { color: var(--tinta-noche); }

/* Anexos: historial de versiones y reemplazo del documento */
.repository-card footer details.annex-history,
.repository-card footer details.annex-replace { flex-basis: 100%; margin-left: 0; }
.repository-card footer details.annex-replace form {
  position: static;
  width: auto;
  margin-top: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.repository-card footer details.annex-replace form label { display: grid; gap: 4px; font-size: 13px; }
.repository-card footer details.annex-replace form .wide,
.repository-card footer details.annex-replace form p,
.repository-card footer details.annex-replace form button,
.repository-card footer details.annex-replace form label:first-of-type { grid-column: 1 / -1; }
.annex-history ol { margin: 8px 0 0; padding-left: 1.2em; display: grid; gap: 6px; font-size: 13px; }
.annex-history small { color: var(--muted, #5a6275); }
@media (max-width: 640px) {
  .repository-card footer details.annex-replace form { grid-template-columns: 1fr; }
}

/* Anexos dentro del contenido de los componentes */
.annex-picker { position: relative; }
.annex-picker-panel {
  position: absolute; z-index: 15; top: calc(100% + 8px); right: 0;
  width: 360px; padding: 15px; display: grid; gap: 10px;
  border: 1px solid #cacedb; border-radius: 6px; background: #fff;
}
.annex-picker-panel[hidden] { display: none; }
.annex-picker-panel > strong { color: var(--tinta); font-size: 14px; }
.annex-picker-panel label { display: grid; gap: 4px; font-size: 13px; }
.annex-picker-panel select { width: 100%; }
.annex-picker-panel .table-header-option { display: flex; align-items: center; gap: 6px; }
.annex-picker-panel .annex-picker-link { font-size: 12.5px; color: var(--tinta); }
.annex-picker-panel .annex-picker-message { font-size: 12.5px; color: #9d2b22; margin: 0; }
.rich-editor a[href^="anexo:"],
.rich-content a.annex-ref {
  background: #eef1fb; color: var(--tinta, #2a44a6); border-radius: 4px;
  padding: 0 4px; font-weight: 600; text-decoration: none; cursor: default;
}
.rich-content a.annex-ref { cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.rich-editor a[href^="anexo:"]::before,
.rich-content a.annex-ref::before { content: "📎 "; font-weight: 400; }
.recommendation-state.is-attached { background: #e2ecfb; color: #1f3d8a; }
.rich-editor a[href^="anexo:"][contenteditable="false"] { user-select: all; white-space: normal; }
