/* ===========================================================
   Organigrama funcional — hoja de estilos
   Los colores de marca se definen en datos.js y se inyectan
   como variables CSS al iniciar la aplicación.
   =========================================================== */

:root {
  --marca: #1f4e79;
  --marca-suave: #eaf1f8;
  --marca-borde: #c5d7e8;

  --tinta: #1a1d21;
  --tinta-2: #5b6570;
  --tinta-3: #8a929b;
  --papel: #ffffff;
  --fondo: #f4f6f8;
  --linea: #d6dbe0;
  --linea-fuerte: #2f3337;

  --vacante: #b4540a;
  --vacante-fondo: #fdf4ec;

  --radio: 4px;
  --sombra: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --sombra-alta: 0 8px 24px rgba(16, 24, 40, .12);

  --barra-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", Roboto, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--tinta);
  background: var(--fondo);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--marca); }

/* ---------- Barra superior ---------- */
.barra {
  height: var(--barra-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: var(--papel);
  border-bottom: 1px solid var(--linea);
  position: relative;
  z-index: 30;
}
.barra__logo { height: 32px; width: auto; max-width: 160px; object-fit: contain; }
.barra__titulos { min-width: 0; margin-right: auto; }
.barra__titulo {
  font-size: 15px; font-weight: 650; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.barra__subtitulo { font-size: 12.5px; color: var(--tinta-2); line-height: 1.3; }

.grupo { display: flex; align-items: center; gap: 6px; }
.separador { width: 1px; height: 26px; background: var(--linea); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px;
  background: var(--papel); color: var(--tinta);
  border: 1px solid var(--linea); border-radius: var(--radio);
  cursor: pointer; white-space: nowrap;
  font-size: 13.5px;
}
.btn:hover { background: #f0f2f5; border-color: #c2c9d0; }
.btn:active { background: #e6e9ed; }
.btn--principal { background: var(--marca); border-color: var(--marca); color: #fff; }
.btn--principal:hover { filter: brightness(1.08); background: var(--marca); }
.btn--icono { width: 34px; padding: 0; justify-content: center; font-size: 16px; }
.btn[aria-pressed="true"] {
  background: var(--marca-suave); border-color: var(--marca-borde); color: var(--marca);
}
.btn:disabled { opacity: .45; cursor: default; }

.busqueda { position: relative; }
.busqueda input {
  height: 34px; width: 220px; padding: 0 30px 0 10px;
  border: 1px solid var(--linea); border-radius: var(--radio); background: var(--papel);
}
.busqueda input:focus { outline: 2px solid var(--marca-borde); outline-offset: -1px; }
.busqueda__limpiar {
  position: absolute; right: 4px; top: 4px; width: 26px; height: 26px;
  border: 0; background: none; cursor: pointer; color: var(--tinta-3); border-radius: 3px;
}
.busqueda__limpiar:hover { background: #eef0f3; color: var(--tinta); }

.resultados {
  position: absolute; top: 38px; left: 0; width: 340px; max-height: 320px;
  overflow: auto; background: var(--papel); border: 1px solid var(--linea);
  border-radius: var(--radio); box-shadow: var(--sombra-alta); padding: 4px;
}
.resultados:empty { display: none; }
.resultados button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 7px 9px; border-radius: 3px; cursor: pointer; line-height: 1.35;
}
.resultados button:hover, .resultados button:focus { background: var(--marca-suave); }
.resultados small { display: block; color: var(--tinta-2); font-size: 12px; }

/* ---------- Lienzo del organigrama ---------- */
.lienzo {
  position: absolute; inset: var(--barra-h) 0 0 0;
  overflow: auto; cursor: grab;
}
.lienzo.arrastrando { cursor: grabbing; }
.lienzo.con-panel { right: 380px; }

.mundo { position: relative; }
.plano { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.trazos { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.trazos path, .trazos line { stroke: var(--linea-fuerte); stroke-width: 1.4; fill: none; }

/* ---------- Cajas ---------- */
.caja {
  position: absolute;
  background: var(--papel);
  border: 1.6px solid var(--linea-fuerte);
  border-radius: var(--radio);
  padding: 7px 9px;
  display: flex; flex-direction: column; justify-content: center;
  cursor: pointer; text-align: center;
  transition: box-shadow .12s, transform .12s;
}
.caja:hover { box-shadow: var(--sombra-alta); }
.caja--seleccionada {
  outline: 3px solid var(--marca); outline-offset: 2px;
}
.caja--resaltada { animation: destello 1.4s ease-out; }
@keyframes destello {
  0%, 40% { box-shadow: 0 0 0 5px rgba(255, 196, 0, .55); }
  100%    { box-shadow: 0 0 0 5px rgba(255, 196, 0, 0); }
}

.caja__puesto {
  font-size: 12.5px; font-weight: 600; line-height: 1.24;
  overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 3; hyphens: auto; overflow-wrap: anywhere;
}
.caja__ocupante {
  font-size: 11.5px; color: var(--tinta-2); line-height: 1.25; margin-top: 3px;
  overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.caja__mas { color: var(--tinta-3); }

/* Equipo de la misma oficina: caja menor, tono claro */
.caja--equipo {
  border-width: 1.2px; border-color: #7d868f; background: #fbfcfd;
}
.caja--equipo .caja__puesto { font-size: 11.8px; font-weight: 550; }

/* Vacante */
.caja--vacante { border-style: dashed; background: var(--vacante-fondo); }
.caja__vacante {
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em;
  color: var(--vacante); text-transform: uppercase; margin-top: 3px;
}

/* Contador de dependencias / botón de despliegue */
.caja__toggle {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: -11px;
  height: 21px; min-width: 21px; padding: 0 7px;
  display: inline-flex; align-items: center; justify-content: center; gap: 3px;
  background: var(--papel); color: var(--tinta-2);
  border: 1.4px solid var(--linea-fuerte); border-radius: 11px;
  font-size: 11px; font-weight: 650; line-height: 1;
  cursor: pointer; z-index: 2;
}
.caja__toggle:hover { background: var(--marca); border-color: var(--marca); color: #fff; }
.caja__toggle span { font-size: 9px; }

/* Recuadro que agrupa al equipo de una misma oficina */
.grupo-equipo {
  position: absolute;
  border: 1px dashed var(--marca-borde);
  background: rgba(31, 78, 121, .035);
  border-radius: 6px;
  pointer-events: none;
}
.grupo-equipo__rotulo {
  position: absolute; top: -9px; left: 12px;
  background: var(--fondo); padding: 0 7px;
  font-size: 10.5px; font-weight: 650; letter-spacing: .03em;
  color: var(--marca); text-transform: uppercase; white-space: nowrap;
}

/* ---------- Panel lateral ---------- */
.panel {
  position: absolute; top: var(--barra-h); right: 0; bottom: 0; width: 380px;
  background: var(--papel); border-left: 1px solid var(--linea);
  display: flex; flex-direction: column; z-index: 20;
}
.panel[hidden] { display: none; }
.panel__cabecera {
  padding: 14px 16px; border-bottom: 1px solid var(--linea);
  display: flex; align-items: flex-start; gap: 10px;
}
.panel__area {
  font-size: 11px; font-weight: 700; letter-spacing: .05em;
  color: var(--marca); text-transform: uppercase; margin-bottom: 3px;
}
.panel__puesto { font-size: 17px; font-weight: 650; line-height: 1.25; }
.panel__cerrar {
  margin-left: auto; border: 0; background: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--tinta-3); padding: 2px 4px; border-radius: 3px;
}
.panel__cerrar:hover { background: #eef0f3; color: var(--tinta); }
.panel__cuerpo { flex: 1; overflow: auto; padding: 14px 16px 24px; }
.panel__pie {
  padding: 10px 16px; border-top: 1px solid var(--linea);
  display: flex; gap: 6px; flex-wrap: wrap;
}

.seccion { margin-bottom: 20px; }
.seccion__titulo {
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  color: var(--tinta-3); text-transform: uppercase; margin-bottom: 8px;
}

.persona {
  border: 1px solid var(--linea); border-radius: var(--radio);
  padding: 10px 12px; margin-bottom: 8px;
}
.persona__nombre { font-weight: 600; margin-bottom: 4px; }
.persona__nombre--sin { color: var(--tinta-3); font-style: italic; font-weight: 500; }
.persona__dato {
  display: flex; gap: 8px; font-size: 13.5px; color: var(--tinta-2);
  padding: 2px 0; align-items: baseline;
}
.persona__dato b { font-weight: 500; color: var(--tinta-3); min-width: 62px; }

.aviso-vacante {
  border: 1px dashed var(--vacante); background: var(--vacante-fondo);
  color: var(--vacante); border-radius: var(--radio);
  padding: 10px 12px; font-size: 13.5px; font-weight: 600;
}

.ficha h4 { margin: 14px 0 5px; font-size: 13.5px; }
.ficha p, .ficha li { font-size: 13.5px; line-height: 1.5; color: var(--tinta-2); margin: 4px 0; }
.ficha ul { padding-left: 18px; margin: 4px 0; }
.ficha__vacia { color: var(--tinta-3); font-size: 13.5px; }

.lista-hijos button {
  display: block; width: 100%; text-align: left;
  border: 1px solid var(--linea); border-radius: var(--radio); background: var(--papel);
  padding: 8px 10px; margin-bottom: 6px; cursor: pointer; line-height: 1.3;
}
.lista-hijos button:hover { background: var(--marca-suave); border-color: var(--marca-borde); }
.lista-hijos small { display: block; color: var(--tinta-2); font-size: 12px; }

.etiqueta {
  display: inline-block; padding: 2px 7px; border-radius: 10px;
  font-size: 11px; font-weight: 600; background: #eef0f3; color: var(--tinta-2);
}
.etiqueta--interna { background: #fff5d6; color: #7a5a00; }

/* ---------- Diálogos ---------- */
dialog {
  border: 0; border-radius: 8px; padding: 0; max-width: 92vw;
  box-shadow: 0 20px 60px rgba(16, 24, 40, .28); color: var(--tinta);
}
dialog::backdrop { background: rgba(16, 24, 40, .45); }
.dlg { width: 620px; max-width: 92vw; display: flex; flex-direction: column; max-height: 86vh; }
.dlg--ancho { width: 860px; }
.dlg__cabecera {
  padding: 16px 20px; border-bottom: 1px solid var(--linea);
  display: flex; align-items: center; gap: 10px;
}
.dlg__cabecera h2 { margin: 0; font-size: 17px; font-weight: 650; }
.dlg__cuerpo { padding: 18px 20px; overflow: auto; }
.dlg__pie {
  padding: 12px 20px; border-top: 1px solid var(--linea);
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
}

.campo { margin-bottom: 14px; }
.campo > label {
  display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; color: var(--tinta-2);
}
.campo input[type=text], .campo input[type=email], .campo input[type=url],
.campo select, .campo textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--linea);
  border-radius: var(--radio); background: var(--papel);
}
.campo textarea { min-height: 86px; resize: vertical; line-height: 1.45; }
.campo input:focus, .campo select:focus, .campo textarea:focus {
  outline: 2px solid var(--marca-borde); outline-offset: -1px;
}
.campo__ayuda { font-size: 12px; color: var(--tinta-3); margin-top: 4px; line-height: 1.4; }
.fila { display: flex; gap: 12px; }
.fila > * { flex: 1; min-width: 0; }

.opcion { display: flex; align-items: flex-start; gap: 8px; padding: 5px 0; font-size: 14px; }
.opcion input { margin-top: 3px; }

.tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabla th, .tabla td {
  border-bottom: 1px solid var(--linea); padding: 6px 8px; text-align: left; vertical-align: top;
}
.tabla th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--tinta-3); }

.avisos { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.5; color: var(--tinta-2); }
.avisos li { margin-bottom: 5px; }

.cartel {
  border-radius: var(--radio); padding: 11px 13px; font-size: 13.5px; line-height: 1.5;
  margin-bottom: 14px;
}
.cartel--info  { background: var(--marca-suave); border: 1px solid var(--marca-borde); }
.cartel--ojo   { background: #fff8e6; border: 1px solid #f0dda8; }
.cartel--error { background: #fdecec; border: 1px solid #f3c3c3; color: #8a2020; }

.aviso-flotante {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--tinta); color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 13.5px; box-shadow: var(--sombra-alta); z-index: 100;
}
.aviso-flotante[hidden] { display: none; }

.modo-edicion-cinta {
  position: absolute; left: 0; right: 0; top: var(--barra-h);
  background: #fff8e6; border-bottom: 1px solid #f0dda8;
  padding: 6px 16px; font-size: 13px; z-index: 25;
  display: flex; align-items: center; gap: 10px;
}
.modo-edicion-cinta[hidden] { display: none; }
body.editando .lienzo, body.editando .panel { top: calc(var(--barra-h) + 33px); }

.pie-credito {
  position: absolute; right: 12px; bottom: 8px;
  font-size: 11.5px; color: var(--tinta-3); z-index: 10;
}
.pie-credito[hidden] { display: none; }

/* ---------- Impresión / PDF ---------- */
@page { size: A3 landscape; margin: 10mm; }

@media print {
  html, body { background: #fff; height: auto; }
  .barra, .panel, .modo-edicion-cinta, .aviso-flotante, .caja__toggle,
  .busqueda, .resultados, dialog { display: none !important; }
  .lienzo {
    position: static; overflow: visible; inset: auto;
    width: auto; height: auto;
  }
  .encabezado-impresion { display: block !important; }
  .caja { box-shadow: none !important; outline: none !important; }
  .caja--seleccionada { outline: 2px solid #000 !important; outline-offset: 1px; }
  .pie-credito { position: fixed; bottom: 2mm; right: 2mm; }
}

.encabezado-impresion { display: none; margin-bottom: 8mm; }
.encabezado-impresion h1 { margin: 0 0 2px; font-size: 18px; }
.encabezado-impresion p { margin: 0; font-size: 12px; color: var(--tinta-2); }
.encabezado-impresion img { height: 34px; float: right; }

/* ---------- Pantallas chicas ---------- */
@media (max-width: 860px) {
  .lienzo.con-panel { right: 0; }
  .panel { width: 100%; left: 0; }
  .barra { gap: 8px; overflow-x: auto; }
  .busqueda input { width: 150px; }
  .barra__subtitulo { display: none; }
}
