/* ==========================================================================
   HEMMI · Componentes de interfaz compartidos
   Modales, gráficos SVG, barra lateral colapsable y editor de documentos.
   Se carga junto a hemmi.css y panel.css en el sitio y en los paneles.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Modales
   Construidos sobre <dialog>: la trampa de foco, Escape y el fondo
   son comportamiento nativo del navegador, no código nuestro.
   -------------------------------------------------------------------------- */
.md {
  width: min(var(--md-w, 620px), calc(100vw - 2rem));
  max-height: calc(100dvh - 3rem);
  padding: 0;
  border: 1px solid var(--hm-line);
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--sh-xl);
  overflow: hidden;
  color: var(--hm-body);
}
.md::backdrop {
  background: rgba(6, 31, 66, .55);
  backdrop-filter: blur(3px);
}
/* El diálogo recibe el foco cuando no tiene campos; no necesita aureola porque
   ya es lo único visible de la pantalla. Los controles de dentro sí la llevan. */
.md:focus, .md:focus-visible { outline: none; }
.md[open] { animation: md-entra .3s cubic-bezier(.22, 1, .36, 1) both; }
.md[open]::backdrop { animation: md-fondo .3s ease both; }

@keyframes md-entra {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
@keyframes md-fondo { from { opacity: 0; } to { opacity: 1; } }

.md--sm { --md-w: 460px; }
.md--lg { --md-w: 840px; }
.md--xl { --md-w: 1100px; }

.md__form { display: flex; flex-direction: column; max-height: calc(100dvh - 3rem); }

.md__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex: none;
  padding: 1.15rem 1.35rem;
  border-bottom: 1px solid var(--hm-line);
}
.md__t { font-size: 1.02rem; font-weight: 700; letter-spacing: -.015em; color: var(--hm-ink); line-height: 1.3; }
.md__s { margin-top: .2rem; font-size: .84rem; color: var(--hm-muted); }
.md__x {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--hm-muted);
  cursor: pointer;
  transition: background-color .2s, color .2s;
}
.md__x:hover { background: var(--hm-canvas); color: var(--hm-ink); }

.md__body { flex: 1; padding: 1.35rem; overflow-y: auto; }
.md__body--flush { padding: 0; }

.md__pie {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: .6rem;
  flex: none;
  padding: 1rem 1.35rem;
  border-top: 1px solid var(--hm-line);
  background: var(--hm-canvas);
}
.md__pie--split { justify-content: space-between; }

/* --------------------------------------------------------------------------
   2. Barra lateral colapsable
   -------------------------------------------------------------------------- */
.pn-shell.is-compacta { grid-template-columns: 76px minmax(0, 1fr); }
@media (max-width: 1100px) {
  .pn-shell.is-compacta { grid-template-columns: minmax(0, 1fr); }
}

.pn-side__toggle {
  display: none;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-left: auto;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, .08);
  color: rgba(220, 233, 251, .8);
  cursor: pointer;
  transition: background-color .2s, color .2s, transform .35s cubic-bezier(.22, 1, .36, 1);
}
.pn-side__toggle:hover { background: rgba(255, 255, 255, .16); color: #fff; }
@media (min-width: 1101px) { .pn-side__toggle { display: grid; } }

.is-compacta .pn-side__toggle { transform: rotate(180deg); margin-left: 0; }

/* En modo compacto solo quedan los iconos */
.is-compacta .pn-side .pn-marca-texto,
.is-compacta .pn-side .pn-link__txt,
.is-compacta .pn-side .pn-yo__datos { display: none; }

.is-compacta .pn-side__marca { justify-content: center; gap: .4rem; padding-inline: .55rem; }
.is-compacta .pn-side__marca img { width: 34px; object-fit: contain; object-position: left center; }

.is-compacta .pn-side__nav { padding-inline: .65rem; }
.is-compacta .pn-link { position: relative; justify-content: center; padding-inline: 0; }
.is-compacta .pn-link.is-active::before { left: -.65rem; }
.is-compacta .pn-link__n {
  position: absolute;
  top: 2px;
  right: 8px;
  min-width: 16px;
  height: 16px;
  padding: 0 .18rem;
  font-size: .62rem;
}
.is-compacta .pn-grupo {
  height: 1px;
  margin: .95rem .55rem;
  padding: 0;
  overflow: hidden;
  text-indent: -999em;
  background: rgba(255, 255, 255, .09);
}
.is-compacta .pn-yo { justify-content: center; }

/* Etiqueta emergente cuando el texto está oculto */
.is-compacta .pn-link[data-titulo]::after {
  content: attr(data-titulo);
  position: absolute;
  left: calc(100% + 14px);
  top: 50%;
  z-index: 60;
  transform: translateY(-50%) translateX(-6px);
  padding: .35rem .7rem;
  border-radius: 8px;
  background: var(--hm-900);
  color: #fff;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.is-compacta .pn-link[data-titulo]:hover::after { opacity: 1; transform: translateY(-50%); }

/* --------------------------------------------------------------------------
   3. Gráficos
   -------------------------------------------------------------------------- */
.gr { position: relative; width: 100%; }
.gr svg { display: block; width: 100%; height: auto; overflow: visible; }

/* La dona es cuadrada: sin tope crecería tanto como su columna y estiraría la fila */
.gr[data-grafico="dona"] svg { max-width: 240px; margin-inline: auto; }
.gr[data-grafico="anillo"] svg { max-width: 150px; margin-inline: auto; }

.gr-linea  { fill: none; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
.gr-punto  { stroke: #fff; stroke-width: 2; transition: r .18s ease; cursor: pointer; }
.gr-punto:hover { r: 5.5; }
.gr-rejilla { stroke: var(--hm-line); stroke-width: 1; stroke-dasharray: 3 4; }
.gr-eje    { font-size: 10px; fill: var(--hm-muted); }
.gr-hoy    { stroke: var(--hm-red-500); stroke-width: 1.5; stroke-dasharray: 4 3; opacity: .65; }

.gr-barra { transition: opacity .18s ease; cursor: pointer; }
.gr-barra:hover { opacity: .78; }

.gr-seg { transition: opacity .18s ease; cursor: pointer; }
.gr-seg:hover { opacity: .82; }

/* Leyenda */
.gr-leyenda { display: flex; flex-wrap: wrap; gap: .4rem 1.15rem; margin-top: .9rem; }
.gr-leyenda__i { display: inline-flex; align-items: center; gap: .45rem; font-size: .78rem; color: var(--hm-body); }
.gr-leyenda__p { flex: none; width: 10px; height: 10px; border-radius: 3px; }
.gr-leyenda__n { margin-left: .2rem; font-weight: 700; color: var(--hm-ink); font-variant-numeric: tabular-nums; }

/* Globo de datos */
.gr-globo {
  position: absolute;
  z-index: 5;
  padding: .4rem .68rem;
  border-radius: 9px;
  background: var(--hm-900);
  color: #fff;
  font-size: .755rem;
  line-height: 1.45;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -130%);
  transition: opacity .15s ease;
  box-shadow: var(--sh-lg);
}
.gr-globo.is-on { opacity: 1; }

/* Comparativa horizontal */
.gr-comp { display: flex; flex-direction: column; gap: .9rem; }
.gr-comp__t { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .38rem; }
.gr-comp__n { font-size: .845rem; font-weight: 500; color: var(--hm-ink); }
.gr-comp__v { font-size: .82rem; font-weight: 700; color: var(--hm-700); font-variant-numeric: tabular-nums; }
.gr-comp__p { height: 8px; border-radius: 99px; background: var(--hm-canvas-2); overflow: hidden; }
.gr-comp__b {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--hm-500), var(--hm-teal-500));
  transform-origin: left;
  animation: gr-crece .7s cubic-bezier(.22, 1, .36, 1) both;
}
@keyframes gr-crece { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* Anillo de progreso */
.gr-anillo__pista { stroke: var(--hm-canvas-2); }
.gr-anillo__valor {
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: center;
  animation: gr-anillo 1s cubic-bezier(.22, 1, .36, 1) both;
}
@keyframes gr-anillo { from { stroke-dashoffset: var(--circ, 999); } }

@media (prefers-reduced-motion: reduce) {
  .gr-comp__b, .gr-anillo__valor, .md[open], .md[open]::backdrop { animation: none; }
}

/* --------------------------------------------------------------------------
   4. Acceso al panel
   -------------------------------------------------------------------------- */
.ac-cab { margin-bottom: 2rem; }
.ac-t {
  margin: 0;
  font-family: 'Newsreader', Georgia, serif;
  font-size: 2rem; line-height: 1.15; letter-spacing: -.01em;
  color: var(--hm-ink);
}
.ac-s { margin: .7rem 0 0; font-size: .95rem; line-height: 1.65; color: var(--hm-body); }

.ac-form { display: grid; gap: .15rem; }

/* Ver la contraseña */
.ac-clave { position: relative; }
.ac-clave .pn-input { padding-right: 3rem; }
.ac-ojo {
  position: absolute; right: .4rem; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border: 0; border-radius: 9px;
  background: transparent;
  color: var(--hm-muted);
  cursor: pointer;
  transition: background-color .18s, color .18s;
}
.ac-ojo:hover { background: var(--hm-50); color: var(--hm-600); }
.ac-ojo:focus-visible { outline: 2px solid var(--hm-400); outline-offset: 1px; }

/* Bloqueo de mayúsculas */
.ac-mayus {
  display: flex; align-items: center; gap: .4rem;
  margin: .45rem 0 0;
  font-size: .79rem; font-weight: 600; color: #92600B;
}
.ac-mayus[hidden] { display: none; }
.ac-mayus svg { flex: none; }

.ac-enviar { margin-top: 1.5rem; }
.ac-enviar.is-enviando { opacity: .72; cursor: progress; }

/* Lo que hay que saber si algo sale mal. Sin caja blanca: son dos apuntes al
   pie, no un aviso que compita con el botón. */
.ac-nota {
  display: grid; gap: .6rem;
  margin-top: 2rem; padding-top: 1.35rem;
  border-top: 1px solid var(--hm-line);
}
.ac-nota p {
  display: flex; align-items: flex-start; gap: .6rem;
  margin: 0;
  font-size: .82rem; line-height: 1.55; color: var(--hm-muted);
}
.ac-nota__i { flex: none; margin-top: .06rem; color: var(--hm-400); }
